From fef4bb55b7b5b3b2e660c4565d13ee84bc9e0ac4 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Tue, 12 May 2020 14:46:25 +0200 Subject: [PATCH 01/12] image: prepend library/ when using registry Signed-off-by: Yoan Blanc --- pkg/util/image_util.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/util/image_util.go b/pkg/util/image_util.go index 9f1e68e51..f241210f9 100644 --- a/pkg/util/image_util.go +++ b/pkg/util/image_util.go @@ -22,6 +22,7 @@ import ( "net/http" "path/filepath" "strconv" + "strings" "github.com/GoogleContainerTools/kaniko/pkg/timing" @@ -118,6 +119,13 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) { return nil, err } + if !strings.ContainsRune(image, '/') { + ref, err = name.ParseReference("library/"+image, name.WeakValidation) + if err != nil { + return nil, err + } + } + toSet = true } From ce8298bb14ac420324de96bf55194285023d98d6 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 6 Jun 2020 10:31:42 +0200 Subject: [PATCH 02/12] image: add test Signed-off-by: Yoan Blanc --- pkg/image/image_util.go | 23 ++++++++++++++++++----- pkg/image/image_util_test.go | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/pkg/image/image_util.go b/pkg/image/image_util.go index c4e044235..44f2f399f 100644 --- a/pkg/image/image_util.go +++ b/pkg/image/image_util.go @@ -118,11 +118,9 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) { return nil, err } - if !strings.ContainsRune(image, '/') { - ref, err = name.ParseReference("library/"+image, name.WeakValidation) - if err != nil { - return nil, err - } + ref, err = normalizeReference(ref, image) + if err != nil { + return nil, err } toSet = true @@ -142,16 +140,31 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) { tag.Repository.Registry = newReg ref = tag } + if digest, ok := ref.(name.Digest); ok { digest.Repository.Registry = newReg ref = digest } } + logrus.Infof("Retrieving image %s", ref) + rOpts := remoteOptions(registryName, opts) return remote.Image(ref, rOpts...) } +// normalizeReference adds the library/ prefix to images without it. +// +// It is mostly useful when using a registry mirror that is not able to perform +// this fix automatically. +func normalizeReference(ref name.Reference, image string) (name.Reference, error) { + if !strings.ContainsRune(image, '/') { + return name.ParseReference("library/"+image, name.WeakValidation) + } + + return ref, nil +} + func remoteOptions(registryName string, opts *config.KanikoOptions) []remote.Option { tr := util.MakeTransport(opts, registryName) diff --git a/pkg/image/image_util_test.go b/pkg/image/image_util_test.go index 3b9e039cf..4a99d4ef1 100644 --- a/pkg/image/image_util_test.go +++ b/pkg/image/image_util_test.go @@ -20,6 +20,7 @@ import ( "bytes" "testing" + "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/empty" "github.com/moby/buildkit/frontend/dockerfile/instructions" @@ -109,6 +110,25 @@ func Test_ScratchImageFromMirror(t *testing.T) { testutil.CheckErrorAndDeepEqual(t, false, err, expected, actual) } +func Test_normalizeReference(t *testing.T) { + image := "debian" + expected := "index.docker.io/library/debian:latest" + + ref, err := name.ParseReference(image) + if err != nil { + t.Fatal(err) + } + + ref2, err := normalizeReference(ref, image) + if err != nil { + t.Fatal(err) + } + + if ref2.Name() != ref.Name() || ref2.Name() != expected { + t.Errorf("%s should have been normalized to %s, got %s", ref2.Name(), expected, ref.Name()) + } +} + // parse parses the contents of a Dockerfile and returns a list of commands func parse(s string) ([]instructions.Stage, error) { p, err := parser.Parse(bytes.NewReader([]byte(s))) From ca23ae441e1abeab7f27a724e1ff503ca5dd7d4a Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Jun 2020 09:49:11 +0200 Subject: [PATCH 03/12] add should fail on 40x Signed-off-by: Yoan Blanc --- integration/dockerfiles/Dockerfile_test_add_404 | 4 ++++ pkg/util/fs_util.go | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 integration/dockerfiles/Dockerfile_test_add_404 diff --git a/integration/dockerfiles/Dockerfile_test_add_404 b/integration/dockerfiles/Dockerfile_test_add_404 new file mode 100644 index 000000000..21b31ae1f --- /dev/null +++ b/integration/dockerfiles/Dockerfile_test_add_404 @@ -0,0 +1,4 @@ +FROM debian:9.11 + +# Testing that any HTTP failure is handled properly +ADD https://httpstat.us/404 . diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 9a34f2974..38c91357e 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -545,6 +545,11 @@ func DownloadFileToDest(rawurl, dest string, uid, gid int64) error { return err } defer resp.Body.Close() + + if resp.StatusCode >= 400 { + return fmt.Errorf("%s failed with %d", rawurl, resp.StatusCode) + } + if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil { return err } From 8cc772ae9c1ea1e7c1e5659af861a78312af467e Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Jun 2020 10:15:50 +0200 Subject: [PATCH 04/12] fixup! add should fail on 40x Signed-off-by: Yoan Blanc --- integration/images.go | 1 + integration/integration_test.go | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/integration/images.go b/integration/images.go index ea5d1f464..3c3f0ccd7 100644 --- a/integration/images.go +++ b/integration/images.go @@ -167,6 +167,7 @@ type DockerFileBuilder struct { func NewDockerFileBuilder() *DockerFileBuilder { d := DockerFileBuilder{filesBuilt: map[string]struct{}{}} d.DockerfilesToIgnore = map[string]struct{}{ + "Dockerfile_test_add_404": {}, // TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed "Dockerfile_test_user_run": {}, } diff --git a/integration/integration_test.go b/integration/integration_test.go index 117ba76d7..8eb356923 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -386,6 +386,45 @@ func TestBuildWithLabels(t *testing.T) { checkContainerDiffOutput(t, diff, expected) } +func TestBuildWithHTTPError(t *testing.T) { + repo := getGitRepo() + dockerfile := fmt.Sprintf("%s/%s/Dockerfile_test_add_404", integrationPath, dockerfilesPath) + + // Build with docker + dockerImage := GetDockerImage(config.imageRepo, "Dockerfile_test_add_404") + dockerCmd := exec.Command("docker", + append([]string{"build", + "-t", dockerImage, + "-f", dockerfile, + repo})...) + out, err := RunCommandWithoutTest(dockerCmd) + if err != nil { + t.Errorf("Failed to build image %s with docker command %q: %s %s", dockerImage, dockerCmd.Args, err, string(out)) + } + + // Build with kaniko + kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_add_404") + dockerRunFlags := []string{"run", "--net=host"} + dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount) + dockerRunFlags = append(dockerRunFlags, ExecutorImage, + "-f", dockerfile, + "-d", kanikoImage, + "-c", fmt.Sprintf("git://%s", repo), + ) + + kanikoCmd := exec.Command("docker", dockerRunFlags...) + + out, err = RunCommandWithoutTest(kanikoCmd) + if err != nil { + t.Errorf("Failed to build image %s with kaniko command %q: %v %s", dockerImage, kanikoCmd.Args, err, string(out)) + } + + diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") + + expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) + checkContainerDiffOutput(t, diff, expected) +} + func TestLayers(t *testing.T) { offset := map[string]int{ "Dockerfile_test_add": 12, From 999365f5f9aa56e65f07d99080d7dde570aff30a Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Jun 2020 10:42:59 +0200 Subject: [PATCH 05/12] fixup! fixup! add should fail on 40x Signed-off-by: Yoan Blanc --- integration/integration_test.go | 17 ++++++----------- pkg/util/fs_util.go | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 8eb356923..4406fe42c 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -397,9 +397,9 @@ func TestBuildWithHTTPError(t *testing.T) { "-t", dockerImage, "-f", dockerfile, repo})...) - out, err := RunCommandWithoutTest(dockerCmd) - if err != nil { - t.Errorf("Failed to build image %s with docker command %q: %s %s", dockerImage, dockerCmd.Args, err, string(out)) + _, err := RunCommandWithoutTest(dockerCmd) + if err == nil { + t.Fatalf("an error was expected") } // Build with kaniko @@ -414,15 +414,10 @@ func TestBuildWithHTTPError(t *testing.T) { kanikoCmd := exec.Command("docker", dockerRunFlags...) - out, err = RunCommandWithoutTest(kanikoCmd) - if err != nil { - t.Errorf("Failed to build image %s with kaniko command %q: %v %s", dockerImage, kanikoCmd.Args, err, string(out)) + _, err = RunCommandWithoutTest(kanikoCmd) + if err == nil { + t.Fatalf("an error was expected") } - - diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") - - expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) - checkContainerDiffOutput(t, diff, expected) } func TestLayers(t *testing.T) { diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 38c91357e..71657ac94 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -547,7 +547,7 @@ func DownloadFileToDest(rawurl, dest string, uid, gid int64) error { defer resp.Body.Close() if resp.StatusCode >= 400 { - return fmt.Errorf("%s failed with %d", rawurl, resp.StatusCode) + return fmt.Errorf("invalid response status %d", resp.StatusCode) } if err := CreateFile(dest, resp.Body, 0600, uint32(uid), uint32(gid)); err != nil { From 5412ac65da6968f233d216cda39e4428f6163f43 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sat, 20 Jun 2020 10:46:41 +0200 Subject: [PATCH 06/12] fixup! fixup! fixup! add should fail on 40x Signed-off-by: Yoan Blanc --- integration/integration_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 4406fe42c..6f0b9b8a6 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -397,9 +397,9 @@ func TestBuildWithHTTPError(t *testing.T) { "-t", dockerImage, "-f", dockerfile, repo})...) - _, err := RunCommandWithoutTest(dockerCmd) + out, err := RunCommandWithoutTest(dockerCmd) if err == nil { - t.Fatalf("an error was expected") + t.Errorf("an error was expected, got %s", string(out)) } // Build with kaniko @@ -414,9 +414,9 @@ func TestBuildWithHTTPError(t *testing.T) { kanikoCmd := exec.Command("docker", dockerRunFlags...) - _, err = RunCommandWithoutTest(kanikoCmd) + out, err = RunCommandWithoutTest(kanikoCmd) if err == nil { - t.Fatalf("an error was expected") + t.Errorf("an error was expected, got %s", string(out)) } } From df3a57d293f04a3190e2a97f20b6cdbb8c09aa2d Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 30 Jun 2020 10:23:50 -0700 Subject: [PATCH 07/12] upgrade version --- CHANGELOG.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97a00174..d738526d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,77 @@ +# v0.24.0 Release 2020-07-01 +This is the 24th release of Kaniko! + +New features: +* Add a new run command along with a new flag [#1300](https://github.com/GoogleContainerTools/kaniko/pull/1300) +* Add redo snapshotter. [#1301](https://github.com/GoogleContainerTools/kaniko/pull/1301) +* Add pkg.dev to automagic config file population [#1328](https://github.com/GoogleContainerTools/kaniko/pull/1328) +* kaniko now clone git repositories recursing submodules by default [#1320](https://github.com/GoogleContainerTools/kaniko/pull/1320) + +Bug fixes: +* Fix README.md [#1323](https://github.com/GoogleContainerTools/kaniko/pull/1323) +* Fix docker-credential-gcr owner and group id [#1307](https://github.com/GoogleContainerTools/kaniko/pull/1307) + +Refactors: +* check file changed in loop [#1302](https://github.com/GoogleContainerTools/kaniko/pull/1302) +* ADD GCB benchmark code [#1299](https://github.com/GoogleContainerTools/kaniko/pull/1299) +* benchmark FileSystem snapshot project added [#1288](https://github.com/GoogleContainerTools/kaniko/pull/1288) +* [Perf] Reduce loops over files when taking FS snapshot. [#1283](https://github.com/GoogleContainerTools/kaniko/pull/1283) +* Fix README.md [#1323](https://github.com/GoogleContainerTools/kaniko/pull/1323) +* Fix docker-credential-gcr owner and group id [#1307](https://github.com/GoogleContainerTools/kaniko/pull/1307) +* benchmark FileSystem snapshot project added [#1288](https://github.com/GoogleContainerTools/kaniko/pull/1288) +* [Perf] Reduce loops over files when taking FS snapshot. [#1283](https://github.com/GoogleContainerTools/kaniko/pull/1283) + +Huge thank you for this release towards our contributors: +- Alexander Sharov +- Alex Szakaly +- Anthony Davies +- Art Begolli +- Batuhan Apaydın +- Ben Einaudi +- Carlos Alexandro Becker +- Carlos Sanchez +- Chris Sng +- Cole Wippern +- cvgw +- Daniel Marks +- Dani Raznikov +- David Dooling +- DracoBlue +- Gábor Lipták +- Gabriel Virga +- Gilbert Gilb's +- Giovan Isa Musthofa +- James Ravn +- Jon Henrik Bjørnstad +- Jon Johnson +- Jordan Goasdoué +- Liubov Grinkevich +- Logan.Price +- Lukasz Jakimczuk +- Mehdi Abaakouk +- Michel Hollands +- Mitchell Friedman +- Moritz Wanzenböck +- ohchang-kwon +- Or Sela +- PhoenixMage +- priyawadhwa +- Sam Stoelinga +- Tejal Desai +- Thomas Bonfort +- Thomas Stromberg +- Thomas Strömberg +- tinkerborg +- Tom Prince +- Vincent Latombe +- Wietse Muizelaar +- xanonid +- Yoan Blanc +- Yoriyasu Yano +- Yuheng Zhang +- yw-liu + + # v0.23.0 Release 2020-06-04 This is the 23rd release of Kaniko! diff --git a/Makefile b/Makefile index 0966fe693..5c40d51fd 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ # Bump these on release VERSION_MAJOR ?= 0 -VERSION_MINOR ?= 23 +VERSION_MINOR ?= 24 VERSION_BUILD ?= 0 VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) From b569cc1913ccda668b1eb2aba40287b28219551f Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 1 Jul 2020 15:47:47 +0200 Subject: [PATCH 08/12] Bump version number mismatch --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0966fe693..6aa1f629b 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,8 @@ # Bump these on release VERSION_MAJOR ?= 0 -VERSION_MINOR ?= 23 -VERSION_BUILD ?= 0 +VERSION_MINOR ?= 24 +VERSION_BUILD ?= 1 VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) VERSION_PACKAGE = $(REPOPATH/pkg/version) From 699a4bee326ee3cd73b5ac4670e93c713715fb52 Mon Sep 17 00:00:00 2001 From: Christopher Hlubek Date: Thu, 16 Jul 2020 10:56:59 +0200 Subject: [PATCH 09/12] Bugfix: Reproducible layers with whiteout When deleting files of previous layers, the whiteout files were not added to the tar file in a consistent order. This change adds a stable sorting to the whiteout files and adds unit tests to check for stable sorting. --- pkg/snapshot/snapshot.go | 6 ++ pkg/snapshot/snapshot_test.go | 154 ++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index e8523d4e3..c0b0a3131 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -108,6 +108,9 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string, } } } + + sort.Strings(filesToWhiteout) + t := util.NewTar(f) defer t.Close() if err := writeToTar(t, filesToAdd, filesToWhiteout); err != nil { @@ -178,7 +181,10 @@ func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) { } } timing.DefaultRun.Stop(timer) + sort.Strings(filesToAdd) + sort.Strings(filesToWhiteOut) + // Add files to the layered map for _, file := range filesToAdd { if err := s.l.Add(file); err != nil { diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 7150ae0c4..37bcf23a4 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -391,6 +391,160 @@ func TestSnasphotPreservesFileOrder(t *testing.T) { } } +func TestSnasphotPreservesWhiteoutOrder(t *testing.T) { + newFiles := map[string]string{ + "foo": "newbaz1", + "bar/bat": "baz", + "bar/qux": "quuz", + "qux": "quuz", + "corge": "grault", + "garply": "waldo", + "fred": "plugh", + "xyzzy": "thud", + } + + newFileNames := []string{} + + for fileName := range newFiles { + newFileNames = append(newFileNames, fileName) + } + + filesInTars := [][]string{} + + for i := 0; i <= 2; i++ { + testDir, snapshotter, cleanup, err := setUpTest() + testDirWithoutLeadingSlash := strings.TrimLeft(testDir, "/") + defer cleanup() + + if err != nil { + t.Fatal(err) + } + // Make some changes to the filesystem + if err := testutil.SetupFiles(testDir, newFiles); err != nil { + t.Fatalf("Error setting up fs: %s", err) + } + + filesToSnapshot := []string{} + for _, file := range newFileNames { + filesToSnapshot = append(filesToSnapshot, filepath.Join(testDir, file)) + } + + // Take a snapshot + _, err = snapshotter.TakeSnapshot(filesToSnapshot, false) + if err != nil { + t.Fatalf("Error taking snapshot of fs: %s", err) + } + + // Delete all files + for p := range newFiles { + err := os.Remove(filepath.Join(testDir, p)) + if err != nil { + t.Fatalf("Error deleting file: %s", err) + } + } + + // Take a snapshot again + tarPath, err := snapshotter.TakeSnapshot(filesToSnapshot, true) + if err != nil { + t.Fatalf("Error taking snapshot of fs: %s", err) + } + + f, err := os.Open(tarPath) + if err != nil { + t.Fatal(err) + } + tr := tar.NewReader(f) + filesInTars = append(filesInTars, []string{}) + for { + hdr, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + t.Fatal(err) + } + filesInTars[i] = append(filesInTars[i], strings.TrimPrefix(hdr.Name, testDirWithoutLeadingSlash)) + } + } + + // Check contents of all snapshots, make sure files appear in consistent order + for i := 1; i < len(filesInTars); i++ { + testutil.CheckErrorAndDeepEqual(t, false, nil, filesInTars[0], filesInTars[i]) + } +} + + +func TestSnasphotFSPreservesWhiteoutOrder(t *testing.T) { + newFiles := map[string]string{ + "foo": "newbaz1", + "bar/bat": "baz", + "bar/qux": "quuz", + "qux": "quuz", + "corge": "grault", + "garply": "waldo", + "fred": "plugh", + "xyzzy": "thud", + } + + filesInTars := [][]string{} + + for i := 0; i <= 2; i++ { + testDir, snapshotter, cleanup, err := setUpTest() + testDirWithoutLeadingSlash := strings.TrimLeft(testDir, "/") + defer cleanup() + + if err != nil { + t.Fatal(err) + } + // Make some changes to the filesystem + if err := testutil.SetupFiles(testDir, newFiles); err != nil { + t.Fatalf("Error setting up fs: %s", err) + } + + // Take a snapshot + _, err = snapshotter.TakeSnapshotFS() + if err != nil { + t.Fatalf("Error taking snapshot of fs: %s", err) + } + + // Delete all files + for p := range newFiles { + err := os.Remove(filepath.Join(testDir, p)) + if err != nil { + t.Fatalf("Error deleting file: %s", err) + } + } + + // Take a snapshot again + tarPath, err := snapshotter.TakeSnapshotFS() + if err != nil { + t.Fatalf("Error taking snapshot of fs: %s", err) + } + + f, err := os.Open(tarPath) + if err != nil { + t.Fatal(err) + } + tr := tar.NewReader(f) + filesInTars = append(filesInTars, []string{}) + for { + hdr, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + t.Fatal(err) + } + filesInTars[i] = append(filesInTars[i], strings.TrimPrefix(hdr.Name, testDirWithoutLeadingSlash)) + } + } + + // Check contents of all snapshots, make sure files appear in consistent order + for i := 1; i < len(filesInTars); i++ { + testutil.CheckErrorAndDeepEqual(t, false, nil, filesInTars[0], filesInTars[i]) + } +} + func TestSnapshotOmitsUnameGname(t *testing.T) { _, snapshotter, cleanup, err := setUpTest() From 5c61bc44bd4f79df9a3b9522327d3c933a830c86 Mon Sep 17 00:00:00 2001 From: Christopher Hlubek Date: Mon, 20 Jul 2020 11:35:25 +0200 Subject: [PATCH 10/12] Remove unreliable unit test for SnasphotFS with whiteout --- pkg/snapshot/snapshot_test.go | 72 ----------------------------------- 1 file changed, 72 deletions(-) diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 37bcf23a4..c10b68426 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -473,78 +473,6 @@ func TestSnasphotPreservesWhiteoutOrder(t *testing.T) { } } - -func TestSnasphotFSPreservesWhiteoutOrder(t *testing.T) { - newFiles := map[string]string{ - "foo": "newbaz1", - "bar/bat": "baz", - "bar/qux": "quuz", - "qux": "quuz", - "corge": "grault", - "garply": "waldo", - "fred": "plugh", - "xyzzy": "thud", - } - - filesInTars := [][]string{} - - for i := 0; i <= 2; i++ { - testDir, snapshotter, cleanup, err := setUpTest() - testDirWithoutLeadingSlash := strings.TrimLeft(testDir, "/") - defer cleanup() - - if err != nil { - t.Fatal(err) - } - // Make some changes to the filesystem - if err := testutil.SetupFiles(testDir, newFiles); err != nil { - t.Fatalf("Error setting up fs: %s", err) - } - - // Take a snapshot - _, err = snapshotter.TakeSnapshotFS() - if err != nil { - t.Fatalf("Error taking snapshot of fs: %s", err) - } - - // Delete all files - for p := range newFiles { - err := os.Remove(filepath.Join(testDir, p)) - if err != nil { - t.Fatalf("Error deleting file: %s", err) - } - } - - // Take a snapshot again - tarPath, err := snapshotter.TakeSnapshotFS() - if err != nil { - t.Fatalf("Error taking snapshot of fs: %s", err) - } - - f, err := os.Open(tarPath) - if err != nil { - t.Fatal(err) - } - tr := tar.NewReader(f) - filesInTars = append(filesInTars, []string{}) - for { - hdr, err := tr.Next() - if err == io.EOF { - break - } - if err != nil { - t.Fatal(err) - } - filesInTars[i] = append(filesInTars[i], strings.TrimPrefix(hdr.Name, testDirWithoutLeadingSlash)) - } - } - - // Check contents of all snapshots, make sure files appear in consistent order - for i := 1; i < len(filesInTars); i++ { - testutil.CheckErrorAndDeepEqual(t, false, nil, filesInTars[0], filesInTars[i]) - } -} - func TestSnapshotOmitsUnameGname(t *testing.T) { _, snapshotter, cleanup, err := setUpTest() From 29a02b08ff4bc4ea185f52e88d29b389abb8761b Mon Sep 17 00:00:00 2001 From: Joe Kutner Date: Sun, 26 Jul 2020 14:28:00 -0500 Subject: [PATCH 11/12] Move snapshotPathPrefix into a method This allows the value to be determined on the fly, which supports consumers that use Kaniko snaphot as a library and may need to change the value of config.KanikoDir --- pkg/snapshot/snapshot.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index e8523d4e3..dfbc49177 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -33,7 +33,7 @@ import ( ) // For testing -var snapshotPathPrefix = config.KanikoDir +var snapshotPathPrefix = "" // Snapshotter holds the root directory from which to take snapshots, and a list of snapshots taken type Snapshotter struct { @@ -119,7 +119,7 @@ func (s *Snapshotter) TakeSnapshot(files []string, shdCheckDelete bool) (string, // TakeSnapshotFS takes a snapshot of the filesystem, avoiding directories in the ignorelist, and creates // a tarball of the changed files. func (s *Snapshotter) TakeSnapshotFS() (string, error) { - f, err := ioutil.TempFile(snapshotPathPrefix, "") + f, err := ioutil.TempFile(s.getSnashotPathPrefix(), "") if err != nil { return "", err } @@ -138,6 +138,13 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) { return f.Name(), nil } +func (s *Snapshotter) getSnashotPathPrefix() string { + if snapshotPathPrefix == "" { + return config.KanikoDir + } + return snapshotPathPrefix +} + func (s *Snapshotter) scanFullFilesystem() ([]string, []string, error) { logrus.Info("Taking snapshot of full filesystem...") From 5f0d30534f67ba77a173d226c5d183617e18f887 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 28 Jul 2020 15:10:07 -0700 Subject: [PATCH 12/12] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6aa1f629b..5c40d51fd 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ # Bump these on release VERSION_MAJOR ?= 0 VERSION_MINOR ?= 24 -VERSION_BUILD ?= 1 +VERSION_BUILD ?= 0 VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) VERSION_PACKAGE = $(REPOPATH/pkg/version)