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
779f4898
Commit
779f4898
authored
May 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Template takes a component finder
parent
30ab9444
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
5 deletions
+13
-5
command/build/command.go
command/build/command.go
+7
-1
packer/template.go
packer/template.go
+2
-2
packer/template_test.go
packer/template_test.go
+4
-2
No files found.
command/build/command.go
View file @
779f4898
...
...
@@ -31,12 +31,18 @@ func (Command) Run(env packer.Environment, args []string) int {
return
1
}
// The component finder for our builds
components
:=
&
packer
.
ComponentFinder
{
Builder
:
env
.
Builder
,
Hook
:
env
.
Hook
,
}
// Go through each builder and compile the builds that we care about
buildNames
:=
tpl
.
BuildNames
()
builds
:=
make
([]
packer
.
Build
,
0
,
len
(
buildNames
))
for
_
,
buildName
:=
range
buildNames
{
log
.
Printf
(
"Creating build: %s
\n
"
,
buildName
)
build
,
err
:=
tpl
.
Build
(
buildName
,
env
.
Builder
)
build
,
err
:=
tpl
.
Build
(
buildName
,
components
)
if
err
!=
nil
{
env
.
Ui
()
.
Error
(
"Failed to create build '%s':
\n\n
%s
\n
"
,
buildName
,
err
.
Error
())
return
1
...
...
packer/template.go
View file @
779f4898
...
...
@@ -96,14 +96,14 @@ 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
,
bf
BuilderFunc
)
(
b
Build
,
err
error
)
{
func
(
t
*
Template
)
Build
(
name
string
,
components
*
ComponentFinder
)
(
b
Build
,
err
error
)
{
builderConfig
,
ok
:=
t
.
Builders
[
name
]
if
!
ok
{
err
=
fmt
.
Errorf
(
"No such build found in template: %s"
,
name
)
return
}
builder
,
err
:=
bf
(
builderConfig
.
builderName
)
builder
,
err
:=
components
.
Builder
(
builderConfig
.
builderName
)
if
err
!=
nil
{
return
}
...
...
packer/template_test.go
View file @
779f4898
...
...
@@ -181,7 +181,8 @@ func TestTemplate_BuildUnknownBuilder(t *testing.T) {
assert
.
Nil
(
err
,
"should not error"
)
builderFactory
:=
func
(
string
)
(
Builder
,
error
)
{
return
nil
,
nil
}
build
,
err
:=
template
.
Build
(
"test1"
,
builderFactory
)
components
:=
&
ComponentFinder
{
Builder
:
builderFactory
}
build
,
err
:=
template
.
Build
(
"test1"
,
components
)
assert
.
Nil
(
build
,
"build should be nil"
)
assert
.
NotNil
(
err
,
"should have error"
)
}
...
...
@@ -215,10 +216,11 @@ func TestTemplate_Build(t *testing.T) {
}
builderFactory
:=
func
(
n
string
)
(
Builder
,
error
)
{
return
builderMap
[
n
],
nil
}
components
:=
&
ComponentFinder
{
Builder
:
builderFactory
}
// 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"
,
builderFactory
)
build
,
err
:=
template
.
Build
(
"test1"
,
components
)
assert
.
Nil
(
err
,
"should not error"
)
build
.
Prepare
()
...
...
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