diff --git a/executor/cmd/root.go b/executor/cmd/root.go index f0c5be45b..b850756f9 100644 --- a/executor/cmd/root.go +++ b/executor/cmd/root.go @@ -85,7 +85,8 @@ func execute() error { } // Initialize source image - if err := image.InitializeSourceImage(baseImage); err != nil { + sourceImage, err := image.NewSourceImage(baseImage) + if err != nil { return err } @@ -142,5 +143,5 @@ func execute() error { } } // Push the image - return image.PushImage(destination) + return image.PushImage(sourceImage, destination) } diff --git a/hack/dep.sh b/hack/dep.sh index c421fccb4..487d7ee07 100755 --- a/hack/dep.sh +++ b/hack/dep.sh @@ -31,7 +31,7 @@ install_dep() { } if [ -z "$VALIDATE_UPSTREAM" ]; then - VALIDATE_REPO='git@github.com:GoogleCloudPlatform/skaffold.git' + VALIDATE_REPO='git@github.com:GoogleCloudPlatform/k8s-container-builder.git' VALIDATE_BRANCH='master' VALIDATE_HEAD="$(git rev-parse --verify HEAD)" diff --git a/integration_tests/dockerfiles/config_test_run.json b/integration_tests/dockerfiles/config_test_run.json index 53f0a3eb2..5bde728c3 100644 --- a/integration_tests/dockerfiles/config_test_run.json +++ b/integration_tests/dockerfiles/config_test_run.json @@ -4,16 +4,7 @@ "Image2": "gcr.io/kbuild-test/kbuild-test-run:latest", "DiffType": "File", "Diff": { - "Adds": [ - { - "Name": "/bin/bzcat", - "Size": 35448 - }, - { - "Name": "/bin/bzip2", - "Size": 35448 - } - ], + "Adds": null, "Dels": null, "Mods": [ { @@ -54,4 +45,4 @@ ] } } -] \ No newline at end of file +] diff --git a/integration_tests/executor/Dockerfile b/integration_tests/executor/Dockerfile index 9a4595d48..1149c2726 100644 --- a/integration_tests/executor/Dockerfile +++ b/integration_tests/executor/Dockerfile @@ -15,5 +15,5 @@ # Builds the static Go image to execute in a Kubernetes job FROM scratch -ADD out/executor /work-dir/executor +ADD out/executor /kbuild/executor ADD files/ca-certificates.crt /etc/ssl/certs/ diff --git a/integration_tests/integration_test_yaml.go b/integration_tests/integration_test_yaml.go index f422c9989..2598a9487 100644 --- a/integration_tests/integration_test_yaml.go +++ b/integration_tests/integration_test_yaml.go @@ -55,7 +55,7 @@ type testyaml struct { } var executorImage = "executor-image" -var executorCommand = "/work-dir/executor" +var executorCommand = "/kbuild/executor" var dockerImage = "gcr.io/cloud-builders/docker" var ubuntuImage = "ubuntu" var testRepo = "gcr.io/kbuild-test/" diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index e8cfa8ebb..e2477c381 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -1,9 +1,12 @@ /* Copyright 2018 Google LLC + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 9b85387b4..16c138e0c 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -1,9 +1,12 @@ /* Copyright 2018 Google LLC + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/pkg/image/image.go b/pkg/image/image.go index a55c122f8..7f389e9a6 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -27,34 +27,22 @@ import ( ) // sourceImage is the image that will be modified by the executor -var sourceImage img.MutableSource // InitializeSourceImage initializes the source image with the base image -func InitializeSourceImage(srcImg string) error { +func NewSourceImage(srcImg string) (*img.MutableSource, error) { logrus.Infof("Initializing source image %s", srcImg) ref, err := docker.ParseReference("//" + srcImg) if err != nil { - return err + return nil, err } - ms, err := img.NewMutableSource(ref) - if err != nil { - return err - } - sourceImage = *ms - return nil -} - -// AppendLayer appends a layer onto the base image -func AppendLayer(contents []byte, author string) error { - logrus.Info("Appending layer to base image") - return sourceImage.AppendLayer(contents, author) + return img.NewMutableSource(ref) } // PushImage pushes the final image -func PushImage(destImg string) error { +func PushImage(ms *img.MutableSource, destImg string) error { srcRef := &img.ProxyReference{ ImageReference: nil, - Src: &sourceImage, + Src: ms, } destRef, err := alltransports.ParseImageName("docker://" + destImg) if err != nil { diff --git a/pkg/snapshot/snapshot_test.go b/pkg/snapshot/snapshot_test.go index 22263aed3..5e51d88bc 100644 --- a/pkg/snapshot/snapshot_test.go +++ b/pkg/snapshot/snapshot_test.go @@ -37,9 +37,9 @@ func TestSnapshotFileChange(t *testing.T) { } // Make some changes to the filesystem newFiles := map[string]string{ - "foo": "newbaz1", - "bar/bat": "baz", - "work-dir/bat": "bat", + "foo": "newbaz1", + "bar/bat": "baz", + "kbuild/bat": "bat", } if err := testutil.SetupFiles(testDir, newFiles); err != nil { t.Fatalf("Error setting up fs: %s", err) @@ -134,15 +134,15 @@ func TestSnapshotFiles(t *testing.T) { } // Make some changes to the filesystem newFiles := map[string]string{ - "foo": "newbaz1", - "work-dir/file": "bat", + "foo": "newbaz1", + "kbuild/file": "bat", } if err := testutil.SetupFiles(testDir, newFiles); err != nil { t.Fatalf("Error setting up fs: %s", err) } filesToSnapshot := []string{ filepath.Join(testDir, "foo"), - filepath.Join(testDir, "work-dir/file"), + filepath.Join(testDir, "kbuild/file"), } contents, err := snapshotter.TakeSnapshotOfFiles(filesToSnapshot) if err != nil { @@ -197,9 +197,9 @@ func setUpTestDir() (string, *Snapshotter, error) { return testDir, nil, errors.Wrap(err, "setting up temp dir") } files := map[string]string{ - "foo": "baz1", - "bar/bat": "baz2", - "work-dir/file": "file", + "foo": "baz1", + "bar/bat": "baz2", + "kbuild/file": "file", } // Set up initial files if err := testutil.SetupFiles(testDir, files); err != nil { diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 7e767b8d5..eafd18916 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -28,7 +28,7 @@ import ( "strings" ) -var whitelist = []string{"/work-dir"} +var whitelist = []string{"/kbuild"} // ExtractFileSystemFromImage pulls an image and unpacks it to a file system at root func ExtractFileSystemFromImage(img string) error { diff --git a/pkg/util/fs_util_test.go b/pkg/util/fs_util_test.go index a474794c4..ccb7b3658 100644 --- a/pkg/util/fs_util_test.go +++ b/pkg/util/fs_util_test.go @@ -46,7 +46,7 @@ func Test_fileSystemWhitelist(t *testing.T) { } actualWhitelist, err := fileSystemWhitelist(path) - expectedWhitelist := []string{"/work-dir", "/proc", "/dev", "/dev/pts", "/sys"} + expectedWhitelist := []string{"/kbuild", "/proc", "/dev", "/dev/pts", "/sys"} sort.Strings(actualWhitelist) sort.Strings(expectedWhitelist) testutil.CheckErrorAndDeepEqual(t, false, err, expectedWhitelist, actualWhitelist)