diff --git a/.github/actions/combine-multi-arch-images/action.yaml b/.github/actions/combine-multi-arch-images/action.yaml index 8c446c5ff2c..120ce696f2e 100644 --- a/.github/actions/combine-multi-arch-images/action.yaml +++ b/.github/actions/combine-multi-arch-images/action.yaml @@ -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 }}" + 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/container-retention-policy@v3.0.0 + 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 diff --git a/.github/workflows/update-docker-manifest.yaml b/.github/workflows/update-docker-manifest.yaml index af9324fb162..db1da50dfaa 100644 --- a/.github/workflows/update-docker-manifest.yaml +++ b/.github/workflows/update-docker-manifest.yaml @@ -7,6 +7,8 @@ on: jobs: update-docker-manifest: + permissions: + packages: write runs-on: ubuntu-latest steps: - name: Check out repository