diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml index c7659113b..510b72d54 100644 --- a/.github/workflows/ghcr.yml +++ b/.github/workflows/ghcr.yml @@ -35,6 +35,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Show Docker Context + run: ./test/check-docker-context.sh --report + - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30547f5a6..16a6bc121 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,6 +56,7 @@ jobs: fetch-depth: 0 fetch-tags: true submodules: recursive + - run: ./test/check-docker-context.sh --report - run: ./test/test-images.sh - if: always() run: docker compose logs diff --git a/test/check-docker-context.sh b/test/check-docker-context.sh new file mode 100755 index 000000000..7e7076ca2 --- /dev/null +++ b/test/check-docker-context.sh @@ -0,0 +1,127 @@ +#!/bin/bash -eu +set -o pipefail +shopt -s inherit_errexit + +log() { echo "[$(basename "$0")] $*"; } + +# See: https://stackoverflow.com/questions/38946683/ + +usage() { + cat < output clipped, log limit 200KiB/s reached +docker buildx rm docker_context_checker || true +docker buildx create --name docker_context_checker \ + --driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \ + --driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1 +docker buildx use docker_context_checker + +log "Building docker image..." +( +docker \ + buildx build --load \ + --no-cache --progress plain --file - . 2>&1 </dev/null +} +throw_err() { + log "!!!" + log "!!! $* !!!" + log "!!!" + cleanup + exit 1 +} + +log "File count: $file_count" +if [[ "${skip_count-}" != "true" ]]; then + if [[ "$file_count" -lt "$min_count" ]] || [[ "$file_count" -gt "$max_count" ]]; then + throw_err "This is a surprising number of files - expected between $min_count and $max_count" + fi +fi + +human_size() { + if [[ "$1" -gt 999999 ]]; then + echo "$(bc <<< "scale=3; $1 / 1000000") GB" + else + echo "$(bc <<< "scale=3; $1 / 1000") MB" + fi +} + +log "Total size: $(human_size "$total_size")" +if [[ "${skip_size-}" != "true" ]]; then + # N.B. busybox `du` outputs in kB + # See: https://www.busybox.net/downloads/BusyBox.html#du + if [[ "$total_size" -lt $min_size ]]; then + throw_err "This is a surprisingly small total size (expected min: $(human_size "$min_size"))" + elif [[ "$total_size" -gt $max_size ]]; then + throw_err "This is a surprisingly large total size (expected max: $(human_size "$max_size"))" + fi +fi + +cleanup +log "Everything looks OK."