From e54e306176a0d12e51b7cf9cbbd559d3150186e2 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Sun, 24 Jan 2021 19:37:02 -0800 Subject: [PATCH] move them back to docker build --- .travis.yml | 24 +++++++ Makefile | 25 +++++--- deploy/Dockerfile | 44 +++++++------ deploy/Dockerfile_debug | 41 ++++++------ deploy/Dockerfile_slim | 14 ++-- deploy/Dockerfile_warmer | 47 +++++++++----- integration/BUILD | 109 ++++++++++++++++++++++++++++++++ integration/config.go | 1 - integration/images.go | 12 ++-- integration/integration_test.go | 16 ++--- scripts/integration-test.sh | 2 +- scripts/minikube-setup.sh | 2 +- scripts/travis-setup.sh | 26 ++------ 13 files changed, 248 insertions(+), 115 deletions(-) create mode 100644 integration/BUILD diff --git a/.travis.yml b/.travis.yml index bc5aa7fc4f..a4cd99b5a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,3 +37,27 @@ jobs: script: - make integration-test-misc + - name: bazel amd64 + arch: amd64 + env: CPU=k8 + before_install: &before_install_multiarch + - export PATH=$PATH:$HOME/bin && mkdir -p $HOME/bin + - eval $(go env) + # install bazelisk as bazel to install the appropriate bazel version + - wget https://github.com/bazelbuild/bazelisk/releases/download/v1.6.1/bazelisk-linux-${GOARCH} && chmod +x bazelisk-linux-${GOARCH} && mv bazelisk-linux-${GOARCH} $HOME/bin/bazel + script: &script_multiarch + # Generate BUILD.bazel files (we do not check them in) + - bazel run //:gazelle + - bazel build --cpu=${CPU} --curses=no //integration:all + # Build all targets tagged with our architecture: + - bazel build --cpu=${CPU} --curses=no $(bazel query 'attr("tags", "'${GOARCH}'", "//...")') + # Run all tests not tagged as "manual": + - bazel test --cpu=${CPU} --curses=no --test_output=errors --test_timeout=900 //integration:all + # Run all tests tagged with our architecture: + - bazel test --cpu=${CPU} --curses=no --test_output=errors --test_timeout=900 $(bazel query 'attr("tags", "'${GOARCH}'", "//...")') + + - name: bazel arm64 + arch: arm64 + env: CPU=aarch64 + before_install: *before_install_multiarch + script: *script_multiarch \ No newline at end of file diff --git a/Makefile b/Makefile index be8b0107bd..486ba00e8e 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ GO_LDFLAGS += ' EXECUTOR_PACKAGE = $(REPOPATH)/cmd/executor WARMER_PACKAGE = $(REPOPATH)/cmd/warmer KANIKO_PROJECT = $(REPOPATH)/kaniko -BUILD_ARG ?=--platform linux/amd64 +BUILD_ARG ?= # Force using Go Modules and always read the dependencies from # the `vendor` folder. @@ -71,24 +71,29 @@ integration-test: .PHONY: integration-test-run integration-test-run: - @ ./scripts/integration-test.sh --run "TestRun" + @ ./scripts/integration-test.sh -run "TestRun" .PHONY: integration-test-layers integration-test-layers: - @ ./scripts/integration-test.sh --run "TestLayers" + @ ./scripts/integration-test.sh -run "TestLayers" .PHONY: integration-test-k8s integration-test-k8s: - @ ./scripts/integration-test.sh --run "TestK8s" + @ ./scripts/integration-test.sh -run "TestK8s" .PHONY: integration-test-misc integration-test-misc: - # $(eval RUN_ARG=$(shell ./scripts/misc-integration-test.sh)) - # @ ./scripts/integration-test.sh -run "$(RUN_ARG)" + $(eval RUN_ARG=$(shell ./scripts/misc-integration-test.sh)) + @ ./scripts/integration-test.sh -run "$(RUN_ARG)" .PHONY: images images: - docker buildx --builder build build ${BUILD_ARG} --push -t $(REGISTRY)/executor:latest -f deploy/Dockerfile . - docker buildx --builder build build ${BUILD_ARG} --push -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug . - docker buildx --builder build build ${BUILD_ARG} --push -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer . - + docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile . + docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug . + docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer . + +.PHONY: push +push: + docker push $(REGISTRY)/executor:latest + docker push $(REGISTRY)/executor:debug + docker push $(REGISTRY)/warmer:latest diff --git a/deploy/Dockerfile b/deploy/Dockerfile index 4ff3465304..2438fb4629 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -12,42 +12,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Get the BUILDPLATFORM ARG # Builds the static Go image to execute in a Kubernetes job -FROM --platform=${BUILDPLATFORM} golang:1.14 as build_env -ARG BUILDPLATFORM -ARG TARGETPLATFORM -ARG TARGETARCH -#Capture all the args -RUN echo "I am running on $BUILDPLATFORM building for $TARGETPLATFORM with $TARGETARCH" +FROM golang:1.14 +ARG GOARCH=amd64 WORKDIR /go/src/github.com/GoogleContainerTools/kaniko +RUN echo $GOARCH > /goarch + +#This arg is passed by docker buildx & contains the platform info in the form linux/amd64, linux/ppc64le etc. +ARG TARGETPLATFORM + +#Capture ARCH has write to /goarch +RUN [ ! "x" = "x$TARGETPLATFORM" ] && `echo $TARGETPLATFORM | awk '{split($0,a,"/"); print a[2]}' > /goarch` || echo "$GOARCH" + # Get GCR credential helper -RUN GOARCH=${TARGETARCH} && CGO_ENABLED=0 && \ +RUN GOARCH=$(cat /goarch) && CGO_ENABLED=0 && \ (mkdir -p /go/src/github.com/GoogleCloudPlatform || true) && \ cd /go/src/github.com/GoogleCloudPlatform && \ git clone https://github.com/GoogleCloudPlatform/docker-credential-gcr.git && \ cd /go/src/github.com/GoogleCloudPlatform/docker-credential-gcr && \ make deps OUT_DIR=/usr/local/bin && \ - go build -ldflags "-linkmode external -extldflags -static" -i -o /usr/local/bin/docker-credential-gcr main.go + go build -ldflags "-linkmode external -extldflags -static" -i -o /usr/local/bin/docker-credential-gcr main.go # Get Amazon ECR credential helper -RUN GOARCH=${TARGETARCH} && go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login && \ +RUN GOARCH=$(cat /goarch) && go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login && \ make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper # ACR docker credential helper COPY ./acr.patch / -RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/Azure || true) && \ +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/Azure || true) && \ cd /go/src/github.com/Azure && \ git clone https://github.com/Azure/acr-docker-credential-helper && \ cd /go/src/github.com/Azure/acr-docker-credential-helper && \ git checkout a79b541f3ee761f6cc4511863ed41fb038c19464 && \ git apply < /acr.patch && \ make && cp -f bin/linux/${GOARCH}/docker-credential-acr-linux /usr/local/bin/docker-credential-acr-linux - + #ACR docker env credential helper -RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/chrismellard || true) && \ +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/chrismellard || true) && \ cd /go/src/github.com/chrismellard && \ git clone https://github.com/chrismellard/docker-credential-acr-env && \ cd docker-credential-acr-env && \ @@ -57,16 +60,15 @@ RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/chrismellard || true) RUN mkdir -p /kaniko/.docker COPY . . -RUN make GOARCH=${TARGETARCH} +RUN make GOARCH=$(cat /goarch.txt) FROM scratch -COPY --from=build_env /go/src/github.com/GoogleContainerTools/kaniko/out/executor /kaniko/executor -COPY --from=build_env /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr -COPY --from=build_env /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/local/docker-credential-ecr-login /kaniko/docker-credential-ecr-login -COPY --from=build_env /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr -COPY --from=build_env /usr/local/bin/docker-credential-acr-env /kaniko/docker-credential-acr-env +COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/executor /kaniko/executor +COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr +COPY --from=0 /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/local/docker-credential-ecr-login /kaniko/docker-credential-ecr-login +COPY --from=0 /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr COPY files/ca-certificates.crt /kaniko/ssl/certs/ -COPY --from=build_env /kaniko/.docker /kaniko/.docker +COPY --from=0 /kaniko/.docker /kaniko/.docker COPY files/nsswitch.conf /etc/nsswitch.conf ENV HOME /root ENV USER root @@ -76,4 +78,6 @@ ENV DOCKER_CONFIG /kaniko/.docker/ ENV DOCKER_CREDENTIAL_GCR_CONFIG /kaniko/.config/gcloud/docker_credential_gcr_config.json WORKDIR /workspace RUN ["docker-credential-gcr", "config", "--token-source=env"] + ENTRYPOINT ["/kaniko/executor"] + diff --git a/deploy/Dockerfile_debug b/deploy/Dockerfile_debug index b3c0f2fc40..aacac0b37d 100644 --- a/deploy/Dockerfile_debug +++ b/deploy/Dockerfile_debug @@ -13,18 +13,21 @@ # limitations under the License. # Builds the static Go image to execute in a Kubernetes job -FROM --platform=${BUILDPLATFORM} golang:1.14 as build_env -ARG BUILDPLATFORM + +# Stage 0: Build the executor binary and get credential helpers +FROM golang:1.14 +ARG GOARCH=amd64 + +#This arg is passed by docker buildx & contains the platform info in the form linux/amd64, linux/ppc64le etc. ARG TARGETPLATFORM -ARG TARGETARCH -#Capture all the args -RUN echo "I am running on $BUILDPLATFORM building for $TARGETPLATFORM with $TARGETARCH" +#Capture ARCH has write to /goarch +RUN [ ! "x" = "x$TARGETPLATFORM" ] && `echo $TARGETPLATFORM | awk '{split($0,a,"/"); print a[2]}' > /goarch` || echo "$GOARCH" WORKDIR /go/src/github.com/GoogleContainerTools/kaniko # Get GCR credential helper -RUN GOARCH=${TARGETARCH} && CGO_ENABLED=0 && \ +RUN GOARCH=$(cat /goarch) && CGO_ENABLED=0 && \ (mkdir -p /go/src/github.com/GoogleCloudPlatform || true) && \ cd /go/src/github.com/GoogleCloudPlatform && \ git clone https://github.com/GoogleCloudPlatform/docker-credential-gcr.git && \ @@ -33,12 +36,12 @@ RUN GOARCH=${TARGETARCH} && CGO_ENABLED=0 && \ go build -ldflags "-linkmode external -extldflags -static" -i -o /usr/local/bin/docker-credential-gcr main.go # Get Amazon ECR credential helper -RUN GOARCH=${TARGETARCH} && go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login && \ +RUN GOARCH=$(cat /goarch) && go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login && \ make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper # ACR docker credential helper COPY ./acr.patch / -RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/Azure || true) && \ +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/Azure || true) && \ cd /go/src/github.com/Azure && \ git clone https://github.com/Azure/acr-docker-credential-helper && \ cd /go/src/github.com/Azure/acr-docker-credential-helper && \ @@ -47,35 +50,31 @@ RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/Azure || true) && \ make && cp -f bin/linux/${GOARCH}/docker-credential-acr-linux /usr/local/bin/docker-credential-acr-linux #ACR docker env credential helper -RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/chrismellard || true) && \ +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/chrismellard || true) && \ cd /go/src/github.com/chrismellard && \ git clone https://github.com/chrismellard/docker-credential-acr-env && \ cd docker-credential-acr-env && \ make build && cp -f ./build/docker-credential-acr-env /usr/local/bin - # Add .docker config dir RUN mkdir -p /kaniko/.docker COPY . . -RUN make GOARCH=${TARGETARCH} && make GOARCH=${TARGETARCH} out/warmer - -FROM --platform=$TARGETPLATFORM busybox:1.32.0 as busybox-arch -ARG $TARGETPLATFORM +RUN make GOARCH=$(cat /goarch.txt) && make out/warmer FROM scratch -COPY --from=build_env /go/src/github.com/GoogleContainerTools/kaniko/out/* /kaniko/ -COPY --from=build_env /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr -COPY --from=build_env /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/local/docker-credential-ecr-login /kaniko/docker-credential-ecr-login -COPY --from=build_env /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr -COPY --from=build_env /usr/local/bin/docker-credential-acr-env /kaniko/docker-credential-acr-env -COPY --from=busybox-arch /bin /busybox +COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/* /kaniko/ +COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr +COPY --from=0 /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/linux-amd64/docker-credential-ecr-login /kaniko/docker-credential-ecr-login +COPY --from=0 /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr +COPY --from=0 /usr/local/bin/docker-credential-acr-env /kaniko/docker-credential-acr-env +COPY --from=amd64/busybox:1.32.0 /bin /busybox # Declare /busybox as a volume to get it automatically in the path to ignore VOLUME /busybox COPY files/ca-certificates.crt /kaniko/ssl/certs/ -COPY --from=build_env /kaniko/.docker /kaniko/.docker +COPY --from=0 /kaniko/.docker /kaniko/.docker COPY files/nsswitch.conf /etc/nsswitch.conf ENV HOME /root ENV USER /root diff --git a/deploy/Dockerfile_slim b/deploy/Dockerfile_slim index e6de8bd7de..a1ee6c6130 100644 --- a/deploy/Dockerfile_slim +++ b/deploy/Dockerfile_slim @@ -13,18 +13,20 @@ # limitations under the License. # Builds the static Go image to execute in a Kubernetes job -FROM --platform=${BUILDPLATFORM} golang:1.14 as build_env -ARG BUILDPLATFORM +FROM golang:1.14 as build_env +RUN echo $GOARCH > /goarch + +#This arg is passed by docker buildx & contains the platform info in the form linux/amd64, linux/ppc64le etc. ARG TARGETPLATFORM -ARG TARGETARCH -#Capture all the args -RUN echo "I am running on $BUILDPLATFORM building for $TARGETPLATFORM with $TARGETARCH" +#Capture ARCH has write to /goarch +RUN [ ! "x" = "x$TARGETPLATFORM" ] && `echo $TARGETPLATFORM | awk '{split($0,a,"/"); print a[2]}' > /goarch` || echo "$GOARCH" + WORKDIR /go/src/github.com/GoogleContainerTools/kaniko COPY . . -RUN make GOARCH=${TARGETARCH} +RUN make GOARCH=$(cat /goarch) FROM scratch COPY --from=build_env /go/src/github.com/GoogleContainerTools/kaniko/out/executor /kaniko/executor diff --git a/deploy/Dockerfile_warmer b/deploy/Dockerfile_warmer index 96b0b3e40f..a91af036bb 100644 --- a/deploy/Dockerfile_warmer +++ b/deploy/Dockerfile_warmer @@ -12,19 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=${BUILDPLATFORM} golang:1.14 as build_env -ARG BUILDPLATFORM -ARG TARGETPLATFORM -ARG TARGETARCH - -#Capture all the args -RUN echo "I am running on $BUILDPLATFORM building for $TARGETPLATFORM with $TARGETARCH" +# Builds the static Go image to execute in a Kubernetes job +FROM golang:1.14 +ARG GOARCH=amd64 WORKDIR /go/src/github.com/GoogleContainerTools/kaniko -# Get GCR credential helper -RUN GOARCH=${TARGETARCH} && CGO_ENABLED=0 && \ + +#This arg is passed by docker buildx & contains the platform info in the form linux/amd64, linux/ppc64le etc. +ARG TARGETPLATFORM + +#Capture ARCH has write to /goarch +RUN [ ! "x" = "x$TARGETPLATFORM" ] && `echo $TARGETPLATFORM | awk '{split($0,a,"/"); print a[2]}' > /goarch` || echo "$GOARCH" + +# Get GCR credential helper +RUN GOARCH=$(cat /goarch) && CGO_ENABLED=0 && \ (mkdir -p /go/src/github.com/GoogleCloudPlatform || true) && \ cd /go/src/github.com/GoogleCloudPlatform && \ git clone https://github.com/GoogleCloudPlatform/docker-credential-gcr.git && \ @@ -32,9 +35,13 @@ RUN GOARCH=${TARGETARCH} && CGO_ENABLED=0 && \ make deps OUT_DIR=/usr/local/bin && \ go build -ldflags "-linkmode external -extldflags -static" -i -o /usr/local/bin/docker-credential-gcr main.go +# Get Amazon ECR credential helper +RUN GOARCH=$(cat /goarch) && go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login && \ + make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper + # ACR docker credential helper COPY ./acr.patch / -RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/Azure || true) && \ +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/Azure || true) && \ cd /go/src/github.com/Azure && \ git clone https://github.com/Azure/acr-docker-credential-helper && \ cd /go/src/github.com/Azure/acr-docker-credential-helper && \ @@ -42,20 +49,26 @@ RUN GOARCH=${TARGETARCH} && (mkdir -p /go/src/github.com/Azure || true) && \ git apply < /acr.patch && \ make && cp -f bin/linux/${GOARCH}/docker-credential-acr-linux /usr/local/bin/docker-credential-acr-linux +#ACR docker env credential helper +RUN GOARCH=$(cat /goarch) && (mkdir -p /go/src/github.com/chrismellard || true) && \ + cd /go/src/github.com/chrismellard && \ + git clone https://github.com/chrismellard/docker-credential-acr-env && \ + cd docker-credential-acr-env && \ + make build && cp -f ./build/docker-credential-acr-env /usr/local/bin + # Add .docker config dir RUN mkdir -p /kaniko/.docker COPY . . -RUN make GOARCH=${TARGETARCH} out/warmer +RUN make GOARCH=${GOARCH} out/warmer FROM scratch -COPY --from=build_env /go/src/github.com/GoogleContainerTools/kaniko/out/warmer /kaniko/warmer -COPY --from=build_env /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr -COPY --from=build_env /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/local/docker-credential-ecr-login /kaniko/docker-credential-ecr-login -COPY --from=build_env /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr -COPY --from=build_env /usr/local/bin/docker-credential-acr-env /kaniko/docker-credential-acr-env +COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/warmer /kaniko/warmer +COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr +COPY --from=0 /go/src/github.com/awslabs/amazon-ecr-credential-helper/bin/linux-amd64/docker-credential-ecr-login /kaniko/docker-credential-ecr-login +COPY --from=0 /usr/local/bin/docker-credential-acr-linux /kaniko/docker-credential-acr COPY files/ca-certificates.crt /kaniko/ssl/certs/ -COPY --from=build_env /kaniko/.docker /kaniko/.docker +COPY --from=0 /kaniko/.docker /kaniko/.docker COPY files/nsswitch.conf /etc/nsswitch.conf ENV HOME /root ENV USER /root diff --git a/integration/BUILD b/integration/BUILD new file mode 100644 index 0000000000..2ba82f9bc7 --- /dev/null +++ b/integration/BUILD @@ -0,0 +1,109 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "integration", + srcs = [ + "cleanup.go", + "cmd.go", + "config.go", + "gcs.go", + "images.go", + ], + importpath = "github.com/GoogleContainerTools/kaniko/integration", + tags = ["manual"], + visibility = ["//visibility:public"], + deps = ["//pkg/timing"], +) + +go_test( + name = "integration_test", + srcs = [ + "benchmark_test.go", + "integration_test.go", + "integration_with_context_test.go", + "integration_with_stdin_test.go", + "k8s_test.go", + ], + data = glob(["testdata/**"]), + embed = [":integration"], + tags = ["manual"], + deps = [ + "//pkg/timing", + "//pkg/util", + "//testutil", + "//vendor/github.com/google/go-containerregistry/pkg/name", + "//vendor/github.com/google/go-containerregistry/pkg/v1/daemon", + "//vendor/github.com/pkg/errors", + ], +) + +load("@io_bazel_rules_docker//container:container.bzl", "container_image") +load("@io_bazel_rules_docker//contrib:test.bzl", "container_test") + +ARCHITECTURES = [ + "amd64", + "arm64", +] + +# Image with testdata +[ + container_image( + name = "buildtest_image_" + arch, + architecture = arch, + base = "//cmd/executor:image_" + arch, + directory = "/workspace", + files = [ + ":testdata/Dockerfile.trivial", + ], + ) + for arch in ARCHITECTURES +] + +# Non-executable tests can run on any architecture, +# so do not tag them. +[ + container_test( + name = "image_files_" + arch + "_test", + configs = ["testdata/files.yaml"], + image = "//cmd/executor:image_" + arch, + ) + for arch in ARCHITECTURES +] + +[ + container_test( + name = "buildtest_image_" + arch + "_test", + configs = [ + "testdata/files.yaml", + "testdata/testfiles.yaml", + ], + image = ":buildtest_image_" + arch, + ) + for arch in ARCHITECTURES +] + +[ + container_test( + name = "image_exec_" + arch + "_test", + configs = ["testdata/exec.yaml"], + image = "//cmd/executor:image_" + arch, + tags = [ + "manual", + arch, + ], + ) + for arch in ARCHITECTURES +] + +[ + container_test( + name = "image_build_" + arch + "_test", + configs = ["testdata/build.yaml"], + image = ":buildtest_image_" + arch, + tags = [ + "manual", + arch, + ], + ) + for arch in ARCHITECTURES +] diff --git a/integration/config.go b/integration/config.go index edec9452b1..2a6df72a21 100644 --- a/integration/config.go +++ b/integration/config.go @@ -25,7 +25,6 @@ type integrationTestConfig struct { hardlinkBaseImage string serviceAccount string dockerMajorVersion int - localRegistry bool } const gcrRepoPrefix string = "gcr.io/" diff --git a/integration/images.go b/integration/images.go index 5cf4446ab2..36ec390c55 100644 --- a/integration/images.go +++ b/integration/images.go @@ -33,6 +33,11 @@ import ( ) const ( + // ExecutorImage is the name of the kaniko executor image + ExecutorImage = "executor-image" + //WarmerImage is the name of the kaniko cache warmer image + WarmerImage = "warmer-image" + dockerPrefix = "docker-" kanikoPrefix = "kaniko-" buildContextPath = "/workspace" @@ -83,13 +88,6 @@ var outputChecks = map[string]func(string, []byte) error{ "Dockerfile_test_arg_secret": checkArgsNotPrinted, } -var ( - // ExecutorImage is the name of the kaniko executor image - ExecutorImage = "executor-image" - //WarmerImage is the name of the kaniko cache warmer image - WarmerImage = "warmer-image" -) - // Checks if argument are not printed in output. // Argument may be passed through --build-arg key=value manner or --build-arg key with key in environment func checkArgsNotPrinted(dockerfile string, out []byte) error { diff --git a/integration/integration_test.go b/integration/integration_test.go index 2d00bb14db..ad8d7ab49f 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -84,10 +84,7 @@ func getDockerMajorVersion() int { return ver } func launchTests(m *testing.M) (int, error) { - if config.localRegistry { - ExecutorImage = "localhost:5000/executor-image" - WarmerImage = "localhost:5000/warmer-image" - } + if config.isGcrRepository() { contextFile, err := CreateIntegrationTarball() if err != nil { @@ -137,18 +134,17 @@ func TestMain(m *testing.M) { } func buildRequiredImages() error { - setupCommands := []struct { name string command []string }{ { name: "Building kaniko image", - command: append([]string{"docker", "buildx", "build", "--platform", "linux/amd64", "-t", ExecutorImage, "--push", "-f", "../deploy/Dockerfile", ".."}), + command: []string{"docker", "build", "-t", ExecutorImage, "-f", "../deploy/Dockerfile", ".."}, }, { name: "Building cache warmer image", - command: append([]string{"docker", "buildx", "build", "--platform", "linux/amd64", "-t", WarmerImage, "--push", "-f", "../deploy/Dockerfile_warmer", ".."}), + command: []string{"docker", "build", "-t", WarmerImage, "-f", "../deploy/Dockerfile_warmer", ".."}, }, { name: "Building onbuild base image", @@ -169,7 +165,7 @@ func buildRequiredImages() error { } for _, setupCmd := range setupCommands { - fmt.Println(setupCmd.name, "-", strings.Join(setupCmd.command, " ")) + fmt.Println(setupCmd.name) cmd := exec.Command(setupCmd.command[0], setupCmd.command[1:]...) if out, err := RunCommandWithoutTest(cmd); err != nil { return errors.Wrap(err, fmt.Sprintf("%s failed: %s", setupCmd.name, string(out))) @@ -714,8 +710,6 @@ func initIntegrationTestConfig() *integrationTestConfig { flag.StringVar(&c.gcsBucket, "bucket", "gs://kaniko-test-bucket", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.") flag.StringVar(&c.imageRepo, "repo", "gcr.io/kaniko-test", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo or serviceAccount must be set.") flag.StringVar(&c.serviceAccount, "serviceAccount", "", "The path to the service account push images to GCR and upload/download files to GCS.") - flag.BoolVar(&c.localRegistry, "localRegistry", false, "Build setup images against local registry") - flag.Parse() if len(c.serviceAccount) > 0 { @@ -767,5 +761,7 @@ func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte containerdiffCmd := exec.Command("container-diff", flags...) diff := RunCommand(containerdiffCmd, t) + t.Logf("diff = %s", string(diff)) + return diff } diff --git a/scripts/integration-test.sh b/scripts/integration-test.sh index 26e8c2ae89..07ac75bdb4 100755 --- a/scripts/integration-test.sh +++ b/scripts/integration-test.sh @@ -24,4 +24,4 @@ docker version echo "Running integration tests..." make out/executor make out/warmer -go test ./integration/... -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --localRegistry true --timeout 50m "$@" +go test ./integration/... -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 50m "$@" diff --git a/scripts/minikube-setup.sh b/scripts/minikube-setup.sh index cba57f905e..34ba001302 100755 --- a/scripts/minikube-setup.sh +++ b/scripts/minikube-setup.sh @@ -34,7 +34,7 @@ sudo mv minikube /usr/local/bin/ sudo apt-get update sudo apt-get install -y liblz4-tool -sudo minikube start --vm-driver=none --force-systemd +sudo minikube start --vm-driver=none sudo minikube status sudo chown -R $USER $HOME/.kube $HOME/.minikube kubectl cluster-info diff --git a/scripts/travis-setup.sh b/scripts/travis-setup.sh index da021f3775..c8e9578430 100755 --- a/scripts/travis-setup.sh +++ b/scripts/travis-setup.sh @@ -15,28 +15,12 @@ set -ex -curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64 && chmod +x container-diff-linux-amd64 && sudo mv container-diff-linux-amd64 /usr/local/bin/container-diff - -sudo rm -rf /var/lib/apt/lists/* curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) edge" +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update -mkdir -p $HOME/.docker/ -echo '{"experimental": "enabled"}' > $HOME/.docker/config.json -echo '{"experimental": "enabled", "exec-opts": ["native.cgroupdriver=systemd"]}' | sudo tee /etc/docker/daemon.json - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce +curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64 && chmod +x container-diff-linux-amd64 && sudo mv container-diff-linux-amd64 /usr/local/bin/container-diff +docker run -d -p 5000:5000 --restart always --name registry registry:2 -mkdir -vp ~/.docker/cli-plugins/ -curl --silent -L "https://github.com/docker/buildx/releases/download/v0.5.1/buildx-v0.5.1.linux-amd64" > ~/.docker/cli-plugins/docker-buildx -chmod a+x ~/.docker/cli-plugins/docker-buildx -docker buildx version -docker info - -# This has to be set otherwise the default driver will not work to push to local registry -docker buildx create --use --name build --node build --driver-opt network=host --platform=linux/amd64 - -docker run -d -p 5000:5000 --restart always --name registry registry:2.6.2 -docker ps | grep registry - - +mkdir -p $HOME/.docker/ +echo '{}' > $HOME/.docker/config.json