github.com/HashDataInc/packer@v1.3.2/.github/CONTRIBUTING.md (about) 1 # Contributing to Packer 2 3 **First:** if you're unsure or afraid of _anything_, just ask or submit the 4 issue or pull request anyway. You won't be yelled at for giving your best 5 effort. The worst that can happen is that you'll be politely asked to change 6 something. We appreciate any sort of contributions, and don't want a wall of 7 rules to get in the way of that. 8 9 However, for those individuals who want a bit more guidance on the best way to 10 contribute to the project, read on. This document will cover what we're looking 11 for. By addressing all the points we're looking for, it raises the chances we 12 can quickly merge or address your contributions. 13 14 ## Issues 15 16 ### Reporting an Issue 17 18 * Make sure you test against the latest released version. It is possible we 19 already fixed the bug you're experiencing. 20 21 * Run the command with debug output with the environment variable `PACKER_LOG`. 22 For example: `PACKER_LOG=1 packer build template.json`. Take the _entire_ 23 output and create a [gist](https://gist.github.com) for linking to in your 24 issue. Packer should strip sensitive keys from the output, but take a look 25 through just in case. 26 27 * Provide a reproducible test case. If a contributor can't reproduce an issue, 28 then it dramatically lowers the chances it'll get fixed. And in some cases, 29 the issue will eventually be closed. 30 31 * Respond promptly to any questions made by the Packer team to your issue. Stale 32 issues will be closed. 33 34 ### Issue Lifecycle 35 36 1. The issue is reported. 37 38 2. The issue is verified and categorized by a Packer collaborator. 39 Categorization is done via tags. For example, bugs are marked as "bugs" and 40 easy fixes are marked as "easy". 41 42 3. Unless it is critical, the issue is left for a period of time (sometimes many 43 weeks), giving outside contributors a chance to address the issue. 44 45 4. The issue is addressed in a pull request or commit. The issue will be 46 referenced in the commit message so that the code that fixes it is clearly 47 linked. 48 49 5. The issue is closed. 50 51 ## Setting up Go 52 53 If you have never worked with Go before, you will have to install its 54 runtime in order to build packer. 55 56 1. [Install go](https://golang.org/doc/install#install) 57 58 ## Setting up Packer for dev 59 60 If/when you have go installed you can already `go get` packer and `make` in 61 order to compile and test Packer. These instructions target 62 POSIX-like environments (macOS, Linux, Cygwin, etc.) so you may need to 63 adjust them for Windows or other shells. 64 The instructions below are for go 1.7. or later. 65 66 67 1. Download the Packer source (and its dependencies) by running 68 `go get github.com/hashicorp/packer`. This will download the Packer source to 69 `$GOPATH/src/github.com/hashicorp/packer`. 70 71 2. When working on Packer, first `cd $GOPATH/src/github.com/hashicorp/packer` 72 so you can run `make` and easily access other files. Run `make help` to get 73 information about make targets. 74 75 3. Make your changes to the Packer source. You can run `make` in 76 `$GOPATH/src/github.com/hashicorp/packer` to run tests and build the Packer 77 binary. Any compilation errors will be shown when the binaries are 78 rebuilding. If you don't have `make` you can simply run 79 `go build -o bin/packer .` from the project root. 80 81 4. After running building Packer successfully, use 82 `$GOPATH/src/github.com/hashicorp/packer/bin/packer` to build a machine and 83 verify your changes work. For instance: 84 `$GOPATH/src/github.com/hashicorp/packer/bin/packer build template.json`. 85 86 5. If everything works well and the tests pass, run `go fmt` on your code before 87 submitting a pull-request. 88 89 ### Opening an Pull Request 90 91 Thank you for contributing! When you are ready to open a pull-request, you will 92 need to [fork 93 Packer](https://github.com/hashicorp/packer#fork-destination-box), push your 94 changes to your fork, and then open a pull-request. 95 96 For example, my github username is `cbednarski`, so I would do the following: 97 98 ``` 99 git checkout -b f-my-feature 100 # Develop a patch. 101 git push https://github.com/cbednarski/Packer f-my-feature 102 ``` 103 104 From there, open your fork in your browser to open a new pull-request. 105 106 **Note:** Go infers package names from their file paths. This means `go build` 107 will break if you `git clone` your fork instead of using `go get` on the main 108 Packer project. 109 110 **Note:** See [Working on forks](#Working on forks) for a better way to use `git push ...`. 111 112 ### Pull Request Lifecycle 113 114 1. You are welcome to submit your pull request for commentary or review before 115 it is fully completed. Please prefix the title of your pull request with 116 "[WIP]" to indicate this. It's also a good idea to include specific questions 117 or items you'd like feedback on. 118 119 1. Once you believe your pull request is ready to be merged, you can remove any 120 "[WIP]" prefix from the title and a core team member will review. 121 122 1. One of Packer's core team members will look over your contribution and 123 either provide comments letting you know if there is anything left to do. We 124 do our best to provide feedback in a timely manner, but it may take some time 125 for us to respond. 126 127 1. Once all outstanding comments and checklist items have been addressed, your 128 contribution will be merged! Merged PRs will be included in the next 129 Packer release. The core team takes care of updating the 130 [CHANGELOG.md](../CHANGELOG.md) as they merge. 131 132 1. In rare cases, we might decide that a PR should be closed without merging. 133 We'll make sure to provide clear reasoning when this happens. 134 135 ### Tips for Working on Packer 136 137 #### Working on forks 138 139 The easiest way to work on a fork is to set it as a remote of the Packer 140 project. After following the steps in "Setting up Go to work on Packer": 141 142 1. Navigate to the code: 143 144 `cd $GOPATH/src/github.com/hashicorp/packer` 145 146 2. Add the remote by running: 147 148 `git remote add <name of remote> <github url of fork>` 149 150 For example: 151 152 `git remote add mwhooker https://github.com/mwhooker/packer.git` 153 154 3. Checkout a feature branch: 155 156 `git checkout -b new-feature` 157 158 4. Make changes. 159 5. (Optional) Push your changes to the fork: 160 161 `git push -u <name of remote> new-feature` 162 163 This way you can push to your fork to create a PR, but the code on disk still 164 lives in the spot where the go cli tools are expecting to find it. 165 166 #### Govendor 167 168 If you are submitting a change that requires new or updated dependencies, please 169 include them in `vendor/vendor.json` and in the `vendor/` folder. This helps 170 everything get tested properly in CI. 171 172 Note that you will need to use [govendor](https://github.com/kardianos/govendor) 173 to do this. This step is recommended but not required; if you don't use govendor 174 please indicate in your PR which dependencies have changed and to what versions. 175 176 Use `govendor fetch <project>` to add dependencies to the project. See 177 [govendor quick start](https://github.com/kardianos/govendor#quick-start-also-see-the-faq) 178 for examples. 179 180 Please only apply the minimal vendor changes to get your PR to work. Packer does 181 not attempt to track the latest version for each dependency. 182 183 #### Running Unit Tests 184 185 You can run tests for individual packages using commands like this: 186 187 ``` 188 make test TEST=./builder/amazon/... 189 ``` 190 191 #### Running Acceptance Tests 192 193 Packer has [acceptance tests](https://en.wikipedia.org/wiki/Acceptance_testing) 194 for various builders. These typically require an API key (AWS, GCE), or 195 additional software to be installed on your computer (VirtualBox, VMware). 196 197 If you're working on a new builder or builder feature and want to verify it is 198 functioning (and also hasn't broken anything else), we recommend running the 199 acceptance tests. 200 201 **Warning:** The acceptance tests create/destroy/modify _real resources_, which 202 may incur costs for real money. In the presence of a bug, it is possible that 203 resources may be left behind, which can cost money even though you were not 204 using them. We recommend running tests in an account used only for that purpose 205 so it is easy to see if there are any dangling resources, and so production 206 resources are not accidentally destroyed or overwritten during testing. 207 208 To run the acceptance tests, invoke `make testacc`: 209 210 ``` 211 make testacc TEST=./builder/amazon/ebs 212 ... 213 ``` 214 215 The `TEST` variable lets you narrow the scope of the acceptance tests to a 216 specific package / folder. The `TESTARGS` variable is recommended to filter down 217 to a specific resource to test, since testing all of them at once can sometimes 218 take a very long time. 219 220 To run only a specific test, use the `-run` argument: 221 222 ``` 223 make testacc TEST=./builder/amazon/ebs TESTARGS="-run TestBuilderAcc_forceDeleteSnapshot" 224 ``` 225 226 Acceptance tests typically require other environment variables to be set for 227 things such as API tokens and keys. Each test should error and tell you which 228 credentials are missing, so those are not documented here.