From d4405699c9f5925725ad67f0054a31fb90d9323f Mon Sep 17 00:00:00 2001 From: Aljoscha Poertner Date: Fri, 13 Oct 2023 11:39:00 +0200 Subject: [PATCH] ci: build nightly for amd64 and arm64 Signed-off-by: Aljoscha Poertner --- .github/workflows/build.yml | 83 ++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1cd98a3..2cd0790 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,6 +45,12 @@ jobs: name: Build a nightly version of runo runs-on: ubuntu-latest needs: coverage + strategy: + fail-fast: false + matrix: + recipe: + - { target: aarch64-unknown-linux-gnu, platform: linux/arm64 } + - { target: x86_64-unknown-linux-gnu, platform: linux/amd64 } steps: - name: Checkout repository uses: actions/checkout@v4 @@ -52,21 +58,29 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable + target: ${{ matrix.recipe.target }} override: true - - name: Build binary - run: cargo build - - name: Compress binary - run: zip target/debug/runo.zip target/debug/runo + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target ${{ matrix.recipe.target }} - name: Archive artifacts uses: actions/upload-artifact@v3 with: - name: binary - path: target/debug/runo.zip - retention-days: 30 + name: ${{ matrix.recipe.target }} + path: target/${{ matrix.recipe.target }}/debug/runo + retention-days: 5 image: name: Build and push image runs-on: ubuntu-latest - needs: coverage + needs: build + strategy: + fail-fast: false + matrix: + recipe: + - { target: aarch64-unknown-linux-gnu, platform: linux/arm64 } + - { target: x86_64-unknown-linux-gnu, platform: linux/amd64 } permissions: contents: read packages: write @@ -76,6 +90,10 @@ jobs: - name: Debug run: | echo "github.ref -> {{ github.ref }}" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Log in to the Container registry uses: docker/login-action@v3 with: @@ -89,11 +107,56 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value={{sha}} + - name: Download a single artifact + uses: actions/download-artifact@v3 + with: + name: ${{ matrix.recipe.target }} - name: Build and push image + id: build uses: docker/build-push-action@v5 with: context: . - push: true - tags: ${{ steps.metadata.outputs.tags }} + platforms: ${{ matrix.recipe.platform }} labels: ${{ steps.metadata.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + merge: + runs-on: ubuntu-latest + needs: + - image + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)