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
637bcbc9
Commit
637bcbc9
authored
Jun 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant: allow config of individual pp's
parent
face87d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
12 deletions
+48
-12
post-processor/vagrant/post-processor.go
post-processor/vagrant/post-processor.go
+48
-12
No files found.
post-processor/vagrant/post-processor.go
View file @
637bcbc9
...
...
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"log"
)
var
builtins
=
map
[
string
]
string
{
...
...
@@ -15,10 +16,12 @@ var builtins = map[string]string{
type
Config
struct
{
OutputPath
string
`mapstructure:"output"`
}
type
PostProcessor
struct
{
config
Config
premade
map
[
string
]
packer
.
PostProcessor
}
func
(
p
*
PostProcessor
)
Configure
(
raw
interface
{})
error
{
...
...
@@ -31,6 +34,29 @@ func (p *PostProcessor) Configure(raw interface{}) error {
return
fmt
.
Errorf
(
"`output` must be specified."
)
}
mapConfig
,
ok
:=
raw
.
(
map
[
string
]
interface
{})
if
!
ok
{
panic
(
"Raw configuration not a map"
)
}
errors
:=
make
([]
error
,
0
)
for
k
,
raw
:=
range
mapConfig
{
pp
:=
keyToPostProcessor
(
k
)
if
pp
==
nil
{
continue
}
if
err
:=
pp
.
Configure
(
raw
);
err
!=
nil
{
errors
=
append
(
errors
,
err
)
}
p
.
premade
[
k
]
=
pp
}
if
len
(
errors
)
>
0
{
return
&
packer
.
MultiError
{
errors
}
}
return
nil
}
...
...
@@ -40,20 +66,30 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
nil
,
fmt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
}
// Get the actual PostProcessor implementation for this type
var
pp
packer
.
PostProcessor
switch
ppName
{
case
"aws"
:
pp
=
new
(
AWSBoxPostProcessor
)
default
:
return
nil
,
fmt
.
Errorf
(
"Vagrant box post-processor not found: %s"
,
ppName
)
}
// Use the premade PostProcessor if we have one. Otherwise, we
// create it and configure it here.
pp
,
ok
:=
p
.
premade
[
ppName
]
if
!
ok
{
log
.
Printf
(
"Premade post-processor for '%s' not found. Creating."
,
ppName
)
pp
=
keyToPostProcessor
(
ppName
)
if
pp
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Vagrant box post-processor not found: %s"
,
ppName
)
}
// Prepare and run the post-processor
config
:=
map
[
string
]
string
{
"output"
:
p
.
config
.
OutputPath
}
if
err
:=
pp
.
Configure
(
config
);
err
!=
nil
{
return
nil
,
err
config
:=
map
[
string
]
string
{
"output"
:
p
.
config
.
OutputPath
}
if
err
:=
pp
.
Configure
(
config
);
err
!=
nil
{
return
nil
,
err
}
}
return
pp
.
PostProcess
(
ui
,
artifact
)
}
func
keyToPostProcessor
(
key
string
)
packer
.
PostProcessor
{
switch
key
{
case
"aws"
:
return
new
(
AWSBoxPostProcessor
)
default
:
return
nil
}
}
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