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
Hide 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 (
...
@@ -11,8 +11,11 @@ import (
"path/filepath"
"path/filepath"
"text/template"
"text/template"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
)
var
builtins
=
map
[
string
]
string
{
var
builtins
=
map
[
string
]
string
{
...
@@ -35,7 +38,7 @@ type Config struct {
...
@@ -35,7 +38,7 @@ type Config struct {
Override
map
[
string
]
interface
{}
Override
map
[
string
]
interface
{}
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
}
type
PostProcessor
struct
{
type
PostProcessor
struct
{
...
@@ -73,10 +76,12 @@ func (p *PostProcessor) PostProcessProvider(name string, provider Provider, ui p
...
@@ -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
))
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
{
ArtifactId
:
artifact
.
Id
(),
Data
:
&
outputPathTemplate
{
BuildName
:
config
.
PackerBuildName
,
ArtifactId
:
artifact
.
Id
(),
Provider
:
name
,
BuildName
:
config
.
PackerBuildName
,
Provider
:
name
,
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
...
@@ -162,21 +167,24 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
...
@@ -162,21 +167,24 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
p
.
PostProcessProvider
(
name
,
provider
,
ui
,
artifact
)
return
p
.
PostProcessProvider
(
name
,
provider
,
ui
,
artifact
)
}
}
func
(
p
*
PostProcessor
)
configureSingle
(
config
*
Config
,
raws
...
interface
{})
error
{
func
(
p
*
PostProcessor
)
configureSingle
(
c
*
Config
,
raws
...
interface
{})
error
{
md
,
err
:=
common
.
DecodeConfig
(
config
,
raws
...
)
var
md
mapstructure
.
Metadata
err
:=
config
.
Decode
(
c
,
&
config
.
DecodeOpts
{
Metadata
:
&
md
,
Interpolate
:
true
,
InterpolateFilter
:
&
interpolate
.
RenderFilter
{
Exclude
:
[]
string
{
"output"
,
},
},
},
raws
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
config
.
tpl
.
UserVars
=
config
.
PackerUserVars
// Defaults
// Defaults
if
c
onfig
.
OutputPath
==
""
{
if
c
.
OutputPath
==
""
{
c
onfig
.
OutputPath
=
"packer_{{ .BuildName }}_{{.Provider}}.box"
c
.
OutputPath
=
"packer_{{ .BuildName }}_{{.Provider}}.box"
}
}
found
:=
false
found
:=
false
...
@@ -188,39 +196,15 @@ func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) err
...
@@ -188,39 +196,15 @@ func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) err
}
}
if
!
found
{
if
!
found
{
c
onfig
.
CompressionLevel
=
flate
.
DefaultCompression
c
.
CompressionLevel
=
flate
.
DefaultCompression
}
}
// Accumulate any errors
var
errs
*
packer
.
MultiError
errs
:=
common
.
CheckUnusedConfig
(
md
)
if
c
.
VagrantfileTemplate
!=
""
{
_
,
err
:=
os
.
Stat
(
c
.
VagrantfileTemplate
)
templates
:=
map
[
string
]
*
string
{
"vagrantfile_template"
:
&
config
.
VagrantfileTemplate
,
}
for
key
,
ptr
:=
range
templates
{
*
ptr
,
err
=
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
}
"vagrantfile_template '%s' does not exist"
,
c
.
VagrantfileTemplate
))
}
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
))
}
}
}
}
...
...
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