# .github/workflows/docker-build-and-push.yml name: build & push the images on: push: branches: [main] tags: ['*'] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }}/cactoide PUBLIC_LANDING_INFO: true jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up QEMU (for multi-arch) uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Normalize image name to lowercase run: echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >> $GITHUB_ENV env: IMAGE_NAME: ${{ env.IMAGE_NAME }} - name: Log in to GHCR uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # Generate tags & labels: # - short SHA on all pushes # - git tag on tag pushes # - latest only on default branch (e.g., main) - name: Extract Docker metadata (tags, labels) id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }} tags: | type=sha,format=short type=ref,event=tag type=raw,value=latest,enable={{is_default_branch}} labels: | org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} - name: Build and push Docker image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true platforms: linux/amd64,linux/arm64 cache-from: type=gha cache-to: type=gha,mode=max tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}