-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (188 loc) · 7.9 KB
/
main.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: NodeJS CI/CD
on:
push:
branches:
- main
jobs:
test:
name: Test
strategy:
matrix:
node-version: [16.x]
mongodb-version: ['6.0']
platform: [ubuntu-latest]
redis-version: [6]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-db: mydb
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}
- name: Install user service dependencies
working-directory: ./user-service
run: npm install
- name: Run All User Service Tests
working-directory: ./user-service
env:
ENV: ${{ secrets.ENV }}
DB_LOCAL_URI: ${{ secrets.DB_LOCAL_URI }}
SECRET_KEY: ${{ secrets.JWT_SECRET_KEY_USER_SVC }}
run: npm run test
- name: Install matching service dependencies
working-directory: ./matching-service
run: npm install
- name: Run All Matching Service Tests
working-directory: ./matching-service
env:
ENV: ${{ secrets.ENV }}
DB_LOCAL_URI: ${{ secrets.DB_LOCAL_URI }}
run: npm run test
- name: Install collaboration service dependencies
working-directory: ./collaboration-service
run: npm install
- name: Run All Collaboration Service Tests
working-directory: ./collaboration-service
env:
ENV: ${{ secrets.ENV }}
run: npm run test
- name: Install question service dependencies
working-directory: ./question-service
run: npm install
- name: Run All Question Service Tests
working-directory: ./question-service
env:
ENV: ${{ secrets.ENV }}
DB_LOCAL_URI: ${{ secrets.DB_LOCAL_URI }}
run: npm run test
- name: Install webcam service dependencies
working-directory: ./webcam-service
run: npm install
- name: Run All Webcam Service Tests
working-directory: ./webcam-service
env:
ENV: ${{ secrets.ENV }}
run: npm run test
deploy:
name: Deploy
needs: [test]
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout the files
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Get timestamp
uses: gerred/actions/current-time@master
id: current-time
- name: Run string replace
uses: frabert/replace-string-action@master
id: format-time
with:
pattern: '[:\.]+'
string: "${{ steps.current-time.outputs.time }}"
replace-with: '-'
flags: 'g'
- name: Generate user-service deployment package
run: ls && cd user-service && zip -r ../user-service-deploy.zip * -x "**node_modules**" && cd ..
- name: Beanstalk Deploy for user-service
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_XR }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_XR }}
application_name: ${{ secrets.AWS_APPLICATION_NAME_USER }}
environment_name: ${{ secrets.AWS_APPLICATION_ENV_USER }}
region: ap-southeast-1
version_label: "user-service-${{ steps.format-time.outputs.replaced }}"
deployment_package: user-service-deploy.zip
wait_for_environment_recovery: 60
- name: Generate matching-service deployment package
run: ls && cd matching-service && zip -r ../matching-service-deploy.zip * -x "**node_modules**" && cd ..
- name: Beanstalk Deploy for matching-service
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_ZH }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ZH }}
application_name: ${{ secrets.AWS_APPLICATION_NAME_MATCH }}
environment_name: ${{ secrets.AWS_APPLICATION_ENV_MATCH }}
region: ap-southeast-1
version_label: "matching-service-${{ steps.format-time.outputs.replaced }}"
deployment_package: matching-service-deploy.zip
wait_for_environment_recovery: 60
- name: Generate collaboration-service deployment package
run: ls && cd collaboration-service && zip -r ../collaboration-service-deploy.zip * -x "**node_modules**" && cd ..
- name: Beanstalk Deploy for collaboration-service
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_KE }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_KE }}
application_name: ${{ secrets.AWS_APPLICATION_NAME_COLLAB }}
environment_name: ${{ secrets.AWS_APPLICATION_ENV_COLLAB }}
region: ap-southeast-1
version_label: "collaboration-service-${{ steps.format-time.outputs.replaced }}"
deployment_package: collaboration-service-deploy.zip
wait_for_environment_recovery: 60
- name: Generate question-service deployment package
run: ls && cd question-service && zip -r ../question-service-deploy.zip * -x "**node_modules**" && cd ..
- name: Beanstalk Deploy for question-service
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_XR }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_XR }}
application_name: ${{ secrets.AWS_APPLICATION_NAME_QUESTION }}
environment_name: ${{ secrets.AWS_APPLICATION_ENV_QUESTION }}
region: ap-southeast-1
version_label: "question-service-${{ steps.format-time.outputs.replaced }}"
deployment_package: question-service-deploy.zip
wait_for_environment_recovery: 60
- name: Generate webcam-service deployment package
run: ls && cd webcam-service && zip -r ../webcam-service-deploy.zip * -x "**node_modules**" && cd ..
- name: Beanstalk Deploy for webcam-service
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_ZH }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ZH }}
application_name: ${{ secrets.AWS_APPLICATION_NAME_WEBCAM }}
environment_name: ${{ secrets.AWS_APPLICATION_ENV_WEBCAM }}
region: ap-southeast-1
version_label: "webcam-service-${{ steps.format-time.outputs.replaced }}"
deployment_package: webcam-service-deploy.zip
wait_for_environment_recovery: 60
# https://ljmocic.medium.com/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace
- name: Install frontend dependencies
working-directory: ./frontend
run: npm install --omit=dev
- name: Generate frontend build
working-directory: ./frontend
env:
REACT_APP_URI_USER_SVC: ${{ secrets.REACT_APP_URI_USER_SVC }}
REACT_APP_URI_MATCH_SVC: ${{ secrets.REACT_APP_URI_MATCH_SVC }}
REACT_APP_URI_COLLAB_SVC: ${{ secrets.REACT_APP_URI_COLLAB_SVC }}
REACT_APP_URI_QUESTION_SVC: ${{ secrets.REACT_APP_URI_QUESTION_SVC }}
REACT_APP_URI_WEBCAM_SVC: ${{ secrets.REACT_APP_URI_WEBCAM_SVC }}
run: CI=false npm run build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_XR }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_XR }}
aws-region: ap-southeast-1
- name: Deploy to S3
run: aws s3 sync . s3://peerprep-g7
working-directory: ./frontend/build
- name: Cloudfront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DIST_ID }} --paths "/*"