(buildCtx context.Context, cla *InitArgs)
| 57 | } |
| 58 | |
| 59 | func (c *InitCommand) RunContext(buildCtx context.Context, cla *InitArgs) int { |
| 60 | packerStarter, ret := c.GetConfig(&cla.MetaArgs) |
| 61 | if ret != 0 { |
| 62 | return ret |
| 63 | } |
| 64 | |
| 65 | // Get plugins requirements |
| 66 | reqs, diags := packerStarter.PluginRequirements() |
| 67 | ret = writeDiags(c.Ui, nil, diags) |
| 68 | if ret != 0 { |
| 69 | return ret |
| 70 | } |
| 71 | |
| 72 | if len(reqs) == 0 { |
| 73 | c.Ui.Message(` |
| 74 | No plugins requirement found, make sure you reference a Packer config |
| 75 | containing a packer.required_plugins block. See |
| 76 | https://www.packer.io/docs/templates/hcl_templates/blocks/packer |
| 77 | for more info.`) |
| 78 | } |
| 79 | |
| 80 | opts := plugingetter.ListInstallationsOptions{ |
| 81 | PluginDirectory: c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory, |
| 82 | BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{ |
| 83 | OS: runtime.GOOS, |
| 84 | ARCH: runtime.GOARCH, |
| 85 | APIVersionMajor: pluginsdk.APIVersionMajor, |
| 86 | APIVersionMinor: pluginsdk.APIVersionMinor, |
| 87 | Checksummers: []plugingetter.Checksummer{ |
| 88 | {Type: "sha256", Hash: sha256.New()}, |
| 89 | }, |
| 90 | ReleasesOnly: true, |
| 91 | }, |
| 92 | } |
| 93 | |
| 94 | if runtime.GOOS == "windows" && opts.Ext == "" { |
| 95 | opts.BinaryInstallationOptions.Ext = ".exe" |
| 96 | } |
| 97 | |
| 98 | log.Printf("[TRACE] init: %#v", opts) |
| 99 | |
| 100 | // the ordering of the getters is important here, place the getter on top which you want to try first |
| 101 | getters := []plugingetter.Getter{ |
| 102 | &release.Getter{ |
| 103 | Name: "releases.hashicorp.com", |
| 104 | }, |
| 105 | &github.Getter{ |
| 106 | // In the past some terraform plugins downloads were blocked from a |
| 107 | // specific aws region by s3. Changing the user agent unblocked the |
| 108 | // downloads so having one user agent per version will help mitigate |
| 109 | // that a little more. Especially in the case someone forks this |
| 110 | // code to make it more aggressive or something. |
| 111 | // TODO: allow to set this from the config file or an environment |
| 112 | // variable. |
| 113 | UserAgent: "packer-getter-github-" + version.String(), |
| 114 | Name: "github.com", |
| 115 | }, |
| 116 | } |
no test coverage detected