Skip to content

Commit

Permalink
create metadata file
Browse files Browse the repository at this point in the history
  • Loading branch information
oker1 committed Sep 25, 2015
1 parent e684d01 commit 196a8db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
35 changes: 35 additions & 0 deletions builder/lxc/step_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 196a8db

Please sign in to comment.