docker-build #19
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: docker-build | |
| on: | |
| # Main-branch images publish only after `ci` (lint + tests) is green — | |
| # avoids burning runner minutes on commits that already failed CI. | |
| workflow_run: | |
| workflows: ["ci"] | |
| types: [completed] | |
| branches: [main] | |
| # Tag releases (`v*`) and manual dispatches bypass the `ci` gate — | |
| # tagging assumes the underlying commit has already passed CI. | |
| push: | |
| tags: ["v*"] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| if: >- | |
| github.event_name != 'workflow_run' || | |
| github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: backend | |
| context: ./backend | |
| - name: frontend | |
| context: ./frontend | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # On workflow_run, github.ref points at the default branch HEAD; | |
| # pin to the SHA that actually passed CI. | |
| ref: ${{ github.event.workflow_run.head_sha || github.ref }} | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }}/${{ matrix.name }} | |
| tags: | | |
| type=sha | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - uses: docker/build-push-action@v6 | |
| with: | |
| context: ${{ matrix.context }} | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=${{ matrix.name }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.name }} |