-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
240 lines (225 loc) · 8.67 KB
/
.gitlab-ci.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
stages:
- test
- build
- push
.setup_python_env: &setup_python_env
before_script:
- cd backend
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install -r requirements.txt -r test-requirements.txt
lint:
stage: test
image: python:3.8
<<: *setup_python_env
script:
- pip install flake8
- flake8 .
cache:
paths:
- backend/venv/
test:
stage: test
image: python:3.8
services:
- postgres:12.2-alpine
variables:
POSTGRES_DB: garden
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_PASSWORD: ""
POSTGRES_USER: postgres
<<: *setup_python_env
script:
- pytest -v --cov=model_garden --cov-report=term-missing --no-cov-on-fail tests
cache:
paths:
- backend/venv/
prettier:
stage: test
image: node
script:
- cd frontend
- npx [email protected] --config ./.prettierrc.js --check "src/**/*.{js,jsx,ts,tsx,json,css}"
backend:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $PROD_BACKEND_ECR_URI
#Set for deployment tag commit short hash code as default
DEPLOY_TAG: $CI_COMMIT_SHORT_SHA
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd backend
script:
- export AWS_ACCESS_KEY_ID=$PROD_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$PROD_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
# Set deployment tag as commit tag instead of short hash code, if commit tag not empty for current deployment
- if [ "$CI_COMMIT_TAG" != ""]; then $DEPLOY_TAG:$CI_COMMIT_TAG ; fi;
- echo $DEPLOY_TAG
- docker build --network host -t $REPOSITORY_URL:latest .
- docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$DEPLOY_TAG
- docker images
- docker push $REPOSITORY_URL:latest
- docker push $REPOSITORY_URL:$DEPLOY_TAG
- aws ecs update-service --cluster model-garden --service model-garden-backend
- aws ecs list-tasks --cluster model-garden --service model-garden-backend | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden --task \""$0"\"";}' | sh
only:
- master
backend release:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $RELEASE_BACKEND_ECR_URI
#Set for deployment tag commit short hash code as default
DEPLOY_TAG: $CI_COMMIT_SHORT_SHA
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd backend
script:
- export AWS_ACCESS_KEY_ID=$RELEASE_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$RELEASE_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
# Set deployment tag as commit tag instead of short hash code, if commit tag not empty for current deployment
- if [ "$CI_COMMIT_TAG" != ""]; then $DEPLOY_TAG:$CI_COMMIT_TAG ; fi;
- echo $DEPLOY_TAG
- docker build --network host -t $REPOSITORY_URL:latest .
- docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$DEPLOY_TAG
- docker images
- docker push $REPOSITORY_URL:latest
- docker push $REPOSITORY_URL:$DEPLOY_TAG
- aws ecs update-service --cluster model-garden --service model-garden-backend
- aws ecs list-tasks --cluster model-garden --service model-garden-backend | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden --task \""$0"\"";}' | sh
only:
- release
backend dev:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $DEV_BACKEND_ECR_URI
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd backend
# Start infrastructure roll-out.
# - call ./deploy/aws_infra_setup.sh
script:
- export AWS_ACCESS_KEY_ID=$DEV_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$DEV_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
- echo $CI_COMMIT_SHORT_SHA
- docker build --network host -t $REPOSITORY_URL:latest-dev .
- docker tag $REPOSITORY_URL:latest-dev $REPOSITORY_URL:$CI_COMMIT_SHORT_SHA
- docker images
- docker push $REPOSITORY_URL:latest-dev
- docker push $REPOSITORY_URL:$CI_COMMIT_SHORT_SHA
- aws ecs update-service --cluster model-garden-dev --service model-garden-backend-dev
- aws ecs list-tasks --cluster model-garden-dev --service model-garden-backend-dev | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden-dev --task \""$0"\"";}' | sh
only:
- develop
frontend:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $PROD_FRONTEND_ECR_URI
#Set for deployment tag commit short hash code as default
DEPLOY_TAG: $CI_COMMIT_SHORT_SHA
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd frontend
script:
- export AWS_ACCESS_KEY_ID=$PROD_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$PROD_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
# Set deployment tag as commit tag instead of short hash code, if commit tag
# is not empty for current deployment.
- if [ "$CI_COMMIT_TAG" != ""]; then $DEPLOY_TAG:$CI_COMMIT_TAG ; fi;
- echo $DEPLOY_TAG
- docker build --network host -t $REPOSITORY_URL:latest .
- docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$DEPLOY_TAG
- docker images
- docker push $REPOSITORY_URL:latest
- docker push $REPOSITORY_URL:$DEPLOY_TAG
- aws ecs update-service --cluster model-garden --service model-garden-frontend
- aws ecs list-tasks --cluster model-garden --service model-garden-frontend | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden --task \""$0"\"";}' | sh
only:
- master
frontend release:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $RELEASE_FRONTEND_ECR_URI
#Set for deployment tag commit short hash code as default
DEPLOY_TAG: $CI_COMMIT_SHORT_SHA
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd frontend
script:
- export AWS_ACCESS_KEY_ID=$RELEASE_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$RELEASE_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
# Set deployment tag as commit tag instead of short hash code, if commit tag
# is not empty for current deployment.
- if [ "$CI_COMMIT_TAG" != ""]; then $DEPLOY_TAG:$CI_COMMIT_TAG ; fi;
- echo $DEPLOY_TAG
- docker build --network host -t $REPOSITORY_URL:latest .
- docker tag $REPOSITORY_URL:latest $REPOSITORY_URL:$DEPLOY_TAG
- docker images
- docker push $REPOSITORY_URL:latest
- docker push $REPOSITORY_URL:$DEPLOY_TAG
- aws ecs update-service --cluster model-garden --service model-garden-frontend
- aws ecs list-tasks --cluster model-garden --service model-garden-frontend | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden --task \""$0"\"";}' | sh
only:
- release
frontend dev:
stage: build
image: docker
services:
- docker:dind
variables:
AWS_DEFAULT_REGION: eu-central-1
DOCKER_HOST: tcp://localhost:2375/
REPOSITORY_URL: $DEV_FRONTEND_ECR_URI
before_script:
- apk add --no-cache curl jq python3 py-pip
- pip install awscli
- cd frontend
script:
- export AWS_ACCESS_KEY_ID=$DEV_AWS_ACCESS_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$DEV_AWS_SECRET_ACCESS_KEY
- $(aws ecr get-login --no-include-email --region eu-central-1)
- echo $CI_COMMIT_SHORT_SHA
- docker build --network host -t $REPOSITORY_URL:latest-dev .
- docker tag $REPOSITORY_URL:latest-dev $REPOSITORY_URL:$CI_COMMIT_SHORT_SHA
- docker images
- docker push $REPOSITORY_URL:latest-dev
- docker push $REPOSITORY_URL:$CI_COMMIT_SHORT_SHA
- aws ecs update-service --cluster model-garden-dev --service model-garden-frontend-dev
- aws ecs list-tasks --cluster model-garden-dev --service model-garden-frontend-dev | jq -r ".taskArns[]" | awk 'END { if (NR==0 || $0=="") exit 0; print "aws ecs stop-task --cluster model-garden-dev --task \""$0"\"";}' | sh
only:
- develop