diff --git a/main.go b/main.go index 4e99b96..1c5ba95 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,12 @@ func main() { Usage: "Will execute multiple builds in parallel as defined in the 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{ Name: "syntax_only", 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"), Vars: vars, Template: c.String("template"), + Context: c.String("context"), VarFiles: c.StringSlice("var_files"), Except: c.StringSlice("except"), Only: c.StringSlice("only"), diff --git a/plugin.go b/plugin.go index 793038f..5d3320d 100644 --- a/plugin.go +++ b/plugin.go @@ -14,6 +14,7 @@ type ( Actions []string Vars map[string]string Template string + Context string VarFiles []string SyntaxOnly bool Except []string @@ -57,10 +58,15 @@ func pkValidate(config Config) *exec.Cmd { } args = append(args, config.Template) - return exec.Command( + + cmd := exec.Command( "packer", args..., ) + + cmd.Dir = config.Context + + return cmd } func pkBuild(config Config) *exec.Cmd { @@ -105,10 +111,15 @@ func pkBuild(config Config) *exec.Cmd { } args = append(args, config.Template) - return exec.Command( + + cmd := exec.Command( "packer", args..., ) + + cmd.Dir = config.Context + + return cmd } // Exec executes the plugin.