From 6722a6ba0cbc1acb681389ae8745968e27fe7b0a Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Wed, 19 Apr 2017 16:37:28 -0700 Subject: [PATCH] post-processor/checksum: fix output template --- post-processor/checksum/post-processor.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/post-processor/checksum/post-processor.go b/post-processor/checksum/post-processor.go index 8da32d5d9..9f95755c6 100644 --- a/post-processor/checksum/post-processor.go +++ b/post-processor/checksum/post-processor.go @@ -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)