-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Summary
This issue tracks the adoption of COPY --link in all Dockerfiles across the repository to improve build performance and cache stability.
Background
The COPY --link flag (available in BuildKit with Dockerfile frontend v1.4+) creates independent layers for copied files, decoupling them from earlier commands in the build stage. This approach offers several advantages over standard COPY instructions.
Reference: Suggested in PR #1166, comment #1166 (comment) by @junhaoliao
Benefits
- Stronger cache stability: COPY steps won't be invalidated when earlier commands in the same stage change, leading to more reliable cache hits
- Faster parallel builds: BuildKit can execute COPY operations without waiting for earlier commands to complete
- Reduced I/O and disk usage: BuildKit avoids duplicating file blobs when possible through hard-link-like behavior
- Improved CI/CD performance: Works well with remote cache and enables easier image rebasing
Implementation Requirements
1. Add syntax header to all Dockerfiles
Each Dockerfile must start with:
# syntax=docker/dockerfile:1.42. Update COPY instructions
Replace COPY with COPY --link where appropriate:
COPY --link ./source ./destination3. Dockerfiles to update
The following Dockerfiles should be evaluated and updated:
tools/docker-images/clp-package/Dockerfiletools/docker-images/clp-execution-base-ubuntu-jammy/Dockerfilecomponents/core/tools/docker-images/clp-core-ubuntu-jammy/Dockerfilecomponents/core/tools/docker-images/clp-env-base-centos-stream-9/Dockerfilecomponents/core/tools/docker-images/clp-env-base-manylinux_2_28-aarch64/Dockerfilecomponents/core/tools/docker-images/clp-env-base-manylinux_2_28-x86_64/Dockerfilecomponents/core/tools/docker-images/clp-env-base-musllinux_1_2-aarch64/Dockerfilecomponents/core/tools/docker-images/clp-env-base-musllinux_1_2-x86_64/Dockerfilecomponents/core/tools/docker-images/clp-env-base-ubuntu-jammy/Dockerfile
Important Caveats
-
Destination semantics:
COPY --linkcreates layers starting from an empty filesystem, which can change behavior when copying to ambiguous destinations. Use explicit trailing slashes for directories. -
Symlink resolution: Avoid copying into or relying on symlink resolution from earlier layers, as linked layers don't inherit the previous layer's filesystem state.
-
Testing required: Before production deployment:
- Validate image behavior and file layouts
- Test across different platforms (Linux, macOS, Windows)
- Verify CI/CD pipelines work correctly
- Check interactions with
--chownflags
-
BuildKit requirement: Ensure CI/CD environments use BuildKit (enabled by default in Docker 23.0+, or set
DOCKER_BUILDKIT=1).
Testing Plan
- Update one Dockerfile as a proof-of-concept
- Verify build times and cache behavior improvements
- Test resulting images for correct runtime behavior
- Roll out to remaining Dockerfiles incrementally
- Update CI/CD workflows if needed to ensure BuildKit is enabled
References
- Docker BuildKit COPY --link documentation
- Docker blog: Image rebase and improved remote cache support
- How-To Geek: Docker COPY --link explanation
Success Criteria
- All Dockerfiles updated with syntax header and
COPY --link - Build times improved or maintained
- Cache hit rates improved
- All images validated for correct runtime behavior
- CI/CD pipelines functioning correctly