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
c9504d50
Commit
c9504d50
authored
Dec 03, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/push: send artifact true/false if we're post-processing
parent
2dfc5d3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
11 deletions
+96
-11
command/push.go
command/push.go
+40
-9
command/push_test.go
command/push_test.go
+41
-2
command/test-fixtures/push-builds/template.json
command/test-fixtures/push-builds/template.json
+15
-0
No files found.
command/push.go
View file @
c9504d50
...
...
@@ -7,8 +7,8 @@ import (
"path/filepath"
"strings"
"github.com/hashicorp/atlas-go/v1"
"github.com/hashicorp/atlas-go/archive"
"github.com/hashicorp/atlas-go/v1"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -21,9 +21,14 @@ type PushCommand struct {
client
*
atlas
.
Client
// For tests:
uploadFn
func
(
io
.
Reader
,
*
uploadOpts
)
(
<-
chan
struct
{},
<-
chan
error
,
error
)
uploadFn
pushUploadFn
}
// pushUploadFn is the callback type used for tests to stub out the uploading
// logic of the push command.
type
pushUploadFn
func
(
io
.
Reader
,
*
uploadOpts
)
(
<-
chan
struct
{},
<-
chan
error
,
error
)
func
(
c
*
PushCommand
)
Run
(
args
[]
string
)
int
{
var
create
bool
var
token
string
...
...
@@ -114,12 +119,32 @@ func (c *PushCommand) Run(args []string) int {
}
}
// Find the Atlas post-processors, if possible
var
atlasPPs
[]
packer
.
RawPostProcessorConfig
for
_
,
list
:=
range
tpl
.
PostProcessors
{
for
_
,
pp
:=
range
list
{
if
pp
.
Type
==
"atlas"
{
atlasPPs
=
append
(
atlasPPs
,
pp
)
}
}
}
// Build the upload options
var
uploadOpts
uploadOpts
uploadOpts
.
Slug
=
tpl
.
Push
.
Name
uploadOpts
.
Builds
=
make
(
map
[
string
]
string
)
uploadOpts
.
Builds
=
make
(
map
[
string
]
*
uploadBuildInfo
)
for
_
,
b
:=
range
tpl
.
Builders
{
uploadOpts
.
Builds
[
b
.
Name
]
=
b
.
Type
info
:=
&
uploadBuildInfo
{
Type
:
b
.
Type
}
// Determine if we're artifacting this build
for
_
,
pp
:=
range
atlasPPs
{
if
!
pp
.
Skip
(
b
.
Name
)
{
info
.
Artifact
=
true
break
}
}
uploadOpts
.
Builds
[
b
.
Name
]
=
info
}
// Create the build config if it doesn't currently exist.
...
...
@@ -206,7 +231,7 @@ func (c *PushCommand) create(name string, create bool) error {
// 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
"
+
"Push target doesn't exist: %s. Either create this online via
\n
"
+
"the website or pass the -create flag."
,
name
)
}
...
...
@@ -242,10 +267,11 @@ func (c *PushCommand) upload(
Name
:
bc
.
Name
,
Builds
:
make
([]
atlas
.
BuildConfigBuild
,
0
,
len
(
opts
.
Builds
)),
}
for
name
,
t
:=
range
opts
.
Builds
{
for
name
,
info
:=
range
opts
.
Builds
{
version
.
Builds
=
append
(
version
.
Builds
,
atlas
.
BuildConfigBuild
{
Name
:
name
,
Type
:
t
,
Name
:
name
,
Type
:
info
.
Type
,
Artifact
:
info
.
Artifact
,
})
}
...
...
@@ -267,5 +293,10 @@ func (c *PushCommand) upload(
type
uploadOpts
struct
{
URL
string
Slug
string
Builds
map
[
string
]
string
Builds
map
[
string
]
*
uploadBuildInfo
}
type
uploadBuildInfo
struct
{
Type
string
Artifact
bool
}
command/push_test.go
View file @
c9504d50
package
command
import
(
"fmt"
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"
"path/filepath"
"reflect"
...
...
@@ -59,7 +59,46 @@ func TestPush(t *testing.T) {
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
expectedBuilds
:=
map
[
string
]
string
{
"dummy"
:
"dummy"
}
expectedBuilds
:=
map
[
string
]
*
uploadBuildInfo
{
"dummy"
:
&
uploadBuildInfo
{
Type
:
"dummy"
,
},
}
if
!
reflect
.
DeepEqual
(
actualOpts
.
Builds
,
expectedBuilds
)
{
t
.
Fatalf
(
"bad: %#v"
,
actualOpts
.
Builds
)
}
}
func
TestPush_builds
(
t
*
testing
.
T
)
{
var
actualOpts
*
uploadOpts
uploadFn
:=
func
(
r
io
.
Reader
,
opts
*
uploadOpts
)
(
<-
chan
struct
{},
<-
chan
error
,
error
)
{
actualOpts
=
opts
doneCh
:=
make
(
chan
struct
{})
close
(
doneCh
)
return
doneCh
,
nil
,
nil
}
c
:=
&
PushCommand
{
Meta
:
testMeta
(
t
),
uploadFn
:
uploadFn
,
}
args
:=
[]
string
{
filepath
.
Join
(
testFixture
(
"push-builds"
),
"template.json"
)}
if
code
:=
c
.
Run
(
args
);
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
expectedBuilds
:=
map
[
string
]
*
uploadBuildInfo
{
"dummy"
:
&
uploadBuildInfo
{
Type
:
"dummy"
,
Artifact
:
true
,
},
"foo"
:
&
uploadBuildInfo
{
Type
:
"dummy"
,
},
}
if
!
reflect
.
DeepEqual
(
actualOpts
.
Builds
,
expectedBuilds
)
{
t
.
Fatalf
(
"bad: %#v"
,
actualOpts
.
Builds
)
}
...
...
command/test-fixtures/push-builds/template.json
0 → 100644
View file @
c9504d50
{
"builders"
:
[
{
"type"
:
"dummy"
},
{
"type"
:
"dummy"
,
"name"
:
"foo"
}
],
"post-processors"
:
[{
"type"
:
"atlas"
,
"only"
:
[
"dummy"
]
}],
"push"
:
{
"name"
:
"foo/bar"
}
}
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