Always create the build configuration if it does not exist
This commit is contained in:
parent
7cb3bb6405
commit
17d4c4396c
|
@ -32,12 +32,10 @@ type pushUploadFn func(
|
||||||
io.Reader, *uploadOpts) (<-chan struct{}, <-chan error, error)
|
io.Reader, *uploadOpts) (<-chan struct{}, <-chan error, error)
|
||||||
|
|
||||||
func (c *PushCommand) Run(args []string) int {
|
func (c *PushCommand) Run(args []string) int {
|
||||||
var create bool
|
|
||||||
var token string
|
var token string
|
||||||
|
|
||||||
f := flag.NewFlagSet("push", flag.ContinueOnError)
|
f := flag.NewFlagSet("push", flag.ContinueOnError)
|
||||||
f.Usage = func() { c.Ui.Error(c.Help()) }
|
f.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
f.BoolVar(&create, "create", false, "create")
|
|
||||||
f.StringVar(&token, "token", "", "token")
|
f.StringVar(&token, "token", "", "token")
|
||||||
if err := f.Parse(args); err != nil {
|
if err := f.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
|
@ -169,12 +167,6 @@ func (c *PushCommand) Run(args []string) int {
|
||||||
"Builds: %s\n\n", strings.Join(badBuilds, ", ")))
|
"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
|
// Start the archiving process
|
||||||
r, err := archive.CreateArchive(path, &opts)
|
r, err := archive.CreateArchive(path, &opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -217,17 +209,19 @@ func (*PushCommand) Help() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: packer push [options] TEMPLATE
|
Usage: packer push [options] TEMPLATE
|
||||||
|
|
||||||
Push the template and the files it needs to a Packer build service.
|
Push the given template and supporting files to a Packer build service such as
|
||||||
This will not initiate any builds, it will only update the templates
|
Atlas.
|
||||||
used for builds.
|
|
||||||
|
|
||||||
The configuration about what is pushed is configured within the
|
If a build configuration for the given template does not exist, it will be
|
||||||
template's "push" section.
|
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:
|
Options:
|
||||||
|
|
||||||
-create Create the build configuration if it doesn't exist.
|
|
||||||
|
|
||||||
-token=<token> Access token to use to upload. If blank, the
|
-token=<token> Access token to use to upload. If blank, the
|
||||||
ATLAS_TOKEN environmental variable will be used.
|
ATLAS_TOKEN environmental variable will be used.
|
||||||
`
|
`
|
||||||
|
@ -236,40 +230,7 @@ Options:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PushCommand) Synopsis() string {
|
func (*PushCommand) Synopsis() string {
|
||||||
return "push template files to a Packer build service"
|
return "push a template and supporting 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PushCommand) upload(
|
func (c *PushCommand) upload(
|
||||||
|
@ -284,10 +245,17 @@ func (c *PushCommand) upload(
|
||||||
return nil, nil, fmt.Errorf("upload: %s", err)
|
return nil, nil, fmt.Errorf("upload: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the app
|
// Get the build configuration
|
||||||
bc, err := c.client.BuildConfig(user, name)
|
bc, err := c.client.BuildConfig(user, name)
|
||||||
if err != nil {
|
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
|
// Build the version to send up
|
||||||
|
|
Loading…
Reference in New Issue