Skip to content

Commit

Permalink
fix digest storage (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwampDragons committed Oct 29, 2021
1 parent aec29a1 commit 6ab394e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion builder/docker/artifact_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (a *ImportArtifact) stateHCPPackerRegistryMetadata() interface{} {
img.Labels["PackerArtifactID"] = a.Id()
// Digest exists in state if we ran the packer push postprocessor.
digest, ok := data["Digest"].(string)
if ok {
if ok && digest != "" {
img.Labels["ImageDigest"] = digest
}

Expand Down
11 changes: 6 additions & 5 deletions post-processor/docker-push/post-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,19 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
// continue.
data := artifact.State("generated_data")

newGenData := map[string]interface{}{}
castData, ok := data.(map[interface{}]interface{})
if ok {
castData["Digest"] = digest
// The RPC turns our original map[string]interface{} into a
// map[interface]interface so we need to turn it back
newGenData := map[string]interface{}{}
for k, v := range castData {
newGenData[k.(string)] = v
}
stateData["generated_data"] = newGenData
}

newGenData["Digest"] = digest
// The RPC turns our original map[string]interface{} into a
// map[interface]interface so we need to turn it back
stateData["generated_data"] = newGenData

artifact = &docker.ImportArtifact{
BuilderIdValue: BuilderIdImport,
Driver: driver,
Expand Down
8 changes: 0 additions & 8 deletions post-processor/docker-tag/post-processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa
}
}

// Store digest in state's generated data.
digest, err := driver.Digest(artifact.Id())
if err != nil {
err := fmt.Errorf("Error determining pushed Docker image digest")
ui.Error(err.Error())
}

// If artifact is a docker input artifact, re-store the state data.
// Otherwise, write what we want to the state data.
stateData := map[string]interface{}{"docker_tags": RepoTags}
Expand All @@ -125,7 +118,6 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifa

castData, ok := data.(map[interface{}]interface{})
if ok {
castData["Digest"] = digest
// The RPC turns our original map[string]interface{} into a
// map[interface]interface so we need to turn it back
newGenData := map[string]interface{}{}
Expand Down

0 comments on commit 6ab394e

Please sign in to comment.