-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (79 loc) · 3.86 KB
/
cd.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
89
90
91
92
93
94
name: Build and Deploy Docker Images
on:
push:
branches:
- main
- dev
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
env:
LOCATION: me-central1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker ${{env.LOCATION}}-docker.pkg.dev
- name: Build and push Docker image for client
run: |
docker build \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg GITHUB_SHA=${{ github.sha }} \
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \
-f apps/client/Dockerfile \
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }} \
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.ref_name }} \
.
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.sha }}
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/client:${{ github.ref_name }}
- name: Build and push Docker image for server
run: |
docker build \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg GITHUB_SHA=${{ github.sha }} \
--build-arg GITHUB_REF_NAME=${{ github.ref_name }} \
-f apps/server/Dockerfile \
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }} \
-t ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.ref_name }} \
.
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.sha }}
docker push ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/server:${{ github.ref_name }}
# Deploy server to Cloud Run with environment variables
- name: Deploy Server to Cloud Run
id: deploy-server
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ secrets.SERVER_SERVICE }}
region: ${{env.LOCATION}}
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.SERVER_SERVICE }}:${{ github.sha }}
env_vars: |
JWT_SECRET=${{ secrets.JWT_KEY_SECRET }}
MONGODB_URI=${{ secrets.MONGODB_URI_SECRET }}
TOKEN_EXPIRATION=${{ secrets.JWT_EXPIRATION }}
# Deploy client to Cloud Run with the server's URL as an environment variable
- name: Deploy Client to Cloud Run
id: deploy-client
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ secrets.CLIENT_SERVICE }}
region: ${{env.LOCATION}}
image: ${{env.LOCATION}}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.REPO_NAME }}/${{ secrets.CLIENT_SERVICE }}:${{ github.sha }}
env_vars: |
SERVER_URL=${{ steps.deploy-server.outputs.url }}
# If required, use the Cloud Run URL outputs in later steps
- name: Show Client URL
run: echo ${{ steps.deploy-client.outputs.url }}
- name: Show Server URL
run: echo ${{ steps.deploy-server.outputs.url }}