From 9e2d69fb974fea2307798785809902832463edd3 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Sat, 21 Jan 2017 23:50:24 -0800 Subject: [PATCH] builder/docker: create export dir if needed --- builder/docker/step_export.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builder/docker/step_export.go b/builder/docker/step_export.go index 6fbdcb63d..b09ea0bd4 100644 --- a/builder/docker/step_export.go +++ b/builder/docker/step_export.go @@ -3,6 +3,7 @@ package docker import ( "fmt" "os" + "path/filepath" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" @@ -26,6 +27,13 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + // Make the directory we're exporting to if it doesn't exist + exportDir := filepath.Dir(config.ExportPath) + if err := os.MkdirAll(exportDir, 0755); err != nil { + state.Put("error", err) + return multistep.ActionHalt + } + // Open the file that we're going to write to f, err := os.Create(config.ExportPath) if err != nil {