diff --git a/README.md b/README.md index d2732cc..eaaea09 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,19 @@ Building wheezy on wheezy: "scripts/lxc/vagrant-lxc-fixes.sh" ] } - ] + ], + "post-processors": [ + { + "type": "compress", + "output": "output-vagrant/wheezy64-lxc.box" + } + ], } ``` Note the differences in template parameters/envvars! -Vagrant publisher -================= +Vagrant publishing +================== -The basebox format will be finalized in [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc) 1.0.0, -then we'll try to get a patch into packer to support this builder in the vagrant publisher. +The output artifact can be compressed with the compress publisher to create a working vagrant box (see example). \ No newline at end of file diff --git a/builder/lxc/step_export.go b/builder/lxc/step_export.go index 3af9ed7..e5c649a 100644 --- a/builder/lxc/step_export.go +++ b/builder/lxc/step_export.go @@ -11,10 +11,16 @@ import ( "path/filepath" "os" "io" + "encoding/json" ) type stepExport struct{} +type Metadata struct { + Provider string `json:"provider"` + Version string `json:"version"` +} + func (s *stepExport) Run(state multistep.StateBag) multistep.StepAction { config := state.Get("config").(*Config) ui := state.Get("ui").(packer.Ui) @@ -24,6 +30,35 @@ func (s *stepExport) Run(state multistep.StateBag) multistep.StepAction { containerDir := fmt.Sprintf("/var/lib/lxc/%s", name) outputPath := filepath.Join(config.OutputDir, "rootfs.tar.gz") configFilePath := filepath.Join(config.OutputDir, "lxc-config") + metadataFilePath := filepath.Join(config.OutputDir, "metadata.json") + + metadata := Metadata{"lxc", "1.0.0"} + metadataFile, err := os.Create(metadataFilePath) + + if err != nil { + err := fmt.Errorf("Error creating metadata file: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + metadataJson, err := json.Marshal(metadata) + if err != nil { + err := fmt.Errorf("Error marshaling metadata : %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + _, err = metadataFile.Write(metadataJson) + metadataFile.Sync() + + if err != nil { + err := fmt.Errorf("Error writing metadata file : %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } configFile, err := os.Create(configFilePath)