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
d55bf3f3
Commit
d55bf3f3
authored
Jun 07, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Support overrides in provisioners for each build
parent
5638cecd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
4 deletions
+69
-4
packer/build.go
packer/build.go
+2
-2
packer/build_test.go
packer/build_test.go
+1
-1
packer/template.go
packer/template.go
+10
-1
packer/template_test.go
packer/template_test.go
+56
-0
No files found.
packer/build.go
View file @
d55bf3f3
...
...
@@ -29,7 +29,7 @@ type coreBuild struct {
// within the build.
type
coreBuildProvisioner
struct
{
provisioner
Provisioner
config
interface
{}
config
[]
interface
{}
}
// Returns the name of the build.
...
...
@@ -51,7 +51,7 @@ func (b *coreBuild) Prepare(ui Ui) (err error) {
// Prepare the provisioners
for
_
,
coreProv
:=
range
b
.
provisioners
{
if
err
=
coreProv
.
provisioner
.
Prepare
(
coreProv
.
config
);
err
!=
nil
{
if
err
=
coreProv
.
provisioner
.
Prepare
(
coreProv
.
config
...
);
err
!=
nil
{
return
}
}
...
...
packer/build_test.go
View file @
d55bf3f3
...
...
@@ -14,7 +14,7 @@ func testBuild() Build {
"foo"
:
[]
Hook
{
&
TestHook
{}},
},
provisioners
:
[]
coreBuildProvisioner
{
coreBuildProvisioner
{
&
TestProvisioner
{},
42
},
coreBuildProvisioner
{
&
TestProvisioner
{},
[]
interface
{}{
42
}
},
},
}
}
...
...
packer/template.go
View file @
d55bf3f3
...
...
@@ -220,7 +220,16 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
return
}
coreProv
:=
coreBuildProvisioner
{
provisioner
,
rawProvisioner
.
rawConfig
}
configs
:=
make
([]
interface
{},
1
,
2
)
configs
[
0
]
=
rawProvisioner
.
rawConfig
if
rawProvisioner
.
Override
!=
nil
{
if
override
,
ok
:=
rawProvisioner
.
Override
[
name
];
ok
{
configs
=
append
(
configs
,
override
)
}
}
coreProv
:=
coreBuildProvisioner
{
provisioner
,
configs
}
provisioners
=
append
(
provisioners
,
coreProv
)
}
...
...
packer/template_test.go
View file @
d55bf3f3
...
...
@@ -448,3 +448,59 @@ func TestTemplate_Build(t *testing.T) {
assert
.
Equal
(
coreBuild
.
builderConfig
,
expectedConfig
,
"should have proper config"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
),
1
,
"should have one provisioner"
)
}
func
TestTemplate_Build_ProvisionerOverride
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
data
:=
`
{
"name": "my-image",
"builders": [
{
"name": "test1",
"type": "test-builder"
}
],
"provisioners": [
{
"type": "test-prov",
"override": {
"test1": {}
}
}
]
}
`
template
,
err
:=
ParseTemplate
([]
byte
(
data
))
assert
.
Nil
(
err
,
"should not error"
)
builder
:=
testBuilder
()
builderMap
:=
map
[
string
]
Builder
{
"test-builder"
:
builder
,
}
provisioner
:=
&
TestProvisioner
{}
provisionerMap
:=
map
[
string
]
Provisioner
{
"test-prov"
:
provisioner
,
}
builderFactory
:=
func
(
n
string
)
(
Builder
,
error
)
{
return
builderMap
[
n
],
nil
}
provFactory
:=
func
(
n
string
)
(
Provisioner
,
error
)
{
return
provisionerMap
[
n
],
nil
}
components
:=
&
ComponentFinder
{
Builder
:
builderFactory
,
Provisioner
:
provFactory
,
}
// Get the build, verifying we can get it without issue, but also
// that the proper builder was looked up and used for the build.
build
,
err
:=
template
.
Build
(
"test1"
,
components
)
assert
.
Nil
(
err
,
"should not error"
)
coreBuild
,
ok
:=
build
.
(
*
coreBuild
)
assert
.
True
(
ok
,
"should be a core build"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
),
1
,
"should have one provisioner"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
[
0
]
.
config
),
2
,
"should have two configs on the provisioner"
)
}
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