|
| 1 | +name: Deploy to Google Cloud Run |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + deploy: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + environment: production |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Authenticate to GCP |
| 16 | + uses: google-github-actions/auth@v1 |
| 17 | + with: |
| 18 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 19 | + |
| 20 | + - name: Set up gcloud |
| 21 | + uses: google-github-actions/setup-gcloud@v1 |
| 22 | + with: |
| 23 | + project_id: ${{ secrets.GCP_PROJECT }} |
| 24 | + |
| 25 | + - name: Build and push backend image |
| 26 | + run: | |
| 27 | + IMAGE=gcr.io/${{ secrets.GCP_PROJECT }}/expense-system-backend |
| 28 | + docker build -f backend/Dockerfile -t ${IMAGE}:${GITHUB_SHA} . |
| 29 | + docker push ${IMAGE}:${GITHUB_SHA} |
| 30 | + docker tag ${IMAGE}:${GITHUB_SHA} ${IMAGE}:latest |
| 31 | + docker push ${IMAGE}:latest |
| 32 | +
|
| 33 | + - name: Deploy backend to Cloud Run |
| 34 | + uses: google-github-actions/deploy-cloudrun@v1 |
| 35 | + with: |
| 36 | + service: expense-backend |
| 37 | + image: gcr.io/${{ secrets.GCP_PROJECT }}/expense-system-backend:${GITHUB_SHA} |
| 38 | + region: ${{ secrets.GCP_REGION }} |
| 39 | + allow-unauthenticated: true |
| 40 | + |
| 41 | + - name: Build and push frontend image |
| 42 | + run: | |
| 43 | + IMAGE=gcr.io/${{ secrets.GCP_PROJECT }}/expense-system-frontend |
| 44 | + docker build -f frontend/Dockerfile -t ${IMAGE}:${GITHUB_SHA} . |
| 45 | + docker push ${IMAGE}:${GITHUB_SHA} |
| 46 | + docker tag ${IMAGE}:${GITHUB_SHA} ${IMAGE}:latest |
| 47 | + docker push ${IMAGE}:latest |
| 48 | +
|
| 49 | + - name: Deploy frontend to Cloud Run |
| 50 | + uses: google-github-actions/deploy-cloudrun@v1 |
| 51 | + with: |
| 52 | + service: expense-frontend |
| 53 | + image: gcr.io/${{ secrets.GCP_PROJECT }}/expense-system-frontend:${GITHUB_SHA} |
| 54 | + region: ${{ secrets.GCP_REGION }} |
| 55 | + allow-unauthenticated: true |
0 commit comments