Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
17d4c439
Commit
17d4c439
authored
Feb 03, 2015
by
Seth Vargo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always create the build configuration if it does not exist
parent
7cb3bb64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
51 deletions
+19
-51
command/push.go
command/push.go
+19
-51
No files found.
command/push.go
View file @
17d4c439
...
...
@@ -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,16 +209,18 @@ 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.
Options:
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.
-create Create the build configuration if it doesn't exist.
Options:
-token=<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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment