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
56c36c12
Commit
56c36c12
authored
Aug 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/build,validate: pass user vars to Prepare
parent
915c8ceb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
2 deletions
+33
-2
command/build/command.go
command/build/command.go
+9
-1
command/build/help.go
command/build/help.go
+1
-0
command/validate/command.go
command/validate/command.go
+9
-1
command/validate/help.go
command/validate/help.go
+1
-0
common/command/template.go
common/command/template.go
+13
-0
No files found.
command/build/command.go
View file @
56c36c12
...
@@ -46,6 +46,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -46,6 +46,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
return
1
return
1
}
}
userVars
,
err
:=
buildOptions
.
AllUserVars
()
if
err
!=
nil
{
env
.
Ui
()
.
Error
(
fmt
.
Sprintf
(
"Error compiling user variables: %s"
,
err
))
env
.
Ui
()
.
Error
(
""
)
env
.
Ui
()
.
Error
(
c
.
Help
())
return
1
}
// Read the file into a byte array so that we can parse the template
// Read the file into a byte array so that we can parse the template
log
.
Printf
(
"Reading template: %s"
,
args
[
0
])
log
.
Printf
(
"Reading template: %s"
,
args
[
0
])
tpl
,
err
:=
packer
.
ParseTemplateFile
(
args
[
0
])
tpl
,
err
:=
packer
.
ParseTemplateFile
(
args
[
0
])
...
@@ -104,7 +112,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -104,7 +112,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
log
.
Printf
(
"Preparing build: %s"
,
b
.
Name
())
log
.
Printf
(
"Preparing build: %s"
,
b
.
Name
())
b
.
SetDebug
(
cfgDebug
)
b
.
SetDebug
(
cfgDebug
)
b
.
SetForce
(
cfgForce
)
b
.
SetForce
(
cfgForce
)
err
:=
b
.
Prepare
(
nil
)
err
:=
b
.
Prepare
(
userVars
)
if
err
!=
nil
{
if
err
!=
nil
{
env
.
Ui
()
.
Error
(
err
.
Error
())
env
.
Ui
()
.
Error
(
err
.
Error
())
return
1
return
1
...
...
command/build/help.go
View file @
56c36c12
...
@@ -12,4 +12,5 @@ Options:
...
@@ -12,4 +12,5 @@ Options:
-force Force a build to continue if artifacts exist, deletes existing artifacts
-force Force a build to continue if artifacts exist, deletes existing artifacts
-except=foo,bar,baz Build all builds other than these
-except=foo,bar,baz Build all builds other than these
-only=foo,bar,baz Only build the given builds by name
-only=foo,bar,baz Only build the given builds by name
-var 'key=value' Variable for templates, can be used multiple times.
`
`
command/validate/command.go
View file @
56c36c12
...
@@ -40,6 +40,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -40,6 +40,14 @@ func (c Command) Run(env packer.Environment, args []string) int {
return
1
return
1
}
}
userVars
,
err
:=
buildOptions
.
AllUserVars
()
if
err
!=
nil
{
env
.
Ui
()
.
Error
(
fmt
.
Sprintf
(
"Error compiling user variables: %s"
,
err
))
env
.
Ui
()
.
Error
(
""
)
env
.
Ui
()
.
Error
(
c
.
Help
())
return
1
}
// Parse the template into a machine-usable format
// Parse the template into a machine-usable format
log
.
Printf
(
"Reading template: %s"
,
args
[
0
])
log
.
Printf
(
"Reading template: %s"
,
args
[
0
])
tpl
,
err
:=
packer
.
ParseTemplateFile
(
args
[
0
])
tpl
,
err
:=
packer
.
ParseTemplateFile
(
args
[
0
])
...
@@ -73,7 +81,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -73,7 +81,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
// Check the configuration of all builds
// Check the configuration of all builds
for
_
,
b
:=
range
builds
{
for
_
,
b
:=
range
builds
{
log
.
Printf
(
"Preparing build: %s"
,
b
.
Name
())
log
.
Printf
(
"Preparing build: %s"
,
b
.
Name
())
err
:=
b
.
Prepare
(
nil
)
err
:=
b
.
Prepare
(
userVars
)
if
err
!=
nil
{
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Errors validating build '%s'. %s"
,
b
.
Name
(),
err
))
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Errors validating build '%s'. %s"
,
b
.
Name
(),
err
))
}
}
...
...
command/validate/help.go
View file @
56c36c12
...
@@ -15,4 +15,5 @@ Options:
...
@@ -15,4 +15,5 @@ Options:
-syntax-only Only check syntax. Do not verify config of the template.
-syntax-only Only check syntax. Do not verify config of the template.
-except=foo,bar,baz Validate all builds other than these
-except=foo,bar,baz Validate all builds other than these
-only=foo,bar,baz Validate only these builds
-only=foo,bar,baz Validate only these builds
-var 'key=value' Variable for templates, can be used multiple times.
`
`
common/command/template.go
View file @
56c36c12
...
@@ -24,6 +24,19 @@ func (f *BuildOptions) Validate() error {
...
@@ -24,6 +24,19 @@ func (f *BuildOptions) Validate() error {
return
nil
return
nil
}
}
// AllUserVars returns the user variables, compiled from both the
// file paths and the vars on the command line.
func
(
f
*
BuildOptions
)
AllUserVars
()
(
map
[
string
]
string
,
error
)
{
all
:=
make
(
map
[
string
]
string
)
// Copy in the command-line vars
for
k
,
v
:=
range
f
.
UserVars
{
all
[
k
]
=
v
}
return
all
,
nil
}
// Builds returns the builds out of the given template that pass the
// Builds returns the builds out of the given template that pass the
// configured options.
// configured options.
func
(
f
*
BuildOptions
)
Builds
(
t
*
packer
.
Template
,
cf
*
packer
.
ComponentFinder
)
([]
packer
.
Build
,
error
)
{
func
(
f
*
BuildOptions
)
Builds
(
t
*
packer
.
Template
,
cf
*
packer
.
ComponentFinder
)
([]
packer
.
Build
,
error
)
{
...
...
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