Initial commit #9
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: Build & Publish Moltis multi-arch image to GHCR | |
| on: | |
| push: | |
| branches: [ master, main ] | |
| paths: | |
| - '.docker/moltis/**' | |
| - '.github/workflows/build-docker-moltis.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-moltis | |
| jobs: | |
| prepare: | |
| name: Prepare tags | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_tag: ${{ steps.tags.outputs.version_tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Resolve image tags | |
| id: tags | |
| run: | | |
| VERSION_TAG="$(awk ' | |
| /^\[workspace.package\]/ { in_section=1; next } | |
| /^\[/ { in_section=0 } | |
| in_section && /^version[[:space:]]*=/ { | |
| gsub(/"/, "", $3); | |
| print $3; | |
| exit | |
| } | |
| ' .docker/moltis/Cargo.toml)" | |
| if [ -z "$VERSION_TAG" ]; then | |
| echo "Failed to resolve moltis version from .docker/moltis/Cargo.toml" | |
| exit 1 | |
| fi | |
| echo "version_tag=$VERSION_TAG" >> "$GITHUB_OUTPUT" | |
| echo "Using tags: latest and $VERSION_TAG" | |
| build-amd64: | |
| name: Build AMD64 image | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Verify vendored source | |
| run: | | |
| test -f .docker/moltis/Cargo.toml | |
| test -f .docker/moltis/crates/memory/Cargo.toml | |
| echo "Moltis source is present" | |
| - 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 GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & push AMD64 image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./.docker/moltis | |
| file: ./.docker/moltis/Dockerfile.stack | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:latest-amd64 | |
| ${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version_tag }}-amd64 | |
| cache-from: type=gha,scope=moltis-amd64 | |
| cache-to: type=gha,mode=max,scope=moltis-amd64 | |
| build-arm64: | |
| name: Build ARM64 image | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Verify vendored source | |
| run: | | |
| test -f .docker/moltis/Cargo.toml | |
| test -f .docker/moltis/crates/memory/Cargo.toml | |
| echo "Moltis source is present" | |
| - 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 GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & push ARM64 image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./.docker/moltis | |
| file: ./.docker/moltis/Dockerfile.stack | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_NAME }}:latest-arm64 | |
| ${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.version_tag }}-arm64 | |
| cache-from: type=gha,scope=moltis-arm64 | |
| cache-to: type=gha,mode=max,scope=moltis-arm64 | |
| create-manifest: | |
| name: Create multi-arch manifest | |
| needs: [prepare, build-amd64, build-arm64] | |
| if: always() && needs.build-amd64.result == 'success' && needs.build-arm64.result == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create and push multi-arch manifest | |
| run: | | |
| VERSION_TAG="${{ needs.prepare.outputs.version_tag }}" | |
| IMAGE="${{ env.IMAGE_NAME }}" | |
| docker buildx imagetools create \ | |
| --tag "${IMAGE}:latest" \ | |
| "${IMAGE}:latest-amd64" \ | |
| "${IMAGE}:latest-arm64" | |
| docker buildx imagetools create \ | |
| --tag "${IMAGE}:${VERSION_TAG}" \ | |
| "${IMAGE}:${VERSION_TAG}-amd64" \ | |
| "${IMAGE}:${VERSION_TAG}-arm64" | |
| echo "Created manifests: ${IMAGE}:latest and ${IMAGE}:${VERSION_TAG}" |