Skip to content

Commit

Permalink
move them back to docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Jan 25, 2021
1 parent 47c0a4b commit e54e306
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 115 deletions.
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
44 changes: 24 additions & 20 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -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
Expand All @@ -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"]

41 changes: 20 additions & 21 deletions deploy/Dockerfile_debug
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -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 && \
Expand All @@ -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
Expand Down
14 changes: 8 additions & 6 deletions deploy/Dockerfile_slim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 30 additions & 17 deletions deploy/Dockerfile_warmer
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,63 @@
# 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 && \
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

# 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 && \
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=$(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
Expand Down
Loading

0 comments on commit e54e306

Please sign in to comment.