packer: PostProcessor can take multiple configs
This commit is contained in:
parent
8cf21324dc
commit
fc78bf3dd6
|
@ -59,7 +59,7 @@ func TestBuild_Prepare(t *testing.T) {
|
||||||
corePP := build.postProcessors[0][0]
|
corePP := build.postProcessors[0][0]
|
||||||
pp := corePP.processor.(*TestPostProcessor)
|
pp := corePP.processor.(*TestPostProcessor)
|
||||||
assert.True(pp.configCalled, "config should be called")
|
assert.True(pp.configCalled, "config should be called")
|
||||||
assert.Equal(pp.configVal, 42, "config should have right value")
|
assert.Equal(pp.configVal, []interface{}{42}, "config should have right value")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuild_Prepare_Twice(t *testing.T) {
|
func TestBuild_Prepare_Twice(t *testing.T) {
|
||||||
|
|
|
@ -10,13 +10,13 @@ type cmdPostProcessor struct {
|
||||||
client *Client
|
client *Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmdPostProcessor) Configure(config interface{}) error {
|
func (c *cmdPostProcessor) Configure(config ...interface{}) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
r := recover()
|
||||||
c.checkExit(r, nil)
|
c.checkExit(r, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return c.p.Configure(config)
|
return c.p.Configure(config...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) {
|
func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
type helperPostProcessor byte
|
type helperPostProcessor byte
|
||||||
|
|
||||||
func (helperPostProcessor) Configure(interface{}) error {
|
func (helperPostProcessor) Configure(...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ type PostProcessor interface {
|
||||||
// Configure is responsible for setting up configuration, storing
|
// Configure is responsible for setting up configuration, storing
|
||||||
// the state for later, and returning and errors, such as validation
|
// the state for later, and returning and errors, such as validation
|
||||||
// errors.
|
// errors.
|
||||||
Configure(interface{}) error
|
Configure(...interface{}) error
|
||||||
|
|
||||||
// PostProcess takes a previously created Artifact and produces another
|
// PostProcess takes a previously created Artifact and produces another
|
||||||
// Artifact. If an error occurs, it should return that error. If `keep`
|
// Artifact. If an error occurs, it should return that error. If `keep`
|
||||||
|
|
|
@ -4,13 +4,13 @@ type TestPostProcessor struct {
|
||||||
artifactId string
|
artifactId string
|
||||||
keep bool
|
keep bool
|
||||||
configCalled bool
|
configCalled bool
|
||||||
configVal interface{}
|
configVal []interface{}
|
||||||
ppCalled bool
|
ppCalled bool
|
||||||
ppArtifact Artifact
|
ppArtifact Artifact
|
||||||
ppUi Ui
|
ppUi Ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *TestPostProcessor) Configure(v interface{}) error {
|
func (pp *TestPostProcessor) Configure(v ...interface{}) error {
|
||||||
pp.configCalled = true
|
pp.configCalled = true
|
||||||
pp.configVal = v
|
pp.configVal = v
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -17,6 +17,10 @@ type PostProcessorServer struct {
|
||||||
p packer.PostProcessor
|
p packer.PostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PostProcessorConfigureArgs struct {
|
||||||
|
Configs []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
type PostProcessorProcessResponse struct {
|
type PostProcessorProcessResponse struct {
|
||||||
Err error
|
Err error
|
||||||
Keep bool
|
Keep bool
|
||||||
|
@ -26,8 +30,9 @@ type PostProcessorProcessResponse struct {
|
||||||
func PostProcessor(client *rpc.Client) *postProcessor {
|
func PostProcessor(client *rpc.Client) *postProcessor {
|
||||||
return &postProcessor{client}
|
return &postProcessor{client}
|
||||||
}
|
}
|
||||||
func (p *postProcessor) Configure(raw interface{}) (err error) {
|
func (p *postProcessor) Configure(raw ...interface{}) (err error) {
|
||||||
if cerr := p.client.Call("PostProcessor.Configure", &raw, &err); cerr != nil {
|
args := &PostProcessorConfigureArgs{Configs: raw}
|
||||||
|
if cerr := p.client.Call("PostProcessor.Configure", args, &err); cerr != nil {
|
||||||
err = cerr
|
err = cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +65,8 @@ func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Art
|
||||||
return Artifact(client), response.Keep, nil
|
return Artifact(client), response.Keep, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PostProcessorServer) Configure(raw *interface{}, reply *error) error {
|
func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply *error) error {
|
||||||
*reply = p.p.Configure(*raw)
|
*reply = p.p.Configure(args.Configs...)
|
||||||
if *reply != nil {
|
if *reply != nil {
|
||||||
*reply = NewBasicError(*reply)
|
*reply = NewBasicError(*reply)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package rpc
|
||||||
import (
|
import (
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,13 +11,13 @@ var testPostProcessorArtifact = new(testArtifact)
|
||||||
|
|
||||||
type TestPostProcessor struct {
|
type TestPostProcessor struct {
|
||||||
configCalled bool
|
configCalled bool
|
||||||
configVal interface{}
|
configVal []interface{}
|
||||||
ppCalled bool
|
ppCalled bool
|
||||||
ppArtifact packer.Artifact
|
ppArtifact packer.Artifact
|
||||||
ppUi packer.Ui
|
ppUi packer.Ui
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pp *TestPostProcessor) Configure(v interface{}) error {
|
func (pp *TestPostProcessor) Configure(v ...interface{}) error {
|
||||||
pp.configCalled = true
|
pp.configCalled = true
|
||||||
pp.configVal = v
|
pp.configVal = v
|
||||||
return nil
|
return nil
|
||||||
|
@ -56,7 +57,7 @@ func TestPostProcessorRPC(t *testing.T) {
|
||||||
t.Fatal("config should be called")
|
t.Fatal("config should be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.configVal != 42 {
|
if !reflect.DeepEqual(p.configVal, []interface{}{42}) {
|
||||||
t.Fatalf("unknown config value: %#v", p.configVal)
|
t.Fatalf("unknown config value: %#v", p.configVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,12 @@ type AWSBoxPostProcessor struct {
|
||||||
config AWSBoxConfig
|
config AWSBoxConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AWSBoxPostProcessor) Configure(raw interface{}) error {
|
func (p *AWSBoxPostProcessor) Configure(raws ...interface{}) error {
|
||||||
err := mapstructure.Decode(raw, &p.config)
|
for _, raw := range raws {
|
||||||
if err != nil {
|
err := mapstructure.Decode(raw, &p.config)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -26,23 +26,26 @@ type PostProcessor struct {
|
||||||
premade map[string]packer.PostProcessor
|
premade map[string]packer.PostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PostProcessor) Configure(raw interface{}) error {
|
func (p *PostProcessor) Configure(raws ...interface{}) error {
|
||||||
err := mapstructure.Decode(raw, &p.config)
|
for _, raw := range raws {
|
||||||
if err != nil {
|
err := mapstructure.Decode(raw, &p.config)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.OutputPath == "" {
|
if p.config.OutputPath == "" {
|
||||||
p.config.OutputPath = "packer_{{.Provider}}.box"
|
p.config.OutputPath = "packer_{{.Provider}}.box"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = template.New("output").Parse(p.config.OutputPath)
|
_, err := template.New("output").Parse(p.config.OutputPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("output invalid template: %s", err)
|
return fmt.Errorf("output invalid template: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(mitchellh): Properly handle multiple raw configs
|
||||||
var mapConfig map[string]interface{}
|
var mapConfig map[string]interface{}
|
||||||
if err := mapstructure.Decode(raw, &mapConfig); err != nil {
|
if err := mapstructure.Decode(raws[0], &mapConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,12 @@ type VBoxBoxPostProcessor struct {
|
||||||
config VBoxBoxConfig
|
config VBoxBoxConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *VBoxBoxPostProcessor) Configure(raw interface{}) error {
|
func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error {
|
||||||
err := mapstructure.Decode(raw, &p.config)
|
for _, raw := range raws {
|
||||||
if err != nil {
|
err := mapstructure.Decode(raw, &p.config)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -179,6 +181,6 @@ func (p *VBoxBoxPostProcessor) renameOVF(dir string) error {
|
||||||
|
|
||||||
var defaultVBoxVagrantfile = `
|
var defaultVBoxVagrantfile = `
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.base_mac = "{{ .BaseMacAddress }}"
|
config.vm.base_mac = "{{ .BaseMacAddress }}"
|
||||||
end
|
end
|
||||||
`
|
`
|
||||||
|
|
|
@ -20,12 +20,15 @@ type VMwareBoxPostProcessor struct {
|
||||||
config VMwareBoxConfig
|
config VMwareBoxConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *VMwareBoxPostProcessor) Configure(raw interface{}) error {
|
func (p *VMwareBoxPostProcessor) Configure(raws ...interface{}) error {
|
||||||
err := mapstructure.Decode(raw, &p.config)
|
for _, raw := range raws {
|
||||||
if err != nil {
|
err := mapstructure.Decode(raw, &p.config)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue