|
| 1 | +name: Build and Release Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Memicu alur kerja setiap kali melakukan push tag seperti v1.0.0, v2.1.3, dll. |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-push: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + packages: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v3 |
| 21 | + |
| 22 | + # Login ke GitHub Container Registry menggunakan token otomatis bawaan GitHub |
| 23 | + - name: Log in to GitHub Container Registry |
| 24 | + uses: docker/login-action@v3 |
| 25 | + with: |
| 26 | + registry: ghcr.io |
| 27 | + username: ${{ github.actor }} |
| 28 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + # ─── BUILD & PUSH BACKEND ────────────────────────────────────────────────── |
| 31 | + - name: Extract Backend Metadata |
| 32 | + id: meta-backend |
| 33 | + uses: docker/metadata-action@v5 |
| 34 | + with: |
| 35 | + images: ghcr.io/${{ github.repository }}-backend |
| 36 | + tags: | |
| 37 | + type=semver,pattern={{version}} |
| 38 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} |
| 39 | +
|
| 40 | + - name: Build and Push Backend Image |
| 41 | + uses: docker/build-push-action@v5 |
| 42 | + with: |
| 43 | + context: ./backend |
| 44 | + push: true |
| 45 | + tags: ${{ id.meta-backend.outputs.tags }} |
| 46 | + labels: ${{ id.meta-backend.outputs.labels }} |
| 47 | + cache-from: type=gha |
| 48 | + cache-to: type=gha,mode=max |
| 49 | + |
| 50 | + # ─── BUILD & PUSH FRONTEND ───────────────────────────────────────────────── |
| 51 | + - name: Extract Frontend Metadata |
| 52 | + id: meta-frontend |
| 53 | + uses: docker/metadata-action@v5 |
| 54 | + with: |
| 55 | + images: ghcr.io/${{ github.repository }}-frontend |
| 56 | + tags: | |
| 57 | + type=semver,pattern={{version}} |
| 58 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }} |
| 59 | +
|
| 60 | + - name: Build and Push Frontend Image |
| 61 | + uses: docker/build-push-action@v5 |
| 62 | + with: |
| 63 | + context: ./frontend |
| 64 | + push: true |
| 65 | + tags: ${{ id.meta-frontend.outputs.tags }} |
| 66 | + labels: ${{ id.meta-frontend.outputs.labels }} |
| 67 | + cache-from: type=gha |
| 68 | + cache-to: type=gha,mode=max |
0 commit comments