Build and Push Docker Image #10
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 and Push Docker Image | |
| # Manually triggered only — auto-building on every commit made the alpha version counter | |
| # climb out of control with no way to signal "this build is actually worth keeping around." | |
| # Run this from the Actions tab (or `gh workflow run docker-build.yml`) once a change has | |
| # been verified, not on every push. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Tag suffix (e.g. "3" for alpha-v0.1.3). Leave blank to auto-use the run number.' | |
| required: false | |
| type: string | |
| update_latest: | |
| description: 'Also update the :latest tag' | |
| required: true | |
| type: boolean | |
| default: true | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # GHCR requires lowercase image names; github.repository preserves repo casing | |
| # ("jherforth/Monastery"), which would fail the push. | |
| - name: Compute lowercase image name | |
| id: image | |
| run: echo "name=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" | |
| # Manual runs still need SOME auto-incrementing fallback for the common case where you | |
| # don't care about a specific number — the run number only advances when you actually | |
| # click "Run workflow", so it stays meaningful now instead of ticking on every commit. | |
| - name: Compute version tag | |
| id: version | |
| run: | | |
| if [ -n "${{ inputs.version }}" ]; then | |
| echo "tag=alpha-v0.1.${{ inputs.version }}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "tag=alpha-v0.1.${{ github.run_number }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: docker/Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ steps.version.outputs.tag }} | |
| ${{ inputs.update_latest && format('{0}/{1}:latest', env.REGISTRY, steps.image.outputs.name) || '' }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |