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 <cplee@nektos.com>
This commit is contained in:
ChristopherHX 2021-08-31 02:01:30 +02:00 committed by GitHub
parent 4c645b3ed9
commit 6e5bd24728
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,10 @@ name: checks
on: [pull_request, workflow_dispatch] on: [pull_request, workflow_dispatch]
env: env:
ACT_OWNER: ${{ github.repository_owner }}
ACT_REPOSITORY: ${{ github.repository }}
CACHED_DOCKER_IMAGES: '"node:12-buster" "node:12-buster-slim" "ubuntu:18.04" "ubuntu:latest" "alpine:3.10" "tonistiigi/binfmt:latest"'
CACHED_DOCKER_IMAGES_KEY: docker-images-0
GO_VERSION: 1.17 GO_VERSION: 1.17
jobs: jobs:
@ -61,7 +65,33 @@ jobs:
files: coverage.txt files: coverage.txt
fail_ci_if_error: true # optional (default = false) fail_ci_if_error: true # optional (default = false)
dump_images:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/cache@v2
id: image_cache
with:
key: ${{ env.CACHED_DOCKER_IMAGES_KEY }}
path: |
registry
docker-registry
- name: Pull and export images
if: steps.image_cache.outputs.cache-hit != 'true'
run: |
docker pull registry:2
docker image save -o registry registry:2
mkdir -p docker-registry
docker run -d -p 5000:5000 --name registry -v $PWD/docker-registry:/var/lib/registry registry:2
npx wait-on tcp:5000
for image in ${{ env.CACHED_DOCKER_IMAGES }}
do
bash -c 'docker pull "'"$image"'" && docker tag "'"$image"'" "localhost:5000/'"$image"'" && docker push "localhost:5000/'"$image"'"'&
done
wait
test-macos: test-macos:
needs: dump_images
name: test-macos name: test-macos
runs-on: macos-latest runs-on: macos-latest
continue-on-error: true # Don't let macos test fail whole workflow continue-on-error: true # Don't let macos test fail whole workflow
@ -69,6 +99,15 @@ jobs:
ISO_PATH: ~/.docker/machine/cache/boot2docker.iso ISO_PATH: ~/.docker/machine/cache/boot2docker.iso
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Restore Docker Image Cache
uses: actions/cache@v2
id: image_cache
continue-on-error: true
with:
key: ${{ env.CACHED_DOCKER_IMAGES_KEY }}
path: |
registry
docker-registry
- uses: actions/setup-go@v1 - uses: actions/setup-go@v1
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
@ -100,9 +139,23 @@ jobs:
echo "DOCKER_HOST=$DOCKER_HOST" | tee -a $GITHUB_ENV echo "DOCKER_HOST=$DOCKER_HOST" | tee -a $GITHUB_ENV
echo "DOCKER_CERT_PATH=$DOCKER_CERT_PATH" | tee -a $GITHUB_ENV echo "DOCKER_CERT_PATH=$DOCKER_CERT_PATH" | tee -a $GITHUB_ENV
echo "DOCKER_MACHINE_NAME=$DOCKER_MACHINE_NAME" | tee -a $GITHUB_ENV echo "DOCKER_MACHINE_NAME=$DOCKER_MACHINE_NAME" | tee -a $GITHUB_ENV
printf " 🛠️ Install Qemu for running containers with different architecture 🛠️ \n\n"
docker run --rm --privileged tonistiigi/binfmt --install all
printf " 🛠️ Finished installing Docker 🛠️ \n\n" printf " 🛠️ Finished installing Docker 🛠️ \n\n"
- name: Import images
if: steps.image_cache.outputs.cache-hit == 'true'
continue-on-error: true
run: |
echo load registry
docker image load -i registry
echo Setup local registry
docker run -d -p 5000:5000 --name registry -v $PWD/docker-registry:/var/lib/registry registry:2
echo pulling images from cache
for image in ${{ env.CACHED_DOCKER_IMAGES }}
do
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"'"'&
done
wait
- name: 🛠️ Install Qemu for running containers with different architecture 🛠️
run: docker run --rm --privileged tonistiigi/binfmt:latest --install all
- run: go test -v -timeout 30m -cover ./... - run: go test -v -timeout 30m -cover ./...
env: env:
CGO_ENABLED: 0 CGO_ENABLED: 0