-
Notifications
You must be signed in to change notification settings - Fork 1
/
post-processor.go
40 lines (30 loc) · 870 Bytes
/
post-processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"io/ioutil"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
type Config struct {
OutputPath string `mapstructure:"output"`
ctx interpolate.Context
}
type PostProcessor struct {
config Config
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
if err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
}, raws...); err != nil {
return err
}
return nil
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
imageName := artifact.State("ImageName").(string)
if err := ioutil.WriteFile(p.config.OutputPath, []byte(imageName), 0644); err != nil {
return artifact, false, err
}
return artifact, true, nil
}