Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ install-syft:

define install-go-tool
@echo "> Installing $(1)..."
$(GOCMD) install $(1)@$(shell $(GOCMD) list -m -f '{{.Version}}' $(2))
GOTOOLCHAIN=go1.25.3 $(GOCMD) install $(1)@$(shell $(GOCMD) list -m -f '{{.Version}}' $(2))
endef

install-goimports:
Expand Down
4 changes: 2 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestVersion(t *testing.T) {
var err error
buildDir, err = os.MkdirTemp("", "lifecycle-acceptance")
h.AssertNil(t, err)
defer func() {
t.Cleanup(func() {
h.AssertNil(t, os.RemoveAll(buildDir))
}()
})

outDir := filepath.Join(buildDir, fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH), "lifecycle")
h.AssertNil(t, os.MkdirAll(outDir, 0755))
Expand Down
2 changes: 1 addition & 1 deletion acceptance/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestAnalyzer(t *testing.T) {
testImageDockerContext := filepath.Join("testdata", "analyzer")
analyzeTest = NewPhaseTest(t, "analyzer", testImageDockerContext)
analyzeTest.Start(t)
defer analyzeTest.Stop(t)
t.Cleanup(func() { analyzeTest.Stop(t) })

analyzeImage = analyzeTest.testImageRef
analyzerPath = analyzeTest.containerBinaryPath
Expand Down
2 changes: 1 addition & 1 deletion acceptance/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestBuilder(t *testing.T) {
"-f", filepath.Join(builderDockerContext, dockerfileName),
),
)
defer h.DockerImageRemoveSafe(t, builderImage)
t.Cleanup(func() { h.DockerImageRemoveSafe(t, builderImage) })

