Sync from open-agri repo (#69) #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: Docker Multi-Platform Builds | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| release: | |
| types: [ created ] | |
| jobs: | |
| # ------------------------- | |
| # AMD64 Build | |
| # ------------------------- | |
| build-amd64: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Build and push AMD64 image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| build-args: SOURCE_REPO=https://github.com/${{ github.repository }} | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 | |
| ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-amd64', env.REPO_LOWER) || '' }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # ------------------------- | |
| # ARM64 Build | |
| # ------------------------- | |
| build-arm64: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker daemon (containerd features) | |
| uses: docker/setup-docker-action@v4 | |
| with: | |
| daemon-config: | | |
| { | |
| "debug": true, | |
| "features": { "containerd-snapshotter": true } | |
| } | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Build and push ARM64 image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile | |
| build-args: BUILDKIT_PROGRESS=plain,SOURCE_REPO=https://github.com/${{ github.repository }} | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64 | |
| ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-arm64', env.REPO_LOWER) || '' }} | |
| cache-from: type=gha,scope=arm64 | |
| cache-to: type=gha,scope=arm64,mode=max | |
| # ------------------------- | |
| # Create multi-arch manifest | |
| # ------------------------- | |
| manifest: | |
| needs: [ build-amd64, build-arm64 ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Docker Buildx (for imagetools) | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Create multi-arch manifest for ref tag | |
| run: | | |
| docker buildx imagetools create \ | |
| --tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }} \ | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 \ | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64 | |
| - name: Also tag :latest on main | |
| if: ${{ github.ref_name == 'main' }} | |
| run: | | |
| docker buildx imagetools create \ | |
| --tag ghcr.io/${{ env.REPO_LOWER }}:latest \ | |
| ghcr.io/${{ env.REPO_LOWER }}:latest-amd64 \ | |
| ghcr.io/${{ env.REPO_LOWER }}:latest-arm64 |