fix: [#342] resolve Docker BuildKit 'image already exists' error in CI#344
Merged
josecelano merged 8 commits intomainfrom Feb 13, 2026
Merged
fix: [#342] resolve Docker BuildKit 'image already exists' error in CI#344josecelano merged 8 commits intomainfrom
josecelano merged 8 commits intomainfrom
Conversation
Apply the same Docker BuildKit fix to the second ImageBuilder in src/testing/e2e/containers/image_builder.rs that was already applied to packages/dependency-installer/tests/containers/image_builder.rs. This ensures both image builders force remove stale images before building and use the --force-rm flag to cleanup intermediate containers.
…building BuildKit uses fully-qualified image names (docker.io/library/...) during the export phase, which was causing 'already exists' errors even after removing the short image name. Now both name formats are removed to ensure clean builds.
Include both stdout and stderr in error messages, and add structured logging with exit codes and output lengths. This will help diagnose the actual failure reason when Docker builds timeout or fail in CI environments.
The docker rmi commands were creating race conditions when multiple tests tried to build the same image concurrently: - Test A: check image doesn't exist -> start building - Test B: check image doesn't exist -> start building - Test A: remove existing images (might remove Test B's partial build!) - Test B: remove existing images (might remove Test A's partial build!) - Both builds complete -> conflict when tagging Docker BuildKit handles concurrent builds to the same tag atomically with internal locking, so we don't need to manually remove images. The image_exists() check at the start is sufficient for the common case. This reverts the image removal logic from commits 74f2151, 3b506dd, and c719c92 which introduced the race condition while trying to fix BuildKit export errors.
…nt tests When parallel tests build the same Docker image simultaneously, the second build may complete all steps successfully but fail at the final export/tagging step with 'already exists' because the first build already claimed the tag. This is not a real failure - the image is available for use. Instead of failing the test, detect this specific error message and treat it as success in both image builders (dependency-installer and e2e containers).
Documents the race condition where parallel tests build the same Docker image simultaneously, causing 'already exists' errors at the tagging step. Records the chosen solution (treat as success), the image staleness caveat for development, and the four alternatives considered and rejected (unique tags, file locks, pre-building, docker rmi).
Adds a new Agent Skill at .github/skills/create-adr/ that guides AI agents through the complete ADR creation workflow: template usage, file naming, index registration, validation, and commit conventions. Registered in AGENTS.md skills table.
Member
Author
|
ACK ff71199 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #342
Resolves Docker BuildKit "image already exists" errors in GitHub Actions CI caused by a race condition during parallel test execution.
Problem
When
cargo testruns multiple integration tests in parallel, each test callsbuild_if_missing()to ensure the Docker image exists. The race condition:build_if_missing()simultaneouslyimage_exists()→ both getfalse(no image yet)docker buildin parallel (~60s each)dependency-installer-test:ubuntu-24.04→ successSolution
When a Docker build fails with "already exists", treat it as success — it means another concurrent test already built and tagged the exact same image, which is now available for use.
Why this is correct
Approaches tried and why they failed
docker rmi -fbefore buildingdocker rmifor fully-qualified namesdocker rmi, trust BuildKit atomicityChanges
packages/dependency-installer/tests/containers/image_builder.rs:build_if_missing()now detects "already exists" in build output and returnsOk(())instead ofErrtracing::{error, info}for structured logging--force-rmflag for intermediate container cleanupsrc/testing/e2e/containers/image_builder.rs:build()method--force-rmflagTesting
cargo clippy,cargo machete,cargo fmtclean