From a5b826d8f09cda41bb896f59a4e6dc0bf6251895 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Tue, 6 Mar 2018 16:21:10 -0800 Subject: [PATCH 1/3] hack: check dep against correct upstream --- hack/dep.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)" From 98826ef9511c49e256441bcc83d9fe635e650625 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 7 Mar 2018 15:38:22 -0800 Subject: [PATCH 2/3] Changed /work-dir to /kbuild --- Makefile | 2 +- integration_tests/executor/Dockerfile | 2 +- integration_tests/integration_test_yaml.go | 2 +- pkg/snapshot/snapshot_test.go | 18 +++++++++--------- pkg/util/fs_util.go | 2 +- pkg/util/fs_util_test.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 80e9fe5f2..df2a2ea82 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ out/executor: $(GO_FILES) out/kbuild: $(GO_FILES) - GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(KBUILD_PACKAGE) + GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(KBUILD_PACKAGE) .PHONY: test test: out/executor out/kbuild 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 c11b901ec..7c59e2e08 100644 --- a/integration_tests/integration_test_yaml.go +++ b/integration_tests/integration_test_yaml.go @@ -48,7 +48,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/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) From 04b9e4bcdffc69a2daaa9774d0ab2e7ff277157d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 7 Mar 2018 15:50:58 -0800 Subject: [PATCH 3/3] Use mutable source directly --- Makefile | 6 +++--- executor/cmd/root.go | 5 +++-- pkg/image/image.go | 21 +++++---------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index df2a2ea82..9d1064eb8 100644 --- a/Makefile +++ b/Makefile @@ -29,17 +29,17 @@ REPOPATH ?= $(ORG)/$(PROJECT) GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*") GO_LDFLAGS := '-extldflags "-static"' -GO_BUILD_TAGS := "containers_image_ostree_stub containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs" +GO_BUILD_TAGS := "containers_image_ostree_stub containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs exclude_graphdriver_overlay" EXECUTOR_PACKAGE = $(REPOPATH)/executor KBUILD_PACKAGE = $(REPOPATH)/kbuild out/executor: $(GO_FILES) - GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(EXECUTOR_PACKAGE) + GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(EXECUTOR_PACKAGE) out/kbuild: $(GO_FILES) - GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(KBUILD_PACKAGE) + GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(KBUILD_PACKAGE) .PHONY: test test: out/executor out/kbuild diff --git a/executor/cmd/root.go b/executor/cmd/root.go index 0afb6dae3..68d39d65f 100644 --- a/executor/cmd/root.go +++ b/executor/cmd/root.go @@ -83,12 +83,13 @@ func execute() error { } // Initialize source image - if err := image.InitializeSourceImage(baseImage); err != nil { + sourceImage, err := image.NewSourceImage(baseImage) + if err != nil { return err } // Execute commands here // Push the image - return image.PushImage(destination) + return image.PushImage(sourceImage, destination) } diff --git a/pkg/image/image.go b/pkg/image/image.go index b76ad1269..a07fe973f 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -26,33 +26,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 { - 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 {