| [a8fe58e] | 1 | name: CI
|
|---|
| [c0086c0] | 2 |
|
|---|
| 3 | on:
|
|---|
| 4 | push:
|
|---|
| [a8fe58e] | 5 | branches: [master, dev]
|
|---|
| [c0086c0] | 6 | pull_request:
|
|---|
| 7 | branches: [master]
|
|---|
| 8 |
|
|---|
| 9 | env:
|
|---|
| 10 | BACKEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/trekr-backend
|
|---|
| 11 | FRONTEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/trekr-frontend
|
|---|
| 12 |
|
|---|
| 13 | jobs:
|
|---|
| 14 | build:
|
|---|
| 15 | name: Build
|
|---|
| 16 | runs-on: ubuntu-latest
|
|---|
| 17 | steps:
|
|---|
| 18 | - uses: actions/checkout@v4
|
|---|
| 19 |
|
|---|
| 20 | - name: Set up Docker Buildx
|
|---|
| 21 | uses: docker/setup-buildx-action@v3
|
|---|
| 22 |
|
|---|
| [a8fe58e] | 23 | - name: Build backend image
|
|---|
| [c0086c0] | 24 | uses: docker/build-push-action@v5
|
|---|
| 25 | with:
|
|---|
| 26 | context: ./backend
|
|---|
| 27 | push: false
|
|---|
| 28 | cache-from: type=gha,scope=backend
|
|---|
| 29 | cache-to: type=gha,scope=backend,mode=max
|
|---|
| 30 |
|
|---|
| [a8fe58e] | 31 | - name: Build frontend image
|
|---|
| [c0086c0] | 32 | uses: docker/build-push-action@v5
|
|---|
| 33 | with:
|
|---|
| 34 | context: ./frontend
|
|---|
| 35 | push: false
|
|---|
| 36 | cache-from: type=gha,scope=frontend
|
|---|
| 37 | cache-to: type=gha,scope=frontend,mode=max
|
|---|
| 38 |
|
|---|
| 39 | push:
|
|---|
| 40 | name: Push to DockerHub
|
|---|
| 41 | runs-on: ubuntu-latest
|
|---|
| 42 | needs: build
|
|---|
| 43 | if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
|---|
| 44 | steps:
|
|---|
| 45 | - uses: actions/checkout@v4
|
|---|
| 46 |
|
|---|
| 47 | - name: Set up Docker Buildx
|
|---|
| 48 | uses: docker/setup-buildx-action@v3
|
|---|
| 49 |
|
|---|
| 50 | - name: Log in to DockerHub
|
|---|
| 51 | uses: docker/login-action@v3
|
|---|
| 52 | with:
|
|---|
| 53 | username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|---|
| 54 | password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|---|
| 55 |
|
|---|
| 56 | - name: Build and push backend
|
|---|
| 57 | uses: docker/build-push-action@v5
|
|---|
| 58 | with:
|
|---|
| 59 | context: ./backend
|
|---|
| 60 | push: true
|
|---|
| [c1798da] | 61 | platforms: linux/amd64,linux/arm64
|
|---|
| [c0086c0] | 62 | tags: |
|
|---|
| 63 | ${{ env.BACKEND_IMAGE }}:latest
|
|---|
| 64 | ${{ env.BACKEND_IMAGE }}:${{ github.sha }}
|
|---|
| 65 | cache-from: type=gha,scope=backend
|
|---|
| 66 | cache-to: type=gha,scope=backend,mode=max
|
|---|
| 67 |
|
|---|
| 68 | - name: Build and push frontend
|
|---|
| 69 | uses: docker/build-push-action@v5
|
|---|
| 70 | with:
|
|---|
| 71 | context: ./frontend
|
|---|
| 72 | push: true
|
|---|
| [c1798da] | 73 | platforms: linux/amd64,linux/arm64
|
|---|
| [c0086c0] | 74 | tags: |
|
|---|
| 75 | ${{ env.FRONTEND_IMAGE }}:latest
|
|---|
| 76 | ${{ env.FRONTEND_IMAGE }}:${{ github.sha }}
|
|---|
| 77 | cache-from: type=gha,scope=frontend
|
|---|
| 78 | cache-to: type=gha,scope=frontend,mode=max
|
|---|