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
2f607074
Commit
2f607074
authored
Oct 28, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/push: actual upload to named build config
parent
0f5ef2ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
4 deletions
+58
-4
command/push.go
command/push.go
+53
-4
command/push_test.go
command/push_test.go
+5
-0
No files found.
command/push.go
View file @
2f607074
...
...
@@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/hashicorp/harmony-go"
"github.com/hashicorp/harmony-go/archive"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -17,6 +18,8 @@ const archiveTemplateEntry = ".packer-template.json"
type
PushCommand
struct
{
Meta
client
*
harmony
.
Client
// For tests:
uploadFn
func
(
io
.
Reader
,
*
uploadOpts
)
(
<-
chan
struct
{},
<-
chan
error
,
error
)
}
...
...
@@ -52,6 +55,10 @@ func (c *PushCommand) Run(args []string) int {
return
1
}
// Build our client
c
.
client
=
harmony
.
DefaultClient
()
defer
func
()
{
c
.
client
=
nil
}()
// Build the archiving options
var
opts
archive
.
ArchiveOpts
opts
.
Include
=
tpl
.
Push
.
Include
...
...
@@ -76,6 +83,10 @@ func (c *PushCommand) Run(args []string) int {
var
uploadOpts
uploadOpts
uploadOpts
.
Slug
=
tpl
.
Push
.
Name
uploadOpts
.
Token
=
token
uploadOpts
.
Builds
=
make
(
map
[
string
]
string
)
for
_
,
b
:=
range
tpl
.
Builders
{
uploadOpts
.
Builds
[
b
.
Name
]
=
b
.
Type
}
// Start the archiving process
r
,
archiveErrCh
,
err
:=
archive
.
Archive
(
path
,
&
opts
)
...
...
@@ -136,11 +147,49 @@ func (c *PushCommand) upload(
return
c
.
uploadFn
(
r
,
opts
)
}
return
nil
,
nil
,
nil
// Separate the slug into the user and name components
user
,
name
,
err
:=
harmony
.
ParseSlug
(
opts
.
Slug
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"upload: %s"
,
err
)
}
// Get the app
bc
,
err
:=
c
.
client
.
BuildConfig
(
user
,
name
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"upload: %s"
,
err
)
}
// Build the version to send up
version
:=
harmony
.
BuildConfigVersion
{
User
:
bc
.
User
,
Name
:
bc
.
Name
,
Builds
:
make
([]
harmony
.
BuildConfigBuild
,
0
,
len
(
opts
.
Builds
)),
}
for
name
,
t
:=
range
opts
.
Builds
{
version
.
Builds
=
append
(
version
.
Builds
,
harmony
.
BuildConfigBuild
{
Name
:
name
,
Type
:
t
,
})
}
// Start the upload
doneCh
,
errCh
:=
make
(
chan
struct
{}),
make
(
chan
error
)
go
func
()
{
err
:=
c
.
client
.
UploadBuildConfigVersion
(
&
version
,
r
)
if
err
!=
nil
{
errCh
<-
err
return
}
close
(
doneCh
)
}()
return
doneCh
,
errCh
,
nil
}
type
uploadOpts
struct
{
URL
string
Slug
string
Token
string
URL
string
Slug
string
Token
string
Builds
map
[
string
]
string
}
command/push_test.go
View file @
2f607074
...
...
@@ -58,6 +58,11 @@ func TestPush(t *testing.T) {
if
!
reflect
.
DeepEqual
(
actual
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
expectedBuilds
:=
map
[
string
]
string
{
"dummy"
:
"dummy"
}
if
!
reflect
.
DeepEqual
(
actualOpts
.
Builds
,
expectedBuilds
)
{
t
.
Fatalf
(
"bad: %#v"
,
actualOpts
.
Builds
)
}
}
func
TestPush_noName
(
t
*
testing
.
T
)
{
...
...
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