Skip to content

Commit

Permalink
Pass previous image explicitly and fix tag slice
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhav committed Nov 23, 2021
1 parent 6091b51 commit 8907075
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,19 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor
return []string{}
}
tags := []string{}
for _, tag := range b.Spec.Tags {
tags = append(tags, "-tag="+tag)
if len(b.Spec.Tags) > 1 {
for _, tag := range b.Spec.Tags[1:] {
tags = append(tags, "-tag="+tag)
}
}
return tags
}(),
func() []string {
if b.Spec.LastBuild != nil && b.Spec.LastBuild.Image != "" {
return []string{b.Spec.LastBuild.Image}
if platformAPILessThan07 {
return []string{b.Spec.LastBuild.Image}
}
return []string{"-previous-image=" + b.Spec.LastBuild.Image, b.Tag()}
}
return []string{b.Tag()}
}(),
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,14 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"home-dir",
}, names(pod.Spec.InitContainers[1].VolumeMounts))
tags := []string{}
for _, tag := range build.Spec.Tags {
for _, tag := range build.Spec.Tags[1:] {
tags = append(tags, "-tag="+tag)
}
assert.Equal(t, append(append([]string{
"-layers=/layers",
"-analyzed=/layers/analyzed.toml"},
tags...),
build.Spec.LastBuild.Image), pod.Spec.InitContainers[1].Args)
"-previous-image="+build.Spec.LastBuild.Image, build.Tag()), pod.Spec.InitContainers[1].Args)
})

it("configures analyze step with the older api", func() {
Expand Down Expand Up @@ -882,7 +882,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"home-dir",
}, names(pod.Spec.InitContainers[1].VolumeMounts))
tags := []string{}
for _, tag := range build.Spec.Tags {
for _, tag := range build.Spec.Tags[1:] {
tags = append(tags, "-tag="+tag)
}
assert.Equal(t, append(append([]string{
Expand Down Expand Up @@ -2201,7 +2201,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
})
assert.Equal(t, []string{"/networkWait/network-wait-launcher"}, analyzeContainer.Command)
tags := []string{}
for _, tag := range build.Spec.Tags {
for _, tag := range build.Spec.Tags[1:] {
tags = append(tags, "-tag="+tag)
}
assert.Equal(t, append(append([]string{
Expand All @@ -2210,7 +2210,7 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"/cnb/lifecycle/analyzer",
"-layers=/layers",
"-analyzed=/layers/analyzed.toml"}, tags...),
"someimage/name@sha256:previous"), analyzeContainer.Args)
"-previous-image=someimage/name@sha256:previous", "someimage/name"), analyzeContainer.Args)
})

it("configures restore step", func() {
Expand Down

0 comments on commit 8907075

Please sign in to comment.