Skip to content

Commit b730d79

Browse files
committed
ci: speed up docker workflow with amd64-only, scoped cache, path filter
- Drop linux/arm64 to avoid QEMU emulation; rebuild on native amd64 only. Re-add setup-qemu-action and the platform if multi-arch images are needed again. - Scope the GHA cache per app (cache-from/cache-to scope=matrix.app) so the four images stop evicting each other's layers. - Add a `changes` job using dorny/paths-filter@v4 that computes the set of apps with relevant diffs (own dir, shared packages, lockfile, Dockerfile) and feeds it as a dynamic matrix into the build job, so unchanged images skip entirely. workflow_dispatch still rebuildsevery image.
1 parent 21e6578 commit b730d79

1 file changed

Lines changed: 87 additions & 19 deletions

File tree

.github/workflows/docker.yml

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,61 @@ env:
1010
IMAGE_PREFIX: ghcr.io/medformatik/openmapx
1111

1212
jobs:
13+
changes:
14+
name: Detect changed apps
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
outputs:
19+
apps: ${{ steps.set.outputs.apps }}
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- id: filter
24+
if: github.event_name != 'workflow_dispatch'
25+
uses: dorny/paths-filter@v4
26+
with:
27+
filters: |
28+
api:
29+
- 'apps/api/**'
30+
- 'packages/**'
31+
- 'integrations/**'
32+
- 'pnpm-lock.yaml'
33+
- 'pnpm-workspace.yaml'
34+
- 'package.json'
35+
- 'apps/api/Dockerfile'
36+
web:
37+
- 'apps/web/**'
38+
- 'packages/**'
39+
- 'integrations/**'
40+
- 'pnpm-lock.yaml'
41+
- 'pnpm-workspace.yaml'
42+
- 'package.json'
43+
- 'apps/web/Dockerfile'
44+
data-manager:
45+
- 'services/data-manager/**'
46+
- 'packages/**'
47+
- 'pnpm-lock.yaml'
48+
- 'pnpm-workspace.yaml'
49+
- 'package.json'
50+
transitous-tools:
51+
- 'services/motis/tools/transitous/**'
52+
53+
- id: set
54+
env:
55+
DISPATCH: ${{ github.event_name == 'workflow_dispatch' }}
56+
FILTER_CHANGES: ${{ steps.filter.outputs.changes }}
57+
run: |
58+
if [ "$DISPATCH" = "true" ]; then
59+
echo 'apps=["api","web","data-manager","transitous-tools"]' >> "$GITHUB_OUTPUT"
60+
else
61+
echo "apps=${FILTER_CHANGES}" >> "$GITHUB_OUTPUT"
62+
fi
63+
1364
build:
65+
name: Build ${{ matrix.app }}
66+
needs: changes
67+
if: needs.changes.outputs.apps != '[]' && needs.changes.outputs.apps != ''
1468
runs-on: ubuntu-latest
1569
permissions:
1670
contents: read
@@ -20,24 +74,38 @@ jobs:
2074
strategy:
2175
fail-fast: false
2276
matrix:
23-
include:
24-
- app: api
25-
context: .
26-
dockerfile: apps/api/Dockerfile
27-
- app: web
28-
context: .
29-
dockerfile: apps/web/Dockerfile
30-
- app: data-manager
31-
context: .
32-
dockerfile: services/data-manager/Dockerfile
33-
- app: transitous-tools
34-
context: services/motis/tools/transitous
35-
dockerfile: services/motis/tools/transitous/Dockerfile
77+
app: ${{ fromJSON(needs.changes.outputs.apps) }}
3678

3779
steps:
3880
- uses: actions/checkout@v6
3981

40-
- uses: docker/setup-qemu-action@v4
82+
- name: Resolve build context
83+
id: ctx
84+
env:
85+
APP: ${{ matrix.app }}
86+
run: |
87+
case "$APP" in
88+
api)
89+
echo "context=." >> "$GITHUB_OUTPUT"
90+
echo "dockerfile=apps/api/Dockerfile" >> "$GITHUB_OUTPUT"
91+
;;
92+
web)
93+
echo "context=." >> "$GITHUB_OUTPUT"
94+
echo "dockerfile=apps/web/Dockerfile" >> "$GITHUB_OUTPUT"
95+
;;
96+
data-manager)
97+
echo "context=." >> "$GITHUB_OUTPUT"
98+
echo "dockerfile=services/data-manager/Dockerfile" >> "$GITHUB_OUTPUT"
99+
;;
100+
transitous-tools)
101+
echo "context=services/motis/tools/transitous" >> "$GITHUB_OUTPUT"
102+
echo "dockerfile=services/motis/tools/transitous/Dockerfile" >> "$GITHUB_OUTPUT"
103+
;;
104+
*)
105+
echo "Unknown app: $APP" >&2
106+
exit 1
107+
;;
108+
esac
41109
42110
- uses: docker/setup-buildx-action@v4
43111

@@ -58,14 +126,14 @@ jobs:
58126
- uses: docker/build-push-action@v7
59127
id: build
60128
with:
61-
context: ${{ matrix.context }}
62-
file: ${{ matrix.dockerfile }}
63-
platforms: linux/amd64,linux/arm64
129+
context: ${{ steps.ctx.outputs.context }}
130+
file: ${{ steps.ctx.outputs.dockerfile }}
131+
platforms: linux/amd64
64132
push: true
65133
tags: ${{ steps.meta.outputs.tags }}
66134
labels: ${{ steps.meta.outputs.labels }}
67-
cache-from: type=gha
68-
cache-to: type=gha,mode=max
135+
cache-from: type=gha,scope=${{ matrix.app }}
136+
cache-to: type=gha,mode=max,scope=${{ matrix.app }}
69137
provenance: mode=max
70138
sbom: true
71139

0 commit comments

Comments
 (0)