-
Notifications
You must be signed in to change notification settings - Fork 2
105 lines (84 loc) · 3.13 KB
/
Copy pathdeploy-main.yml
File metadata and controls
105 lines (84 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Deploy On Main
on:
push:
branches:
- main
concurrency:
group: deploy-main
cancel-in-progress: false
permissions:
contents: read
id-token: write
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
REGION: us-central1
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_DEPLOY_SERVICE_ACCOUNT }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker auth for gcloud builds
run: gcloud auth configure-docker --quiet
- name: Build + push Node backend image
run: |
docker build -t "gcr.io/$PROJECT_ID/witness-backend" .
docker push "gcr.io/$PROJECT_ID/witness-backend"
- name: Deploy Node backend (Cloud Run)
run: |
gcloud run deploy witness-backend \
--image "gcr.io/$PROJECT_ID/witness-backend" \
--region "$REGION" \
--platform managed \
--allow-unauthenticated \
--max-instances 2 \
--set-env-vars "GEMINI_API_KEY=$GEMINI_API_KEY"
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
- name: Build + push live backend image
run: |
docker build -t "gcr.io/$PROJECT_ID/witness-live" -f live/Dockerfile live
docker push "gcr.io/$PROJECT_ID/witness-live"
- name: Deploy live backend (Cloud Run)
run: |
gcloud run deploy witness-live \
--image "gcr.io/$PROJECT_ID/witness-live" \
--region "$REGION" \
--platform managed \
--allow-unauthenticated \
--port 8081 \
--max-instances 2 \
--set-env-vars "GOOGLE_API_KEY=$GEMINI_API_KEY"
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
- name: Resolve deployed service URLs
run: |
BACKEND_URL="$(gcloud run services describe witness-backend --region "$REGION" --format='value(status.url)')"
LIVE_HTTP_URL="$(gcloud run services describe witness-live --region "$REGION" --format='value(status.url)')"
LIVE_WS_URL="wss://${LIVE_HTTP_URL#https://}/live"
echo "VITE_API_BASE_URL=$BACKEND_URL" >> "$GITHUB_ENV"
echo "VITE_LIVE_WS_URL=$LIVE_WS_URL" >> "$GITHUB_ENV"
echo "Backend URL: $BACKEND_URL"
echo "Live WS URL: $LIVE_WS_URL"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install frontend dependencies
run: npm ci
- name: Build frontend for production
run: npm run build
env:
VITE_API_BASE_URL: ${{ env.VITE_API_BASE_URL }}
VITE_LIVE_WS_URL: ${{ env.VITE_LIVE_WS_URL }}
- name: Install Firebase CLI
run: npm install -g firebase-tools
- name: Deploy Firebase Hosting
run: firebase deploy --only hosting --project "$PROJECT_ID" --non-interactive