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
39095e48
Commit
39095e48
authored
Jul 01, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: make output contain build name by default
[GH-92]
parent
44e0a7de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
123 deletions
+139
-123
packer/template.go
packer/template.go
+116
-116
post-processor/vagrant/aws.go
post-processor/vagrant/aws.go
+4
-1
post-processor/vagrant/post-processor.go
post-processor/vagrant/post-processor.go
+8
-2
post-processor/vagrant/util.go
post-processor/vagrant/util.go
+3
-1
post-processor/vagrant/virtualbox.go
post-processor/vagrant/virtualbox.go
+4
-1
post-processor/vagrant/vmware.go
post-processor/vagrant/vmware.go
+4
-2
No files found.
packer/template.go
View file @
39095e48
...
@@ -76,14 +76,14 @@ func ParseTemplate(data []byte) (t *Template, err error) {
...
@@ -76,14 +76,14 @@ func ParseTemplate(data []byte) (t *Template, err error) {
newline
:=
[]
byte
{
'\x0a'
}
newline
:=
[]
byte
{
'\x0a'
}
// Calculate the start/end position of the line where the error is
// Calculate the start/end position of the line where the error is
start
:=
bytes
.
LastIndex
(
data
[
:
syntaxErr
.
Offset
],
newline
)
+
1
start
:=
bytes
.
LastIndex
(
data
[
:
syntaxErr
.
Offset
],
newline
)
+
1
end
:=
len
(
data
)
end
:=
len
(
data
)
if
idx
:=
bytes
.
Index
(
data
[
start
:
],
newline
);
idx
>=
0
{
if
idx
:=
bytes
.
Index
(
data
[
start
:
],
newline
);
idx
>=
0
{
end
=
start
+
idx
end
=
start
+
idx
}
}
// Count the line number we're on plus the offset in the line
// Count the line number we're on plus the offset in the line
line
:=
bytes
.
Count
(
data
[
:
start
],
newline
)
+
1
line
:=
bytes
.
Count
(
data
[
:
start
],
newline
)
+
1
pos
:=
int
(
syntaxErr
.
Offset
)
-
start
-
1
pos
:=
int
(
syntaxErr
.
Offset
)
-
start
-
1
err
=
fmt
.
Errorf
(
"Error in line %d, char %d: %s
\n
%s"
,
err
=
fmt
.
Errorf
(
"Error in line %d, char %d: %s
\n
%s"
,
...
@@ -230,151 +230,151 @@ func parsePostProvisioner(i int, rawV interface{}) (result []map[string]interfac
...
@@ -230,151 +230,151 @@ func parsePostProvisioner(i int, rawV interface{}) (result []map[string]interfac
errors
=
append
(
errors
=
append
(
errors
,
errors
,
fmt
.
Errorf
(
"Post-processor %d.%d: sequences not allowed to be nested in sequences"
,
i
+
1
,
j
+
1
))
fmt
.
Errorf
(
"Post-processor %d.%d: sequences not allowed to be nested in sequences"
,
i
+
1
,
j
+
1
))
default
:
default
:
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Post-processor %d.%d is in a bad format."
,
i
+
1
,
j
+
1
))
errors
=
append
(
errors
,
fmt
.
Errorf
(
"Post-processor %d.%d is in a bad format."
,
i
+
1
,
j
+
1
))
}
}
if
len
(
errors
)
==
0
{
errors
=
nil
}
}
default
:
result
=
nil
errors
=
[]
error
{
fmt
.
Errorf
(
"Post-processor %d is in a bad format."
,
i
+
1
)}
}
}
return
if
len
(
errors
)
==
0
{
errors
=
nil
}
default
:
result
=
nil
errors
=
[]
error
{
fmt
.
Errorf
(
"Post-processor %d is in a bad format."
,
i
+
1
)}
}
}
// BuildNames returns a slice of the available names of builds that
return
// this template represents.
}
func
(
t
*
Template
)
BuildNames
()
[]
string
{
names
:=
make
([]
string
,
0
,
len
(
t
.
Builders
))
for
name
,
_
:=
range
t
.
Builders
{
names
=
append
(
names
,
name
)
}
return
names
// BuildNames returns a slice of the available names of builds that
// this template represents.
func
(
t
*
Template
)
BuildNames
()
[]
string
{
names
:=
make
([]
string
,
0
,
len
(
t
.
Builders
))
for
name
,
_
:=
range
t
.
Builders
{
names
=
append
(
names
,
name
)
}
}
// Build returns a Build for the given name.
return
names
//
}
// If the build does not exist as part of this template, an error is
// returned.
func
(
t
*
Template
)
Build
(
name
string
,
components
*
ComponentFinder
)
(
b
Build
,
err
error
)
{
// Setup the Builder
builderConfig
,
ok
:=
t
.
Builders
[
name
]
if
!
ok
{
err
=
fmt
.
Errorf
(
"No such build found in template: %s"
,
name
)
return
}
// We panic if there is no builder function because this is really
// Build returns a Build for the given name.
// an internal bug that always needs to be fixed, not an error.
//
if
components
.
Builder
==
nil
{
// If the build does not exist as part of this template, an error is
panic
(
"no builder function"
)
// returned.
}
func
(
t
*
Template
)
Build
(
name
string
,
components
*
ComponentFinder
)
(
b
Build
,
err
error
)
{
// Setup the Builder
builderConfig
,
ok
:=
t
.
Builders
[
name
]
if
!
ok
{
err
=
fmt
.
Errorf
(
"No such build found in template: %s"
,
name
)
return
}
// Panic if there are provisioners on the template but no provisioner
// We panic if there is no builder function because this is really
// component finder. This is always an internal error, so we panic
.
// an internal bug that always needs to be fixed, not an error
.
if
len
(
t
.
Provisioners
)
>
0
&&
components
.
Provision
er
==
nil
{
if
components
.
Build
er
==
nil
{
panic
(
"no provision
er function"
)
panic
(
"no build
er function"
)
}
}
builder
,
err
:=
components
.
Builder
(
builderConfig
.
Type
)
// Panic if there are provisioners on the template but no provisioner
if
err
!=
nil
{
// component finder. This is always an internal error, so we panic.
return
if
len
(
t
.
Provisioners
)
>
0
&&
components
.
Provisioner
==
nil
{
}
panic
(
"no provisioner function"
)
}
if
builder
==
nil
{
builder
,
err
:=
components
.
Builder
(
builderConfig
.
Type
)
err
=
fmt
.
Errorf
(
"Builder type not found: %s"
,
builderConfig
.
Type
)
if
err
!=
nil
{
return
return
}
}
// Gather the Hooks
if
builder
==
nil
{
hooks
:=
make
(
map
[
string
][]
Hook
)
err
=
fmt
.
Errorf
(
"Builder type not found: %s"
,
builderConfig
.
Type
)
for
tplEvent
,
tplHooks
:=
range
t
.
Hooks
{
return
curHooks
:=
make
([]
Hook
,
0
,
len
(
tplHooks
))
}
for
_
,
hookName
:=
range
tplHooks
{
// Gather the Hooks
var
hook
Hook
hooks
:=
make
(
map
[
string
][]
Hook
)
hook
,
err
=
components
.
Hook
(
hookName
)
for
tplEvent
,
tplHooks
:=
range
t
.
Hooks
{
if
err
!=
nil
{
curHooks
:=
make
([]
Hook
,
0
,
len
(
tplHooks
))
return
}
if
hook
==
nil
{
for
_
,
hookName
:=
range
tplHooks
{
err
=
fmt
.
Errorf
(
"Hook not found: %s"
,
hookName
)
var
hook
Hook
return
hook
,
err
=
components
.
Hook
(
hookName
)
}
if
err
!=
nil
{
return
}
curHooks
=
append
(
curHooks
,
hook
)
if
hook
==
nil
{
err
=
fmt
.
Errorf
(
"Hook not found: %s"
,
hookName
)
return
}
}
hooks
[
tplEvent
]
=
curHooks
curHooks
=
append
(
curHooks
,
hook
)
}
}
// Prepare the post-processors
hooks
[
tplEvent
]
=
curHooks
postProcessors
:=
make
([][]
coreBuildPostProcessor
,
0
,
len
(
t
.
PostProcessors
))
}
for
_
,
rawPPs
:=
range
t
.
PostProcessors
{
current
:=
make
([]
coreBuildPostProcessor
,
len
(
rawPPs
))
for
i
,
rawPP
:=
range
rawPPs
{
pp
,
err
:=
components
.
PostProcessor
(
rawPP
.
Type
)
if
err
!=
nil
{
return
nil
,
err
}
if
pp
==
nil
{
return
nil
,
fmt
.
Errorf
(
"PostProcessor type not found: %s"
,
rawPP
.
Type
)
}
current
[
i
]
=
coreBuildPostProcessor
{
// Prepare the post-processors
processor
:
pp
,
postProcessors
:=
make
([][]
coreBuildPostProcessor
,
0
,
len
(
t
.
PostProcessors
))
processorType
:
rawPP
.
Type
,
for
_
,
rawPPs
:=
range
t
.
PostProcessors
{
config
:
rawPP
.
rawConfig
,
current
:=
make
([]
coreBuildPostProcessor
,
len
(
rawPPs
))
keepInputArtifact
:
rawPP
.
KeepInputArtifact
,
for
i
,
rawPP
:=
range
rawPPs
{
}
pp
,
err
:=
components
.
PostProcessor
(
rawPP
.
Type
)
if
err
!=
nil
{
return
nil
,
err
}
}
postProcessors
=
append
(
postProcessors
,
current
)
if
pp
==
nil
{
}
return
nil
,
fmt
.
Errorf
(
"PostProcessor type not found: %s"
,
rawPP
.
Type
)
// Prepare the provisioners
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
t
.
Provisioners
))
for
_
,
rawProvisioner
:=
range
t
.
Provisioners
{
var
provisioner
Provisioner
provisioner
,
err
=
components
.
Provisioner
(
rawProvisioner
.
Type
)
if
err
!=
nil
{
return
}
}
if
provisioner
==
nil
{
current
[
i
]
=
coreBuildPostProcessor
{
err
=
fmt
.
Errorf
(
"Provisioner type not found: %s"
,
rawProvisioner
.
Type
)
processor
:
pp
,
return
processorType
:
rawPP
.
Type
,
config
:
rawPP
.
rawConfig
,
keepInputArtifact
:
rawPP
.
KeepInputArtifact
,
}
}
}
configs
:=
make
([]
interface
{},
1
,
2
)
postProcessors
=
append
(
postProcessors
,
current
)
configs
[
0
]
=
rawProvisioner
.
rawConfig
}
if
rawProvisioner
.
Override
!=
nil
{
// Prepare the provisioners
if
override
,
ok
:=
rawProvisioner
.
Override
[
name
];
ok
{
provisioners
:=
make
([]
coreBuildProvisioner
,
0
,
len
(
t
.
Provisioners
))
configs
=
append
(
configs
,
override
)
for
_
,
rawProvisioner
:=
range
t
.
Provisioners
{
}
var
provisioner
Provisioner
}
provisioner
,
err
=
components
.
Provisioner
(
rawProvisioner
.
Type
)
if
err
!=
nil
{
return
}
coreProv
:=
coreBuildProvisioner
{
provisioner
,
configs
}
if
provisioner
==
nil
{
provisioners
=
append
(
provisioners
,
coreProv
)
err
=
fmt
.
Errorf
(
"Provisioner type not found: %s"
,
rawProvisioner
.
Type
)
return
}
}
b
=
&
coreBuild
{
configs
:=
make
([]
interface
{},
1
,
2
)
name
:
name
,
configs
[
0
]
=
rawProvisioner
.
rawConfig
builder
:
builder
,
builderConfig
:
builderConfig
.
rawConfig
,
if
rawProvisioner
.
Override
!=
nil
{
builderType
:
builderConfig
.
Type
,
if
override
,
ok
:=
rawProvisioner
.
Override
[
name
];
ok
{
hooks
:
hooks
,
configs
=
append
(
configs
,
override
)
postProcessors
:
postProcessors
,
}
provisioners
:
provisioners
,
}
}
return
coreProv
:=
coreBuildProvisioner
{
provisioner
,
configs
}
provisioners
=
append
(
provisioners
,
coreProv
)
}
b
=
&
coreBuild
{
name
:
name
,
builder
:
builder
,
builderConfig
:
builderConfig
.
rawConfig
,
builderType
:
builderConfig
.
Type
,
hooks
:
hooks
,
postProcessors
:
postProcessors
,
provisioners
:
provisioners
,
}
}
return
}
post-processor/vagrant/aws.go
View file @
39095e48
...
@@ -14,6 +14,8 @@ import (
...
@@ -14,6 +14,8 @@ import (
type
AWSBoxConfig
struct
{
type
AWSBoxConfig
struct
{
OutputPath
string
`mapstructure:"output"`
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
PackerBuildName
string
`mapstructure:"packer_build_name"`
}
}
type
AWSVagrantfileTemplate
struct
{
type
AWSVagrantfileTemplate
struct
{
...
@@ -51,7 +53,8 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
...
@@ -51,7 +53,8 @@ func (p *AWSBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact
}
}
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"aws"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
p
.
config
.
PackerBuildName
,
"aws"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
...
post-processor/vagrant/post-processor.go
View file @
39095e48
...
@@ -19,6 +19,8 @@ var builtins = map[string]string{
...
@@ -19,6 +19,8 @@ var builtins = map[string]string{
type
Config
struct
{
type
Config
struct
{
OutputPath
string
`mapstructure:"output"`
OutputPath
string
`mapstructure:"output"`
PackerBuildName
string
`mapstructure:"packer_build_name"`
}
}
type
PostProcessor
struct
{
type
PostProcessor
struct
{
...
@@ -35,7 +37,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
...
@@ -35,7 +37,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
}
if
p
.
config
.
OutputPath
==
""
{
if
p
.
config
.
OutputPath
==
""
{
p
.
config
.
OutputPath
=
"packer_{{.Provider}}.box"
p
.
config
.
OutputPath
=
"packer_{{
.BuildName }}_{{
.Provider}}.box"
}
}
_
,
err
:=
template
.
New
(
"output"
)
.
Parse
(
p
.
config
.
OutputPath
)
_
,
err
:=
template
.
New
(
"output"
)
.
Parse
(
p
.
config
.
OutputPath
)
...
@@ -49,6 +51,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
...
@@ -49,6 +51,10 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
return
err
return
err
}
}
packerConfig
:=
map
[
string
]
interface
{}{
packer
.
BuildNameConfigKey
:
p
.
config
.
PackerBuildName
,
}
p
.
premade
=
make
(
map
[
string
]
packer
.
PostProcessor
)
p
.
premade
=
make
(
map
[
string
]
packer
.
PostProcessor
)
errors
:=
make
([]
error
,
0
)
errors
:=
make
([]
error
,
0
)
for
k
,
raw
:=
range
mapConfig
{
for
k
,
raw
:=
range
mapConfig
{
...
@@ -57,7 +63,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
...
@@ -57,7 +63,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
continue
continue
}
}
if
err
:=
pp
.
Configure
(
raw
);
err
!=
nil
{
if
err
:=
pp
.
Configure
(
raw
,
packerConfig
);
err
!=
nil
{
errors
=
append
(
errors
,
err
)
errors
=
append
(
errors
,
err
)
}
}
...
...
post-processor/vagrant/util.go
View file @
39095e48
...
@@ -17,6 +17,7 @@ import (
...
@@ -17,6 +17,7 @@ import (
// OutputPath variables.
// OutputPath variables.
type
OutputPathTemplate
struct
{
type
OutputPathTemplate
struct
{
ArtifactId
string
ArtifactId
string
BuildName
string
Provider
string
Provider
string
}
}
...
@@ -83,11 +84,12 @@ func DirToBox(dst, dir string) error {
...
@@ -83,11 +84,12 @@ func DirToBox(dst, dir string) error {
// ProcessOutputPath takes an output path template and executes it,
// ProcessOutputPath takes an output path template and executes it,
// replacing variables with their respective values.
// replacing variables with their respective values.
func
ProcessOutputPath
(
path
string
,
provider
string
,
artifact
packer
.
Artifact
)
(
string
,
error
)
{
func
ProcessOutputPath
(
path
string
,
buildName
string
,
provider
string
,
artifact
packer
.
Artifact
)
(
string
,
error
)
{
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
tplData
:=
&
OutputPathTemplate
{
tplData
:=
&
OutputPathTemplate
{
ArtifactId
:
artifact
.
Id
(),
ArtifactId
:
artifact
.
Id
(),
BuildName
:
buildName
,
Provider
:
provider
,
Provider
:
provider
,
}
}
...
...
post-processor/vagrant/virtualbox.go
View file @
39095e48
...
@@ -18,6 +18,8 @@ import (
...
@@ -18,6 +18,8 @@ import (
type
VBoxBoxConfig
struct
{
type
VBoxBoxConfig
struct
{
OutputPath
string
`mapstructure:"output"`
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
PackerBuildName
string
`mapstructure:"packer_build_name"`
}
}
type
VBoxVagrantfileTemplate
struct
{
type
VBoxVagrantfileTemplate
struct
{
...
@@ -48,7 +50,8 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
...
@@ -48,7 +50,8 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
}
}
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"virtualbox"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
p
.
config
.
PackerBuildName
,
"virtualbox"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
err
}
}
...
...
post-processor/vagrant/vmware.go
View file @
39095e48
...
@@ -14,6 +14,8 @@ import (
...
@@ -14,6 +14,8 @@ import (
type
VMwareBoxConfig
struct
{
type
VMwareBoxConfig
struct
{
OutputPath
string
`mapstructure:"output"`
OutputPath
string
`mapstructure:"output"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
VagrantfileTemplate
string
`mapstructure:"vagrantfile_template"`
PackerBuildName
string
`mapstructure:"packer_build_name"`
}
}
type
VMwareBoxPostProcessor
struct
{
type
VMwareBoxPostProcessor
struct
{
...
@@ -28,13 +30,13 @@ func (p *VMwareBoxPostProcessor) Configure(raws ...interface{}) error {
...
@@ -28,13 +30,13 @@ func (p *VMwareBoxPostProcessor) Configure(raws ...interface{}) error {
}
}
}
}
return
nil
return
nil
}
}
func
(
p
*
VMwareBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
func
(
p
*
VMwareBoxPostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
// Compile the output path
// Compile the output path
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
"vmware"
,
artifact
)
outputPath
,
err
:=
ProcessOutputPath
(
p
.
config
.
OutputPath
,
p
.
config
.
PackerBuildName
,
"vmware"
,
artifact
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
false
,
err
return
nil
,
false
,
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