Update docker.yaml #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & Push to GHCR | |
| on: | |
| workflow_dispatch: | |
| push: | |
| # tags: | |
| # - 'v*' | |
| # - '!v*-alpha*' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract version & image name | |
| id: vars | |
| run: | | |
| if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | |
| raw_tag="${GITHUB_REF#refs/tags/}" | |
| version="${raw_tag#v}" | |
| else | |
| # ----- Branch / PR fallback ----- | |
| branch="${GITHUB_REF#refs/heads/}" | |
| # Replace / and uppercase chars with safe lowercase dashes | |
| safe_branch=$(echo "$branch" | tr '[:upper:]/' '[:lower:]-') | |
| sha=${GITHUB_SHA::8} | |
| raw_tag="${safe_branch}-${sha}" | |
| version="$raw_tag" | |
| fi | |
| image_repo="ghcr.io/${GITHUB_REPOSITORY,,}" | |
| echo "raw_tag=$raw_tag" >> "$GITHUB_OUTPUT" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "image_repo=$image_repo" >> "$GITHUB_OUTPUT" | |
| - name: Build & push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: | | |
| ${{ steps.vars.outputs.image_repo }}:${{ steps.vars.outputs.version }} | |
| ${{ steps.vars.outputs.image_repo }}:${{ steps.vars.outputs.raw_tag }} | |
| ${{ steps.vars.outputs.image_repo }}:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |