Blacksmith Build #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Blacksmith Build | |
| on: | |
| push: | |
| branches: [master] | |
| tags: ['v*'] | |
| workflow_dispatch: | |
| jobs: | |
| init: | |
| name: Init Build Metadata | |
| runs-on: blacksmith-2vcpu-ubuntu-2404 | |
| outputs: | |
| image_name: ${{ steps.vars.outputs.image_name }} | |
| tag: ${{ steps.vars.outputs.tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract version and tag | |
| id: vars | |
| run: | | |
| # Lowercase the owner name for Docker registry compatibility | |
| OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| IMAGE_NAME=ghcr.io/${OWNER_LC}/oxidechat | |
| # Extract version from Cargo.toml | |
| VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*= *"\([^"]*\)".*/\1/') | |
| [ -z "$VERSION" ] && VERSION="0.0.0" | |
| TIMESTAMP=$(date +%Y%m%d-%H%M) | |
| TAG="${VERSION}-${TIMESTAMP}" | |
| echo "image_name=$IMAGE_NAME" >> "$GITHUB_OUTPUT" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "📦 Image: $IMAGE_NAME" | |
| echo "🏷️ Tag: $TAG" | |
| build: | |
| needs: init | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runner: blacksmith-2vcpu-ubuntu-2404 | |
| suffix: amd64 | |
| - platform: linux/arm64 | |
| runner: blacksmith-2vcpu-ubuntu-2404-arm | |
| suffix: arm64 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| cache-from: type=gha,scope=${{ matrix.suffix }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.suffix }} | |
| provenance: false | |
| outputs: type=image,name=${{ needs.init.outputs.image_name }},push-by-digest=${{ github.event_name != 'pull_request' }},name-canonical=true | |
| - name: Export digest | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ matrix.suffix }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # ============================================================================ | |
| # Docker - Create multi-arch manifest after parallel builds complete | |
| # ============================================================================ | |
| docker: | |
| needs: [init, build] | |
| runs-on: blacksmith-2vcpu-ubuntu-2404 | |
| if: github.event_name != 'pull_request' | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - 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: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create manifest list and push | |
| env: | |
| IMAGE_NAME: ${{ needs.init.outputs.image_name }} | |
| TAG: ${{ needs.init.outputs.tag }} | |
| working-directory: /tmp/digests | |
| run: | | |
| # Create versioned tag and latest tag | |
| docker buildx imagetools create \ | |
| -t $IMAGE_NAME:$TAG \ | |
| -t $IMAGE_NAME:latest \ | |
| $(printf "$IMAGE_NAME@sha256:%s " *) | |
| echo "✅ Pushed $IMAGE_NAME:$TAG" | |
| echo "✅ Pushed $IMAGE_NAME:latest" | |
| - name: Inspect image | |
| env: | |
| IMAGE_NAME: ${{ needs.init.outputs.image_name }} | |
| TAG: ${{ needs.init.outputs.tag }} | |
| run: | | |
| docker buildx imagetools inspect $IMAGE_NAME:$TAG |