Skip to content

Commit

Permalink
fix: sanitize Docker image tags to remove invalid characters
Browse files Browse the repository at this point in the history
The workflow was failing when attempting to build and push images with tags
containing characters that aren't allowed in Docker image tags. This was
particularly problematic with Dependabot branch names like
"dependabot/go_modules/github.com/go-jose/go-jose/v3-3.0.4".

This commit adds tag sanitization by replacing invalid characters (slashes
and periods) with hyphens, ensuring all generated Docker image tags comply
with the requirement that repository names only contain the characters
`abcdefghijklmnopqrstuvwxyz0123456789_-./`.

Fixes the error:
"repository can only contain the characters
`abcdefghijklmnopqrstuvwxyz0123456789_-./`"

cf: #1966

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
  • Loading branch information
chmouel committed Feb 27, 2025
1 parent 516e0e8 commit 13b434c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ jobs:
elif [[ ${{ github.ref }} == refs/pull/* ]]; then
tag=pr-$(echo ${{ github.ref }} | cut -c11-|sed 's,/merge,,')
else
tag=$(echo ${{ github.ref_name }}|sed 's,/merge,,')
# Sanitize the tag by replacing invalid characters with hyphens
tag=$(echo ${{ github.ref_name }}|sed 's,/merge,,' | sed 's,[/.],-,g')
fi
for image in ./cmd/*;do
ko build -B -t "${tag}" --platform="${{ env.PLATFORMS }}" "${image}"
Expand Down

0 comments on commit 13b434c

Please sign in to comment.