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 <quenting@element.io>
This commit is contained in:
parent
a8c1ca6740
commit
4f6855b733
1 changed files with 11 additions and 9 deletions
20
Dockerfile
20
Dockerfile
|
@ -1,18 +1,20 @@
|
||||||
FROM golang:alpine as builder
|
ARG GO_VERSION=1.17
|
||||||
RUN apk add --update --no-cache git ca-certificates
|
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
|
WORKDIR /build
|
||||||
COPY go.mod .
|
COPY go.mod go.sum ./
|
||||||
COPY go.sum .
|
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
COPY . .
|
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 /build/rageshake /rageshake
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
EXPOSE 9110
|
EXPOSE 9110
|
||||||
CMD ["/rageshake"]
|
ENTRYPOINT ["/rageshake"]
|
||||||
|
|
Reference in a new issue