Browse Source

Add context dir (#4)

* Add `context` as parameter to use when the packer files are all
located in a relative path and not root itself
update-packer-186
Ravi Kumar 5 years ago
committed by Bo-Yi Wu
parent
commit
21c1afc448
  1. 7
      main.go
  2. 15
      plugin.go

7
main.go

@ -50,6 +50,12 @@ func main() {
Usage: "Will execute multiple builds in parallel as defined in the template", Usage: "Will execute multiple builds in parallel as defined in the template",
EnvVar: "PLUGIN_TEMPLATE", EnvVar: "PLUGIN_TEMPLATE",
}, },
cli.StringFlag{
Name: "context",
Usage: "The context directory path to use for executing `packer` command, defaults to root of the git repo",
Value: ".",
EnvVar: "PLUGIN_CONTEXT",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "syntax_only", Name: "syntax_only",
Usage: "Only check syntax. Do not verify config of the template", Usage: "Only check syntax. Do not verify config of the template",
@ -114,6 +120,7 @@ func run(c *cli.Context) error {
Actions: c.StringSlice("actions"), Actions: c.StringSlice("actions"),
Vars: vars, Vars: vars,
Template: c.String("template"), Template: c.String("template"),
Context: c.String("context"),
VarFiles: c.StringSlice("var_files"), VarFiles: c.StringSlice("var_files"),
Except: c.StringSlice("except"), Except: c.StringSlice("except"),
Only: c.StringSlice("only"), Only: c.StringSlice("only"),

15
plugin.go

@ -14,6 +14,7 @@ type (
Actions []string Actions []string
Vars map[string]string Vars map[string]string
Template string Template string
Context string
VarFiles []string VarFiles []string
SyntaxOnly bool SyntaxOnly bool
Except []string Except []string
@ -57,10 +58,15 @@ func pkValidate(config Config) *exec.Cmd {
} }
args = append(args, config.Template) args = append(args, config.Template)
return exec.Command(
cmd := exec.Command(
"packer", "packer",
args..., args...,
) )
cmd.Dir = config.Context
return cmd
} }
func pkBuild(config Config) *exec.Cmd { func pkBuild(config Config) *exec.Cmd {
@ -105,10 +111,15 @@ func pkBuild(config Config) *exec.Cmd {
} }
args = append(args, config.Template) args = append(args, config.Template)
return exec.Command(
cmd := exec.Command(
"packer", "packer",
args..., args...,
) )
cmd.Dir = config.Context
return cmd
} }
// Exec executes the plugin. // Exec executes the plugin.

Loading…
Cancel
Save