| 
 | 1 | +name: Build and Publish Docker Image  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  push:  | 
 | 5 | +    branches: [ main, develop ]  | 
 | 6 | +    tags: [ 'v*' ]  | 
 | 7 | +  pull_request:  | 
 | 8 | +    branches: [ main ]  | 
 | 9 | +  workflow_dispatch:  | 
 | 10 | + | 
 | 11 | +env:  | 
 | 12 | +  REGISTRY: ghcr.io  | 
 | 13 | +  IMAGE_NAME: ${{ github.repository }}  | 
 | 14 | + | 
 | 15 | +jobs:  | 
 | 16 | +  build:  | 
 | 17 | +    runs-on: ubuntu-latest  | 
 | 18 | +    permissions:  | 
 | 19 | +      contents: read  | 
 | 20 | +      packages: write  | 
 | 21 | +      id-token: write  | 
 | 22 | + | 
 | 23 | +    steps:  | 
 | 24 | +      - name: Checkout repository  | 
 | 25 | +        uses: actions/checkout@v4  | 
 | 26 | + | 
 | 27 | +      - name: Set up Docker Buildx  | 
 | 28 | +        uses: docker/setup-buildx-action@v3  | 
 | 29 | + | 
 | 30 | +      - name: Log in to the Container registry  | 
 | 31 | +        if: github.event_name != 'pull_request'  | 
 | 32 | +        uses: docker/login-action@v3  | 
 | 33 | +        with:  | 
 | 34 | +          registry: ${{ env.REGISTRY }}  | 
 | 35 | +          username: ${{ github.actor }}  | 
 | 36 | +          password: ${{ secrets.GITHUB_TOKEN }}  | 
 | 37 | + | 
 | 38 | +      - name: Extract metadata  | 
 | 39 | +        id: meta  | 
 | 40 | +        uses: docker/metadata-action@v5  | 
 | 41 | +        with:  | 
 | 42 | +          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}  | 
 | 43 | +          tags: |  | 
 | 44 | +            type=ref,event=branch  | 
 | 45 | +            type=ref,event=pr  | 
 | 46 | +            type=semver,pattern={{version}}  | 
 | 47 | +            type=semver,pattern={{major}}.{{minor}}  | 
 | 48 | +            type=semver,pattern={{major}}  | 
 | 49 | +            type=sha,prefix={{branch}}-  | 
 | 50 | +            type=raw,value=latest,enable={{is_default_branch}}  | 
 | 51 | +
  | 
 | 52 | +      - name: Build and push Docker image  | 
 | 53 | +        uses: docker/build-push-action@v5  | 
 | 54 | +        with:  | 
 | 55 | +          context: .  | 
 | 56 | +          platforms: linux/amd64,linux/arm64  | 
 | 57 | +          push: ${{ github.event_name != 'pull_request' }}  | 
 | 58 | +          tags: ${{ steps.meta.outputs.tags }}  | 
 | 59 | +          labels: ${{ steps.meta.outputs.labels }}  | 
 | 60 | +          cache-from: type=gha  | 
 | 61 | +          cache-to: type=gha,mode=max  | 
 | 62 | +          build-args: |  | 
 | 63 | +            USER_UID=1000  | 
 | 64 | +            USER_GID=1000  | 
0 commit comments