|
| 1 | +# name: Deploy to GCP |
| 2 | + |
| 3 | +# on: |
| 4 | +# push: |
| 5 | +# branches: |
| 6 | +# - main |
| 7 | + |
| 8 | +# jobs: |
| 9 | +# deploy: |
| 10 | +# permissions: |
| 11 | +# contents: "read" |
| 12 | +# id-token: "write" |
| 13 | + |
| 14 | +# runs-on: ubuntu-latest |
| 15 | +# steps: |
| 16 | +# - uses: actions/checkout@v3 |
| 17 | + |
| 18 | +# - id: "auth" |
| 19 | +# name: "Authenticate to Google Cloud" |
| 20 | +# uses: "google-github-actions/auth@v2" |
| 21 | +# with: |
| 22 | +# credentials_json: "${{ secrets.GCP_SA_KEY }}" |
| 23 | + |
| 24 | +# - name: "Set up Cloud SDK" |
| 25 | +# uses: "google-github-actions/setup-gcloud@v2" |
| 26 | + |
| 27 | +# - name: "Use gcloud CLI" |
| 28 | +# run: "gcloud info" |
| 29 | + |
| 30 | +# - name: "Trigger Cloud Build" |
| 31 | +# env: # have to use env here as cant use secrets in kubernetes for nextJS |
| 32 | +# NEXT_PUBLIC_API_GATEWAY_URL: ${{ secrets.NEXT_PUBLIC_API_GATEWAY_URL }} |
| 33 | +# NEXT_PUBLIC_GITHUB_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_GITHUB_CLIENT_ID }} |
| 34 | +# run: | |
| 35 | +# gcloud builds submit --config cloudbuild.yaml --substitutions _NEXT_PUBLIC_API_GATEWAY_URL="$NEXT_PUBLIC_API_GATEWAY_URL",_NEXT_PUBLIC_GITHUB_CLIENT_ID="$NEXT_PUBLIC_GITHUB_CLIENT_ID" |
| 36 | + |
1 | 37 | name: Deploy to GCP
|
2 | 38 |
|
3 | 39 | on:
|
|
6 | 42 | - main
|
7 | 43 |
|
8 | 44 | jobs:
|
9 |
| - deploy: |
10 |
| - permissions: |
11 |
| - contents: "read" |
12 |
| - id-token: "write" |
13 |
| - |
| 45 | + check-changes: |
14 | 46 | runs-on: ubuntu-latest
|
| 47 | + outputs: |
| 48 | + fe: ${{ steps.filter.outputs.fe }} |
| 49 | + api: ${{ steps.filter.outputs.api }} |
| 50 | + question: ${{ steps.filter.outputs.question }} |
| 51 | + user: ${{ steps.filter.outputs.user }} |
15 | 52 | steps:
|
16 | 53 | - uses: actions/checkout@v3
|
| 54 | + - uses: dorny/paths-filter@v2 |
| 55 | + id: filter |
| 56 | + with: |
| 57 | + filters: | |
| 58 | + fe: |
| 59 | + - 'peerprep-fe/**' |
| 60 | + api: |
| 61 | + - 'api-gateway/**' |
| 62 | + question: |
| 63 | + - 'question-service/**' |
| 64 | + user: |
| 65 | + - 'user-service/**' |
17 | 66 |
|
| 67 | + deploy-fe: |
| 68 | + needs: check-changes |
| 69 | + if: ${{ needs.check-changes.outputs.fe == 'true' }} |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v3 |
18 | 73 | - id: "auth"
|
19 |
| - name: "Authenticate to Google Cloud" |
20 | 74 | uses: "google-github-actions/auth@v2"
|
21 | 75 | with:
|
22 | 76 | credentials_json: "${{ secrets.GCP_SA_KEY }}"
|
| 77 | + - uses: "google-github-actions/setup-gcloud@v2" |
| 78 | + - name: "Trigger FE Cloud Build" |
| 79 | + env: |
| 80 | + NEXT_PUBLIC_API_GATEWAY_URL: ${{ secrets.NEXT_PUBLIC_API_GATEWAY_URL }} |
| 81 | + NEXT_PUBLIC_GITHUB_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_GITHUB_CLIENT_ID }} |
| 82 | + run: | |
| 83 | + gcloud builds submit --config cloudbuilds/fe.yaml \ |
| 84 | + --substitutions _NEXT_PUBLIC_API_GATEWAY_URL="$NEXT_PUBLIC_API_GATEWAY_URL",_NEXT_PUBLIC_GITHUB_CLIENT_ID="$NEXT_PUBLIC_GITHUB_CLIENT_ID" |
23 | 85 |
|
24 |
| - - name: "Set up Cloud SDK" |
25 |
| - uses: "google-github-actions/setup-gcloud@v2" |
| 86 | + deploy-api-gateway: |
| 87 | + needs: check-changes |
| 88 | + if: ${{ needs.check-changes.outputs.api == 'true' }} |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v3 |
| 92 | + - id: "auth" |
| 93 | + uses: "google-github-actions/auth@v2" |
| 94 | + with: |
| 95 | + credentials_json: "${{ secrets.GCP_SA_KEY }}" |
| 96 | + - uses: "google-github-actions/setup-gcloud@v2" |
| 97 | + - name: "Trigger API Gateway Cloud Build" |
| 98 | + run: | |
| 99 | + gcloud builds submit --config cloudbuilds/api-gateway.yaml |
26 | 100 |
|
27 |
| - - name: "Use gcloud CLI" |
28 |
| - run: "gcloud info" |
| 101 | + deploy-question-svc: |
| 102 | + needs: check-changes |
| 103 | + if: ${{ needs.check-changes.outputs.question == 'true' }} |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v3 |
| 107 | + - id: "auth" |
| 108 | + uses: "google-github-actions/auth@v2" |
| 109 | + with: |
| 110 | + credentials_json: "${{ secrets.GCP_SA_KEY }}" |
| 111 | + - uses: "google-github-actions/setup-gcloud@v2" |
| 112 | + - name: "Trigger Question Service Cloud Build" |
| 113 | + run: | |
| 114 | + gcloud builds submit --config cloudbuilds/question-service.yaml |
29 | 115 |
|
30 |
| - - name: "Trigger Cloud Build" |
31 |
| - env: # have to use env here as cant use secrets in kubernetes for nextJS |
32 |
| - NEXT_PUBLIC_API_GATEWAY_URL: ${{ secrets.NEXT_PUBLIC_API_GATEWAY_URL }} |
33 |
| - NEXT_PUBLIC_GITHUB_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_GITHUB_CLIENT_ID }} |
| 116 | + deploy-user-svc: |
| 117 | + needs: check-changes |
| 118 | + if: ${{ needs.check-changes.outputs.user == 'true' }} |
| 119 | + runs-on: ubuntu-latest |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v3 |
| 122 | + - id: "auth" |
| 123 | + uses: "google-github-actions/auth@v2" |
| 124 | + with: |
| 125 | + credentials_json: "${{ secrets.GCP_SA_KEY }}" |
| 126 | + - uses: "google-github-actions/setup-gcloud@v2" |
| 127 | + - name: "Trigger User Service Cloud Build" |
34 | 128 | run: |
|
35 |
| - gcloud builds submit --config cloudbuild.yaml --substitutions _NEXT_PUBLIC_API_GATEWAY_URL="$NEXT_PUBLIC_API_GATEWAY_URL",_NEXT_PUBLIC_GITHUB_CLIENT_ID="$NEXT_PUBLIC_GITHUB_CLIENT_ID" |
| 129 | + gcloud builds submit --config cloudbuilds/user-service.yaml |
0 commit comments