builder/docker: create export dir if needed

This commit is contained in:
Matthew Hooker 2017-01-21 23:50:24 -08:00
parent 198824a25f
commit 9e2d69fb97
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
1 changed files with 8 additions and 0 deletions

View File

@ -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 {