From 3710b089955b90ad240bcee1c1711490520788f2 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Wed, 18 Feb 2026 16:42:44 -0500 Subject: [PATCH] Add Docker build and cache cleanup steps in CI, prevent redundant builds in Swarm E2E tests - Updated GitHub workflow to include Docker cache cleanup and image build steps. - Modified Swarm E2E test logic to skip Docker image build if it already exists, optimizing CI performance. --- .github/workflows/build.yml | 8 ++++++++ tests_e2e/test_swarm.py | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9f2184..2717c7b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -148,6 +148,14 @@ jobs: export PATH="$HOME/.local/bin:$PATH" uv sync --group dev + - name: Clean Docker build cache + run: docker builder prune -af + + - name: Build Docker image + env: + DOCKER_BUILDKIT: "0" + run: docker build -t byjg/easy-haproxy:local -f deploy/docker/Dockerfile . + - name: Run Swarm E2E tests run: | export PATH="$HOME/.local/bin:$PATH" diff --git a/tests_e2e/test_swarm.py b/tests_e2e/test_swarm.py index b355e95..3f18c34 100644 --- a/tests_e2e/test_swarm.py +++ b/tests_e2e/test_swarm.py @@ -60,14 +60,25 @@ _cloudflare_config_created = False def ensure_haproxy_image(): """Build byjg/easy-haproxy:local from source at the start of the test session. - Always builds on the first call so tests run against the current codebase, - never a stale image left over from a previous session or docker compose run. + If the image already exists (e.g. pre-built by a CI step), the build is + skipped so that CI can control how/when the image is built without the + pytest session re-triggering a potentially slow or hanging `docker build`. Subsequent calls within the same session are no-ops (image already built). """ global _swarm_image_built if _swarm_image_built: return + # Skip build if image already exists (e.g. pre-built in CI) + inspect = subprocess.run( + ["docker", "image", "inspect", "byjg/easy-haproxy:local"], + capture_output=True, + ) + if inspect.returncode == 0: + print("\n ✓ byjg/easy-haproxy:local already exists, skipping build") + _swarm_image_built = True + return + project_root = BASE_DIR.parent print("\n → Building byjg/easy-haproxy:local from source...") subprocess.run(