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
fbcc6cb2
Commit
fbcc6cb2
authored
May 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Build now has provisioners, template parses and builds
parent
11d46a3a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
19 deletions
+62
-19
packer/build.go
packer/build.go
+13
-5
packer/build_test.go
packer/build_test.go
+3
-3
packer/template.go
packer/template.go
+25
-4
packer/template_test.go
packer/template_test.go
+21
-7
No files found.
packer/build.go
View file @
fbcc6cb2
...
...
@@ -15,14 +15,22 @@ type Build interface {
// multiple files, of course, but it should be for only a single provider
// (such as VirtualBox, EC2, etc.).
type
coreBuild
struct
{
name
string
builder
Builder
hooks
map
[
string
][]
Hook
rawConfig
interface
{}
name
string
builder
Builder
builderConfig
interface
{}
hooks
map
[
string
][]
Hook
provisioners
[]
coreBuildProvisioner
prepareCalled
bool
}
// Keeps track of the provisioner and the configuration of the provisioner
// within the build.
type
coreBuildProvisioner
struct
{
provisioner
Provisioner
config
interface
{}
}
// Returns the name of the build.
func
(
b
*
coreBuild
)
Name
()
string
{
return
b
.
name
...
...
@@ -32,7 +40,7 @@ func (b *coreBuild) Name() string {
// and any hooks. This _must_ be called prior to Run.
func
(
b
*
coreBuild
)
Prepare
()
(
err
error
)
{
b
.
prepareCalled
=
true
err
=
b
.
builder
.
Prepare
(
b
.
raw
Config
)
err
=
b
.
builder
.
Prepare
(
b
.
builder
Config
)
if
err
!=
nil
{
log
.
Printf
(
"Build '%s' prepare failure: %s
\n
"
,
b
.
name
,
err
)
}
...
...
packer/build_test.go
View file @
fbcc6cb2
...
...
@@ -28,9 +28,9 @@ func (tb *TestBuilder) Run(ui Ui, h Hook) Artifact {
func
testBuild
()
Build
{
return
&
coreBuild
{
name
:
"test"
,
builder
:
&
TestBuilder
{},
raw
Config
:
42
,
name
:
"test"
,
builder
:
&
TestBuilder
{},
builder
Config
:
42
,
}
}
...
...
packer/template.go
View file @
fbcc6cb2
...
...
@@ -149,6 +149,7 @@ func (t *Template) BuildNames() []string {
// If the build does not exist as part of this template, an error is
// returned.
func
(
t
*
Template
)
Build
(
name
string
,
components
*
ComponentFinder
)
(
b
Build
,
err
error
)
{
// Setup the Builder
builderConfig
,
ok
:=
t
.
Builders
[
name
]
if
!
ok
{
err
=
fmt
.
Errorf
(
"No such build found in template: %s"
,
name
)
...
...
@@ -165,6 +166,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
return
}
// Gather the Hooks
hooks
:=
make
(
map
[
string
][]
Hook
)
for
tplEvent
,
tplHooks
:=
range
t
.
Hooks
{
curHooks
:=
make
([]
Hook
,
0
,
len
(
tplHooks
))
...
...
@@ -187,11 +189,30 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
hooks
[
tplEvent
]
=
curHooks
}
// Prepare the provisioners
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
t
.
Provisioners
))
for
_
,
rawProvisioner
:=
range
t
.
Provisioners
{
var
provisioner
Provisioner
provisioner
,
err
=
components
.
Provisioner
(
rawProvisioner
.
pType
)
if
err
!=
nil
{
return
}
if
provisioner
==
nil
{
err
=
fmt
.
Errorf
(
"Provisioner type not found: %s"
,
rawProvisioner
.
pType
)
return
}
coreProv
:=
coreBuildProvisioner
{
provisioner
,
rawProvisioner
.
rawConfig
}
provisioners
=
append
(
provisioners
,
coreProv
)
}
b
=
&
coreBuild
{
name
:
name
,
builder
:
builder
,
hooks
:
hooks
,
rawConfig
:
builderConfig
.
rawConfig
,
name
:
name
,
builder
:
builder
,
builderConfig
:
builderConfig
.
rawConfig
,
hooks
:
hooks
,
provisioners
:
provisioners
,
}
return
...
...
packer/template_test.go
View file @
fbcc6cb2
...
...
@@ -302,6 +302,12 @@ func TestTemplate_Build(t *testing.T) {
"name": "test1",
"type": "test-builder"
}
],
"provisioners": [
{
"type": "test-prov"
}
]
}
`
...
...
@@ -319,18 +325,26 @@ func TestTemplate_Build(t *testing.T) {
"test-builder"
:
builder
,
}
provisioner
:=
&
TestProvisioner
{}
provisionerMap
:=
map
[
string
]
Provisioner
{
"test-prov"
:
provisioner
,
}
builderFactory
:=
func
(
n
string
)
(
Builder
,
error
)
{
return
builderMap
[
n
],
nil
}
components
:=
&
ComponentFinder
{
Builder
:
builderFactory
}
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"
)
build
.
Prepare
()
build
.
Run
(
testUi
())
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
expectedConfig
,
"prepare config should be correct"
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
coreBuild
,
ok
:=
build
.
(
*
coreBuild
)
assert
.
True
(
ok
,
"should be a core build"
)
assert
.
Equal
(
coreBuild
.
builder
,
builder
,
"should have the same builder"
)
assert
.
Equal
(
coreBuild
.
builderConfig
,
expectedConfig
,
"should have proper config"
)
assert
.
Equal
(
len
(
coreBuild
.
provisioners
),
1
,
"should have one 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