Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 6a6c547

Browse files
authored
Merge pull request #980 from PhoenixMage/PR646_rebase_fix
Prefer platform that is currently running for pulling remote images and kaniko binary Makefile target
2 parents d362359 + 76f0bf4 commit 6a6c547

6 files changed

Lines changed: 27 additions & 9 deletions

File tree

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ VERSION_MINOR ?= 16
1818
VERSION_BUILD ?= 0
1919

2020
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
21+
VERSION_PACKAGE = $(REPOPATH/pkg/version)
2122

2223
SHELL := /bin/bash
2324
GOOS ?= $(shell go env GOOS)
24-
GOARCH = amd64
25+
GOARCH ?= $(shell go env GOARCH)
2526
ORG := github.com/GoogleContainerTools
2627
PROJECT := kaniko
2728
REGISTRY?=gcr.io/kaniko-project
@@ -38,7 +39,7 @@ GO_LDFLAGS += '
3839
EXECUTOR_PACKAGE = $(REPOPATH)/cmd/executor
3940
WARMER_PACKAGE = $(REPOPATH)/cmd/warmer
4041
KANIKO_PROJECT = $(REPOPATH)/kaniko
41-
BUILD_ARG ?=
42+
BUILD_ARG ?=
4243

4344
# Force using Go Modules and always read the dependencies from
4445
# the `vendor` folder.
@@ -62,9 +63,9 @@ integration-test:
6263

6364
.PHONY: images
6465
images:
65-
docker build ${BUILD_ARG} -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
66-
docker build ${BUILD_ARG} -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug .
67-
docker build ${BUILD_ARG} -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer .
66+
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
67+
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug .
68+
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer .
6869

6970
.PHONY: push
7071
push:

deploy/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Builds the static Go image to execute in a Kubernetes job
1616

1717
FROM golang:1.12
18+
ARG GOARCH=amd64
1819
WORKDIR /go/src/github.com/GoogleContainerTools/kaniko
1920
# Get GCR credential helper
2021
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
2829
RUN tar -C /usr/local/bin/ -xvzf /usr/local/bin/docker-credential-acr-linux-amd64.tar.gz
2930

3031
COPY . .
31-
RUN make
32+
RUN make GOARCH=${GOARCH}
3233

3334
FROM scratch
3435
COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/executor /kaniko/executor

deploy/Dockerfile_debug

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# Stage 0: Build the executor binary and get credential helpers
1818
FROM golang:1.12
19+
ARG GOARCH=amd64
1920
WORKDIR /go/src/github.com/GoogleContainerTools/kaniko
2021
# Get GCR credential helper
2122
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
2526
RUN go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login
2627
RUN make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper linux-amd64
2728
COPY . .
28-
RUN make && make out/warmer
29+
RUN make GOARCH=${GOARCH} && make out/warmer
2930

3031
# Stage 1: Get the busybox shell
3132
FROM gcr.io/cloud-builders/bazel:latest

deploy/Dockerfile_warmer

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Builds the static Go image to execute in a Kubernetes job
1616

1717
FROM golang:1.12
18+
ARG GOARCH=amd64
1819
WORKDIR /go/src/github.com/GoogleContainerTools/kaniko
1920
# Get GCR credential helper
2021
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
2526
RUN make -C /go/src/github.com/awslabs/amazon-ecr-credential-helper linux-amd64
2627

2728
COPY . .
28-
RUN make out/warmer
29+
RUN make GOARCH=${GOARCH} out/warmer
2930

3031
FROM scratch
3132
COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/warmer /kaniko/warmer

pkg/util/image_util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ func remoteOptions(registryName string, opts *config.KanikoOptions) []remote.Opt
134134
}
135135
}
136136

137-
return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain())}
137+
// on which v1.Platform is this currently running?
138+
platform := currentPlatform()
139+
140+
return []remote.Option{remote.WithTransport(tr), remote.WithAuthFromKeychain(creds.GetKeychain()), remote.WithPlatform(platform)}
138141
}
139142

140143
func cachedImage(opts *config.KanikoOptions, image string) (v1.Image, error) {

pkg/util/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ import (
2222
"encoding/hex"
2323
"io"
2424
"os"
25+
"runtime"
2526
"strconv"
2627
"sync"
2728
"syscall"
2829

2930
"github.com/minio/highwayhash"
3031
"github.com/pkg/errors"
3132
"github.com/sirupsen/logrus"
33+
34+
v1 "github.com/google/go-containerregistry/pkg/v1"
3235
)
3336

3437
// ConfigureLogging sets the logrus logging level and forces logs to be colorful (!)
@@ -138,3 +141,11 @@ func SHA256(r io.Reader) (string, error) {
138141
}
139142
return hex.EncodeToString(hasher.Sum(make([]byte, 0, hasher.Size()))), nil
140143
}
144+
145+
// CurrentPlatform returns the v1.Platform on which the code runs
146+
func currentPlatform() v1.Platform {
147+
return v1.Platform{
148+
OS: runtime.GOOS,
149+
Architecture: runtime.GOARCH,
150+
}
151+
}

0 commit comments

Comments
 (0)