|
| 1 | +name: Docker |
| 2 | + |
| 3 | +# This workflow builds Docker images on push to main/dev branches |
| 4 | +# and publishes (pushes) them to GHCR on version tags. |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + - dev |
| 11 | + tags: |
| 12 | + - "v*" |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-and-push: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - context: . |
| 29 | + file: server/Dockerfile |
| 30 | + image: ghcr.io/${{ github.repository }}-backend |
| 31 | + - context: ui-ssr |
| 32 | + file: ui-ssr/Dockerfile |
| 33 | + image: ghcr.io/${{ github.repository }}-frontend |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Free Disk Space |
| 37 | + uses: jlumbroso/free-disk-space@main |
| 38 | + with: |
| 39 | + tool-cache: true |
| 40 | + android: true |
| 41 | + dotnet: true |
| 42 | + haskell: true |
| 43 | + large-packages: true |
| 44 | + swap-storage: true |
| 45 | + |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + submodules: "true" |
| 50 | + |
| 51 | + - name: Set up QEMU |
| 52 | + uses: docker/setup-qemu-action@v3 |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Log in to the Container registry |
| 58 | + # Only login if we are going to push |
| 59 | + if: startsWith(github.ref, 'refs/tags/v') |
| 60 | + uses: docker/login-action@v3 |
| 61 | + with: |
| 62 | + registry: ${{ env.REGISTRY }} |
| 63 | + username: ${{ github.actor }} |
| 64 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + |
| 66 | + - name: Extract metadata (tags, labels) for Docker |
| 67 | + id: meta |
| 68 | + uses: docker/metadata-action@v5 |
| 69 | + with: |
| 70 | + images: ${{ matrix.image }} |
| 71 | + tags: | |
| 72 | + # Tag with the exact git tag |
| 73 | + type=ref,event=tag |
| 74 | + # Extract version from tag (stripping 'v' prefix if present) |
| 75 | + type=match,pattern=v(.*),group=1 |
| 76 | + # Standard semver (if valid) |
| 77 | + type=semver,pattern={{version}} |
| 78 | + type=semver,pattern={{major}}.{{minor}} |
| 79 | + # Branch and SHA |
| 80 | + type=ref,event=branch |
| 81 | + type=sha |
| 82 | + # latest tag only for stable releases (no 'a', 'b', 'rc' etc. in the tag name) |
| 83 | + type=raw,value=latest,enable=${{ github.ref_type == 'tag' && !contains(github.ref_name, 'a') && !contains(github.ref_name, 'b') && !contains(github.ref_name, 'rc') }} |
| 84 | +
|
| 85 | + - name: Build and push Docker image |
| 86 | + uses: docker/build-push-action@v5 |
| 87 | + with: |
| 88 | + context: ${{ matrix.context }} |
| 89 | + file: ${{ matrix.file }} |
| 90 | + # Only push on tags |
| 91 | + push: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 92 | + tags: ${{ steps.meta.outputs.tags }} |
| 93 | + labels: ${{ steps.meta.outputs.labels }} |
| 94 | + cache-from: type=gha |
| 95 | + cache-to: type=gha,mode=max |
0 commit comments