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
5b343ca9
Commit
5b343ca9
authored
May 27, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: interpolation
parent
4bb16ac2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
45 deletions
+29
-45
post-processor/vagrant/post-processor.go
post-processor/vagrant/post-processor.go
+29
-45
No files found.
post-processor/vagrant/post-processor.go
View file @
5b343ca9
...
...
@@ -11,8 +11,11 @@ import (
"path/filepath"
"text/template"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
var
builtins
=
map
[
string
]
string
{
...
...
@@ -35,7 +38,7 @@ type Config struct {
Override
map
[
string
]
interface
{}
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
type
PostProcessor
struct
{
...
...
@@ -73,10 +76,12 @@ func (p *PostProcessor) PostProcessProvider(name string, provider Provider, ui p
ui
.
Say
(
fmt
.
Sprintf
(
"Creating Vagrant box for '%s' provider"
,
name
))
outputPath
,
err
:=
config
.
tpl
.
Process
(
config
.
OutputPath
,
&
outputPathTemplate
{
outputPath
,
err
:=
interpolate
.
Render
(
config
.
OutputPath
,
&
interpolate
.
Context
{
Data
:
&
outputPathTemplate
{
ArtifactId
:
artifact
.
Id
(),
BuildName
:
config
.
PackerBuildName
,
Provider
:
name
,
},
})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -162,21 +167,24 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
p
.
PostProcessProvider
(
name
,
provider
,
ui
,
artifact
)
}
func
(
p
*
PostProcessor
)
configureSingle
(
config
*
Config
,
raws
...
interface
{})
error
{
md
,
err
:=
common
.
DecodeConfig
(
config
,
raws
...
)
func
(
p
*
PostProcessor
)
configureSingle
(
c
*
Config
,
raws
...
interface
{})
error
{
var
md
mapstructure
.
Metadata
err
:=
config
.
Decode
(
c
,
&
config
.
DecodeOpts
{
Metadata
:
&
md
,
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{
"output"
,
},
},
},
raws
...
)
if
err
!=
nil
{
return
err
}
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
config
.
tpl
.
UserVars
=
config
.
PackerUserVars
// Defaults
if
c
onfig
.
OutputPath
==
""
{
c
onfig
.
OutputPath
=
"packer_{{ .BuildName }}_{{.Provider}}.box"
if
c
.
OutputPath
==
""
{
c
.
OutputPath
=
"packer_{{ .BuildName }}_{{.Provider}}.box"
}
found
:=
false
...
...
@@ -188,39 +196,15 @@ func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) err
}
if
!
found
{
c
onfig
.
CompressionLevel
=
flate
.
DefaultCompression
c
.
CompressionLevel
=
flate
.
DefaultCompression
}
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"vagrantfile_template"
:
&
config
.
VagrantfileTemplate
,
}
for
key
,
ptr
:=
range
templates
{
*
ptr
,
err
=
config
.
tpl
.
Process
(
*
ptr
,
nil
)
var
errs
*
packer
.
MultiError
if
c
.
VagrantfileTemplate
!=
""
{
_
,
err
:=
os
.
Stat
(
c
.
VagrantfileTemplate
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
validates
:=
map
[
string
]
*
string
{
"output"
:
&
config
.
OutputPath
,
"vagrantfile_template"
:
&
config
.
VagrantfileTemplate
,
}
if
config
.
VagrantfileTemplate
!=
""
{
_
,
err
:=
os
.
Stat
(
config
.
VagrantfileTemplate
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"vagrantfile_template '%s' does not exist"
,
config
.
VagrantfileTemplate
))
}
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
config
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"vagrantfile_template '%s' does not exist"
,
c
.
VagrantfileTemplate
))
}
}
...
...
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