Commit e0c62850 authored by Andrey Levkin's avatar Andrey Levkin

Change creating boxes for customizing metadata.json

parent dc555d6b
......@@ -101,6 +101,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
}
defer os.RemoveAll(dir)
// Copy all of the includes files into the temporary directory
for _, src := range config.Include {
ui.Message(fmt.Sprintf("Copying from include: %s", src))
dst := filepath.Join(dir, filepath.Base(src))
if err := CopyContents(dst, src); err != nil {
err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err)
return nil, false, err
}
}
// Run the provider processing step
vagrantfile, metadata, err := provider.Process(ui, artifact, dir)
if err != nil {
......@@ -112,16 +122,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return nil, false, err
}
// Copy all of the includes files into the temporary directory
for _, src := range config.Include {
ui.Message(fmt.Sprintf("Copying from include: %s", src))
dst := filepath.Join(dir, filepath.Base(src))
if err := CopyContents(dst, src); err != nil {
err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err)
return nil, false, err
}
}
// Write our Vagrantfile
var customVagrantfile string
if config.VagrantfileTemplate != "" {
......
......@@ -130,12 +130,15 @@ func DirToBox(dst, dir string, ui packer.Ui, level int) error {
// WriteMetadata writes the "metadata.json" file for a Vagrant box.
func WriteMetadata(dir string, contents interface{}) error {
f, err := os.Create(filepath.Join(dir, "metadata.json"))
if err != nil {
return err
}
defer f.Close()
if _, err := os.Stat(filepath.Join(dir, "metadata.json")); os.IsNotExist(err) {
f, err := os.Create(filepath.Join(dir, "metadata.json"))
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
return enc.Encode(contents)
enc := json.NewEncoder(f)
return enc.Encode(contents)
}
return nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment