diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8fb7ae8fd..c621637f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,30 +11,78 @@ env: SPEEDTEST_IMAGE_NAME: ozark-connect/speedtest jobs: - test: - runs-on: ubuntu-latest + build: + strategy: + fail-fast: true + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-latest + - platform: linux/arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + permissions: + contents: read + packages: write steps: - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 + - name: Set platform pair + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 with: - dotnet-version: '10.0.x' + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Restore dependencies - run: dotnet restore + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build - run: dotnet build --no-restore --configuration Release + - name: Extract version from tag + id: version + run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT - - name: Test - env: - FLUENT_ASSERTIONS_LICENSED: ${{ secrets.FLUENT_ASSERTIONS_LICENSED }} - run: dotnet test --no-build --configuration Release --verbosity normal + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=${{ steps.version.outputs.version }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true + cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }} + cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }},mode=max - build-and-push: - needs: test + - 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: + needs: build runs-on: ubuntu-latest permissions: contents: read @@ -43,6 +91,13 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -67,24 +122,17 @@ jobs: type=semver,pattern={{major}} type=raw,value=latest,enable={{is_default_branch}} - - name: Extract version from tag - id: version - run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT + - 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: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./docker/Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - VERSION=${{ steps.version.outputs.version }} - cache-from: type=gha - cache-to: type=gha,mode=max + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} + # Speedtest image - trivial build (copy files into nginx:alpine), QEMU is fine - name: Extract metadata for speedtest image id: speedtest-meta uses: docker/metadata-action@v5 @@ -109,7 +157,7 @@ jobs: cache-to: type=gha,mode=max publish-release: - needs: build-and-push + needs: merge runs-on: ubuntu-latest permissions: contents: write