From 04b9e4bcdffc69a2daaa9774d0ab2e7ff277157d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 7 Mar 2018 15:50:58 -0800 Subject: [PATCH] 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 {