From c71a30de76664bb3712952c3e618831c15d8e917 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 10 Mar 2021 13:00:51 +0100 Subject: [PATCH] chore: set vars for platform in dockerfile (#1399) --- build/dockerfile | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/build/dockerfile b/build/dockerfile index 4cc57d933..b59cf06a6 100644 --- a/build/dockerfile +++ b/build/dockerfile @@ -2,16 +2,26 @@ ARG GO_VERSION=1.15.8 ARG NODE_VERSION=15.8.0 ARG ENV=prod +####################### +## These steps set platform / arch type specific variables +####################### +FROM alpine AS arm64-base +ENV PROTOC_ARCH aarch_64 + +FROM alpine AS amd64-base +ENV PROTOC_ARCH x86_64 + ####################### ## This step sets up the folder structure, ## initalices go mods, -## downloads the protofiles, +## downloads the protofiles, ## protoc and protoc-gen-grpc-web for later use ####################### -FROM alpine AS base +FROM ${BUILDARCH}-base AS base ARG PROTOC_VERSION=3.14.0 -ARG PROTOC_ZIP=protoc-${PROTOC_VERSION}-linux-x86_64.zip +ARG PROTOC_ZIP=protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip ARG GRPC_WEB_VERSION=1.2.1 +# no arm specific version available and x86 works fine at the moment: ARG GRPC_WEB=protoc-gen-grpc-web-${GRPC_WEB_VERSION}-linux-x86_64 @@ -133,13 +143,14 @@ COPY --from=go-test /go/src/github.com/caos/zitadel/profile.cov profile.cov ## Go prod build ####################### FROM go-test as prod-go-build +ARG BUILDARCH COPY --from=prod-angular-build console/dist/console console/dist/console/ RUN go get github.com/rakyll/statik \ && ./build/console/generate-static.sh \ && ./build/login/generate-static.sh \ && ./build/notification/generate-static.sh \ && ./build/zitadel/generate-static.sh -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o zitadel-linux-amd64 cmd/zitadel/main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${BUILDARCH} go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o zitadel-linux-${BUILDARCH} cmd/zitadel/main.go ####################### @@ -153,9 +164,10 @@ RUN go get github.com/go-delve/delve/cmd/dlv ## Final Production Image ####################### FROM alpine:latest as artifact +ARG BUILDARCH RUN adduser -D zitadel COPY cmd/zitadel/*.yaml /app/ -COPY --from=prod-go-build /go/src/github.com/caos/zitadel/zitadel-linux-amd64 /app/zitadel +COPY --from=prod-go-build /go/src/github.com/caos/zitadel/zitadel-linux-${BUILDARCH} /app/zitadel RUN chmod a+x /app/zitadel RUN ls -la /