🐳 Adjustment to Dockerfile

This commit is contained in:
Daniel Aloni 2023-12-28 16:03:24 +02:00
parent b8c53bdd72
commit 1ab7df48d6

View file

@ -1,9 +1,11 @@
#syntax=docker/dockerfile:1.2
# #
# base installs required dependencies and runs go mod download to cache dependencies # base installs required dependencies and runs go mod download to cache dependencies
# #
# Pinned to alpine3.18 until https://github.com/mattn/go-sqlite3/issues/1164 is solved # Pinned to alpine3.18 until https://github.com/mattn/go-sqlite3/issues/1164 is solved
ARG BUILDPLATFORM=${BUILDPLATFORM} ARG BUILDPLATFORM=${BUILDPLATFORM}
FROM --platform=$BUILDPLATFORM docker.io/golang:1.21-alpine AS base FROM --platform=$BUILDPLATFORM docker.io/golang:1.21-alpine3.18 AS base
RUN apk --update --no-cache add bash build-base curl git RUN apk --update --no-cache add bash build-base curl git
# #
@ -13,8 +15,9 @@ FROM --platform=$BUILDPLATFORM base AS build
WORKDIR /src WORKDIR /src
ARG TARGETOS ARG TARGETOS
ARG TARGETARCH ARG TARGETARCH
ARG FLAGS
# Mount volumes using the -v flag instead of --mount to avoid requiring BuildKit which is not easily supported using cloudbuild. # Not mounting volumes using the --mount flag to avoid requiring BuildKit which is not easily supported using cloudbuild.
COPY . . COPY . .
RUN mkdir -p /root/.cache/go-build && \ RUN mkdir -p /root/.cache/go-build && \
mkdir -p /go/pkg/mod mkdir -p /go/pkg/mod
@ -23,10 +26,10 @@ VOLUME /go/pkg/mod
# Run the build command in multiple RUN commands # Run the build command in multiple RUN commands
RUN USERARCH=`go env GOARCH` RUN USERARCH=`go env GOARCH`
ENV GOARCH="$TARGETARCH" RUN GOARCH="$TARGETARCH"
ENV GOOS="linux" RUN GOOS="linux"
RUN CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0") RUN CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0")
RUN go build -v -trimpath -o /out/ ./cmd/... RUN go build -v -ldflags="${FLAGS}" -trimpath -o /out/ ./cmd/...
# #
# Builds the Dendrite image containing all required binaries # Builds the Dendrite image containing all required binaries
@ -37,8 +40,8 @@ LABEL org.opencontainers.image.title="Dendrite"
LABEL org.opencontainers.image.description="Next-generation Matrix homeserver written in Go" LABEL org.opencontainers.image.description="Next-generation Matrix homeserver written in Go"
LABEL org.opencontainers.image.source="https://github.com/matrix-org/dendrite" LABEL org.opencontainers.image.source="https://github.com/matrix-org/dendrite"
LABEL org.opencontainers.image.licenses="Apache-2.0" LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.vendor="The Matrix.org Foundation C.I.C."
LABEL org.opencontainers.image.documentation="https://matrix-org.github.io/dendrite/" LABEL org.opencontainers.image.documentation="https://matrix-org.github.io/dendrite/"
LABEL org.opencontainers.image.vendor="The Matrix.org Foundation C.I.C."
COPY --from=build /out/create-account /usr/bin/create-account COPY --from=build /out/create-account /usr/bin/create-account
COPY --from=build /out/generate-config /usr/bin/generate-config COPY --from=build /out/generate-config /usr/bin/generate-config