Skip to content

Commit

Permalink
chore(ci) cache httpbin docker image
Browse files Browse the repository at this point in the history
CI has been failing rather frequently due to Docker registry returning
`502 Bad Gateway` when the `setup-httpbin-server` action attempts to
pull httpbin's docker image.

In fact, this image has been pulled by 16 jobs (Unit and Valgrind) for every GHA
workflow run. This might explain why we eventually fail to pull it.

Caching it should greatly reduce the number of times httpbin image is
actually pulled, which should prevent us from being rate limited.
  • Loading branch information
casimiro committed Nov 8, 2024
1 parent d04cb7f commit ed025a5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/actions/load-docker-image/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: load-docker-image
decription: |
Pull a docker image and cache it.
inputs:
image:
required: true
type: string
cache_dir:
required: false
type: string
default: "$GITHUB_WORKSPACE/.docker-images-cache"

runs:
using: 'composite'
steps:
- name: Create cache directory
shell: bash
run: mkdir -p ${{ inputs.cache_dir }}

- name: Setup cache
uses: actions/cache@v4
with:
path: ${{ inputs.cache_dir }}
key: pulled-docker-images

- name: Setup cache path
id: cache_setup
shell: bash
run: |
filename="$(echo ${{ inputs.image }} | sed 's/\//_/g').tar"
cache_path="${{ inputs.cache_dir }}/$filename"
if [ -f "$cache_path" ]; then
echo "cache_hit=true" >> $GITHUB_OUTPUT
else
echo "cache_hit=false" >> $GITHUB_OUTPUT
fi
echo "cache_path=$cache_path" >> $GITHUB_OUTPUT
- name: Pull Docker image
if: steps.cache_setup.outputs.cache_hit == 'false'
shell: bash
run: |
docker pull ${{ inputs.image }}
docker save -o ${{ steps.cache_setup.outputs.cache_path }} ${{ inputs.image }}
- name: Load Docker image from cache
if: steps.cache_setup.outputs.cache-hit == 'true'
shell: bash
run: docker load -i ${{ steps.cache_setup.outputs.cache_path }}
13 changes: 13 additions & 0 deletions .github/actions/setup-httpbin-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ runs:
sudo apt-get update
sudo apt-get install -y dnsmasq
- name: 'Setup deps - macOS'
if: ${{ contains(inputs.os, 'macos') }}
shell: bash
run: |
brew install dnsmasq docker colima
colima start --network-address
- name: Setup Docker image tag
id: setup
shell: bash
Expand All @@ -54,16 +56,19 @@ runs:
echo "push=false" >> $GITHUB_OUTPUT
echo "tag=wasmx-ci-httpbin-proxy:latest" >> $GITHUB_OUTPUT
fi
- name: Login to GitHub Container Registry
if: ${{ steps.setup.outputs.push == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.ghcr_username }}
password: ${{ inputs.ghcr_password }}

- name: Setup Docker Buildx
if: ${{ !env.ACT }}
uses: docker/setup-buildx-action@v3

- name: Build httpbin-proxy image
uses: docker/build-push-action@v5
with:
Expand All @@ -74,6 +79,13 @@ runs:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Load httpbin docker image
if: ${{ !env.ACT }}
uses: ./.github/actions/load-docker-image
with:
image: "kennethreitz/httpbin"

- name: Start dnsmasq
shell: bash
run: |
Expand All @@ -83,6 +95,7 @@ runs:
--server=${{ inputs.upstream_dns_server }} \
--address=/httpbin.org/127.0.0.1 \
--address=/example.com/127.0.0.1
- name: Start httpbin proxy + server
shell: bash
run: |
Expand Down

0 comments on commit ed025a5

Please sign in to comment.