chore: set vars for platform in dockerfile (#1399)

This commit is contained in:
Livio Amstutz 2021-03-10 13:00:51 +01:00 committed by GitHub
parent 5d3d957756
commit c71a30de76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 /