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
2f65b1bb
Commit
2f65b1bb
authored
Oct 28, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/push: create the build config if we can
parent
2f607074
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletion
+47
-1
command/push.go
command/push.go
+47
-1
No files found.
command/push.go
View file @
2f65b1bb
...
...
@@ -13,7 +13,7 @@ import (
)
// archiveTemplateEntry is the name the template always takes within the slug.
const
archiveTemplateEntry
=
".packer-template
.json
"
const
archiveTemplateEntry
=
".packer-template"
type
PushCommand
struct
{
Meta
...
...
@@ -25,10 +25,12 @@ type PushCommand struct {
}
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
...
...
@@ -88,6 +90,12 @@ func (c *PushCommand) Run(args []string) int {
uploadOpts
.
Builds
[
b
.
Name
]
=
b
.
Type
}
// 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
,
archiveErrCh
,
err
:=
archive
.
Archive
(
path
,
&
opts
)
if
err
!=
nil
{
...
...
@@ -128,8 +136,13 @@ Usage: packer push [options] TEMPLATE
This will not initiate any builds, it will only update the templates
used for builds.
The configuration about what is pushed is configured within the
template's "push" section.
Options:
-create Create the build configuration if it doesn't exist.
-token=<token> Access token to use to upload. If blank, the
TODO environmental variable will be used.
`
...
...
@@ -141,6 +154,39 @@ 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
:=
harmony
.
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
!=
harmony
.
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."
)
}
// Create it
if
err
:=
c
.
client
.
CreateBuildConfig
(
user
,
name
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
c
*
PushCommand
)
upload
(
r
io
.
Reader
,
opts
*
uploadOpts
)
(
<-
chan
struct
{},
<-
chan
error
,
error
)
{
if
c
.
uploadFn
!=
nil
{
...
...
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