From 16d9c323bba57c373e97949a9286bf7250d389ef Mon Sep 17 00:00:00 2001 From: lennoxlotl Date: Tue, 22 Oct 2024 00:16:35 +0200 Subject: [PATCH] feat: test new build format --- .github/workflows/api.yml | 75 +++++++++------------------------------ 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 816f860..5c20d8b 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -2,6 +2,8 @@ name: Build api on: push: + tags: + - "*" branches: - "main" @@ -22,29 +24,32 @@ jobs: fail-fast: false matrix: platform: - - linux/amd64 - - linux/arm64 + - { docker: linux/amd64, fancy: amd64 } + - { docker: linux/arm64, fancy: arm64 } steps: - - name: Prepare environemnt + - name: Prepare environment run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + else + echo "VERSION=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV + fi - name: Checkout repository uses: actions/checkout@v4 - name: Install cross (for aarch64 builds) - if: matrix.platform == 'linux/arm64' + if: matrix.platform.fancy == 'arm64' run: cargo install cross - name: Build binary (aarch64) - if: matrix.platform == 'linux/arm64' + if: matrix.platform.fancy == 'arm64' run: cross build --target aarch64-unknown-linux-gnu --release - name: Copy binary (aarch64) - if: matrix.platform == 'linux/arm64' + if: matrix.platform.fancy == 'arm64' run: mv target/aarch64-unknown-linux-gnu/release/api api/api - name: Build binary (amd64) - if: matrix.platform == 'linux/amd64' + if: matrix.platform.fancy == 'amd64' run: cargo build --release - name: Copy binary (amd64) - if: matrix.platform == 'linux/amd64' + if: matrix.platform.fancy == 'amd64' run: mv target/release/api api/api - name: Docker meta id: meta @@ -66,54 +71,8 @@ jobs: uses: docker/build-push-action@v6 with: push: true - platforms: ${{ matrix.platform }} + platforms: ${{ matrix.platform.docker }} context: api/ file: api/Dockerfile labels: ${{ steps.meta.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@v4 - with: - name: digests-${{ env.PLATFORM_PAIR }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - merge: - runs-on: ubuntu-latest - needs: - - build - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Download digests - uses: actions/download-artifact@v4 - with: - path: /tmp/digests - pattern: digests-* - merge-multiple: true - - 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: Login to repository - 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 ' *) - - name: Inspect image - run: | - docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ matrix.platform.fancy }}