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
1b775cca
Commit
1b775cca
authored
May 29, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: core interpolates Push
parent
579264bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
19 deletions
+63
-19
command/push.go
command/push.go
+1
-8
packer/core.go
packer/core.go
+17
-11
packer/core_test.go
packer/core_test.go
+34
-0
packer/test-fixtures/push-vars.json
packer/test-fixtures/push-vars.json
+11
-0
No files found.
command/push.go
View file @
1b775cca
...
...
@@ -11,7 +11,6 @@ import (
"github.com/hashicorp/atlas-go/archive"
"github.com/hashicorp/atlas-go/v1"
"github.com/mitchellh/packer/template"
"github.com/mitchellh/packer/template/interpolate"
)
// archiveTemplateEntry is the name the template always takes within the slug.
...
...
@@ -73,13 +72,7 @@ func (c *PushCommand) Run(args []string) int {
c
.
Ui
.
Error
(
err
.
Error
())
return
1
}
push
:=
tpl
.
Push
pushRaw
,
err
:=
interpolate
.
RenderInterface
(
&
push
,
core
.
Context
())
if
err
!=
nil
{
c
.
Ui
.
Error
(
err
.
Error
())
return
1
}
push
=
*
pushRaw
.
(
*
template
.
Push
)
push
:=
core
.
Template
.
Push
// If we didn't pass name from the CLI, use the template
if
name
==
""
{
...
...
packer/core.go
View file @
1b775cca
...
...
@@ -12,8 +12,9 @@ import (
// Core is the main executor of Packer. If Packer is being used as a
// library, this is the struct you'll want to instantiate to get anything done.
type
Core
struct
{
Template
*
template
.
Template
components
ComponentFinder
template
*
template
.
Template
variables
map
[
string
]
string
builds
map
[
string
]
*
template
.
Builder
}
...
...
@@ -51,8 +52,8 @@ type ComponentFinder struct {
// NewCore creates a new Core.
func
NewCore
(
c
*
CoreConfig
)
(
*
Core
,
error
)
{
result
:=
&
Core
{
Template
:
c
.
Template
,
components
:
c
.
Components
,
template
:
c
.
Template
,
variables
:
c
.
Variables
,
}
if
err
:=
result
.
validate
();
err
!=
nil
{
...
...
@@ -112,8 +113,8 @@ func (c *Core) Build(n string) (Build, error) {
rawName
:=
configBuilder
.
Name
// Setup the provisioners for this build
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
c
.
t
emplate
.
Provisioners
))
for
_
,
rawP
:=
range
c
.
t
emplate
.
Provisioners
{
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
c
.
T
emplate
.
Provisioners
))
for
_
,
rawP
:=
range
c
.
T
emplate
.
Provisioners
{
// If we're skipping this, then ignore it
if
rawP
.
Skip
(
rawName
)
{
continue
...
...
@@ -155,8 +156,8 @@ func (c *Core) Build(n string) (Build, error) {
}
// Setup the post-processors
postProcessors
:=
make
([][]
coreBuildPostProcessor
,
0
,
len
(
c
.
t
emplate
.
PostProcessors
))
for
_
,
rawPs
:=
range
c
.
t
emplate
.
PostProcessors
{
postProcessors
:=
make
([][]
coreBuildPostProcessor
,
0
,
len
(
c
.
T
emplate
.
PostProcessors
))
for
_
,
rawPs
:=
range
c
.
T
emplate
.
PostProcessors
{
current
:=
make
([]
coreBuildPostProcessor
,
0
,
len
(
rawPs
))
for
_
,
rawP
:=
range
rawPs
{
// If we skip, ignore
...
...
@@ -201,7 +202,7 @@ func (c *Core) Build(n string) (Build, error) {
builderType
:
configBuilder
.
Type
,
postProcessors
:
postProcessors
,
provisioners
:
provisioners
,
templatePath
:
c
.
t
emplate
.
Path
,
templatePath
:
c
.
T
emplate
.
Path
,
variables
:
c
.
variables
,
},
nil
}
...
...
@@ -209,7 +210,7 @@ func (c *Core) Build(n string) (Build, error) {
// Context returns an interpolation context.
func
(
c
*
Core
)
Context
()
*
interpolate
.
Context
{
return
&
interpolate
.
Context
{
TemplatePath
:
c
.
t
emplate
.
Path
,
TemplatePath
:
c
.
T
emplate
.
Path
,
UserVariables
:
c
.
variables
,
}
}
...
...
@@ -221,13 +222,13 @@ func (c *Core) Context() *interpolate.Context {
func
(
c
*
Core
)
validate
()
error
{
// First validate the template in general, we can't do anything else
// unless the template itself is valid.
if
err
:=
c
.
t
emplate
.
Validate
();
err
!=
nil
{
if
err
:=
c
.
T
emplate
.
Validate
();
err
!=
nil
{
return
err
}
// Validate variables are set
var
err
error
for
n
,
v
:=
range
c
.
t
emplate
.
Variables
{
for
n
,
v
:=
range
c
.
T
emplate
.
Variables
{
if
v
.
Required
{
if
_
,
ok
:=
c
.
variables
[
n
];
!
ok
{
err
=
multierror
.
Append
(
err
,
fmt
.
Errorf
(
...
...
@@ -252,7 +253,7 @@ func (c *Core) init() error {
ctx
:=
c
.
Context
()
ctx
.
EnableEnv
=
true
ctx
.
UserVariables
=
nil
for
k
,
v
:=
range
c
.
t
emplate
.
Variables
{
for
k
,
v
:=
range
c
.
T
emplate
.
Variables
{
// Ignore variables that are required
if
v
.
Required
{
continue
...
...
@@ -274,5 +275,10 @@ func (c *Core) init() error {
c
.
variables
[
k
]
=
def
}
// Interpolate the push configuration
if
_
,
err
:=
interpolate
.
RenderInterface
(
&
c
.
Template
.
Push
,
c
.
Context
());
err
!=
nil
{
return
fmt
.
Errorf
(
"Error interpolating 'push': %s"
,
err
)
}
return
nil
}
packer/core_test.go
View file @
1b775cca
...
...
@@ -368,6 +368,40 @@ func TestCoreBuild_templatePath(t *testing.T) {
}
}
func
TestCore_pushInterpolate
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
File
string
Vars
map
[
string
]
string
Result
template
.
Push
}{
{
"push-vars.json"
,
map
[
string
]
string
{
"foo"
:
"bar"
},
template
.
Push
{
Name
:
"bar"
},
},
}
for
_
,
tc
:=
range
cases
{
tpl
,
err
:=
template
.
ParseFile
(
fixtureDir
(
tc
.
File
))
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s
\n\n
%s"
,
tc
.
File
,
err
)
}
core
,
err
:=
NewCore
(
&
CoreConfig
{
Template
:
tpl
,
Variables
:
tc
.
Vars
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s
\n\n
%s"
,
tc
.
File
,
err
)
}
expected
:=
core
.
Template
.
Push
if
!
reflect
.
DeepEqual
(
expected
,
tc
.
Result
)
{
t
.
Fatalf
(
"err: %s
\n\n
%#v"
,
tc
.
File
,
expected
)
}
}
}
func
TestCoreValidate
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
File
string
...
...
packer/test-fixtures/push-vars.json
0 → 100644
View file @
1b775cca
{
"variables"
:
{
"foo"
:
null
},
"builders"
:
[{
"type"
:
"test"
}],
"push"
:
{
"name"
:
"{{user `foo`}}"
}
}
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