Skip to content
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
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 81 additions & 38 deletions .github/actions/combine-multi-arch-images/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,55 +54,98 @@ runs:
- name: Get base tags
id: get-base-tags
run: |
Comment on lines 54 to 56
Copy link
Member

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.

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 }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be redundant.
https://github.com/autowarefoundation/autoware/actions/runs/11219103356/job/31184311855#step:3:576

Suggested change
echo "All tags: ${{ steps.get-all-tags.outputs.tags }}"

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
2 changes: 2 additions & 0 deletions .github/workflows/update-docker-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

jobs:
update-docker-manifest:
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: Check out repository
Expand Down
Loading