| | name: Build Docker Image |
| |
|
| | on: |
| | push: |
| | branches: |
| | - main |
| | tags: |
| | - 'v*' |
| | pull_request: |
| | branches: |
| | - main |
| |
|
| | env: |
| | REGISTRY: ghcr.io |
| | IMAGE_NAME: ${{ github.repository }} |
| |
|
| | jobs: |
| | build-and-push: |
| | runs-on: ubuntu-latest |
| | permissions: |
| | contents: read |
| | packages: write |
| | id-token: write |
| | |
| | strategy: |
| | fail-fast: false |
| | matrix: |
| | include: |
| | |
| | - platform: linux/amd64 |
| | suffix: amd64 |
| | |
| | - platform: linux/arm64 |
| | suffix: arm64 |
| |
|
| | steps: |
| | - name: Checkout repository |
| | uses: actions/checkout@v4 |
| |
|
| | - name: Set up Docker Buildx |
| | uses: docker/setup-buildx-action@v3 |
| |
|
| | - name: Log in to Container Registry |
| | uses: docker/login-action@v3 |
| | with: |
| | registry: ${{ env.REGISTRY }} |
| | username: ${{ github.actor }} |
| | password: ${{ secrets.GITHUB_TOKEN }} |
| |
|
| | - name: Extract metadata |
| | id: meta |
| | uses: docker/metadata-action@v5 |
| | with: |
| | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| | tags: | |
| | # Branch push |
| | type=ref,event=branch,suffix=-${{ matrix.suffix }} |
| | # Semver: full version |
| | type=semver,pattern={{version}},suffix=-${{ matrix.suffix }} |
| | # latest tag |
| | type=raw,value=latest-${{ matrix.suffix }},enable={{is_default_branch}} |
| | |
| | - name: Build and push Docker image |
| | uses: docker/build-push-action@v5 |
| | with: |
| | context: . |
| | platforms: ${{ matrix.platform }} |
| | push: ${{ github.event_name != 'pull_request' }} |
| | tags: ${{ steps.meta.outputs.tags }} |
| | labels: ${{ steps.meta.outputs.labels }} |
| | cache-from: type=gha,scope=${{ matrix.suffix }} |
| | cache-to: type=gha,mode=max,scope=${{ matrix.suffix }} |
| | pull: true |
| | |
| | |
| | merge-manifests: |
| | runs-on: ubuntu-latest |
| | needs: build-and-push |
| | if: github.event_name != 'pull_request' |
| | permissions: |
| | contents: read |
| | packages: write |
| | |
| | steps: |
| | - name: Log in to Container Registry |
| | uses: docker/login-action@v3 |
| | with: |
| | registry: ${{ env.REGISTRY }} |
| | username: ${{ github.actor }} |
| | password: ${{ secrets.GITHUB_TOKEN }} |
| | |
| | - name: Extract metadata |
| | id: meta |
| | uses: docker/metadata-action@v5 |
| | with: |
| | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| | tags: | |
| | type=ref,event=branch |
| | type=semver,pattern={{version}} |
| | type=raw,value=latest,enable={{is_default_branch}} |
| | |
| | - name: Create and push manifest |
| | run: | |
| | TAGS="${{ steps.meta.outputs.tags }}" |
| | for tag in $TAGS; do |
| | echo "Merging tag: $tag" |
| | docker buildx imagetools create -t $tag \ |
| | ${tag}-amd64 \ |
| | ${tag}-arm64 |
| | done |
| | |