packer: PostProcessor takes a UI [GH-20]

This commit is contained in:
Mitchell Hashimoto 2013-06-18 20:38:21 -07:00
parent 44087ca7df
commit 9e78cbaa89
7 changed files with 16 additions and 10 deletions

View File

@ -169,7 +169,7 @@ PostProcessorRunSeqLoop:
artifact := builderArtifact artifact := builderArtifact
for _, corePP := range ppSeq { for _, corePP := range ppSeq {
var err error var err error
artifact, err = corePP.processor.PostProcess(artifact) artifact, err = corePP.processor.PostProcess(ui, artifact)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err)) errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
continue PostProcessorRunSeqLoop continue PostProcessorRunSeqLoop

View File

@ -19,13 +19,13 @@ func (c *cmdPostProcessor) Configure(config interface{}) error {
return c.p.Configure(config) return c.p.Configure(config)
} }
func (c *cmdPostProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) { func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
defer func() { defer func() {
r := recover() r := recover()
c.checkExit(r, nil) c.checkExit(r, nil)
}() }()
return c.p.PostProcess(a) return c.p.PostProcess(ui, a)
} }
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {

View File

@ -12,7 +12,7 @@ func (helperPostProcessor) Configure(interface{}) error {
return nil return nil
} }
func (helperPostProcessor) PostProcess(packer.Artifact) (packer.Artifact, error) { func (helperPostProcessor) PostProcess(packer.Ui, packer.Artifact) (packer.Artifact, error) {
return nil, nil return nil, nil
} }

View File

@ -13,5 +13,5 @@ type PostProcessor interface {
// 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. // Artifact. If an error occurs, it should return that error.
PostProcess(Artifact) (Artifact, error) PostProcess(Ui, Artifact) (Artifact, error)
} }

View File

@ -5,6 +5,7 @@ type TestPostProcessor struct {
configVal interface{} configVal interface{}
ppCalled bool ppCalled bool
ppArtifact Artifact ppArtifact Artifact
ppUi Ui
} }
func (pp *TestPostProcessor) Configure(v interface{}) error { func (pp *TestPostProcessor) Configure(v interface{}) error {
@ -13,8 +14,9 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return nil return nil
} }
func (pp *TestPostProcessor) PostProcess(a Artifact) (Artifact, error) { func (pp *TestPostProcessor) PostProcess(ui Ui, a Artifact) (Artifact, error) {
pp.ppCalled = true pp.ppCalled = true
pp.ppArtifact = a pp.ppArtifact = a
pp.ppUi = ui
return nil, nil return nil, nil
} }

View File

@ -33,9 +33,10 @@ func (p *postProcessor) Configure(raw interface{}) (err error) {
return return
} }
func (p *postProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) { func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
server := rpc.NewServer() server := rpc.NewServer()
RegisterArtifact(server, a) RegisterArtifact(server, a)
RegisterUi(server, ui)
var response PostProcessorProcessResponse var response PostProcessorProcessResponse
if err := p.client.Call("PostProcessor.PostProcess", serveSingleConn(server), &response); err != nil { if err := p.client.Call("PostProcessor.PostProcess", serveSingleConn(server), &response); err != nil {
@ -71,7 +72,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
responseAddress := "" responseAddress := ""
artifact, err := p.p.PostProcess(Artifact(client)) artifact, err := p.p.PostProcess(&Ui{client}, Artifact(client))
if err == nil && artifact != nil { if err == nil && artifact != nil {
server := rpc.NewServer() server := rpc.NewServer()
RegisterArtifact(server, artifact) RegisterArtifact(server, artifact)

View File

@ -13,6 +13,7 @@ type TestPostProcessor struct {
configVal interface{} configVal interface{}
ppCalled bool ppCalled bool
ppArtifact packer.Artifact ppArtifact packer.Artifact
ppUi packer.Ui
} }
func (pp *TestPostProcessor) Configure(v interface{}) error { func (pp *TestPostProcessor) Configure(v interface{}) error {
@ -21,9 +22,10 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return nil return nil
} }
func (pp *TestPostProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) { func (pp *TestPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
pp.ppCalled = true pp.ppCalled = true
pp.ppArtifact = a pp.ppArtifact = a
pp.ppUi = ui
return testPostProcessorArtifact, nil return testPostProcessorArtifact, nil
} }
@ -60,7 +62,8 @@ func TestPostProcessorRPC(t *testing.T) {
// Test PostProcess // Test PostProcess
a := new(testArtifact) a := new(testArtifact)
artifact, err := pClient.PostProcess(a) ui := new(testUi)
artifact, err := pClient.PostProcess(ui, a)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }