From 6cbe3f424e3c5804f28bf2841020b9238f2a36ed Mon Sep 17 00:00:00 2001
From: Emmanuel Bruno <emmanuel.bruno@univ-tln.fr>
Date: Thu, 13 Apr 2023 07:50:27 +0200
Subject: [PATCH] moves to qemu multiarch.

---
 .github/workflows/ci-baremetal.yml        | 88 +++++++++++++++++++++++
 .github/workflows/{ci.yml => ci-qemu.yml} | 43 ++++++-----
 2 files changed, 115 insertions(+), 16 deletions(-)
 create mode 100644 .github/workflows/ci-baremetal.yml
 rename .github/workflows/{ci.yml => ci-qemu.yml} (77%)

diff --git a/.github/workflows/ci-baremetal.yml b/.github/workflows/ci-baremetal.yml
new file mode 100644
index 0000000..1a10496
--- /dev/null
+++ b/.github/workflows/ci-baremetal.yml
@@ -0,0 +1,88 @@
+name: Multi Arch Bare Metal CI
+
+on:
+  workflow_dispatch:  
+#  push:
+#    branches:
+#      - 'releases/v*'
+#      - 'develop'
+#    tags:
+#      - 'v*.*.*'
+
+concurrency:
+  group: ${{ github.ref }}
+  cancel-in-progress: true
+
+jobs:
+  docker:
+    runs-on: [self-hosted, multiarch]
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+      - name: Set the environment variable
+        run: echo REPOSITORY_NAME=${GITHUB_REPOSITORY#*\/} >> $GITHUB_ENV
+      - name: Docker meta
+        id: meta
+        uses: docker/metadata-action@v4     
+        with:
+          images: |
+            "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}"
+          tags: |
+            type=ref,event=branch
+            type=ref,event=pr
+            type=semver,pattern={{version}}
+            type=semver,pattern={{major}}.{{minor}}
+            type=semver,pattern={{major}}
+          labels: |
+            org.opencontainers.image.description=A test for Docker CI with Github Actions.            
+      - name: Login to DockerHub
+        if: github.event_name != 'pull_request'
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+#      - name: Login to Private registry
+#        if: github.event_name != 'pull_request'
+#        uses: docker/login-action@v2
+#        with:
+#          registry: ${{ secrets.PRIVATEHUB_HOSTNAME }}
+#          username: ${{ secrets.PRIVATEHUB_USERNAME }}
+#          password: ${{ secrets.PRIVATEHUB_TOKEN }}          
+      - uses: webfactory/ssh-agent@v0.7.0
+        with:
+          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v2
+        with:       
+#          config-inline: |
+#            [registry."docker.io"]
+#              mirrors = ["${{ secrets.DOCKERHUB_PROXY_HOSTNAME }}"]
+          driver-opts: |
+            network=host
+          buildkitd-flags: |
+            --debug 
+            --allow-insecure-entitlement network.host
+            --allow-insecure-entitlement security.insecure            
+          endpoint: ssh://bruno@pc-bruno-gpu
+          platforms: linux/amd64
+          append: |
+            - endpoint: ssh://bruno@mbp-bruno
+              platforms: linux/arm64/v8
+      - name: Build and push
+        uses: docker/build-push-action@v4
+        with:
+          context: .
+          platforms: |
+            linux/amd64
+            linux/arm64/v8
+          push: ${{ github.event_name != 'pull_request' }}
+          tags: ${{ steps.meta.outputs.tags }}
+          labels: ${{ steps.meta.outputs.labels }}
+#          cache-from: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ secrets.PRIVATEHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}:buildcache
+#          cache-to: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ secrets.PRIVATEHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}:buildcache,mode=min,compression=zstd
+      - name: Update repo description
+        uses: peter-evans/dockerhub-description@v3
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+          repository: "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}"          
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci-qemu.yml
similarity index 77%
rename from .github/workflows/ci.yml
rename to .github/workflows/ci-qemu.yml
index 6706f17..54b5bdd 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci-qemu.yml
@@ -1,4 +1,4 @@
-name: ci
+name: Multi Arch QEMU CI
 
 on:
   workflow_dispatch:  
@@ -9,14 +9,23 @@ on:
     tags:
       - 'v*.*.*'
 
+concurrency:
+  group: ${{ github.ref }}
+  cancel-in-progress: true
+
 jobs:
   docker:
-    runs-on: [self-hosted, multiarch]
+    runs-on: [self-hosted, qemu]
     steps:
       - name: Checkout
         uses: actions/checkout@v3
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v2
+
       - name: Set the environment variable
         run: echo REPOSITORY_NAME=${GITHUB_REPOSITORY#*\/} >> $GITHUB_ENV
+
       - name: Docker meta
         id: meta
         uses: docker/metadata-action@v4     
@@ -31,12 +40,14 @@ jobs:
             type=semver,pattern={{major}}
           labels: |
             org.opencontainers.image.description=A test for Docker CI with Github Actions.            
+
       - name: Login to DockerHub
         if: github.event_name != 'pull_request'
         uses: docker/login-action@v2
         with:
           username: ${{ secrets.DOCKERHUB_USERNAME }}
           password: ${{ secrets.DOCKERHUB_TOKEN }}
+
       - name: Login to Private registry
         if: github.event_name != 'pull_request'
         uses: docker/login-action@v2
@@ -44,38 +55,38 @@ jobs:
           registry: ${{ secrets.PRIVATEHUB_HOSTNAME }}
           username: ${{ secrets.PRIVATEHUB_USERNAME }}
           password: ${{ secrets.PRIVATEHUB_TOKEN }}          
-      - uses: webfactory/ssh-agent@v0.7.0
-        with:
-          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
+
       - name: Set up Docker Buildx
         uses: docker/setup-buildx-action@v2
         with:       
           config-inline: |
             [registry."docker.io"]
               mirrors = ["${{ secrets.DOCKERHUB_PROXY_HOSTNAME }}"]
+            [registry."${{ secrets.DOCKERHUB_PROXY_HOSTNAME }}"]
+              http = true              
+              insecure = true
+            [registry."${{ secrets.PRIVATEHUB_HOSTNAME }}"]
+              http = true
+              insecure = true
           driver-opts: |
             network=host
           buildkitd-flags: |
             --debug 
             --allow-insecure-entitlement network.host
-            --allow-insecure-entitlement security.insecure            
-          endpoint: ssh://bruno@pc-bruno-gpu
-          platforms: linux/amd64
-          append: |
-            - endpoint: ssh://bruno@mbp-bruno
-              platforms: linux/arm64/v8
+            --allow-insecure-entitlement security.insecure  
+
       - name: Build and push
         uses: docker/build-push-action@v4
         with:
           context: .
-          platforms: |
-            linux/amd64
-            linux/arm64/v8
+          platforms: linux/amd64,linux/arm64/v8
+#          platforms: linux/amd64
           push: ${{ github.event_name != 'pull_request' }}
           tags: ${{ steps.meta.outputs.tags }}
           labels: ${{ steps.meta.outputs.labels }}
-          cache-from: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ secrets.PRIVATEHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}:buildcache
-          cache-to: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ secrets.PRIVATEHUB_USERNAME }}/${{ env.REPOSITORY_NAME }}:buildcache,mode=max
+          cache-from: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ env.REPOSITORY_NAME }}:buildcache
+          cache-to: type=registry,ref=${{ secrets.PRIVATEHUB_HOSTNAME }}/${{ env.REPOSITORY_NAME }}:buildcache,mode=min,compression=zstd
+
       - name: Update repo description
         uses: peter-evans/dockerhub-description@v3
         with:
-- 
GitLab