-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (72 loc) · 3.36 KB
/
GCP_Deploy.yml
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
name: CI/CD Pipeline
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v2
# Step 2: Load .env file
- name: Load .env file
run: |
echo "PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }}" >> .env
echo "gemini_key=${{ secrets.gemini_key }}" >> .env
echo "REACT_APP_BASE_URL is set to: ${{ secrets.REACT_APP_BASE_URL }}" >> .env
cat .env # Print the contents of the .env file for debugging
# Step 3: Authenticate to Google Cloud
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} # The GCP service account key stored in GitHub repository secrets
# Step 4: Set up Google Cloud SDK
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }} # GCP project ID stored in GitHub secrets
# Step 5: Authenticate Docker to use Google Artifact Registry (GAR)
- name: Authenticate Docker with GAR
run: gcloud auth configure-docker us-east1-docker.pkg.dev --quiet
# Step 6: Build backend Docker image
- name: Build backend Docker image
run: |
cd backend
docker build -t us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest \
--build-arg gemini_key=${{ secrets.gemini_key }} \
--build-arg PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }} \
--build-arg ENVIRONMENT=${{ secrets.ENVIRONMENT }} \
--build-arg FRONTEND_URL=${{ secrets.FRONTEND_URL }} .
# Step 7: Build frontend Docker image (navigate back to root first)
- name: Build frontend Docker image
run: |
cd frontend
docker build -t us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest \
--build-arg gemini_key=${{ secrets.gemini_key }} \
--build-arg PERSONAL_ACCESS_TOKEN_GITHUB=${{ secrets.PERSONAL_ACCESS_TOKEN_GITHUB }} \
--build-arg REACT_APP_BASE_URL=${{ secrets.REACT_APP_BASE_URL }} .
# Step 8: Push backend Docker image to GAR
- name: Push backend Docker image to GAR
run: |
docker push us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest
# Step 9: Push frontend Docker image to GAR
- name: Push frontend Docker image to GAR
run: |
docker push us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest
- name: Deploy frontend to Cloud Run
run: |
gcloud run deploy devopsgeni-frontend \
--image us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/frontend:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated
- name: Deploy frontend to Cloud Run
run: |
gcloud run deploy devopsgeni-baackend \
--image us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/devopsgeni/backend:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated