-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
240 lines (220 loc) · 6.32 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
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:stable
variables:
DOCKER_DRIVER: overlay2
DJANGO: django-app
REACT: react-lib
DOCKER_HOST: tcp://localhost:2375
DOCKER_API_VERSION: "1.39"
.next-environment: &next_environment
variables:
EXAMPLE_DIR: nextjs
IMAGE_TAG_BACKEND: $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/backend:$CI_COMMIT_REF_SLUG
IMAGE_TAG_FRONTEND: $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/frontend:$CI_COMMIT_REF_SLUG
.react-router-environment: &react-router_environment
variables:
EXAMPLE_DIR: react-router
IMAGE_TAG_BACKEND: $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/backend:$CI_COMMIT_REF_SLUG
IMAGE_TAG_FRONTEND: $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/frontend:$CI_COMMIT_REF_SLUG
stages:
- lint
- test
- build
- e2e
- deploy
services:
- ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:18.09-dind
lint-django:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:3.9-slim
stage: lint
except:
- tags
tags:
- low-load
before_script:
- pip install black
script:
- black --check $DJANGO/**/*.py --exclude .*/migrations/.*
lint-react:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:15
stage: lint
except:
- tags
tags:
- low-load
before_script:
- yarn install --pure-lockfile --cwd $REACT
script:
- yarn --cwd $REACT lint
unit-test-django:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:3.9-slim
stage: test
except:
- tags
dependencies:
- lint-django
tags:
- normal-load
before_script:
- cd $DJANGO
- pip install -U pip pipenv
- pipenv install --deploy --system -d
script:
- python runtests.py
unit-test-react:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:15
stage: test
except:
- tags
dependencies:
- lint-react
tags:
- normal-load
before_script:
- yarn install --pure-lockfile --cwd $REACT
script:
- yarn --cwd $REACT test
.build-backend-template: &build_backend
stage: build
except:
- tags
dependencies:
- unit-test-django
tags:
- normal-load
before_script:
- docker login -u $CI_DEPENDENCY_PROXY_USER -p $CI_DEPENDENCY_PROXY_PASSWORD $CI_DEPENDENCY_PROXY_SERVER
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#using-docker-caching
- docker pull $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/backend:develop || true
- docker build
--cache-from $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/backend:develop
-t $IMAGE_TAG_BACKEND
--build-arg DOCKER_IMAGE_PREFIX=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/
--file ./examples/${EXAMPLE_DIR}/backend/Dockerfile
./
- docker push $IMAGE_TAG_BACKEND
.build-frontend-template: &build_frontend
stage: build
except:
- tags
dependencies:
- unit-test-react
tags:
- normal-load
before_script:
- docker login -u $CI_DEPENDENCY_PROXY_USER -p $CI_DEPENDENCY_PROXY_PASSWORD $CI_DEPENDENCY_PROXY_SERVER
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/frontend:develop || true
- docker build
--cache-from $CI_REGISTRY_IMAGE/${EXAMPLE_DIR}/frontend:develop
-t $IMAGE_TAG_FRONTEND
--build-arg app_env=production
--build-arg DOCKER_IMAGE_PREFIX=${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/
--file ./examples/${EXAMPLE_DIR}/frontend/Dockerfile
./
- docker push $IMAGE_TAG_FRONTEND
.e2e-template: &e2e
stage: e2e
except:
- tags
tags:
- high-load
artifacts:
name: "$CI_JOB_STAGE-$CI_COMMIT_REF_NAME-screenshots"
expire_in: 1 week
when: always
paths:
- screenshots/
- videos/
reports:
junit: test-reports/reporter*.xml
before_script:
- docker login -u $CI_DEPENDENCY_PROXY_USER -p $CI_DEPENDENCY_PROXY_PASSWORD $CI_DEPENDENCY_PROXY_SERVER
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $IMAGE_TAG_FRONTEND
- docker run -d -p 3000:3000 $IMAGE_TAG_FRONTEND bash -c ./run.sh
- docker pull $IMAGE_TAG_BACKEND
- docker run -d -p 8000:8000 -e DJANGO_SESSION_COOKIE_SECURE=False -e DJANGO_CACHE_BACKEND=local $IMAGE_TAG_BACKEND ./run_backend.sh loadfixtures
- docker run --rm
-v ${PWD}/cypress/cypress:/app/cypress
-v ${PWD}/cypress/cypress.json:/app/cypress.json
-v ${PWD}/cypress/package.json:/app/package.json
-v ${PWD}/screenshots:/app/cypress/screenshots
-v ${PWD}/videos:/app/cypress/videos
-v ${PWD}/test-reports:/app/cypress/results
--network="host"
--ipc=host
${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/cypress/browsers:node14.7.0-chrome84
bash -c "cd app && yarn install && yarn cypress run --browser chrome"
build-react-router-backend:
<<: *react-router_environment
<<: *build_backend
build-react-router-frontend:
<<: *react-router_environment
<<: *build_frontend
e2e-test-react-router:
<<: *react-router_environment
<<: *e2e
dependencies:
- build-react-router-backend
- build-react-router-frontend
build-next-backend:
<<: *next_environment
<<: *build_backend
build-next-frontend:
<<: *next_environment
<<: *build_frontend
e2e-test-next-router:
<<: *next_environment
<<: *e2e
dependencies:
- build-next-backend
- build-next-frontend
deploy-react:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:15
stage: deploy
except:
- tags
dependencies:
- unit-test-react
- e2e-test-react-router
- e2e-test-next-router
variables:
GITLAB_URL: gitlab.ambient-innovation.com
only:
- master
tags:
- low-load
before_script:
- yarn install --pure-lockfile --cwd $REACT
script:
- cd $REACT
- yarn build
- npx semantic-release
deploy-django:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:3.9-slim
stage: deploy
except:
- tags
dependencies:
- unit-test-django
- e2e-test-react-router
- e2e-test-next-router
variables:
PYPI_USERNAME: ambient-innovation
only:
- master
tags:
- low-load
before_script:
- apt-get update && apt-get install -y git
- git config --global user.name "semantic-release"
- git config --global user.email "[email protected]"
- cd $DJANGO
- pip install -U pip pipenv
- pipenv install --deploy --system -d
script:
- semantic-release publish