Skip to content

Commit

Permalink
Merge pull request #495 from jstrachan/481-2
Browse files Browse the repository at this point in the history
alternative fix for #481
  • Loading branch information
dgageot authored May 5, 2018
2 parents 339e92d + 41f2f06 commit f161f18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/skaffold/build/tag/env_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ func (c *EnvTemplateTagger) GenerateFullyQualifiedImageName(workingDir string, o
}

envMap["IMAGE_NAME"] = opts.ImageName
envMap["DIGEST"] = opts.Digest
digest := opts.Digest
envMap["DIGEST"] = digest
if digest != "" {
names := strings.SplitN(digest, ":", 2)
if len(names) >= 2 {
envMap["DIGEST_ALGO"] = names[0]
envMap["DIGEST_HEX"] = names[1]
}
}

logrus.Debugf("Executing template %v with environment %v", c.Template, envMap)
if err := c.Template.Execute(&buf, envMap); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/skaffold/build/tag/env_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func TestEnvTemplateTagger_GenerateFullyQualifiedImageName(t *testing.T) {
},
want: "image_name-FOO:latest",
},
{
name: "digest algo hex",
template: "{{.IMAGE_NAME}}:{{.DIGEST_ALGO}}-{{.DIGEST_HEX}}",
opts: &TagOptions{
ImageName: "foo",
Digest: "sha256:abcd",
},
want: "foo:sha256-abcd",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit f161f18

Please sign in to comment.