Skip to content

Commit 6e5bd24

Browse files
ChristopherHXcplee
andauthored
Cache dockerhub images from linux for macOS (#768)
* Cache dockerhub images from linux for macOS An attempt to avoid hitting the dockerhub Pull Rate Limit. * parallelize / refactor docker cache Co-authored-by: Casey Lee <[email protected]>
1 parent 4c645b3 commit 6e5bd24

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

.github/workflows/checks.yml

+55-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: checks
22
on: [pull_request, workflow_dispatch]
33

44
env:
5+
ACT_OWNER: ${{ github.repository_owner }}
6+
ACT_REPOSITORY: ${{ github.repository }}
7+
CACHED_DOCKER_IMAGES: '"node:12-buster" "node:12-buster-slim" "ubuntu:18.04" "ubuntu:latest" "alpine:3.10" "tonistiigi/binfmt:latest"'
8+
CACHED_DOCKER_IMAGES_KEY: docker-images-0
59
GO_VERSION: 1.17
610

711
jobs:
@@ -61,14 +65,49 @@ jobs:
6165
files: coverage.txt
6266
fail_ci_if_error: true # optional (default = false)
6367

68+
dump_images:
69+
runs-on: ubuntu-latest
70+
continue-on-error: true
71+
steps:
72+
- uses: actions/cache@v2
73+
id: image_cache
74+
with:
75+
key: ${{ env.CACHED_DOCKER_IMAGES_KEY }}
76+
path: |
77+
registry
78+
docker-registry
79+
- name: Pull and export images
80+
if: steps.image_cache.outputs.cache-hit != 'true'
81+
run: |
82+
docker pull registry:2
83+
docker image save -o registry registry:2
84+
mkdir -p docker-registry
85+
docker run -d -p 5000:5000 --name registry -v $PWD/docker-registry:/var/lib/registry registry:2
86+
npx wait-on tcp:5000
87+
for image in ${{ env.CACHED_DOCKER_IMAGES }}
88+
do
89+
bash -c 'docker pull "'"$image"'" && docker tag "'"$image"'" "localhost:5000/'"$image"'" && docker push "localhost:5000/'"$image"'"'&
90+
done
91+
wait
92+
6493
test-macos:
94+
needs: dump_images
6595
name: test-macos
6696
runs-on: macos-latest
6797
continue-on-error: true # Don't let macos test fail whole workflow
6898
env:
6999
ISO_PATH: ~/.docker/machine/cache/boot2docker.iso
70100
steps:
71101
- uses: actions/checkout@v2
102+
- name: Restore Docker Image Cache
103+
uses: actions/cache@v2
104+
id: image_cache
105+
continue-on-error: true
106+
with:
107+
key: ${{ env.CACHED_DOCKER_IMAGES_KEY }}
108+
path: |
109+
registry
110+
docker-registry
72111
- uses: actions/setup-go@v1
73112
with:
74113
go-version: ${{ env.GO_VERSION }}
@@ -100,9 +139,23 @@ jobs:
100139
echo "DOCKER_HOST=$DOCKER_HOST" | tee -a $GITHUB_ENV
101140
echo "DOCKER_CERT_PATH=$DOCKER_CERT_PATH" | tee -a $GITHUB_ENV
102141
echo "DOCKER_MACHINE_NAME=$DOCKER_MACHINE_NAME" | tee -a $GITHUB_ENV
103-
printf " 🛠️ Install Qemu for running containers with different architecture 🛠️ \n\n"
104-
docker run --rm --privileged tonistiigi/binfmt --install all
105142
printf " 🛠️ Finished installing Docker 🛠️ \n\n"
143+
- name: Import images
144+
if: steps.image_cache.outputs.cache-hit == 'true'
145+
continue-on-error: true
146+
run: |
147+
echo load registry
148+
docker image load -i registry
149+
echo Setup local registry
150+
docker run -d -p 5000:5000 --name registry -v $PWD/docker-registry:/var/lib/registry registry:2
151+
echo pulling images from cache
152+
for image in ${{ env.CACHED_DOCKER_IMAGES }}
153+
do
154+
bash -c '(sleep 1 && docker pull "localhost:5000/'"$image"'" || sleep 2 && docker pull "localhost:5000/'"$image"'" || sleep 10 && docker pull "localhost:5000/'"$image"'") && docker tag "localhost:5000/'"$image"'" "'"$image"'"'&
155+
done
156+
wait
157+
- name: 🛠️ Install Qemu for running containers with different architecture 🛠️
158+
run: docker run --rm --privileged tonistiigi/binfmt:latest --install all
106159
- run: go test -v -timeout 30m -cover ./...
107160
env:
108161
CGO_ENABLED: 0

0 commit comments

Comments
 (0)