refactor: upgrade Docker build-push action to v6 and improve manifest… #24
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 and Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| env: | |
| DOCKERHUB_REGISTRY: docker.io | |
| DOCKERHUB_IMAGE: productdevbook/nitroping | |
| GHCR_REGISTRY: ghcr.io | |
| GHCR_IMAGE: ${{ github.repository }} | |
| jobs: | |
| build-amd64: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }} | |
| ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }} | |
| tags: | | |
| type=ref,event=branch,suffix=-amd64 | |
| type=semver,pattern={{version}},suffix=-amd64 | |
| type=semver,pattern={{major}}.{{minor}},suffix=-amd64 | |
| type=semver,pattern={{major}},suffix=-amd64 | |
| type=raw,value=latest-amd64,enable={{is_default_branch}} | |
| - name: Build and push AMD64 Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| target: production | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=amd64 | |
| cache-to: type=gha,mode=max,scope=amd64 | |
| build-args: | | |
| DATABASE_URL=postgresql://dummy:dummy@localhost:5432/dummy | |
| JWT_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| WEBHOOK_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| AUTO_MIGRATE=false | |
| build-arm64: | |
| runs-on: ubuntu-24.04-arm | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }} | |
| ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }} | |
| tags: | | |
| type=ref,event=branch,suffix=-arm64 | |
| type=semver,pattern={{version}},suffix=-arm64 | |
| type=semver,pattern={{major}}.{{minor}},suffix=-arm64 | |
| type=semver,pattern={{major}},suffix=-arm64 | |
| type=raw,value=latest-arm64,enable={{is_default_branch}} | |
| - name: Build and push ARM64 Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| target: production | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=arm64 | |
| cache-to: type=gha,mode=max,scope=arm64 | |
| build-args: | | |
| DATABASE_URL=postgresql://dummy:dummy@localhost:5432/dummy | |
| JWT_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| WEBHOOK_SECRET=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | |
| AUTO_MIGRATE=false | |
| create-manifest: | |
| runs-on: ubuntu-latest | |
| needs: [build-amd64, build-arm64] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker Hub | |
| id: meta-dockerhub | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Extract metadata for GHCR | |
| id: meta-ghcr | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{major}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Create and push Docker Hub manifest | |
| run: | | |
| echo '${{ steps.meta-dockerhub.outputs.tags }}' | while IFS= read -r tag; do | |
| [ -z "$tag" ] && continue | |
| docker buildx imagetools create \ | |
| --tag "${tag}" \ | |
| "${tag}-amd64" \ | |
| "${tag}-arm64" | |
| done | |
| - name: Create and push GHCR manifest | |
| run: | | |
| echo '${{ steps.meta-ghcr.outputs.tags }}' | while IFS= read -r tag; do | |
| [ -z "$tag" ] && continue | |
| docker buildx imagetools create \ | |
| --tag "${tag}" \ | |
| "${tag}-amd64" \ | |
| "${tag}-arm64" | |
| done |