From ed025a54413b3fc308050a7124a5f8b36ecdc0c4 Mon Sep 17 00:00:00 2001 From: Caio Ramos Casimiro Date: Tue, 29 Oct 2024 12:14:58 +0000 Subject: [PATCH] chore(ci) cache httpbin docker image 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. --- .github/actions/load-docker-image/action.yml | 52 +++++++++++++++++++ .../actions/setup-httpbin-server/action.yml | 13 +++++ 2 files changed, 65 insertions(+) create mode 100644 .github/actions/load-docker-image/action.yml diff --git a/.github/actions/load-docker-image/action.yml b/.github/actions/load-docker-image/action.yml new file mode 100644 index 000000000..cf8b941af --- /dev/null +++ b/.github/actions/load-docker-image/action.yml @@ -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 }} diff --git a/.github/actions/setup-httpbin-server/action.yml b/.github/actions/setup-httpbin-server/action.yml index 55a4e15eb..060b64af5 100644 --- a/.github/actions/setup-httpbin-server/action.yml +++ b/.github/actions/setup-httpbin-server/action.yml @@ -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 @@ -54,6 +56,7 @@ 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 @@ -61,9 +64,11 @@ runs: 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: @@ -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: | @@ -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: |