Skip to content

Commit d5653eb

Browse files
committed
Add Docker image caching using save/load approach
Cache Docker images across workflow runs using docker save/load: - Save images to tar files after pulling - Cache tar files using GitHub Actions cache - Load images from cache on subsequent runs Benefits: - Images persist across separate workflow runs - First run: full pull + save to cache - Subsequent runs: load from cache (much faster) - Each test job caches only the image it needs Note: Docker images are large (~100-500MB each), but GitHub Actions cache limit is 10GB, so this should work fine for our use case.
1 parent f49ede2 commit d5653eb

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

.github/workflows/main.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,72 @@ jobs:
197197
sudo apt-get update -qq
198198
sudo apt-get install -y --no-install-recommends mysql-client
199199
200+
- name: Cache Docker images (save/load approach)
201+
if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')
202+
id: cache-docker-images
203+
uses: actions/cache@v4
204+
with:
205+
path: /tmp/docker-images
206+
key: ${{ runner.os }}-docker-${{ matrix.target }}-v1
207+
restore-keys: |
208+
${{ runner.os }}-docker-${{ matrix.target }}-
209+
${{ runner.os }}-docker-
210+
211+
- name: Load Docker image from cache (if available)
212+
if: (contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')) && steps.cache-docker-images.outputs.cache-hit == 'true'
213+
run: |
214+
# Load cached image if available
215+
if [[ "${{ matrix.target }}" == testversion5.6 ]] && [ -f /tmp/docker-images/mysql-5.6.tar ]; then
216+
docker load -i /tmp/docker-images/mysql-5.6.tar
217+
elif [[ "${{ matrix.target }}" == testversion5.7 ]] && [ -f /tmp/docker-images/mysql-5.7.tar ]; then
218+
docker load -i /tmp/docker-images/mysql-5.7.tar
219+
elif [[ "${{ matrix.target }}" == testversion8.0 ]] && [ -f /tmp/docker-images/mysql-8.0.tar ]; then
220+
docker load -i /tmp/docker-images/mysql-8.0.tar
221+
elif [[ "${{ matrix.target }}" == testpercona5.7 ]] && [ -f /tmp/docker-images/percona-5.7.tar ]; then
222+
docker load -i /tmp/docker-images/percona-5.7.tar
223+
elif [[ "${{ matrix.target }}" == testpercona8.0 ]] && [ -f /tmp/docker-images/percona-8.0.tar ]; then
224+
docker load -i /tmp/docker-images/percona-8.0.tar
225+
elif [[ "${{ matrix.target }}" == testmariadb10.3 ]] && [ -f /tmp/docker-images/mariadb-10.3.tar ]; then
226+
docker load -i /tmp/docker-images/mariadb-10.3.tar
227+
elif [[ "${{ matrix.target }}" == testmariadb10.8 ]] && [ -f /tmp/docker-images/mariadb-10.8.tar ]; then
228+
docker load -i /tmp/docker-images/mariadb-10.8.tar
229+
elif [[ "${{ matrix.target }}" == testmariadb10.10 ]] && [ -f /tmp/docker-images/mariadb-10.10.tar ]; then
230+
docker load -i /tmp/docker-images/mariadb-10.10.tar
231+
fi
232+
233+
- name: Pre-pull Docker image for this test
234+
if: contains(matrix.target, 'testversion') || contains(matrix.target, 'testpercona') || contains(matrix.target, 'testmariadb')
235+
run: |
236+
# Pre-pull the Docker image needed for this test
237+
# If cache hit, docker pull will be fast (only missing layers)
238+
# If cache miss, full pull happens and we'll save it for next run
239+
mkdir -p /tmp/docker-images
240+
if [[ "${{ matrix.target }}" == testversion5.6 ]]; then
241+
docker pull mysql:5.6
242+
docker save mysql:5.6 -o /tmp/docker-images/mysql-5.6.tar || true
243+
elif [[ "${{ matrix.target }}" == testversion5.7 ]]; then
244+
docker pull mysql:5.7
245+
docker save mysql:5.7 -o /tmp/docker-images/mysql-5.7.tar || true
246+
elif [[ "${{ matrix.target }}" == testversion8.0 ]]; then
247+
docker pull mysql:8.0
248+
docker save mysql:8.0 -o /tmp/docker-images/mysql-8.0.tar || true
249+
elif [[ "${{ matrix.target }}" == testpercona5.7 ]]; then
250+
docker pull percona:5.7
251+
docker save percona:5.7 -o /tmp/docker-images/percona-5.7.tar || true
252+
elif [[ "${{ matrix.target }}" == testpercona8.0 ]]; then
253+
docker pull percona:8.0
254+
docker save percona:8.0 -o /tmp/docker-images/percona-8.0.tar || true
255+
elif [[ "${{ matrix.target }}" == testmariadb10.3 ]]; then
256+
docker pull mariadb:10.3
257+
docker save mariadb:10.3 -o /tmp/docker-images/mariadb-10.3.tar || true
258+
elif [[ "${{ matrix.target }}" == testmariadb10.8 ]]; then
259+
docker pull mariadb:10.8
260+
docker save mariadb:10.8 -o /tmp/docker-images/mariadb-10.8.tar || true
261+
elif [[ "${{ matrix.target }}" == testmariadb10.10 ]]; then
262+
docker pull mariadb:10.10
263+
docker save mariadb:10.10 -o /tmp/docker-images/mariadb-10.10.tar || true
264+
fi
265+
200266
- name: Extract TiDB version from test target
201267
id: extract-tidb-version
202268
if: contains(matrix.target, 'tidb')

0 commit comments

Comments
 (0)