ci(docker): distribute build across multiple runners (#286)

Docker build for multiplatform arch is too slow sequentially on the same runner.

The build is now distributed on multiple runners. Each architecure image is pushed as a digest and is reconciled into a single image afterwards.
This commit is contained in:
Alexis Couvreur
2024-04-21 00:20:24 -04:00
committed by GitHub
parent 28e75c9ce9
commit 9be18808ce
4 changed files with 174 additions and 37 deletions

View File

@@ -1,25 +1,26 @@
FROM golang:1.21 AS build
ENV PORT 10000
WORKDIR /src
RUN go env -w GOMODCACHE=/root/.cache/go-build
WORKDIR /go/src/sablier
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . /go/src/sablier
# See https://docs.docker.com/build/guide/mounts/#add-bind-mounts for cached builds
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download
COPY . /src
ARG BUILDTIME
ARG VERSION
ARG REVISION
ARG TARGETOS
ARG TARGETARCH
RUN make BUILDTIME=${BUILDTIME} VERSION=${VERSION} GIT_REVISION=${REVISION} ${TARGETOS}/${TARGETARCH}
RUN --mount=type=cache,target=/root/.cache/go-build \
make BUILDTIME=${BUILDTIME} VERSION=${VERSION} GIT_REVISION=${REVISION} ${TARGETOS}/${TARGETARCH}
FROM alpine:3.19.1
COPY --from=build /go/src/sablier/sablier* /etc/sablier/sablier
COPY --from=build /src/sablier* /etc/sablier/sablier
COPY docker/sablier.yaml /etc/sablier/sablier.yaml
EXPOSE 10000