Skip to content

Commit 800b29c

Browse files
committed
Use cached docker images in pipeline to speed up test runs
1 parent cc3814a commit 800b29c

2 files changed

Lines changed: 121 additions & 2 deletions

File tree

.github/workflows/stage-2-test.yaml

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,70 @@ on:
3333
type: string
3434

3535
jobs:
36+
build-compose-cache:
37+
name: "Build Docker Compose cache"
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 10
40+
steps:
41+
- name: "Checkout code"
42+
uses: actions/checkout@v6
43+
- name: "Set up Docker Buildx"
44+
uses: docker/setup-buildx-action@v3
45+
- name: "Build asset_builder for cache"
46+
uses: docker/build-push-action@v6
47+
with:
48+
context: .
49+
target: asset_builder
50+
push: false
51+
load: true
52+
tags: ${{ github.event.repository.name }}_asset_builder:latest
53+
cache-from: type=gha,scope=compose-asset
54+
cache-to: type=gha,scope=compose-asset,mode=max
55+
- name: "Build web image for cache"
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: .
59+
target: development
60+
push: false
61+
load: true
62+
tags: ${{ github.event.repository.name }}_web:latest
63+
cache-from: type=gha,scope=compose-web
64+
cache-to: type=gha,scope=compose-web,mode=max
65+
3666
test-unit:
3767
name: "Unit tests"
68+
needs: [build-compose-cache]
3869
runs-on: ubuntu-latest
39-
timeout-minutes: 5
70+
timeout-minutes: 10
4071
steps:
4172
- name: "Checkout code"
4273
uses: actions/checkout@v6
74+
- name: "Set up Docker Buildx"
75+
uses: docker/setup-buildx-action@v3
76+
- name: "Build asset_builder from cache"
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: .
80+
target: asset_builder
81+
push: false
82+
load: true
83+
tags: ${{ github.event.repository.name }}_asset_builder:latest
84+
cache-from: type=gha,scope=compose-asset
85+
cache-to: type=gha,scope=compose-asset,mode=max
86+
- name: "Build web image from cache"
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: .
90+
target: development
91+
push: false
92+
load: true
93+
tags: ${{ github.event.repository.name }}_web:latest
94+
cache-from: type=gha,scope=compose-web
95+
cache-to: type=gha,scope=compose-web,mode=max
4396
- name: "Run unit test suite"
97+
env:
98+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
99+
COMPOSE_PROJECT_NAME: ${{ github.event.repository.name }}
44100
run: |
45101
cp .env.example .env
46102
make test-unit
@@ -49,12 +105,38 @@ jobs:
49105
echo "Nothing to save"
50106
test-lint:
51107
name: "Linting"
108+
needs: [build-compose-cache]
52109
runs-on: ubuntu-latest
53-
timeout-minutes: 5
110+
timeout-minutes: 10
54111
steps:
55112
- name: "Checkout code"
56113
uses: actions/checkout@v6
114+
- name: "Set up Docker Buildx"
115+
uses: docker/setup-buildx-action@v3
116+
- name: "Build asset_builder from cache"
117+
uses: docker/build-push-action@v6
118+
with:
119+
context: .
120+
target: asset_builder
121+
push: false
122+
load: true
123+
tags: ${{ github.event.repository.name }}_asset_builder:latest
124+
cache-from: type=gha,scope=compose-asset
125+
cache-to: type=gha,scope=compose-asset,mode=max
126+
- name: "Build web image from cache"
127+
uses: docker/build-push-action@v6
128+
with:
129+
context: .
130+
target: development
131+
push: false
132+
load: true
133+
tags: ${{ github.event.repository.name }}_web:latest
134+
cache-from: type=gha,scope=compose-web
135+
cache-to: type=gha,scope=compose-web,mode=max
57136
- name: "Run linting"
137+
env:
138+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
139+
COMPOSE_PROJECT_NAME: ${{ github.event.repository.name }}
58140
run: |
59141
cp .env.example .env
60142
make test-lint
@@ -63,12 +145,38 @@ jobs:
63145
echo "Nothing to save"
64146
test-features:
65147
name: "Feature tests"
148+
needs: [build-compose-cache]
66149
runs-on: ubuntu-latest
67150
timeout-minutes: 10
68151
steps:
69152
- name: "Checkout code"
70153
uses: actions/checkout@v6
154+
- name: "Set up Docker Buildx"
155+
uses: docker/setup-buildx-action@v3
156+
- name: "Build asset_builder from cache"
157+
uses: docker/build-push-action@v6
158+
with:
159+
context: .
160+
target: asset_builder
161+
push: false
162+
load: true
163+
tags: ${{ github.event.repository.name }}_asset_builder:latest
164+
cache-from: type=gha,scope=compose-asset
165+
cache-to: type=gha,scope=compose-asset,mode=max
166+
- name: "Build web image from cache"
167+
uses: docker/build-push-action@v6
168+
with:
169+
context: .
170+
target: development
171+
push: false
172+
load: true
173+
tags: ${{ github.event.repository.name }}_web:latest
174+
cache-from: type=gha,scope=compose-web
175+
cache-to: type=gha,scope=compose-web,mode=max
71176
- name: "Run feature tests"
177+
env:
178+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
179+
COMPOSE_PROJECT_NAME: ${{ github.event.repository.name }}
72180
run: |
73181
cp .env.example .env
74182
make test-features

docker-compose.ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Used only in CI (COMPOSE_FILE=docker-compose.yml:docker-compose.ci.yml) to pin
2+
# pre-built image names so tests use the cached images instead of rebuilding.
3+
# Not loaded when running docker compose locally.
4+
5+
services:
6+
web:
7+
image: ${COMPOSE_PROJECT_NAME}_web:latest
8+
pull_policy: never
9+
asset_builder:
10+
image: ${COMPOSE_PROJECT_NAME}_asset_builder:latest
11+
pull_policy: never

0 commit comments

Comments
 (0)