generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 4
147 lines (123 loc) · 4.43 KB
/
build_push_registry.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Selectively Build and Push to Artifact Registry
on:
push:
branches: ["master"]
env:
PROJECT_ID: cs3219-400714
REGION: asia-southeast1
GAR_LOCATION: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/
jobs:
build-push-artifact:
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.deploy.outputs.BUILD_STEP_RAN }}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: Detect Changes in Microservices
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
frontend:
- 'frontend/**'
user_service:
- 'user_service/**'
question_service:
- 'question_service/**'
matching_service:
- 'matching_service/**'
collab_service:
- 'collab_service/**'
code_execution:
- 'code_execution/**'
api_gateway:
- 'api_gateway/**'
- name: 'Create env file'
run: |
echo "${{ secrets.ENV_FILE }}" > .env
- name: "Set up google auth"
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: "Docker auth"
run: |-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: 1. Build and Push frontend
id: a
if: steps.changes.outputs.frontend == 'true'
run: |
docker-compose build frontend
docker-compose push frontend
- name: 2. Build and Push question-service
id: b
if: steps.changes.outputs.question_service == 'true'
run: |
docker-compose build question-service
docker-compose push question-service
- name: 3. Build and Push user-service
id: c
if: steps.changes.outputs.user_service == 'true'
run: |
docker-compose build user-service
docker-compose push user-service
- name: 4. Build and Push matching-service
id: d
if: steps.changes.outputs.matching_service == 'true'
run: |
docker-compose build matching-service
docker-compose push matching-service
- name: 5. Build and Push collab-service
id: e
if: steps.changes.outputs.collab_service == 'true'
run: |
docker-compose build collab-service
docker-compose push collab-service
- name: 6. Build and Push code-execution
id: f
if: steps.changes.outputs.code_execution == 'true'
run: |
docker-compose build code-execution
docker-compose push code-execution
- name: 7. Build and Push api-gateway
id: g
if: steps.changes.outputs.api_gateway == 'true'
run: |
docker-compose build api-gateway
docker-compose push api-gateway
- name: determine deploy step
id: deploy
if: ${{ steps.a.conclusion == 'success' || steps.b.conclusion == 'success' || steps.c.conclusion == 'success' || steps.d.conclusion == 'success' || steps.e.conclusion == 'success' || steps.f.conclusion == 'success' }}
run: |
echo "BUILD_STEP_RAN=true" >> $GITHUB_OUTPUT
deploy:
needs: build-push-artifact
if: ${{needs.build-push-artifact.outputs.should_deploy== 'true'}}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: "Set up google auth"
id: auth
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
- name: "Use gcloud CLI"
run: "gcloud info"
- name: "SSH to VM"
id: 'compute-ssh'
uses: 'google-github-actions/ssh-compute@v0'
with:
instance_name: 'peerprep-prod'
zone: 'asia-southeast1-b'
ssh_private_key: '${{ secrets.SSH_KEY }}'
command: 'echo "${{ secrets.ENV_FILE }}" | sudo tee /usr/src/peerprep/.env > /dev/null && sudo chmod 777 /usr/src/peerprep/scripts/init.sh && sudo /usr/src/peerprep/scripts/init.sh'
- id: 'test'
run: |-
echo '${{ steps.compute-ssh.outputs.stdout }}'
echo '${{ steps.compute-ssh.outputs.stderr }}'