diff --git a/command/push.go b/command/push.go index 42c1bc465..f0ff1e1e4 100644 --- a/command/push.go +++ b/command/push.go @@ -32,12 +32,10 @@ type pushUploadFn func( io.Reader, *uploadOpts) (<-chan struct{}, <-chan error, error) func (c *PushCommand) Run(args []string) int { - var create bool var token string f := flag.NewFlagSet("push", flag.ContinueOnError) f.Usage = func() { c.Ui.Error(c.Help()) } - f.BoolVar(&create, "create", false, "create") f.StringVar(&token, "token", "", "token") if err := f.Parse(args); err != nil { return 1 @@ -169,12 +167,6 @@ func (c *PushCommand) Run(args []string) int { "Builds: %s\n\n", strings.Join(badBuilds, ", "))) } - // Create the build config if it doesn't currently exist. - if err := c.create(uploadOpts.Slug, create); err != nil { - c.Ui.Error(err.Error()) - return 1 - } - // Start the archiving process r, err := archive.CreateArchive(path, &opts) if err != nil { @@ -217,17 +209,19 @@ func (*PushCommand) Help() string { helpText := ` Usage: packer push [options] TEMPLATE - Push the template and the files it needs to a Packer build service. - This will not initiate any builds, it will only update the templates - used for builds. + Push the given template and supporting files to a Packer build service such as + Atlas. - The configuration about what is pushed is configured within the - template's "push" section. + If a build configuration for the given template does not exist, it will be + created automatically. If the build configuration already exists, a new + version will be created with this template and the supporting files. + + Additional configuration options (such as the Atlas server URL and files to + include) may be specified in the "push" section of the Packer template. Please + see the online documentation for more information about these configurables. Options: - -create Create the build configuration if it doesn't exist. - -token= Access token to use to upload. If blank, the ATLAS_TOKEN environmental variable will be used. ` @@ -236,40 +230,7 @@ Options: } func (*PushCommand) Synopsis() string { - return "push template files to a Packer build service" -} - -func (c *PushCommand) create(name string, create bool) error { - if c.uploadFn != nil { - return nil - } - - // Separate the slug into the user and name components - user, name, err := atlas.ParseSlug(name) - if err != nil { - return fmt.Errorf("Malformed push name: %s", err) - } - - // Check if it exists. If so, we're done. - if _, err := c.client.BuildConfig(user, name); err == nil { - return nil - } else if err != atlas.ErrNotFound { - return err - } - - // Otherwise, show an error if we're not creating. - if !create { - return fmt.Errorf( - "Push target doesn't exist: %s. Either create this online via\n"+ - "the website or pass the -create flag.", name) - } - - // Create it - if err := c.client.CreateBuildConfig(user, name); err != nil { - return err - } - - return nil + return "push a template and supporting files to a Packer build service" } func (c *PushCommand) upload( @@ -284,10 +245,17 @@ func (c *PushCommand) upload( return nil, nil, fmt.Errorf("upload: %s", err) } - // Get the app + // Get the build configuration bc, err := c.client.BuildConfig(user, name) if err != nil { - return nil, nil, fmt.Errorf("upload: %s", err) + if err == atlas.ErrNotFound { + // Build configuration doesn't exist, attempt to create it + bc, err = c.client.CreateBuildConfig(user, name) + } + + if err != nil { + return nil, nil, fmt.Errorf("upload: %s", err) + } } // Build the version to send up