|
| 1 | +name: Build & Publish Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + |
| 10 | +env: |
| 11 | + REGISTRY: ghcr.io |
| 12 | + FRONTEND_IMAGE: ghcr.io/gamedirection/open-trivia-frontend |
| 13 | + BACKEND_IMAGE: ghcr.io/gamedirection/open-trivia-backend |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-and-push: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Log in to GHCR |
| 27 | + uses: docker/login-action@v3 |
| 28 | + with: |
| 29 | + registry: ${{ env.REGISTRY }} |
| 30 | + username: ${{ github.actor }} |
| 31 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Read frontend version |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + VERSION=$(node -p "require('./frontend/package.json').version") |
| 37 | + echo "value=$VERSION" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + # ── Frontend ──────────────────────────────────────────────────────────── |
| 40 | + |
| 41 | + - name: Frontend metadata |
| 42 | + id: frontend-meta |
| 43 | + uses: docker/metadata-action@v5 |
| 44 | + with: |
| 45 | + images: ${{ env.FRONTEND_IMAGE }} |
| 46 | + tags: | |
| 47 | + type=raw,value=latest,enable={{is_default_branch}} |
| 48 | + type=raw,value=v${{ steps.version.outputs.value }} |
| 49 | + type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }} |
| 50 | +
|
| 51 | + - name: Build & push frontend |
| 52 | + uses: docker/build-push-action@v5 |
| 53 | + with: |
| 54 | + context: ./frontend |
| 55 | + push: true |
| 56 | + tags: ${{ steps.frontend-meta.outputs.tags }} |
| 57 | + labels: ${{ steps.frontend-meta.outputs.labels }} |
| 58 | + |
| 59 | + # ── Backend ───────────────────────────────────────────────────────────── |
| 60 | + |
| 61 | + - name: Backend metadata |
| 62 | + id: backend-meta |
| 63 | + uses: docker/metadata-action@v5 |
| 64 | + with: |
| 65 | + images: ${{ env.BACKEND_IMAGE }} |
| 66 | + tags: | |
| 67 | + type=raw,value=latest,enable={{is_default_branch}} |
| 68 | + type=raw,value=v${{ steps.version.outputs.value }} |
| 69 | + type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }} |
| 70 | +
|
| 71 | + - name: Build & push backend |
| 72 | + uses: docker/build-push-action@v5 |
| 73 | + with: |
| 74 | + context: ./backend |
| 75 | + push: true |
| 76 | + tags: ${{ steps.backend-meta.outputs.tags }} |
| 77 | + labels: ${{ steps.backend-meta.outputs.labels }} |
0 commit comments