[llvm] workflows/build-ci-container: Add an arm64 container (PR #120828)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 02:29:19 PST 2025


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/120828

>From 466f273a11a57a83a5df5756c0ee6894efc1c45f Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 20 Dec 2024 22:42:36 -0800
Subject: [PATCH 1/2] workflows/build-ci-container: Add an arm64 container

This also changes the container version numbers in the tag from unix
timestamps to the github run_id and run_attempt for the workflow.
This ensures that the amd64 and arm64 containers have the same version
number.

For amd64 we now generate 4 tags:

* ghcr.io/llvm/ci-ubuntu-22.04:$run_id:latest
* ghcr.io/llvm/ci-ubuntu-22.04:$run_id.$run_attempt
* ghcr.io/llvm/amd64/ci-ubuntu-22.04:latest
* ghcr.io/llvm/amd64/ci-ubuntu-22.04:$run_id.$run_attempt

For arm64 we generate 2 tags:

* ghcr.io/tstellar/arm64v8/ci-ubuntu-22.04:latest
* ghcr.io/tstellar/arm64v8/ci-ubuntu-22.04:$run_id.$run_attempt
---
 .github/workflows/build-ci-container.yml | 49 +++++++++++++++++-------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/build-ci-container.yml b/.github/workflows/build-ci-container.yml
index 50729e0173506e..28ba9c21fefc48 100644
--- a/.github/workflows/build-ci-container.yml
+++ b/.github/workflows/build-ci-container.yml
@@ -20,11 +20,16 @@ on:
 jobs:
   build-ci-container:
     if: github.repository_owner == 'llvm'
-    runs-on: depot-ubuntu-22.04-16
-    outputs:
-      container-name: ${{ steps.vars.outputs.container-name }}
-      container-name-tag: ${{ steps.vars.outputs.container-name-tag }}
-      container-filename: ${{ steps.vars.outputs.container-filename }}
+    runs-on: ${{ matrix.runs-on }}
+    strategy:
+      matrix:
+        include:
+          # The arch names should match the names used on dockerhub.
+          # See https://github.com/docker-library/official-images#architectures-other-than-amd64
+          - arch: amd64
+            runs-on: depot-ubuntu-22.04-16
+          - arch: arm64v8
+            runs-on: depot-ubuntu-22.04-arm-16
     steps:
       - name: Checkout LLVM
         uses: actions/checkout at v4
@@ -33,8 +38,8 @@ jobs:
       - name: Write Variables
         id: vars
         run: |
-          tag=`date +%s`
-          container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/ci-ubuntu-22.04"
+          tag="${{ github.run_id}}.${{ github.run_attempt }}"
+          container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/${{ matrix.arch }}/ci-ubuntu-22.04"
           echo "container-name=$container_name" >> $GITHUB_OUTPUT
           echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT
           echo "container-filename=$(echo $container_name:$tag  | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT
@@ -53,7 +58,7 @@ jobs:
       - name: Upload container image
         uses: actions/upload-artifact at v4
         with:
-          name: container
+          name: container-${{ matrix.arch }}
           path: ${{ steps.vars.outputs.container-filename }}
           retention-days: 14
 
@@ -75,13 +80,29 @@ jobs:
     steps:
       - name: Download container
         uses: actions/download-artifact at v4
-        with:
-          name: container
 
       - name: Push Container
         run: |
-          podman load -i ${{ needs.build-ci-container.outputs.container-filename }}
-          podman tag ${{ needs.build-ci-container.outputs.container-name-tag }} ${{ needs.build-ci-container.outputs.container-name }}:latest
+          function push_container {
+            image_name=$1
+            latest_name=$(echo $image_name | sed 's/:[.0-9]\+$/:latest/g')
+            podman tag $image_name $latest_name
+            echo "Pushing $image_name ..."
+            podman push $image_name
+            echo "Pushing $latest_name ..."
+            podman push $latest_name
+          }
+
           podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io
-          podman push ${{ needs.build-ci-container.outputs.container-name-tag }}
-          podman push ${{ needs.build-ci-container.outputs.container-name }}:latest
+          for f in $(find . -iname *.tar); do
+            image_name=$(podman load -q -i $f | sed 's/Loaded image: //g')
+            push_container $image_name
+
+            if echo $image_name | grep '/amd64/'; then
+              # For amd64, create an alias with the arch component removed.
+              # This matches the convention used on dockerhub.
+              default_image_name=$(echo $(dirname $(dirname $image_name))/$(basename $image_name))
+              podman tag $image_name $default_image_name
+              push_container $default_image_name
+            fi
+          done

>From 77a1267d40e4dc32d7702125894885db58a615e7 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 6 Jan 2025 02:28:06 -0800
Subject: [PATCH 2/2] Use short git sha for container label

---
 .github/workflows/build-ci-container.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-ci-container.yml b/.github/workflows/build-ci-container.yml
index 28ba9c21fefc48..1d9cd90824ea48 100644
--- a/.github/workflows/build-ci-container.yml
+++ b/.github/workflows/build-ci-container.yml
@@ -38,7 +38,7 @@ jobs:
       - name: Write Variables
         id: vars
         run: |
-          tag="${{ github.run_id}}.${{ github.run_attempt }}"
+          tag=$(git rev-parse --short=12 HEAD)
           container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/${{ matrix.arch }}/ci-ubuntu-22.04"
           echo "container-name=$container_name" >> $GITHUB_OUTPUT
           echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT



More information about the llvm-commits mailing list