Commit f8c87777 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge branch 'f-packer-push-name'

parents da694a6e 344c7416
...@@ -34,6 +34,7 @@ type pushUploadFn func( ...@@ -34,6 +34,7 @@ type pushUploadFn func(
func (c *PushCommand) Run(args []string) int { func (c *PushCommand) Run(args []string) int {
var token string var token string
var message string var message string
var name string
var create bool var create bool
f := flag.NewFlagSet("push", flag.ContinueOnError) f := flag.NewFlagSet("push", flag.ContinueOnError)
...@@ -41,6 +42,7 @@ func (c *PushCommand) Run(args []string) int { ...@@ -41,6 +42,7 @@ func (c *PushCommand) Run(args []string) int {
f.StringVar(&token, "token", "", "token") f.StringVar(&token, "token", "", "token")
f.StringVar(&message, "m", "", "message") f.StringVar(&message, "m", "", "message")
f.StringVar(&message, "message", "", "message") f.StringVar(&message, "message", "", "message")
f.StringVar(&name, "name", "", "name")
f.BoolVar(&create, "create", false, "create (deprecated)") f.BoolVar(&create, "create", false, "create (deprecated)")
if err := f.Parse(args); err != nil { if err := f.Parse(args); err != nil {
return 1 return 1
...@@ -65,11 +67,17 @@ func (c *PushCommand) Run(args []string) int { ...@@ -65,11 +67,17 @@ func (c *PushCommand) Run(args []string) int {
return 1 return 1
} }
// If we didn't pass name from the CLI, use the template
if name == "" {
name = tpl.Push.Name
}
// Validate some things // Validate some things
if tpl.Push == nil || tpl.Push.Name == "" { if name == "" {
c.Ui.Error(fmt.Sprintf( c.Ui.Error(fmt.Sprintf(
"The 'push' section must be specified in the template with\n" + "The 'push' section must be specified in the template with\n" +
"at least the 'name' option set.")) "at least the 'name' option set. Alternatively, you can pass the\n" +
"name parameter from the CLI."))
return 1 return 1
} }
...@@ -245,6 +253,9 @@ Options: ...@@ -245,6 +253,9 @@ Options:
-m, -message=<detail> A message to identify the purpose or changes in this -m, -message=<detail> A message to identify the purpose or changes in this
Packer template much like a VCS commit message Packer template much like a VCS commit message
-name=<name> The destination build in Atlas. This is in a format
"username/name".
-token=<token> The access token to use to when uploading -token=<token> The access token to use to when uploading
` `
......
...@@ -120,6 +120,42 @@ func TestPush_noName(t *testing.T) { ...@@ -120,6 +120,42 @@ func TestPush_noName(t *testing.T) {
} }
} }
func TestPush_cliName(t *testing.T) {
var actual []string
var actualOpts *uploadOpts
uploadFn := func(r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) {
actual = testArchive(t, r)
actualOpts = opts
doneCh := make(chan struct{})
close(doneCh)
return doneCh, nil, nil
}
c := &PushCommand{
Meta: testMeta(t),
uploadFn: uploadFn,
}
args := []string{
"-name=foo/bar",
filepath.Join(testFixture("push-no-name"), "template.json"),
}
if code := c.Run(args); code != 0 {
fatalCommand(t, c.Meta)
}
expected := []string{
archiveTemplateEntry,
"template.json",
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestPush_uploadError(t *testing.T) { func TestPush_uploadError(t *testing.T) {
uploadFn := func(r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) { uploadFn := func(r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) {
return nil, nil, fmt.Errorf("bad") return nil, nil, fmt.Errorf("bad")
......
...@@ -187,7 +187,7 @@ func (r *rawTemplate) Template() (*Template, error) { ...@@ -187,7 +187,7 @@ func (r *rawTemplate) Template() (*Template, error) {
"push: %s", err)) "push: %s", err))
} }
result.Push = &p result.Push = p
} }
// If we have errors, return those with a nil result // If we have errors, return those with a nil result
......
...@@ -18,7 +18,7 @@ type Template struct { ...@@ -18,7 +18,7 @@ type Template struct {
Builders map[string]*Builder Builders map[string]*Builder
Provisioners []*Provisioner Provisioners []*Provisioner
PostProcessors [][]*PostProcessor PostProcessors [][]*PostProcessor
Push *Push Push Push
// RawContents is just the raw data for this template // RawContents is just the raw data for this template
RawContents []byte RawContents []byte
......
...@@ -33,6 +33,9 @@ must be completed within the template. ...@@ -33,6 +33,9 @@ must be completed within the template.
service such as Atlas. This can also be specified within the push service such as Atlas. This can also be specified within the push
configuration in the template. configuration in the template.
* `-name` - The name of the build in the service. This typically
looks like `hashicorp/precise64`.
## Examples ## Examples
Push a Packer template: Push a Packer template:
......
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