-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
226 lines (202 loc) · 5.98 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
image: xwiillz/node-chromium-mongo:lts-bionic
cache:
key: '${CI_COMMIT_REF_SLUG}-client'
paths:
- packages/client/node_modules/
- packages/server/node_modules/
policy: pull
.only-client: &only-client
only:
refs:
- master
- merge_requests
changes:
- packages/client/**/*
cache:
key: '${CI_COMMIT_REF_SLUG}-client'
paths:
- packages/client/node_modules/
policy: pull
.only-server: &only-server
only:
refs:
- master
- merge_requests
changes:
- packages/server/**/*
cache:
key: '${CI_COMMIT_REF_SLUG}-server'
paths:
- packages/server/node_modules/
policy: pull
.only-mobile: &only-mobile
only:
refs:
- master
- merge_requests
changes:
- packages/mobile/**/*
stages:
- install
- lint
- build
- test
- deploy
- deploy:push
install:client:
stage: install
<<: *only-client
needs: []
script:
- cd packages/client
- npm ci --cache .npm --prefer-offline
cache:
key: '${CI_COMMIT_REF_SLUG}-client'
paths:
- packages/client/node_modules/
- packages/client/.npm/
policy: pull-push
install:server:
stage: install
<<: *only-server
needs: []
script:
- cd packages/server
- npm ci --cache .npm --prefer-offline
cache:
key: '${CI_COMMIT_REF_SLUG}-server'
paths:
- packages/server/node_modules/
- packages/server/.npm/
policy: pull-push
lint:client:
stage: lint
allow_failure: true
<<: *only-client
needs: ['install:client']
script:
- cd packages/client
- npm run lint
lint:server:
stage: lint
allow_failure: true
<<: *only-server
needs: ['install:server']
script:
- cd packages/server
- npm run lint
build:client:
stage: build
<<: *only-client
needs: ['install:client']
script:
- cd packages/client
- npm run build
artifacts:
paths:
- packages/client/dist/
build:server:
stage: build
<<: *only-server
needs: ['install:server']
script:
- cd packages/server
- npm run build
artifacts:
paths:
- packages/server/out/
test:server:
stage: test
<<: *only-server
needs: ['build:server']
script:
- cd packages/server
- npm run coverage
dependencies:
- build:server
artifacts:
paths:
- packages/server/coverage/
test:mobile:
stage: test
<<: *only-mobile
needs: []
script:
- cd packages/mobile
- echo "The job's stage is '$CI_JOB_STAGE'"
pages:
image: node:14.15.0
stage: deploy
rules:
- if: '$CI_COMMIT_TAG =~ /deploy/'
when: manual
script:
- cd packages/client
- npm ci --cache .npm --prefer-offline
- npm run deploy -- --base-href $BASE_HREF
- mkdir ../public
- mv dist/client/* ../public/
artifacts:
paths:
- public
variables:
EC2_USER: ec2-user
ORIGIN: 'https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}'
deploy:client:
image: docker
services:
- docker:20.10.16-dind
stage: deploy
rules:
- if: '$CI_COMMIT_TAG'
when: manual
script:
- export DOCKER_BUILDKIT=1
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --target=client-prod -t $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/client:$CI_COMMIT_TAG -t $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/client:latest .
- docker push $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/client --all-tags
deploy:server:
image: docker
services:
- docker:20.10.16-dind
stage: deploy
rules:
- if: '$CI_COMMIT_TAG'
when: manual
script:
- export DOCKER_BUILDKIT=1
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --target=server-prod -t $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/server:$CI_COMMIT_TAG -t $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/server:latest .
- docker push $CI_REGISTRY/polytechnique-montr-al/log3900/23-1/equipe-103/log3900-103/server --all-tags
deploy:push:
stage: deploy:push
environment:
name: production
url: http://scrabble.cfstcyr.com
needs: []
rules:
- if: '$CI_COMMIT_TAG'
when: manual
script:
- 'which ssh-agent || (apt-get update -qq && apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$EC2_PEM_FILE_CONTENT")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- |
timeout 600 ssh -t -o ServerAliveInterval=15 -o ServerAliveCountMax=5 "${EC2_USER}@${EC2_HOST}" "
set -x -ev
git clone ${ORIGIN} --branch develop LOG3900-103 || echo Git repository already exist
cd LOG3900-103
# Update the remote origin
# This action is important because the CI_JOB_TOKEN become invalid after each pipeline
git remote remove origin
git remote add origin ${ORIGIN}
# Checkout to the targeted commit
git fetch origin ${CI_COMMIT_SHA} --depth 1
git checkout ${CI_COMMIT_SHA}
export IMAGE_SERVER_VERSION=latest
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker-compose up --pull always --detach --remove-orphans --force-recreate
docker image prune -af
"