From 0538953a3977594e766a5e8dcf60896bafdce7ef Mon Sep 17 00:00:00 2001 From: Sudarsan Reddy Date: Fri, 12 Aug 2022 16:01:32 +0100 Subject: [PATCH] TUN-6652: Publish dockerfile for both amd64 and arm64 This change seeks to push an arm64 built image to dockerhub for arm users to run. This should spin cloudflared on arm machines without the warning WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested --- .docker-images | 5 ++++- Dockerfile | 4 ++-- Dockerfile.amd64 | 27 +++++++++++++++++++++++++++ Dockerfile.arm64 | 27 +++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.amd64 create mode 100644 Dockerfile.arm64 diff --git a/.docker-images b/.docker-images index 28bf15aa..984a3183 100644 --- a/.docker-images +++ b/.docker-images @@ -1,6 +1,6 @@ images: - name: cloudflared - dockerfile: Dockerfile + dockerfile: Dockerfile.$ARCH context: . versions: - latest @@ -8,3 +8,6 @@ images: - name: docker.io/cloudflare user: env:DOCKER_USER password: env:DOCKER_PASSWORD + architectures: + - amd64 + - arm64 diff --git a/Dockerfile b/Dockerfile index f10076d9..8ca108e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # use a builder image for building cloudflare ARG TARGET_GOOS ARG TARGET_GOARCH -FROM golang:1.18.1 as builder +FROM golang:1.19 as builder ENV GO111MODULE=on \ CGO_ENABLED=0 \ TARGET_GOOS=${TARGET_GOOS} \ @@ -18,7 +18,7 @@ COPY . . RUN make cloudflared # use a distroless base image with glibc -FROM gcr.io/distroless/base-debian10:nonroot +FROM gcr.io/distroless/base-debian11:nonroot # copy our compiled binary COPY --from=builder --chown=nonroot /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/ diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 new file mode 100644 index 00000000..cadfebfc --- /dev/null +++ b/Dockerfile.amd64 @@ -0,0 +1,27 @@ +# use a builder image for building cloudflare +FROM golang:1.19 as builder +ENV GO111MODULE=on \ + CGO_ENABLED=0 + +LABEL org.opencontainers.image.source="https://github.com/cloudflare/cloudflared" + +WORKDIR /go/src/github.com/cloudflare/cloudflared/ + +# copy our sources into the builder image +COPY . . + +# compile cloudflared +RUN GOOS=linux GOARCH=amd64 make cloudflared + +# use a distroless base image with glibc +FROM gcr.io/distroless/base-debian11:nonroot + +# copy our compiled binary +COPY --from=builder --chown=nonroot /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/ + +# run as non-privileged user +USER nonroot + +# command / entrypoint of container +ENTRYPOINT ["cloudflared", "--no-autoupdate"] +CMD ["version"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 00000000..2bc6d982 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,27 @@ +# use a builder image for building cloudflare +FROM golang:1.19 as builder +ENV GO111MODULE=on \ + CGO_ENABLED=0 + +LABEL org.opencontainers.image.source="https://github.com/cloudflare/cloudflared" + +WORKDIR /go/src/github.com/cloudflare/cloudflared/ + +# copy our sources into the builder image +COPY . . + +# compile cloudflared +RUN GOOS=linux GOARCH=arm64 make cloudflared + +# use a distroless base image with glibc +FROM gcr.io/distroless/base-debian11:nonroot + +# copy our compiled binary +COPY --from=builder --chown=nonroot /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/ + +# run as non-privileged user +USER nonroot + +# command / entrypoint of container +ENTRYPOINT ["cloudflared", "--no-autoupdate"] +CMD ["version"]