Skip to content

Commit 5418120

Browse files
committed
Use cached docker images in pipeline to speed up test runs
1 parent a4478a2 commit 5418120

2 files changed

Lines changed: 126 additions & 7 deletions

File tree

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

Lines changed: 115 additions & 7 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd
43+
- name: "Set up Docker Buildx"
44+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
45+
- name: "Build asset_builder for cache"
46+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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"
42-
uses: actions/checkout@v6
73+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
74+
- name: "Set up Docker Buildx"
75+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
76+
- name: "Build asset_builder from cache"
77+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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"
56-
uses: actions/checkout@v6
113+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
114+
- name: "Set up Docker Buildx"
115+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
116+
- name: "Build asset_builder from cache"
117+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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"
70-
uses: actions/checkout@v6
153+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
154+
- name: "Set up Docker Buildx"
155+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
156+
- name: "Build asset_builder from cache"
157+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8
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
@@ -82,7 +190,7 @@ jobs:
82190
timeout-minutes: 5
83191
steps:
84192
- name: "Checkout code"
85-
uses: actions/checkout@v6
193+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
86194
- name: "Run test coverage check"
87195
run: |
88196
make test-coverage
@@ -99,7 +207,7 @@ jobs:
99207
timeout-minutes: 5
100208
steps:
101209
- name: "Checkout code"
102-
uses: actions/checkout@v6
210+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
103211
with:
104212
fetch-depth: 0 # Full history is needed to improving relevancy of reporting
105213
- name: "Perform static analysis"

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)