Speedup building docker images in CI (#3467)

This should significantly speedup building the pinecone and yggdrasil
demos, as they now reuse the new `dendrite:buildcache`, which already
builds all binaries.
This commit is contained in:
Till 2024-12-18 11:23:41 +01:00 committed by GitHub
parent a8d842bd05
commit c56b2bfe33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 48 additions and 62 deletions

View file

@ -1,29 +1,16 @@
FROM docker.io/golang:1.22-alpine AS base
#
# Needs to be separate from the main Dockerfile for OpenShift,
# as --target is not supported there.
#
RUN apk --update --no-cache add bash build-base
WORKDIR /build
COPY . /build
RUN mkdir -p bin
RUN go build -trimpath -o bin/ ./cmd/dendrite-demo-pinecone
RUN go build -trimpath -o bin/ ./cmd/create-account
RUN go build -trimpath -o bin/ ./cmd/generate-keys
FROM --platform=${BUILDPLATFORM} ghcr.io/element-hq/dendrite:buildcache AS build
FROM alpine:latest
RUN apk --update --no-cache add curl
LABEL org.opencontainers.image.title="Dendrite (Pinecone demo)"
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.licenses="Apache-2.0"
LABEL org.opencontainers.image.licenses="AGPL-3.0-only OR LicenseRef-Element-Commercial"
COPY --from=base /build/bin/* /usr/bin/
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-keys /usr/bin/generate-keys
COPY --from=build /out/dendrite-demo-pinecone /usr/bin/dendrite-demo-pinecone
VOLUME /etc/dendrite
WORKDIR /etc/dendrite

View file

@ -1,28 +1,15 @@
FROM docker.io/golang:1.22-alpine AS base
#
# Needs to be separate from the main Dockerfile for OpenShift,
# as --target is not supported there.
#
RUN apk --update --no-cache add bash build-base
WORKDIR /build
COPY . /build
RUN mkdir -p bin
RUN go build -trimpath -o bin/ ./cmd/dendrite-demo-yggdrasil
RUN go build -trimpath -o bin/ ./cmd/create-account
RUN go build -trimpath -o bin/ ./cmd/generate-keys
FROM --platform=${BUILDPLATFORM} ghcr.io/element-hq/dendrite:buildcache AS build
FROM alpine:latest
LABEL org.opencontainers.image.title="Dendrite (Yggdrasil demo)"
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.licenses="Apache-2.0"
LABEL org.opencontainers.image.licenses="AGPL-3.0-only OR LicenseRef-Element-Commercial"
COPY --from=base /build/bin/* /usr/bin/
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-keys /usr/bin/generate-keys
COPY --from=build /out/dendrite-demo-yggdrasil /usr/bin/dendrite-demo-yggdrasil
VOLUME /etc/dendrite
WORKDIR /etc/dendrite

View file

@ -12,7 +12,7 @@ The `Dockerfile` is a multistage file which can build Dendrite. From the root of
repository, run:
```
docker build . -t matrixdotorg/dendrite-monolith
docker build -t ghcr.io/element-hq/dendrite-monolith:latest .
```
## Compose file
@ -36,7 +36,7 @@ To generate keys:
```
docker run --rm --entrypoint="" \
-v $(pwd):/mnt \
matrixdotorg/dendrite-monolith:latest \
ghcr.io/element-hq/dendrite-monolith:latest \
/usr/bin/generate-keys \
-private-key /mnt/matrix_key.pem \
-tls-cert /mnt/server.crt \

View file

@ -23,7 +23,7 @@ services:
monolith:
hostname: monolith
image: matrixdotorg/dendrite-monolith:latest
image: ghcr.io/element-hq/dendrite-monolith:latest
ports:
- 8008:8008
- 8448:8448

View file

@ -6,6 +6,9 @@ TAG=${1:-latest}
echo "Building tag '${TAG}'"
docker build . --target monolith -t matrixdotorg/dendrite-monolith:${TAG}
docker build . --target demo-pinecone -t matrixdotorg/dendrite-demo-pinecone:${TAG}
docker build . --target demo-yggdrasil -t matrixdotorg/dendrite-demo-yggdrasil:${TAG}
docker build -t ghcr.io/element-hq/dendrite:buildcache --target build .
docker build -t ghcr.io/element-hq/dendrite-monolith:${TAG} .
docker build -t ghcr.io/element-hq/dendrite-demo-yggdrasil:${TAG} -f build/docker/Dockerfile.demo-yggdrasil .
docker build -t ghcr.io/element-hq/dendrite-demo-pinecone:${TAG} -f build/docker/Dockerfile.demo-pinecone .

View file

@ -4,4 +4,4 @@ TAG=${1:-latest}
echo "Pulling tag '${TAG}'"
docker pull matrixdotorg/dendrite-monolith:${TAG}
docker pull ghcr.io/element-hq/dendrite-monolith:${TAG}

View file

@ -4,4 +4,4 @@ TAG=${1:-latest}
echo "Pushing tag '${TAG}'"
docker push matrixdotorg/dendrite-monolith:${TAG}
docker push ghcr.io/element-hq/dendrite-monolith:${TAG}