From 73c5192b352b053a97159f9c10b15703d0df00df Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 1 Dec 2014 19:49:55 -0800 Subject: [PATCH] command/push: add base_dir setting --- command/push.go | 25 +++++++++++++++++++++---- packer/template.go | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/command/push.go b/command/push.go index 603ef85dc..f7c4f5ebe 100644 --- a/command/push.go +++ b/command/push.go @@ -86,15 +86,32 @@ func (c *PushCommand) Run(args []string) int { archiveTemplateEntry: args[0], } - // Determine the path we're archiving + // Determine the path we're archiving. This logic is a bit complicated + // as there are three possibilities: + // + // 1.) BaseDir is an absolute path, just use that. + // + // 2.) BaseDir is empty, so we use the directory of the template. + // + // 3.) BaseDir is relative, so we use the path relative to the directory + // of the template. + // path := tpl.Push.BaseDir - if path == "" { - path, err = filepath.Abs(args[0]) + if path == "" || !filepath.IsAbs(path) { + tplPath, err := filepath.Abs(args[0]) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err)) + return 1 + } + tplPath = filepath.Dir(tplPath) + if path != "" { + tplPath = filepath.Join(tplPath, path) + } + path, err = filepath.Abs(tplPath) if err != nil { c.Ui.Error(fmt.Sprintf("Error determining path to archive: %s", err)) return 1 } - path = filepath.Dir(path) } // Build the upload options diff --git a/packer/template.go b/packer/template.go index a65dbcc90..5cbef4fac 100644 --- a/packer/template.go +++ b/packer/template.go @@ -46,7 +46,7 @@ type Template struct { type PushConfig struct { Name string Address string - BaseDir string + BaseDir string `mapstructure:"base_dir"` Include []string Exclude []string Token string