command/push: Push CLI vars to Atlas

This commit is contained in:
Justin Campbell 2016-01-12 11:05:44 -05:00 committed by Matthew Hooker
parent d81c06765d
commit 56cd8171cc
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 24 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/atlas-go/archive"
"github.com/hashicorp/atlas-go/v1"
"github.com/mitchellh/packer/helper/flag-kv"
"github.com/mitchellh/packer/template"
)
@ -188,6 +189,17 @@ func (c *PushCommand) Run(args []string) int {
uploadOpts.Builds[b.Name] = info
}
// Collect the variables from CLI args and any var files
uploadOpts.Vars = make(map[string]string)
if vs := f.Lookup("var"); vs != nil {
flags := vs.Value.(*kvflag.Flag)
vars := map[string]string(*flags)
for k, v := range vars {
uploadOpts.Vars[k] = v
}
}
// Add the upload metadata
metadata := make(map[string]interface{})
if message != "" {
@ -331,7 +343,7 @@ func (c *PushCommand) upload(
// Start the upload
doneCh, errCh := make(chan struct{}), make(chan error)
go func() {
err := c.client.UploadBuildConfigVersion(&version, opts.Metadata, r, r.Size)
err := c.client.UploadBuildConfigVersion(&version, opts.Metadata, opts.Vars, r, r.Size)
if err != nil {
errCh <- err
return
@ -348,6 +360,7 @@ type uploadOpts struct {
Slug string
Builds map[string]*uploadBuildInfo
Metadata map[string]interface{}
Vars map[string]string
}
type uploadBuildInfo struct {

View File

@ -205,16 +205,24 @@ func TestPush_vars(t *testing.T) {
args := []string{
"-var", "name=foo/bar",
"-var", "one=two",
filepath.Join(testFixture("push-vars"), "template.json"),
}
if code := c.Run(args); code != 0 {
fatalCommand(t, c.Meta)
}
expected := "foo/bar"
if actualOpts.Slug != expected {
if actualOpts.Slug != "foo/bar" {
t.Fatalf("bad: %#v", actualOpts.Slug)
}
expected := map[string]string{
"name": "foo/bar",
"one": "two",
}
if !reflect.DeepEqual(actualOpts.Vars, expected) {
t.Fatalf("bad: %#v", actualOpts.Vars)
}
}
func testArchive(t *testing.T, r io.Reader) []string {