-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(docker): update docker manifest #5310
Draft
oguzkaganozt
wants to merge
21
commits into
main
Choose a base branch
from
fix-update-docker-manifest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+83
−38
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7bf0bc2
update docker manifest action
oguzkaganozt ca233a9
update docker manifest actionwith tag removal to prevent confusion
oguzkaganozt 777b995
fix tag removeal
oguzkaganozt b85e8c2
style(pre-commit): autofix
pre-commit-ci[bot] 6f285f7
remove dry-run
oguzkaganozt 50eb3b8
style(pre-commit): autofix
pre-commit-ci[bot] ff7c503
add permission to write to packages
oguzkaganozt ce22dc3
update delete action version
oguzkaganozt a5a1cf3
.
oguzkaganozt a74a61f
.
oguzkaganozt bb6193e
.
oguzkaganozt a4f905f
.
oguzkaganozt e97f1e5
.
oguzkaganozt ede48d6
.
oguzkaganozt af34cf8
.
oguzkaganozt 4fb2b6d
select only tagged versions to remove
oguzkaganozt 39c05b7
test
oguzkaganozt c8b4719
.
oguzkaganozt e7bb052
enable
oguzkaganozt d3038ca
fix precommit checks
oguzkaganozt 546f0b7
remove comment
oguzkaganozt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -54,55 +54,98 @@ runs: | |||
- name: Get base tags | ||||
id: get-base-tags | ||||
run: | | ||||
amd64_tags=$(printf "%s\n" $ALL_TAGS | grep "\-amd64" | sed "s/-amd64$//g") | ||||
arm64_tags=$(printf "%s\n" $ALL_TAGS | grep "\-arm64" | sed "s/-arm64$//g") | ||||
base_tags=$(printf "%s\n" "$amd64_tags" "$arm64_tags" | sort | uniq) | ||||
echo "All tags: ${{ steps.get-all-tags.outputs.tags }}" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be redundant.
Suggested change
|
||||
amd64_tags=() | ||||
arm64_tags=() | ||||
for tag in ${{ steps.get-all-tags.outputs.tags }}; do | ||||
echo "Processing tag: $tag" | ||||
if [[ $tag == *-amd64 ]]; then | ||||
amd64_tags+=("${tag%-amd64}") | ||||
echo "Added to amd64_tags: ${tag%-amd64}" | ||||
elif [[ $tag == *-arm64 ]]; then | ||||
arm64_tags+=("${tag%-arm64}") | ||||
echo "Added to arm64_tags: ${tag%-arm64}" | ||||
else | ||||
echo "Tag doesn't match expected pattern: $tag" | ||||
fi | ||||
done | ||||
base_tags=($(printf "%s\n" "${amd64_tags[@]}" "${arm64_tags[@]}" | sort -u)) | ||||
|
||||
echo -e "\n[amd64_tags]\n$amd64_tags" | ||||
echo -e "\n[arm64_tags]\n$arm64_tags" | ||||
echo -e "\n[base_tags]\n$base_tags" | ||||
echo -e "\n[amd64_tags]\n${amd64_tags[*]}" | ||||
echo -e "\n[arm64_tags]\n${arm64_tags[*]}" | ||||
echo -e "\n[base_tags]\n${base_tags[*]}" | ||||
|
||||
echo "tags=$(printf "%s " $base_tags | sed 's/\s*$//')" >> $GITHUB_OUTPUT | ||||
env: | ||||
ALL_TAGS: ${{ steps.get-all-tags.outputs.tags }} | ||||
echo "tags=${base_tags[*]}" >> $GITHUB_OUTPUT | ||||
shell: bash | ||||
|
||||
- name: Create Docker manifest | ||||
- name: Create Docker manifests | ||||
id: create-manifests | ||||
run: | | ||||
for base_tag in $BASE_TAGS; do | ||||
echo -e "\nbase_tag: $base_tag" | ||||
IFS=' ' read -ra BASE_TAGS <<< "${{ steps.get-base-tags.outputs.tags }}" | ||||
echo "Base tags: ${BASE_TAGS[*]}" | ||||
tags_to_remove="" | ||||
for base_tag in "${BASE_TAGS[@]}"; do | ||||
echo -e "\nProcessing base_tag: $base_tag" | ||||
|
||||
amd64_tag=$(printf "%s\n" $ALL_TAGS | grep "^$base_tag\-amd64" || true) | ||||
arm64_tag=$(printf "%s\n" $ALL_TAGS | grep "^$base_tag\-arm64" || true) | ||||
amd64_tag=$(echo "${{ steps.get-all-tags.outputs.tags }}" | tr ' ' '\n' | grep "^${base_tag}-amd64$" || true) | ||||
arm64_tag=$(echo "${{ steps.get-all-tags.outputs.tags }}" | tr ' ' '\n' | grep "^${base_tag}-arm64$" || true) | ||||
|
||||
echo "amd64_tag: $amd64_tag" | ||||
echo "arm64_tag: $arm64_tag" | ||||
|
||||
if [ "$amd64_tag" != "" ]; then | ||||
amd64_image="${{ steps.set-image-name.outputs.image-name }}:$amd64_tag" | ||||
if [ -n "$amd64_tag" ] && [ -n "$arm64_tag" ]; then | ||||
echo "Both amd64 and arm64 tags found for '$base_tag'. Creating manifest." | ||||
manifest_args=( | ||||
"${{ steps.set-image-name.outputs.image-name }}:$amd64_tag" | ||||
"${{ steps.set-image-name.outputs.image-name }}:$arm64_tag" | ||||
) | ||||
|
||||
echo "Creating manifest for $base_tag with 2 architectures" | ||||
echo "Manifest command: docker manifest create ${{ steps.set-image-name.outputs.image-name }}:$base_tag ${manifest_args[*]}" | ||||
if docker manifest create "${{ steps.set-image-name.outputs.image-name }}:$base_tag" "${manifest_args[@]}"; then | ||||
echo "Pushing manifest: docker manifest push ${{ steps.set-image-name.outputs.image-name }}:$base_tag" | ||||
if docker manifest push "${{ steps.set-image-name.outputs.image-name }}:$base_tag"; then | ||||
echo "Successfully pushed manifest for $base_tag" | ||||
|
||||
# Verify the manifest | ||||
echo "Verifying manifest:" | ||||
docker manifest inspect "${{ steps.set-image-name.outputs.image-name }}:$base_tag" | ||||
|
||||
# Check if both architectures are present in the manifest | ||||
if docker manifest inspect "${{ steps.set-image-name.outputs.image-name }}:$base_tag" | grep -q "arm64" && \ | ||||
docker manifest inspect "${{ steps.set-image-name.outputs.image-name }}:$base_tag" | grep -q "amd64"; then | ||||
echo "Manifest verification successful. Adding tags to removal list." | ||||
tags_to_remove+="$amd64_tag $arm64_tag " | ||||
else | ||||
echo "Manifest verification failed. Skipping tag removal to prevent data loss." | ||||
fi | ||||
else | ||||
echo "Failed to push manifest for $base_tag" | ||||
docker manifest inspect "${{ steps.set-image-name.outputs.image-name }}:$base_tag" | ||||
fi | ||||
else | ||||
echo "Failed to create manifest for $base_tag" | ||||
echo "Docker info:" | ||||
docker info | ||||
echo "Docker version:" | ||||
docker version | ||||
fi | ||||
else | ||||
echo "No amd64 tag found for '$base_tag'." | ||||
amd64_image="" | ||||
fi | ||||
|
||||
if [ "$arm64_tag" != "" ]; then | ||||
arm64_image="${{ steps.set-image-name.outputs.image-name }}:$arm64_tag" | ||||
else | ||||
echo "No arm64 tag found for '$base_tag'." | ||||
arm64_image="" | ||||
fi | ||||
|
||||
echo "amd64_image: $amd64_image" | ||||
echo "arm64_image: $arm64_image" | ||||
|
||||
if docker manifest create ${{ steps.set-image-name.outputs.image-name }}:$base_tag \ | ||||
$amd64_image \ | ||||
$arm64_image; then | ||||
|
||||
docker manifest push ${{ steps.set-image-name.outputs.image-name }}:$base_tag | ||||
echo "Both amd64 and arm64 tags not found for '$base_tag'. Skipping manifest creation." | ||||
fi | ||||
done | ||||
env: | ||||
ALL_TAGS: ${{ steps.get-all-tags.outputs.tags }} | ||||
BASE_TAGS: ${{ steps.get-base-tags.outputs.tags }} | ||||
|
||||
tags_to_remove=${tags_to_remove% } | ||||
echo "tags-to-remove=$tags_to_remove" >> $GITHUB_OUTPUT | ||||
shell: bash | ||||
|
||||
- name: Remove old images | ||||
uses: snok/[email protected] | ||||
with: | ||||
account: autowarefoundation | ||||
token: ${{ github.token }} | ||||
image-names: autoware | ||||
image-tags: ${{ steps.create-manifests.outputs.tags-to-remove }} | ||||
cut-off: 1h | ||||
dry-run: false | ||||
tag-selection: tagged |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a shell script file that performs this process and rewrite this action to just call it? This will improve readability and maintainability.