spec.Run(t, "acceptance-builder", testBuilder, spec.Parallel(), spec.Report(report.Terminal{}))
}
Expand Down
2 changes: 1 addition & 1 deletion acceptance/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestCreator(t *testing.T) {
testImageDockerContext := filepath.Join("testdata", "creator")
createTest = NewPhaseTest(t, "creator", testImageDockerContext)
createTest.Start(t)
defer createTest.Stop(t)
t.Cleanup(func() { createTest.Stop(t) })

createImage = createTest.testImageRef
creatorPath = createTest.containerBinaryPath
Expand Down
2 changes: 1 addition & 1 deletion acceptance/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestDetector(t *testing.T) {
detectDockerContext,
h.WithArgs("--build-arg", fmt.Sprintf("cnb_platform_api=%s", api.Platform.Latest())),
)
defer h.DockerImageRemoveSafe(t, detectImage)
t.Cleanup(func() { h.DockerImageRemoveSafe(t, detectImage) })

for _, platformAPI := range api.Platform.Supported {
if platformAPI.LessThan("0.12") {
Expand Down
2 changes: 1 addition & 1 deletion acceptance/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestExporter(t *testing.T) {
exportTest = NewPhaseTest(t, "exporter", testImageDockerContext)

exportTest.Start(t, updateTOMLFixturesWithTestRegistry)
defer exportTest.Stop(t)
t.Cleanup(func() { exportTest.Stop(t) })

exportImage = exportTest.testImageRef
exporterPath = exportTest.containerBinaryPath
Expand Down
84 changes: 71 additions & 13 deletions acceptance/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestExtender(t *testing.T) {
testImageDockerContext := filepath.Join("testdata", "extender")
extendTest = NewPhaseTest(t, "extender", testImageDockerContext)
extendTest.Start(t)
defer extendTest.Stop(t)
t.Cleanup(func() { extendTest.Stop(t) })

extendImage = extendTest.testImageRef
extenderPath = extendTest.containerBinaryPath
Expand Down Expand Up @@ -162,7 +162,15 @@ func testExtenderFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
t.Log("cleans the kaniko directory")
fis, err := os.ReadDir(kanikoDir)
h.AssertNil(t, err)
h.AssertEq(t, len(fis), 1) // 1: /kaniko/cache
var expectedFiles = []string{"cache"}
var actualFiles []string
for _, fi := range fis {
if fi.Name() == "layers" {
continue
}
actualFiles = append(actualFiles, fi.Name())
}
h.AssertEq(t, actualFiles, expectedFiles)

t.Log("second build extends the build image by pulling from the cache directory")
secondOutput := h.DockerRunWithCombinedOutput(t,
Expand Down Expand Up @@ -220,7 +228,22 @@ func testExtenderFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
t.Log("cleans the kaniko directory")
caches, err := os.ReadDir(kanikoDir)
h.AssertNil(t, err)
h.AssertEq(t, len(caches), 1) // 1: /kaniko/cache
var expectedFiles = []string{"cache"}
var actualFiles []string
for _, fi := range caches {
if fi.Name() == "layers" {
continue
}
actualFiles = append(actualFiles, fi.Name())
}
if len(actualFiles) != 1 || actualFiles[0] != "cache" {
var names []string
for _, fi := range caches {
names = append(names, fi.Name())
}
t.Logf("kanikoDir contents (1): %v", names)
}
h.AssertEq(t, actualFiles, expectedFiles)

t.Log("second build extends the build image by pulling from the cache directory")
secondOutput := h.DockerRunWithCombinedOutput(t,
Expand All @@ -241,7 +264,21 @@ func testExtenderFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
t.Log("cleans the kaniko directory")
caches, err = os.ReadDir(kanikoDir)
h.AssertNil(t, err)
h.AssertEq(t, len(caches), 1) // 1: /kaniko/cache
actualFiles = nil
for _, fi := range caches {
if fi.Name() == "layers" {
continue
}
actualFiles = append(actualFiles, fi.Name())
}
if len(actualFiles) != 1 || actualFiles[0] != "cache" {
var names []string
for _, fi := range caches {
names = append(names, fi.Name())
}
t.Logf("kanikoDir contents (2): %v", names)
}
h.AssertEq(t, actualFiles, expectedFiles)
})
})
})
Expand All @@ -254,20 +291,41 @@ func assertExpectedImage(t *testing.T, imagePath, platformAPI string) {
configFile, err := image.ConfigFile()
h.AssertNil(t, err)
h.AssertEq(t, configFile.Config.Labels["io.buildpacks.rebasable"], "false")
layers, err := image.Layers()
_, err = image.Layers()
h.AssertNil(t, err)
history := configFile.History
h.AssertEq(t, len(history), len(configFile.RootFS.DiffIDs))
var expectedLayers []string
if api.MustParse(platformAPI).AtLeast("0.13") {
h.AssertEq(t, len(layers), 7) // base (3), curl (2), tree (2)
h.AssertEq(t, history[3].CreatedBy, "Layer: 'RUN apt-get update && apt-get install -y curl', Created by extension: curl")
h.AssertEq(t, history[4].CreatedBy, "Layer: 'COPY run-file /', Created by extension: curl")
h.AssertEq(t, history[5].CreatedBy, "Layer: 'RUN apt-get update && apt-get install -y tree', Created by extension: tree")
h.AssertEq(t, history[6].CreatedBy, "Layer: 'COPY shared-file /shared-run', Created by extension: tree")
expectedLayers = []string{
"Layer: 'RUN apt-get update && apt-get install -y curl', Created by extension: curl",
"Layer: 'COPY run-file /', Created by extension: curl",
"Layer: 'RUN apt-get update && apt-get install -y tree', Created by extension: tree",
"Layer: 'COPY shared-file /shared-run', Created by extension: tree",
}
} else {
h.AssertEq(t, len(layers), 5) // base (3), curl (1), tree (1)
h.AssertEq(t, history[3].CreatedBy, "Layer: 'RUN apt-get update && apt-get install -y curl', Created by extension: curl")
h.AssertEq(t, history[4].CreatedBy, "Layer: 'RUN apt-get update && apt-get install -y tree', Created by extension: tree")
expectedLayers = []string{
"Layer: 'RUN apt-get update && apt-get install -y curl', Created by extension: curl",
"Layer: 'RUN apt-get update && apt-get install -y tree', Created by extension: tree",
}
}

lastIndex := -1
for _, expected := range expectedLayers {
found := false
for i, hItem := range history {
if hItem.CreatedBy == expected {
if i <= lastIndex {
t.Errorf("expected layer %q to appear after index %d", expected, lastIndex)
}
lastIndex = i
found = true
break
}
}
if !found {
t.Errorf("expected layer %q not found in history", expected)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion acceptance/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestLauncher(t *testing.T) {
phaseTest.containerBinaryDir = containerBinaryDir
}
launchTest.Start(t, withCustomContainerBinaryDir)
defer launchTest.Stop(t)
t.Cleanup(func() { launchTest.Stop(t) })

launchImage = launchTest.testImageRef
launcherPath = launchTest.containerBinaryPath
Expand Down
2 changes: 1 addition & 1 deletion acceptance/restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRestorer(t *testing.T) {
testImageDockerContext := filepath.Join("testdata", "restorer")
restoreTest = NewPhaseTest(t, "restorer", testImageDockerContext)
restoreTest.Start(t, updateTOMLFixturesWithTestRegistry)
defer restoreTest.Stop(t)
t.Cleanup(func() { restoreTest.Stop(t) })

restoreImage = restoreTest.testImageRef
restorerPath = restoreTest.containerBinaryPath
Expand Down
Loading
Loading