From 45cb7f30429a9c8334b347749b3e2a988373bf6b Mon Sep 17 00:00:00 2001 From: "yulai.linda@gmail.com" Date: Sat, 27 Apr 2024 22:12:30 -0400 Subject: [PATCH 1/5] use arm64 github runner for building arm image --- .github/workflows/main.yml | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c83cdf..c7abe02 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,9 @@ on: push + jobs: - build: + build-amd64: runs-on: ubuntu-latest-64-cores steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -37,6 +35,41 @@ jobs: run: | docker push cs50/cli:amd64 + build-arm64: + needs: build-amd64 + runs-on: ubuntu-latest-64-cores-arm + steps: + - name: Install Docker + run: | + export DEBIAN_FRONTEND=noninteractive + sudo apt update + sudo apt install -y ca-certificates curl + sudo install -m 0755 -d /etc/apt/keyrings + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + sudo chmod a+r /etc/apt/keyrings/docker.asc + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt update + sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + sudo usermod -aG docker $USER + sudo apt install -y acl + sudo setfacl --modify user:$USER:rw /var/run/docker.sock + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log into Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Install Python + run: | + sudo apt install -y python3 + - name: Build for linux/arm64 uses: docker/build-push-action@v3 with: From 372761f60d628806486c5e6ef70d3253521f7ddc Mon Sep 17 00:00:00 2001 From: "yulai.linda@gmail.com" Date: Sat, 27 Apr 2024 22:45:20 -0400 Subject: [PATCH 2/5] build amd64 and arm64 docker images concurrently --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7abe02..e1c742c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,6 @@ jobs: docker push cs50/cli:amd64 build-arm64: - needs: build-amd64 runs-on: ubuntu-latest-64-cores-arm steps: - name: Install Docker @@ -87,6 +86,10 @@ jobs: run: | docker push cs50/cli:arm64 + finalize: + needs: [build-amd64, build-arm64] + runs-on: ubuntu-latest + steps: - name: Create multi-arch manifest and push to Docker Hub if: ${{ github.ref == 'refs/heads/main' }} run: | @@ -111,4 +114,4 @@ jobs: workflow_id: 'main.yml', ref: 'main' }); - } + } \ No newline at end of file From b9a5ee3b741fd882e2d68517fcb803411a6a1982 Mon Sep 17 00:00:00 2001 From: "yulai.linda@gmail.com" Date: Sat, 27 Apr 2024 22:55:10 -0400 Subject: [PATCH 3/5] create canary build --- .github/workflows/main.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e1c742c..9e5e478 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,9 @@ jobs: BUILDARCH=amd64 load: true platforms: linux/amd64 - tags: cs50/cli:amd64 + tags: | + cs50/cli:amd64 + cs50/cli:canary-amd64 cache-from: type=registry,ref=cs50/cli:amd64-buildcache cache-to: type=registry,ref=cs50/cli:amd64-buildcache,mode=max @@ -35,6 +37,10 @@ jobs: run: | docker push cs50/cli:amd64 + - name: Push linux/amd64 build to Docker Hub (canary) + run: | + docker push cs50/cli:canary-amd64 + build-arm64: runs-on: ubuntu-latest-64-cores-arm steps: @@ -77,7 +83,9 @@ jobs: BUILDARCH=arm64 load: true platforms: linux/arm64 - tags: cs50/cli:arm64 + tags: | + cs50/cli:arm64 + cs50/cli:canary-arm64 cache-from: type=registry,ref=cs50/cli:arm64-buildcache cache-to: type=registry,ref=cs50/cli:arm64-buildcache,mode=max @@ -86,10 +94,20 @@ jobs: run: | docker push cs50/cli:arm64 + - name: Push linux/arm64 build to Docker Hub (canary) + run: | + docker push cs50/cli:canary-arm64 + finalize: needs: [build-amd64, build-arm64] runs-on: ubuntu-latest steps: + - name: Log into Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Create multi-arch manifest and push to Docker Hub if: ${{ github.ref == 'refs/heads/main' }} run: | @@ -98,6 +116,13 @@ jobs: --amend cs50/cli:arm64 docker manifest push cs50/cli:latest + - name: Create multi-arch manifest and push to Docker Hub (canary) + run: | + docker manifest create cs50/cli:canary \ + --amend cs50/cli:canary-amd64 \ + --amend cs50/cli:canary-arm64 + docker manifest push cs50/cli:canary + - name: Re-deploy depdendents if: ${{ github.ref == 'refs/heads/main' }} uses: actions/github-script@v6 From 2919d87c1eb8203c261509af0071c34fc1674ea7 Mon Sep 17 00:00:00 2001 From: "yulai.linda@gmail.com" Date: Sat, 27 Apr 2024 23:02:17 -0400 Subject: [PATCH 4/5] updated workflow actions versions --- .github/workflows/main.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e5e478..35ba217 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,10 +5,10 @@ jobs: runs-on: ubuntu-latest-64-cores steps: - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -19,7 +19,7 @@ jobs: python-version: '3.11' - name: Build for linux/amd64 - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: build-args: | VCS_REF=${{ github.sha }} @@ -63,10 +63,10 @@ jobs: sudo setfacl --modify user:$USER:rw /var/run/docker.sock - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -76,7 +76,7 @@ jobs: sudo apt install -y python3 - name: Build for linux/arm64 - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: build-args: | VCS_REF=${{ github.sha }} @@ -103,7 +103,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Log into Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} From f5b22c4a337d5006ea9e91b86e3007457ff129e6 Mon Sep 17 00:00:00 2001 From: "yulai.linda@gmail.com" Date: Sun, 28 Apr 2024 18:09:51 -0400 Subject: [PATCH 5/5] added comments --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 35ba217..2aff497 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,7 @@ jobs: build-arm64: runs-on: ubuntu-latest-64-cores-arm steps: - - name: Install Docker + - name: Install Docker (remove once Docker is pre-installed on arm64 runners) run: | export DEBIAN_FRONTEND=noninteractive sudo apt update @@ -71,7 +71,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Install Python + - name: Install Python (replace with setup-python once available on arm64 runners) run: | sudo apt install -y python3