Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Dockerfile): use temporary busybox mount to create /kaniko directory #2155

Merged
merged 23 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,10 @@ k8s-executor-build-push:
DOCKER_BUILDKIT=1 docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
docker push $(REGISTRY)/executor:latest

files/kaniko:
mkdir files/kaniko

files/kaniko.tar: files/kaniko
chmod 777 files/kaniko
cd files && tar cf kaniko.tar kaniko

.PHONY: images
images: DOCKER_BUILDKIT=1
images: files/kaniko.tar
images:
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)/executor:slim -f deploy/Dockerfile_slim .
Expand Down
11 changes: 7 additions & 4 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ RUN mkdir -p /kaniko/.docker

COPY . .
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH

# Generate latest ca-certificates
FROM debian:bullseye-slim AS certs
RUN apt update && apt install -y ca-certificates

FROM scratch
# Create kaniko directory with world write permission to allow non root run
ADD files/kaniko.tar /
RUN --mount=from=busybox:latest,src=/bin/,dst=/bin/ \
mkdir -p /kaniko && \
chmod 777 /kaniko

COPY --from=0 /src/out/executor /kaniko/executor
COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr
COPY --from=0 /usr/local/bin/docker-credential-ecr-login /kaniko/docker-credential-ecr-login
Expand Down
4 changes: 4 additions & 0 deletions deploy/Dockerfile_debug
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ FROM debian:bullseye-slim AS certs
RUN apt update && apt install -y ca-certificates

FROM scratch
# Create kaniko directory with world write permission to allow non root run
RUN --mount=from=busybox:latest,src=/bin/,dst=/bin/ \
mkdir -p /kaniko && \
chmod 777 /kaniko
COPY --from=0 /src/out/executor /kaniko/executor
COPY --from=0 /src/out/warmer /kaniko/warmer
COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr
Expand Down
5 changes: 5 additions & 0 deletions deploy/Dockerfile_slim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ FROM debian:bullseye-slim AS certs
RUN apt update && apt install -y ca-certificates

FROM scratch

# Create kaniko directory with world write permission to allow non root run
RUN --mount=from=busybox:latest,src=/bin/,dst=/bin/ \
mkdir -p /kaniko && \
chmod 777 /kaniko
COPY --from=0 /src/out/executor /kaniko/executor
COPY files/nsswitch.conf /etc/nsswitch.conf
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /kaniko/ssl/certs/
Expand Down
4 changes: 4 additions & 0 deletions deploy/Dockerfile_warmer
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ FROM debian:bullseye-slim AS certs
RUN apt update && apt install -y ca-certificates

FROM scratch
# Create kaniko directory with world write permission to allow non root run
RUN --mount=from=busybox:latest,src=/bin/,dst=/bin/ \
mkdir -p /kaniko && \
chmod 777 /kaniko
COPY --from=0 /src/out/warmer /kaniko/warmer
COPY --from=0 /usr/local/bin/docker-credential-gcr /kaniko/docker-credential-gcr
COPY --from=0 /usr/local/bin/docker-credential-ecr-login /kaniko/docker-credential-ecr-login
Expand Down