mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 15:03:09 -06:00
🐳 Build docker image without --mount.
This commit is contained in:
parent
e16a7363e7
commit
9177911152
25
Dockerfile
25
Dockerfile
|
|
@ -2,26 +2,31 @@
|
||||||
# base installs required dependencies and runs go mod download to cache dependencies
|
# base installs required dependencies and runs go mod download to cache dependencies
|
||||||
#
|
#
|
||||||
ARG BUILDPLATFORM=${BUILDPLATFORM}
|
ARG BUILDPLATFORM=${BUILDPLATFORM}
|
||||||
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.20-alpine AS base
|
FROM --platform=$BUILDPLATFORM docker.io/golang:1.20-alpine AS base
|
||||||
RUN apk --update --no-cache add bash build-base curl
|
RUN apk --update --no-cache add bash build-base curl
|
||||||
|
|
||||||
#
|
#
|
||||||
# build creates all needed binaries
|
# build creates all needed binaries
|
||||||
#
|
#
|
||||||
FROM --platform=${BUILDPLATFORM} base AS build
|
FROM --platform=$BUILDPLATFORM base AS build
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
ARG TARGETOS
|
ARG TARGETOS
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG FLAGS
|
ARG FLAGS
|
||||||
RUN --mount=target=. \
|
|
||||||
--mount=type=cache,target=/root/.cache/go-build \
|
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
|
||||||
USERARCH=`go env GOARCH` \
|
|
||||||
GOARCH="$TARGETARCH" \
|
|
||||||
GOOS="linux" \
|
|
||||||
CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0") \
|
|
||||||
go build -v -ldflags="${FLAGS}" -trimpath -o /out/ ./cmd/...
|
|
||||||
|
|
||||||
|
# Mount volumes using the -v flag instead of --mount to avoid requiring BuildKit which is not easily supported using cloudbuild.
|
||||||
|
COPY . .
|
||||||
|
RUN mkdir -p /root/.cache/go-build && \
|
||||||
|
mkdir -p /go/pkg/mod
|
||||||
|
VOLUME /root/.cache/go-build
|
||||||
|
VOLUME /go/pkg/mod
|
||||||
|
|
||||||
|
# Run the build command in multiple RUN commands
|
||||||
|
RUN USERARCH=`go env GOARCH`
|
||||||
|
ENV GOARCH="$TARGETARCH"
|
||||||
|
ENV GOOS="linux"
|
||||||
|
RUN CGO_ENABLED=$([ "$TARGETARCH" = "$USERARCH" ] && echo "1" || echo "0")
|
||||||
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue