name: Build and Publish Docker Image on: push: branches: [main, master] tags: ['v*'] pull_request: branches: [main, master] env: REGISTRY: ${{ github.server_url == 'https://github.com' && 'ghcr.io' || 'git.ipao.vip' }} IMAGE_NAME: ${{ github.repository }} jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 with: cache-image: ${{ github.server_url == 'https://github.com' }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to container registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.server_url == 'https://github.com' && github.actor || github.repository_owner }} password: ${{ github.server_url == 'https://github.com' && secrets.GITHUB_TOKEN || secrets.PACKAGE_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: ${{ github.server_url == 'https://github.com' && 'type=gha' || '' }} cache-to: ${{ github.server_url == 'https://github.com' && 'type=gha,mode=max' || '' }} platforms: linux/amd64,linux/arm64