Skip to content

Commit c56b2bf

Browse files
authored
Speedup building docker images in CI (element-hq#3467)
This should significantly speedup building the pinecone and yggdrasil demos, as they now reuse the new `dendrite:buildcache`, which already builds all binaries.
1 parent a8d842b commit c56b2bf

File tree

9 files changed

+48
-62
lines changed

9 files changed

+48
-62
lines changed

.github/workflows/docker.yml

+21-12
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,25 @@ jobs:
4848
username: ${{ github.repository_owner }}
4949
password: ${{ secrets.GITHUB_TOKEN }}
5050

51+
# Build until the "build" stage, this then can be used by other steps.
52+
- name: Build "build" image
53+
if: github.ref_name == 'main' || github.event_name == 'release'
54+
id: docker_build_monolith
55+
uses: docker/build-push-action@v3
56+
with:
57+
target: build
58+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
59+
cache-to: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache,mode=max
60+
context: .
61+
platforms: ${{ env.PLATFORMS }}
62+
push: true
63+
5164
- name: Build main monolith image
5265
if: github.ref_name == 'main'
5366
id: docker_build_monolith
5467
uses: docker/build-push-action@v3
5568
with:
56-
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-monolith:buildcache
57-
cache-to: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite-monolith:buildcache,mode=max
69+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
5870
context: .
5971
platforms: ${{ env.PLATFORMS }}
6072
push: true
@@ -67,8 +79,7 @@ jobs:
6779
id: docker_build_monolith_release
6880
uses: docker/build-push-action@v3
6981
with:
70-
cache-from: type=gha
71-
cache-to: type=gha,mode=max
82+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
7283
context: .
7384
platforms: ${{ env.PLATFORMS }}
7485
push: true
@@ -93,6 +104,7 @@ jobs:
93104
demo-pinecone:
94105
name: Pinecone demo image
95106
runs-on: ubuntu-latest
107+
needs: monolith
96108
permissions:
97109
contents: read
98110
packages: write
@@ -124,8 +136,7 @@ jobs:
124136
id: docker_build_demo_pinecone
125137
uses: docker/build-push-action@v3
126138
with:
127-
cache-from: type=gha
128-
cache-to: type=gha,mode=max
139+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
129140
context: .
130141
file: ./build/docker/Dockerfile.demo-pinecone
131142
platforms: ${{ env.PLATFORMS }}
@@ -139,8 +150,7 @@ jobs:
139150
id: docker_build_demo_pinecone_release
140151
uses: docker/build-push-action@v3
141152
with:
142-
cache-from: type=gha
143-
cache-to: type=gha,mode=max
153+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
144154
context: .
145155
file: ./build/docker/Dockerfile.demo-pinecone
146156
platforms: ${{ env.PLATFORMS }}
@@ -154,6 +164,7 @@ jobs:
154164
demo-yggdrasil:
155165
name: Yggdrasil demo image
156166
runs-on: ubuntu-latest
167+
needs: monolith
157168
permissions:
158169
contents: read
159170
packages: write
@@ -185,8 +196,7 @@ jobs:
185196
id: docker_build_demo_yggdrasil
186197
uses: docker/build-push-action@v3
187198
with:
188-
cache-from: type=gha
189-
cache-to: type=gha,mode=max
199+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
190200
context: .
191201
file: ./build/docker/Dockerfile.demo-yggdrasil
192202
platforms: ${{ env.PLATFORMS }}
@@ -200,8 +210,7 @@ jobs:
200210
id: docker_build_demo_yggdrasil_release
201211
uses: docker/build-push-action@v3
202212
with:
203-
cache-from: type=gha
204-
cache-to: type=gha,mode=max
213+
cache-from: type=registry,ref=ghcr.io/${{ env.GHCR_NAMESPACE }}/dendrite:buildcache
205214
context: .
206215
file: ./build/docker/Dockerfile.demo-yggdrasil
207216
platforms: ${{ env.PLATFORMS }}

build/docker/Dockerfile.demo-pinecone

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
1-
FROM docker.io/golang:1.22-alpine AS base
2-
3-
#
4-
# Needs to be separate from the main Dockerfile for OpenShift,
5-
# as --target is not supported there.
6-
#
7-
8-
RUN apk --update --no-cache add bash build-base
9-
10-
WORKDIR /build
11-
12-
COPY . /build
13-
14-
RUN mkdir -p bin
15-
RUN go build -trimpath -o bin/ ./cmd/dendrite-demo-pinecone
16-
RUN go build -trimpath -o bin/ ./cmd/create-account
17-
RUN go build -trimpath -o bin/ ./cmd/generate-keys
1+
FROM --platform=${BUILDPLATFORM} ghcr.io/element-hq/dendrite:buildcache AS build
182

193
FROM alpine:latest
204
RUN apk --update --no-cache add curl
215
LABEL org.opencontainers.image.title="Dendrite (Pinecone demo)"
226
LABEL org.opencontainers.image.description="Next-generation Matrix homeserver written in Go"
237
LABEL org.opencontainers.image.source="https://github.com/matrix-org/dendrite"
24-
LABEL org.opencontainers.image.licenses="Apache-2.0"
8+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only OR LicenseRef-Element-Commercial"
259

26-
COPY --from=base /build/bin/* /usr/bin/
10+
COPY --from=build /out/create-account /usr/bin/create-account
11+
COPY --from=build /out/generate-config /usr/bin/generate-config
12+
COPY --from=build /out/generate-keys /usr/bin/generate-keys
13+
COPY --from=build /out/dendrite-demo-pinecone /usr/bin/dendrite-demo-pinecone
2714

2815
VOLUME /etc/dendrite
2916
WORKDIR /etc/dendrite

build/docker/Dockerfile.demo-yggdrasil

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
FROM docker.io/golang:1.22-alpine AS base
2-
3-
#
4-
# Needs to be separate from the main Dockerfile for OpenShift,
5-
# as --target is not supported there.
6-
#
7-
8-
RUN apk --update --no-cache add bash build-base
9-
10-
WORKDIR /build
11-
12-
COPY . /build
13-
14-
RUN mkdir -p bin
15-
RUN go build -trimpath -o bin/ ./cmd/dendrite-demo-yggdrasil
16-
RUN go build -trimpath -o bin/ ./cmd/create-account
17-
RUN go build -trimpath -o bin/ ./cmd/generate-keys
1+
FROM --platform=${BUILDPLATFORM} ghcr.io/element-hq/dendrite:buildcache AS build
182

193
FROM alpine:latest
204
LABEL org.opencontainers.image.title="Dendrite (Yggdrasil demo)"
215
LABEL org.opencontainers.image.description="Next-generation Matrix homeserver written in Go"
226
LABEL org.opencontainers.image.source="https://github.com/matrix-org/dendrite"
23-
LABEL org.opencontainers.image.licenses="Apache-2.0"
7+
LABEL org.opencontainers.image.licenses="AGPL-3.0-only OR LicenseRef-Element-Commercial"
248

25-
COPY --from=base /build/bin/* /usr/bin/
9+
COPY --from=build /out/create-account /usr/bin/create-account
10+
COPY --from=build /out/generate-config /usr/bin/generate-config
11+
COPY --from=build /out/generate-keys /usr/bin/generate-keys
12+
COPY --from=build /out/dendrite-demo-yggdrasil /usr/bin/dendrite-demo-yggdrasil
2613

2714
VOLUME /etc/dendrite
2815
WORKDIR /etc/dendrite

build/docker/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The `Dockerfile` is a multistage file which can build Dendrite. From the root of
1212
repository, run:
1313

1414
```
15-
docker build . -t matrixdotorg/dendrite-monolith
15+
docker build -t ghcr.io/element-hq/dendrite-monolith:latest .
1616
```
1717

1818
## Compose file
@@ -36,7 +36,7 @@ To generate keys:
3636
```
3737
docker run --rm --entrypoint="" \
3838
-v $(pwd):/mnt \
39-
matrixdotorg/dendrite-monolith:latest \
39+
ghcr.io/element-hq/dendrite-monolith:latest \
4040
/usr/bin/generate-keys \
4141
-private-key /mnt/matrix_key.pem \
4242
-tls-cert /mnt/server.crt \

build/docker/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323

2424
monolith:
2525
hostname: monolith
26-
image: matrixdotorg/dendrite-monolith:latest
26+
image: ghcr.io/element-hq/dendrite-monolith:latest
2727
ports:
2828
- 8008:8008
2929
- 8448:8448

build/docker/images-build.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ TAG=${1:-latest}
66

77
echo "Building tag '${TAG}'"
88

9-
docker build . --target monolith -t matrixdotorg/dendrite-monolith:${TAG}
10-
docker build . --target demo-pinecone -t matrixdotorg/dendrite-demo-pinecone:${TAG}
11-
docker build . --target demo-yggdrasil -t matrixdotorg/dendrite-demo-yggdrasil:${TAG}
9+
docker build -t ghcr.io/element-hq/dendrite:buildcache --target build .
10+
11+
docker build -t ghcr.io/element-hq/dendrite-monolith:${TAG} .
12+
13+
docker build -t ghcr.io/element-hq/dendrite-demo-yggdrasil:${TAG} -f build/docker/Dockerfile.demo-yggdrasil .
14+
docker build -t ghcr.io/element-hq/dendrite-demo-pinecone:${TAG} -f build/docker/Dockerfile.demo-pinecone .

build/docker/images-pull.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ TAG=${1:-latest}
44

55
echo "Pulling tag '${TAG}'"
66

7-
docker pull matrixdotorg/dendrite-monolith:${TAG}
7+
docker pull ghcr.io/element-hq/dendrite-monolith:${TAG}

build/docker/images-push.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ TAG=${1:-latest}
44

55
echo "Pushing tag '${TAG}'"
66

7-
docker push matrixdotorg/dendrite-monolith:${TAG}
7+
docker push ghcr.io/element-hq/dendrite-monolith:${TAG}

docs/installation/docker/1_docker.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ First we'll generate private key, which is used to sign events, the following wi
2424
mkdir -p ./config
2525
docker run --rm --entrypoint="/usr/bin/generate-keys" \
2626
-v $(pwd)/config:/mnt \
27-
matrixdotorg/dendrite-monolith:latest \
27+
ghcr.io/element-hq/dendrite-monolith:latest \
2828
-private-key /mnt/matrix_key.pem
2929

30-
# Windows equivalent: docker run --rm --entrypoint="/usr/bin/generate-keys" -v %cd%/config:/mnt matrixdotorg/dendrite-monolith:latest -private-key /mnt/matrix_key.pem
30+
# Windows equivalent: docker run --rm --entrypoint="/usr/bin/generate-keys" -v %cd%/config:/mnt ghcr.io/element-hq/dendrite-monolith:latest -private-key /mnt/matrix_key.pem
3131
```
3232
(**NOTE**: This only needs to be executed **once**, as you otherwise overwrite the key)
3333

@@ -41,13 +41,13 @@ to the docker-compose file (`services.postgres.environment` values):
4141
mkdir -p ./config
4242
docker run --rm --entrypoint="/bin/sh" \
4343
-v $(pwd)/config:/mnt \
44-
matrixdotorg/dendrite-monolith:latest \
44+
ghcr.io/element-hq/dendrite-monolith:latest \
4545
-c "/usr/bin/generate-config \
4646
-dir /var/dendrite/ \
4747
-db postgres://dendrite:itsasecret@postgres/dendrite?sslmode=disable \
4848
-server YourDomainHere > /mnt/dendrite.yaml"
4949

50-
# Windows equivalent: docker run --rm --entrypoint="/bin/sh" -v %cd%/config:/mnt matrixdotorg/dendrite-monolith:latest -c "/usr/bin/generate-config -dir /var/dendrite/ -db postgres://dendrite:itsasecret@postgres/dendrite?sslmode=disable -server YourDomainHere > /mnt/dendrite.yaml"
50+
# Windows equivalent: docker run --rm --entrypoint="/bin/sh" -v %cd%/config:/mnt ghcr.io/element-hq/dendrite-monolith:latest -c "/usr/bin/generate-config -dir /var/dendrite/ -db postgres://dendrite:itsasecret@postgres/dendrite?sslmode=disable -server YourDomainHere > /mnt/dendrite.yaml"
5151
```
5252

5353
You can then change `config/dendrite.yaml` to your liking.

0 commit comments

Comments
 (0)