Skip to content

Commit

Permalink
Use digest returned after pushing the built invocation image in templ…
Browse files Browse the repository at this point in the history
…ates, as it will depend on which docker version actually built the image.

Signed-off-by: Silvin Lubecki <[email protected]>
  • Loading branch information
silvin-lubecki committed Sep 10, 2019
1 parent 45fdf5a commit 51fc7a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func TestPushAndPullCNAB(t *testing.T) {
}()

// Push the images to the registry
runCmd(t, icmd.Command("docker", "push", invocationImageName))
output := runCmd(t, icmd.Command("docker", "push", invocationImageName))
invocDigest := getDigest(t, output)

runCmd(t, icmd.Command("docker", "push", serviceImageName))

// Templatize the bundle
applyTemplate(t, serviceImageName, invocationImageName, filepath.Join("testdata", "hello-world", "bundle.json.template"), dir.Join("bundle.json"))
applyTemplate(t, serviceImageName, invocationImageName, invocDigest, filepath.Join("testdata", "hello-world", "bundle.json.template"), dir.Join("bundle.json"))

// Save the fixed bundle
runCmd(t, icmd.Command("cnab-to-oci", "fixup", dir.Join("bundle.json"),
Expand All @@ -59,7 +61,7 @@ func TestPushAndPullCNAB(t *testing.T) {
"--auto-update-bundle"))

// Check the fixed bundle
applyTemplate(t, serviceImageName, invocationImageName, filepath.Join("testdata", "bundle.json.golden.template"), filepath.Join("testdata", "bundle.json.golden"))
applyTemplate(t, serviceImageName, invocationImageName, invocDigest, filepath.Join("testdata", "bundle.json.golden.template"), filepath.Join("testdata", "bundle.json.golden"))
buf, err := ioutil.ReadFile(dir.Join("fixed-bundle.json"))
assert.NilError(t, err)
golden.Assert(t, string(buf), "bundle.json.golden")
Expand Down Expand Up @@ -105,14 +107,16 @@ func runCmd(t *testing.T, cmd icmd.Cmd) string {
return result.Stdout()
}

func applyTemplate(t *testing.T, serviceImageName, invocationImageName, templateFile, resultFile string) {
func applyTemplate(t *testing.T, serviceImageName, invocationImageName, invocationDigest, templateFile, resultFile string) {
tmpl, err := template.ParseFiles(templateFile)
assert.NilError(t, err)
data := struct {
InvocationImage string
ServiceImage string
InvocationImage string
InvocationDigest string
ServiceImage string
}{
invocationImageName,
invocationDigest,
serviceImageName,
}
f, err := os.Create(resultFile)
Expand All @@ -133,3 +137,12 @@ func checkRelocationMap(t *testing.T, serviceImageName, invocationImageName, app
assert.Assert(t, strings.HasPrefix(relocationMap[serviceImageName], appImageName))
assert.Assert(t, strings.HasPrefix(relocationMap[invocationImageName], appImageName))
}

func getDigest(t *testing.T, output string) string {
re := regexp.MustCompile(`digest: (.+) size:`)
result := re.FindStringSubmatch(output)
assert.Equal(t, len(result), 2)
digest := result[1]
assert.Assert(t, digest != "")
return digest
}
2 changes: 1 addition & 1 deletion e2e/testdata/bundle.json.golden.template
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"actions":{"io.cnab.status":{}},"definitions":{"port":{"default":"8080","type":"string"},"text":{"default":"Hello, World!","type":"string"}},"description":"Hello, World!","images":{"hello":{"contentDigest":"sha256:61d5cb94d7e546518a7bbd5bee06bfad0ecea8f56a75b084522a43dccbbcd845","description":"hello","image":"{{ .ServiceImage }}","imageType":"docker","mediaType":"application/vnd.docker.distribution.manifest.v2+json","size":528}},"invocationImages":[{"contentDigest":"sha256:5be99f09470367463607bd9eb4139d80fdd0c4020266c503c84f89e795f4e875","image":"{{ .InvocationImage }}","imageType":"docker","mediaType":"application/vnd.docker.distribution.manifest.v2+json","size":941}],"maintainers":[{"email":"[email protected]","name":"user"}],"name":"hello-world","parameters":{"fields":{"definition":"","destination":null}},"schemaVersion":"v1.0.0-WD","version":"0.1.0"}
{"actions":{"io.cnab.status":{}},"definitions":{"port":{"default":"8080","type":"string"},"text":{"default":"Hello, World!","type":"string"}},"description":"Hello, World!","images":{"hello":{"contentDigest":"sha256:61d5cb94d7e546518a7bbd5bee06bfad0ecea8f56a75b084522a43dccbbcd845","description":"hello","image":"{{ .ServiceImage }}","imageType":"docker","mediaType":"application/vnd.docker.distribution.manifest.v2+json","size":528}},"invocationImages":[{"contentDigest":"{{ .InvocationDigest }}","image":"{{ .InvocationImage }}","imageType":"docker","mediaType":"application/vnd.docker.distribution.manifest.v2+json","size":941}],"maintainers":[{"email":"[email protected]","name":"user"}],"name":"hello-world","parameters":{"fields":{"definition":"","destination":null}},"schemaVersion":"v1.0.0-WD","version":"0.1.0"}

0 comments on commit 51fc7a3

Please sign in to comment.