name: Build & Push Docker Image on: push: branches: [main] workflow_dispatch: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} # e.g. owner/repo → ghcr.io/owner/repo jobs: build-and-push: 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 GitHub Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=sha,prefix=sha- - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max # Optional: trigger xCloud to pull & redeploy # Add XCLOUD_DEPLOY_WEBHOOK to GitHub repo secrets - name: Trigger xCloud deploy if: ${{ secrets.XCLOUD_DEPLOY_WEBHOOK != '' }} run: | curl -s -X POST "${{ secrets.XCLOUD_DEPLOY_WEBHOOK }}" \ -H "Content-Type: application/json" \ -d '{"ref": "${{ github.sha }}"}' # ───────────────────────────────────────────── # Multi-service variant (uncomment if needed) # ───────────────────────────────────────────── # jobs: # build-and-push: # strategy: # matrix: # include: # - service: app # dockerfile: Dockerfile # image_suffix: app # - service: worker # dockerfile: Dockerfile.worker # image_suffix: worker # steps: # - name: Build and push # uses: docker/build-push-action@v5 # with: # context: . # file: ${{ matrix.dockerfile }} # tags: ghcr.io/${{ github.repository }}-${{ matrix.image_suffix }}:latest