From 4f6855b7332c7f6cf471aa5a4c1bcea7a0b86aa1 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Thu, 20 Jan 2022 11:43:13 +0100 Subject: [PATCH] Allow cross-platform build of the Docker image Also allows it to run as non-root and set the rageshake binary as the entrypoint rather than setting the command. Signed-off-by: Quentin Gliech --- Dockerfile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 093e8c5..ea66fa6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,20 @@ -FROM golang:alpine as builder -RUN apk add --update --no-cache git ca-certificates +ARG GO_VERSION=1.17 +ARG DEBIAN_VERSION=11 +ARG DEBIAN_VERSION_NAME=bullseye + +# Build stage +FROM --platform=${BUILDPLATFORM} docker.io/library/golang:${GO_VERSION}-${DEBIAN_VERSION_NAME} as builder -RUN mkdir /build WORKDIR /build -COPY go.mod . -COPY go.sum . +COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o rageshake +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o rageshake -FROM scratch +# Runtime stage +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/static-debian${DEBIAN_VERSION}:nonroot COPY --from=builder /build/rageshake /rageshake -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ WORKDIR / EXPOSE 9110 -CMD ["/rageshake"] +ENTRYPOINT ["/rageshake"]