post-processor/checksum: fix output template

This commit is contained in:
Matthew Hooker 2017-04-19 16:37:28 -07:00
parent 3608d81319
commit 6722a6ba0c
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
1 changed files with 19 additions and 3 deletions

View File

@ -30,6 +30,13 @@ type PostProcessor struct {
config Config
}
type outputPathTemplate struct {
BuildName string
BuilderType string
ArtifactID string
HashType string
}
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
@ -46,7 +53,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
if p.config.OutputPath == "" {
p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}" + ".checksum"
p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}_{{.HashType}}.checksum"
}
errs := new(packer.MultiError)
@ -85,15 +92,24 @@ func getHash(t string) hash.Hash {
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, error) {
files := artifact.Files()
var h hash.Hash
var checksumFile string
newartifact := NewArtifact(artifact.Files())
opTpl := &outputPathTemplate{
BuildName: p.config.PackerBuildName,
BuilderType: p.config.PackerBuilderType,
ArtifactID: artifact.Id(),
}
for _, ct := range p.config.ChecksumTypes {
h = getHash(ct)
opTpl.HashType = ct
p.config.ctx.Data = &opTpl
for _, art := range files {
checksumFile = p.config.OutputPath
checksumFile, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
return nil, false, err
}
if _, err := os.Stat(checksumFile); err != nil {
newartifact.files = append(newartifact.files, checksumFile)