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
063adf4b
Commit
063adf4b
authored
Aug 15, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: process user variabels [GH-295]
parent
4f568a0a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
21 deletions
+136
-21
CHANGELOG.md
CHANGELOG.md
+1
-0
post-processor/vagrant/aws.go
post-processor/vagrant/aws.go
+45
-7
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+45
-7
post-processor/vagrant/vmware.go
post-processor/vagrant/vmware.go
+45
-7
No files found.
CHANGELOG.md
View file @
063adf4b
...
...
@@ -32,6 +32,7 @@ BUG FIXES:
actually starts. [GH-288]
*
builder/vmware: dowload progress won't be shown until download
actually starts. [GH-288]
*
post-processor/vagrant: Process user variables. [GH-295]
## 0.3.1 (August 12, 2013)
...
...
post-processor/vagrant/aws.go
View file @
063adf4b
...
...
@@ -2,7 +2,6 @@ package vagrant
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
...
...
@@ -10,7 +9,6 @@ import (
"os"
"path/filepath"
"strings"
"text/template"
)
type
AWSBoxConfig
struct
{
...
...
@@ -18,6 +16,8 @@ type AWSBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
tpl
*
common
.
Template
}
type
AWSVagrantfileTemplate
struct
{
...
...
@@ -29,13 +29,48 @@ type AWSBoxPostProcessor struct {
}
func
(
p
*
AWSBoxPostProcessor
)
Configure
(
raws
...
interface
{})
error
{
for
_
,
raw
:=
range
raws
{
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
md
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
return
err
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
validates
:=
map
[
string
]
*
string
{
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
p
.
config
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
}
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
return
nil
}
...
...
@@ -94,8 +129,11 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
vagrantfileContents
=
string
(
contents
)
}
t
:=
template
.
Must
(
template
.
New
(
"vagrantfile"
)
.
Parse
(
vagrantfileContents
))
t
.
Execute
(
vf
,
tplData
)
vagrantfileContents
,
err
=
p
.
config
.
tpl
.
Process
(
vagrantfileContents
,
tplData
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Error writing Vagrantfile: %s"
,
err
)
}
vf
.
Write
([]
byte
(
vagrantfileContents
))
vf
.
Close
()
// Create the metadata
...
...
post-processor/vagrant/virtualbox.go
View file @
063adf4b
...
...
@@ -3,7 +3,6 @@ package vagrant
import
(
"errors"
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
...
...
@@ -12,7 +11,6 @@ import (
"path/filepath"
"regexp"
"strings"
"text/template"
)
type
VBoxBoxConfig
struct
{
...
...
@@ -20,6 +18,8 @@ type VBoxBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
tpl
*
common
.
Template
}
type
VBoxVagrantfileTemplate
struct
{
...
...
@@ -31,13 +31,48 @@ type VBoxBoxPostProcessor struct {
}
func
(
p
*
VBoxBoxPostProcessor
)
Configure
(
raws
...
interface
{})
error
{
for
_
,
raw
:=
range
raws
{
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
md
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
return
err
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
validates
:=
map
[
string
]
*
string
{
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
p
.
config
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
}
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
return
nil
}
...
...
@@ -96,8 +131,11 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
vagrantfileContents
=
string
(
contents
)
}
t
:=
template
.
Must
(
template
.
New
(
"vagrantfile"
)
.
Parse
(
vagrantfileContents
))
t
.
Execute
(
vf
,
tplData
)
vagrantfileContents
,
err
=
p
.
config
.
tpl
.
Process
(
vagrantfileContents
,
tplData
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Error writing Vagrantfile: %s"
,
err
)
}
vf
.
Write
([]
byte
(
vagrantfileContents
))
vf
.
Close
()
// Create the metadata
...
...
post-processor/vagrant/vmware.go
View file @
063adf4b
...
...
@@ -2,13 +2,11 @@ package vagrant
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"path/filepath"
"text/template"
)
type
VMwareBoxConfig
struct
{
...
...
@@ -16,6 +14,8 @@ type VMwareBoxConfig struct {
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
tpl
*
common
.
Template
}
type
VMwareBoxPostProcessor
struct
{
...
...
@@ -23,13 +23,48 @@ type VMwareBoxPostProcessor struct {
}
func
(
p
*
VMwareBoxPostProcessor
)
Configure
(
raws
...
interface
{})
error
{
for
_
,
raw
:=
range
raws
{
err
:=
mapstructure
.
Decode
(
raw
,
&
p
.
config
)
md
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
err
}
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"output"
:
&
p
.
config
.
OutputPath
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
return
err
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
validates
:=
map
[
string
]
*
string
{
"vagrantfile_template"
:
&
p
.
config
.
VagrantfileTemplate
,
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
p
.
config
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
}
}
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
return
nil
}
...
...
@@ -77,8 +112,11 @@ func (p *VMwareBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artif
}
defer
vf
.
Close
()
t
:=
template
.
Must
(
template
.
New
(
"vagrantfile"
)
.
Parse
(
string
(
contents
)))
t
.
Execute
(
vf
,
new
(
struct
{}))
vagrantfileContents
,
err
:=
p
.
config
.
tpl
.
Process
(
string
(
contents
),
nil
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Error writing Vagrantfile: %s"
,
err
)
}
vf
.
Write
([]
byte
(
vagrantfileContents
))
vf
.
Close
()
}
...
...
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