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
d95f0a62
Commit
d95f0a62
authored
Jun 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: builds now have post processors as part of them
parent
eee22b32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
12 deletions
+59
-12
packer/build.go
packer/build.go
+13
-5
packer/template.go
packer/template.go
+29
-5
packer/template_test.go
packer/template_test.go
+17
-2
No files found.
packer/build.go
View file @
d95f0a62
...
@@ -44,17 +44,25 @@ type Build interface {
...
@@ -44,17 +44,25 @@ type Build interface {
// multiple files, of course, but it should be for only a single provider
// multiple files, of course, but it should be for only a single provider
// (such as VirtualBox, EC2, etc.).
// (such as VirtualBox, EC2, etc.).
type
coreBuild
struct
{
type
coreBuild
struct
{
name
string
name
string
builder
Builder
builder
Builder
builderConfig
interface
{}
builderConfig
interface
{}
hooks
map
[
string
][]
Hook
hooks
map
[
string
][]
Hook
provisioners
[]
coreBuildProvisioner
postProcessors
[][]
coreBuildPostProcessor
provisioners
[]
coreBuildProvisioner
debug
bool
debug
bool
l
sync
.
Mutex
l
sync
.
Mutex
prepareCalled
bool
prepareCalled
bool
}
}
// Keeps track of the post-processor and the configuration of the
// post-processor used within a build.
type
coreBuildPostProcessor
struct
{
processor
PostProcessor
config
interface
{}
}
// Keeps track of the provisioner and the configuration of the provisioner
// Keeps track of the provisioner and the configuration of the provisioner
// within the build.
// within the build.
type
coreBuildProvisioner
struct
{
type
coreBuildProvisioner
struct
{
...
...
packer/template.go
View file @
d95f0a62
...
@@ -285,6 +285,29 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
...
@@ -285,6 +285,29 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
hooks
[
tplEvent
]
=
curHooks
hooks
[
tplEvent
]
=
curHooks
}
}
// Prepare the post-processors
postProcessors
:=
make
([][]
coreBuildPostProcessor
,
0
,
len
(
t
.
PostProcessors
))
for
_
,
rawPPs
:=
range
t
.
PostProcessors
{
current
:=
make
([]
coreBuildPostProcessor
,
len
(
rawPPs
))
for
i
,
rawPP
:=
range
rawPPs
{
pp
,
err
:=
components
.
PostProcessor
(
rawPP
.
Type
)
if
err
!=
nil
{
return
nil
,
err
}
if
pp
==
nil
{
return
nil
,
fmt
.
Errorf
(
"PostProcessor type not found: %s"
,
rawPP
.
Type
)
}
current
[
i
]
=
coreBuildPostProcessor
{
processor
:
pp
,
config
:
rawPP
.
rawConfig
,
}
}
postProcessors
=
append
(
postProcessors
,
current
)
}
// Prepare the provisioners
// Prepare the provisioners
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
t
.
Provisioners
))
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
t
.
Provisioners
))
for
_
,
rawProvisioner
:=
range
t
.
Provisioners
{
for
_
,
rawProvisioner
:=
range
t
.
Provisioners
{
...
@@ -313,11 +336,12 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
...
@@ -313,11 +336,12 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
}
}
b
=
&
coreBuild
{
b
=
&
coreBuild
{
name
:
name
,
name
:
name
,
builder
:
builder
,
builder
:
builder
,
builderConfig
:
builderConfig
.
rawConfig
,
builderConfig
:
builderConfig
.
rawConfig
,
hooks
:
hooks
,
hooks
:
hooks
,
provisioners
:
provisioners
,
postProcessors
:
postProcessors
,
provisioners
:
provisioners
,
}
}
return
return
...
...
packer/template_test.go
View file @
d95f0a62
...
@@ -443,6 +443,11 @@ func TestTemplate_Build(t *testing.T) {
...
@@ -443,6 +443,11 @@ func TestTemplate_Build(t *testing.T) {
{
{
"type": "test-prov"
"type": "test-prov"
}
}
],
"post-processors": [
"simple",
["simple", "simple"]
]
]
}
}
`
`
...
@@ -465,11 +470,18 @@ func TestTemplate_Build(t *testing.T) {
...
@@ -465,11 +470,18 @@ func TestTemplate_Build(t *testing.T) {
"test-prov"
:
provisioner
,
"test-prov"
:
provisioner
,
}
}
pp
:=
new
(
TestPostProcessor
)
ppMap
:=
map
[
string
]
PostProcessor
{
"simple"
:
pp
,
}
builderFactory
:=
func
(
n
string
)
(
Builder
,
error
)
{
return
builderMap
[
n
],
nil
}
builderFactory
:=
func
(
n
string
)
(
Builder
,
error
)
{
return
builderMap
[
n
],
nil
}
ppFactory
:=
func
(
n
string
)
(
PostProcessor
,
error
)
{
return
ppMap
[
n
],
nil
}
provFactory
:=
func
(
n
string
)
(
Provisioner
,
error
)
{
return
provisionerMap
[
n
],
nil
}
provFactory
:=
func
(
n
string
)
(
Provisioner
,
error
)
{
return
provisionerMap
[
n
],
nil
}
components
:=
&
ComponentFinder
{
components
:=
&
ComponentFinder
{
Builder
:
builderFactory
,
Builder
:
builderFactory
,
Provisioner
:
provFactory
,
PostProcessor
:
ppFactory
,
Provisioner
:
provFactory
,
}
}
// Get the build, verifying we can get it without issue, but also
// Get the build, verifying we can get it without issue, but also
...
@@ -482,6 +494,9 @@ func TestTemplate_Build(t *testing.T) {
...
@@ -482,6 +494,9 @@ func TestTemplate_Build(t *testing.T) {
assert
.
Equal
(
coreBuild
.
builder
,
builder
,
"should have the same builder"
)
assert
.
Equal
(
coreBuild
.
builder
,
builder
,
"should have the same builder"
)
assert
.
Equal
(
coreBuild
.
builderConfig
,
expectedConfig
,
"should have proper config"
)
assert
.
Equal
(
coreBuild
.
builderConfig
,
expectedConfig
,
"should have proper config"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
),
1
,
"should have one provisioner"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
),
1
,
"should have one provisioner"
)
assert
.
Equal
(
len
(
coreBuild
.
postProcessors
),
2
,
"should have pps"
)
assert
.
Equal
(
len
(
coreBuild
.
postProcessors
[
0
]),
1
,
"should have correct number"
)
assert
.
Equal
(
len
(
coreBuild
.
postProcessors
[
1
]),
2
,
"should have correct number"
)
}
}
func
TestTemplate_Build_ProvisionerOverride
(
t
*
testing
.
T
)
{
func
TestTemplate_Build_ProvisionerOverride
(
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