Fix Docker cache tag length exceeding 128 character limit #1029
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.
Problem
Docker image tags have a maximum length of 128 characters. When building with long base image names (e.g., SWE-Bench images like
docker.io/s/swebench/s/sweb.eval.x86_64.scikit-learn__scikit-learn-25973:latest), the generated cache tags can exceed this limit and cause build failures with:This issue occurs when the
base_image_slug(created from the base image name with/and:replaced by_s_) combined with the cache prefix (buildcache-{target}-) and branch name suffix exceeds 128 characters.Example of a tag that exceeds the limit:
This tag is 133 characters long, exceeding Docker's 128-character limit by 5 characters.
Solution
This PR implements a fix that hashes the
base_image_slugwhen it would cause the final cache tag to exceed 128 characters. It uses SHA256 hash (first 12 chars) to create a shorter unique identifier while maintaining cache efficiency across builds.Changes:
hashlibfor SHA256 hashingbase_sluggiven the prefix and branch suffixbase_slugwould cause overflow, replaces it with a 12-char hashExample with the fix:
For the same scikit-learn image, the new cache tag would be:
This is well under the 128-character limit while maintaining uniqueness.
Testing
This fix has been tested in the OpenHands/benchmarks repository PR OpenHands/benchmarks#51, where it successfully resolves the build failures for SWE-Bench images with long names.
Impact
Related Issues
This fix is being used in OpenHands/benchmarks#51 to enable building SWE-Bench Docker images.
@xingyaoww can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:336db96-pythonRun
All tags pushed for this build
About Multi-Architecture Support
336db96-python) is a multi-arch manifest supporting both amd64 and arm64336db96-python-amd64) are also available if needed