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
6bed06e0
Commit
6bed06e0
authored
Apr 15, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lots of template parsing stuff
parent
298a7cdb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
2 deletions
+89
-2
packer/build_command.go
packer/build_command.go
+8
-0
packer/template.go
packer/template.go
+32
-2
packer/template_test.go
packer/template_test.go
+49
-0
No files found.
packer/build_command.go
View file @
6bed06e0
...
...
@@ -26,6 +26,14 @@ func (buildCommand) Run(env *Environment, args []string) int {
return
1
}
// Go through each builder and compile the builds that we care about
//builds := make([]Build, 0, len(tpl.Builders))
//for name, rawConfig := range tpl.Builders {
//builder := env.Builder(name, rawConfig)
//build := env.Build(name, builder)
//builds = append(builds, build)
//}
return
0
}
...
...
packer/template.go
View file @
6bed06e0
...
...
@@ -34,8 +34,38 @@ func ParseTemplate(data []byte) (t *Template, err error) {
return
}
t
=
&
Template
{
Name
:
rawTpl
.
Name
,
t
=
&
Template
{}
t
.
Name
=
rawTpl
.
Name
t
.
Builders
=
make
(
map
[
string
]
rawBuilderConfig
)
for
_
,
v
:=
range
rawTpl
.
Builders
{
rawType
,
ok
:=
v
[
"type"
]
if
!
ok
{
// TODO: Missing type error
return
}
// Attempt to get the name of the builder. If the "name" key
// missing, use the "type" field, which is guaranteed to exist
// at this point.
rawName
,
ok
:=
v
[
"name"
]
if
!
ok
{
rawName
=
v
[
"type"
]
}
// TODO: Error checking if we can't convert
name
:=
rawName
.
(
string
)
typeName
:=
rawType
.
(
string
)
// Check if we already have a builder with this name and record
// an error.
_
,
ok
=
t
.
Builders
[
name
]
if
ok
{
// TODO: We already have a builder with this name
return
}
t
.
Builders
[
name
]
=
rawBuilderConfig
{
typeName
,
v
}
}
return
...
...
packer/template_test.go
View file @
6bed06e0
...
...
@@ -38,3 +38,52 @@ func TestParseTemplate_Invalid(t *testing.T) {
assert
.
NotNil
(
err
,
"should have an error"
)
assert
.
Nil
(
result
,
"should have no result"
)
}
func
TestParseTemplate_BuilderWithoutName
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
data
:=
`
{
"name": "my-image",
"builders": [
{
"type": "amazon-ebs"
}
]
}
`
result
,
err
:=
ParseTemplate
([]
byte
(
data
))
assert
.
Nil
(
err
,
"should not error"
)
assert
.
NotNil
(
result
,
"template should not be nil"
)
assert
.
Length
(
result
.
Builders
,
1
,
"should have one builder"
)
builder
,
ok
:=
result
.
Builders
[
"amazon-ebs"
]
assert
.
True
(
ok
,
"should have amazon-ebs builder"
)
assert
.
Equal
(
builder
.
builderName
,
"amazon-ebs"
,
"builder should be amazon-ebs"
)
}
func
TestParseTemplate_BuilderWithName
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
data
:=
`
{
"name": "my-image",
"builders": [
{
"name": "bob",
"type": "amazon-ebs"
}
]
}
`
result
,
err
:=
ParseTemplate
([]
byte
(
data
))
assert
.
Nil
(
err
,
"should not error"
)
assert
.
NotNil
(
result
,
"template should not be nil"
)
assert
.
Length
(
result
.
Builders
,
1
,
"should have one builder"
)
builder
,
ok
:=
result
.
Builders
[
"bob"
]
assert
.
True
(
ok
,
"should have bob builder"
)
assert
.
Equal
(
builder
.
builderName
,
"amazon-ebs"
,
"builder should be amazon-ebs"
)
}
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