From ed22afc19be2933b1930e6e1f4171f6823db0e4a Mon Sep 17 00:00:00 2001 From: Anthony Davies Date: Mon, 20 Jan 2020 13:43:45 +1100 Subject: [PATCH 1/2] Rebase fix for PR #646 I needed this for my arm64 k8s cluster. I have zero Go experience but enough experience with other things to fix the rebase (I think!). This patch is working fine on my cluster. --- Makefile | 11 ++++++----- deploy/Dockerfile | 3 ++- deploy/Dockerfile_debug | 3 ++- deploy/Dockerfile_warmer | 3 ++- pkg/util/image_util.go | 5 ++++- pkg/util/util.go | 11 +++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index b7d4c4516f..132f992ddc 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,11 @@ VERSION_MINOR ?= 16 VERSION_BUILD ?= 0 VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) +VERSION_PACKAGE = $(REPOPATH/pkg/version) SHELL := /bin/bash GOOS ?= $(shell go env GOOS) -GOARCH = amd64 +GOARCH ?= $(shell go env GOARCH) ORG := github.com/GoogleContainerTools PROJECT := kaniko REGISTRY?=gcr.io/kaniko-project @@ -38,7 +39,7 @@ GO_LDFLAGS += ' EXECUTOR_PACKAGE = $(REPOPATH)/cmd/executor WARMER_PACKAGE = $(REPOPATH)/cmd/warmer KANIKO_PROJECT = $(REPOPATH)/kaniko -BUILD_ARG ?= +BUILD_ARG ?= # Force using Go Modules and always read the dependencies from # the `vendor` folder. @@ -62,9 +63,9 @@ integration-test: .PHONY: images images: - docker build ${BUILD_ARG} -t $(REGISTRY)/executor:latest -f deploy/Dockerfile . - docker build ${BUILD_ARG} -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug . - docker build ${BUILD_ARG} -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: diff --git a/deploy/Dockerfile b/deploy/Dockerfile index f8ca388a1a..1ed34a4d8e 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -15,6 +15,7 @@ # Builds the static Go image to execute in a Kubernetes job FROM golang:1.12 +ARG GOARCH=amd64 WORKDIR /go/src/github.com/GoogleContainerTools/kaniko # Get GCR credential helper ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.5.0/docker-credential-gcr_linux_amd64-1.5.0.tar.gz /usr/local/bin/ @@ -28,7 +29,7 @@ ADD https://aadacr.blob.core.windows.net/acr-docker-credential-helper/docker-cre RUN tar -C /usr/local/bin/ -xvzf /usr/local/bin/docker-credential-acr-linux-amd64.tar.gz COPY . . -RUN make +RUN make GOARCH=${GOARCH} FROM scratch COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/executor /kaniko/executor diff --git a/deploy/Dockerfile_debug b/deploy/Dockerfile_debug index c1e4107f77..a57151babc 100644 --- a/deploy/Dockerfile_debug +++ b/deploy/Dockerfile_debug @@ -16,6 +16,7 @@ # Stage 0: Build the executor binary and get credential helpers FROM golang:1.12 +ARG GOARCH=amd64 WORKDIR /go/src/github.com/GoogleContainerTools/kaniko # Get GCR credential helper ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.5.0/docker-credential-gcr_linux_amd64-1.5.0.tar.gz /usr/local/bin/ @@ -25,7 +26,7 @@ RUN docker-credential-gcr configure-docker RUN go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login RUN make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper linux-amd64 COPY . . -RUN make && make out/warmer +RUN make GOARCH=${GOARCH} && make out/warmer # Stage 1: Get the busybox shell FROM gcr.io/cloud-builders/bazel:latest diff --git a/deploy/Dockerfile_warmer b/deploy/Dockerfile_warmer index 0ae81ead9b..b81df44130 100644 --- a/deploy/Dockerfile_warmer +++ b/deploy/Dockerfile_warmer @@ -15,6 +15,7 @@ # Builds the static Go image to execute in a Kubernetes job FROM golang:1.12 +ARG GOARCH=amd64 WORKDIR /go/src/github.com/GoogleContainerTools/kaniko # Get GCR credential helper ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.5.0/docker-credential-gcr_linux_amd64-1.5.0.tar.gz /usr/local/bin/ @@ -25,7 +26,7 @@ RUN go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/dock RUN make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper linux-amd64 COPY . . -RUN make out/warmer +RUN make GOARCH=${GOARCH} out/warmer FROM scratch COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/warmer /kaniko/warmer diff --git a/pkg/util/image_util.go b/pkg/util/image_util.go index a654e815cc..a214528f49 100644 --- a/pkg/util/image_util.go +++ b/pkg/util/image_util.go @@ -134,7 +134,10 @@ func remoteOptions(registryName string, opts *config.KanikoOptions) []remote.Opt } } - return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain())} + // on which v1.Platform is this currently running? + platform := currentPlatform() + + return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain()), remote.WithPlatform(platform)} } func cachedImage(opts *config.KanikoOptions, image string) (v1.Image, error) { diff --git a/pkg/util/util.go b/pkg/util/util.go index 8ba5d88f3a..03a7f9bb8b 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -22,6 +22,7 @@ import ( "encoding/hex" "io" "os" + "runtime" "strconv" "sync" "syscall" @@ -29,6 +30,8 @@ import ( "github.com/minio/highwayhash" "github.com/pkg/errors" "github.com/sirupsen/logrus" + + "github.com/google/go-containerregistry/pkg/v1" ) // ConfigureLogging sets the logrus logging level and forces logs to be colorful (!) @@ -138,3 +141,11 @@ func SHA256(r io.Reader) (string, error) { } return hex.EncodeToString(hasher.Sum(make([]byte, 0, hasher.Size()))), nil } + +// CurrentPlatform returns the v1.Platform on which the code runs +func currentPlatform() v1.Platform { + return v1.Platform{ + OS: runtime.GOOS, + Architecture: runtime.GOARCH, + } +} From 76f0bf44e5c48a1e96fcfbf0d58a334106b2ab9f Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 21 Jan 2020 15:22:49 -0800 Subject: [PATCH 2/2] fix hack linter --- pkg/util/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/util.go b/pkg/util/util.go index 03a7f9bb8b..3d3755ae8d 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -31,7 +31,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/google/go-containerregistry/pkg/v1" + v1 "github.com/google/go-containerregistry/pkg/v1" ) // ConfigureLogging sets the logrus logging level and forces logs to be colorful (!)