Skip to content

Commit c94bb56

Browse files
committed
implement image caching with setup-buildx-action; update cache and checkout actions to v4
1 parent 10a8a08 commit c94bb56

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,24 @@ jobs:
5151
- name: Install Nextflow
5252
if: ${{ steps.cache-nextflow.outputs.cache-hit != 'true' }}
5353
run: cat .github/workflows/install_nextflow_v24.10.5.sh | bash && mv nextflow /usr/local/bin && chmod +x /usr/local/bin/nextflow
54+
55+
# Check-out the repo under $GITHUB_WORKSPACE so that the job can access it
56+
- uses: actions/checkout@v3
5457

5558
# Build/cache containers
56-
- name: Cache containers
57-
id: cache-containers
58-
uses: actions/cache@v3
59+
- name: Set up Docker Buildx
60+
uses: docker/setup-build-action@v3
61+
62+
- name: Cache Docker layers
63+
uses: actions/cache@v4
5964
with:
60-
key: ${{ runner.os }}-containers
61-
path: /var/lib/docker/overlay2
65+
path: /tmp/.buildx-cache
66+
key: ${{ runner.os }}-buildx-${{ github.sha }}
6267
restore-keys: |
63-
${{ runner.os }}-containers
64-
- name: Build Containers
65-
if: ${{ steps.cache-containers.outputs.cache-hit != 'true'}}
66-
run: bash build_all.sh
68+
${{ runner.os }}-buildx-
6769
68-
# Check-out the repo under $GITHUB_WORKSPACE so that the job can access it
69-
- uses: actions/checkout@v3
70+
- name: Build images
71+
run: bash build_all.sh github_action
7072

7173
# Run test(s)
7274
- name: test short single

build_all.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env sh
22

3+
build_mode=$1
4+
35
# get architecture
46
arch=$(uname -m)
57
# set architecture to docker buildx
@@ -11,6 +13,8 @@ for dir in docker/*
1113
do
1214
cd ${dir}
1315
imgname=$(echo $dir | rev | cut -d/ -f1 | rev)
16+
17+
echo ██████████████████▓▒░ Building ${imgname} ░▒▓██████████████████
1418

1519
# Reditools2 does not compile on arm64, force using amd64 compilation
1620
if [[ $dir =~ "reditools2" ]];then
@@ -19,8 +23,13 @@ do
1923
docker_arch_option=" --platform linux/amd64"
2024
fi
2125
fi
22-
23-
docker build ${docker_arch_option} -t ${imgname} .
26+
27+
# Check "github_action" mode to enable cache
28+
if [[ ${build_mode} == 'github_action' ]]; then
29+
docker buildx build --cache-from type=local,src=/tmp/.buildx-cache --cache-to type=local,dest=/tmp/.buildx-cache ${docker_arch_option} -t ${imgname} .
30+
else
31+
docker build ${docker_arch_option} -t ${imgname} .
32+
fi
2433

2534
# back to the original working directory
2635
cd $wd

0 commit comments

Comments
 (0)