-
Notifications
You must be signed in to change notification settings - Fork 31
/
.gitlab-ci.yml
195 lines (172 loc) · 5.01 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
stages:
- build
- deploy
variables:
DOMAIN: iotagency.sigfox.com
API_VERSION: api
SUBDOMAIN: dev
PRIMUS_URL: https://primus.${SUBDOMAIN}.${DOMAIN}
API_URL: https://api.${SUBDOMAIN}.${DOMAIN}
BUILD_ENV: prod
SERVER_NAME: ${SUBDOMAIN}.${DOMAIN}
PRIMUS_IMG: ${CI_REGISTRY_IMAGE}/primus-${SUBDOMAIN}:latest
BACKEND_IMG: ${CI_REGISTRY_IMAGE}/backend-${SUBDOMAIN}:latest
FRONTEND_IMG: ${CI_REGISTRY_IMAGE}/frontend-${SUBDOMAIN}:latest
FRONTEND_BUILDER_IMG: ${CI_REGISTRY_IMAGE}/frontend-${SUBDOMAIN}:builder
MONGO_IMG: ${CI_REGISTRY_IMAGE}/mongodb-${SUBDOMAIN}:latest
RABBIT_IMG: ${CI_REGISTRY_IMAGE}/rabbitmq-${SUBDOMAIN}:latest
.build_job: &build_job
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# cache
- docker pull $PRIMUS_IMG || true
- docker pull $BACKEND_IMG || true
- docker pull $FRONTEND_BUILDER_IMG || true
- docker pull $FRONTEND_IMG || true
- docker pull $MONGO_IMG || true
- docker pull $RABBIT_IMG || true
# build
- export FRONTEND_BUILD_ARGS="--build-arg BUILD_ENV=${BUILD_ENV} --build-arg SERVER_NAME=${SERVER_NAME} --build-arg API_URL=${API_URL} --build-arg API_VERSION=${API_VERSION} --build-arg PRIMUS_URL=${PRIMUS_URL}"
- docker build --cache-from $PRIMUS_IMG -t $PRIMUS_IMG primus
- docker build --cache-from $BACKEND_IMG -t $BACKEND_IMG --build-arg GIT_REV=${CI_COMMIT_SHORT_SHA} backend
- docker build --cache-from $FRONTEND_BUILDER_IMG -t $FRONTEND_BUILDER_IMG --target builder $FRONTEND_BUILD_ARGS frontend
- docker build --cache-from $FRONTEND_BUILDER_IMG --cache-from $FRONTEND_IMG -t $FRONTEND_IMG $FRONTEND_BUILD_ARGS frontend
- docker build --cache-from $MONGO_IMG -t $MONGO_IMG mongodb
- docker build --cache-from $RABBIT_IMG -t $RABBIT_IMG rabbitmq
# push
- docker push $PRIMUS_IMG
- docker push $BACKEND_IMG
- docker push $FRONTEND_BUILDER_IMG
- docker push $FRONTEND_IMG
- docker push $MONGO_IMG
- docker push $RABBIT_IMG
.deploy_job: &deploy_job
stage: deploy
image: kroniak/ssh-client:latest
variables: &deploy_var
GIT_STRATEGY: none
ARGS: '--health-start-period 5s --with-registry-auth --update-failure-action rollback --update-parallelism 2 --update-order start-first'
script:
# add the server as a known host
- mkdir ~/.ssh
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# log into Docker registry
- |
ssh [email protected] "docker login -u "$DEPLOY_USER" -p "$DEPLOY_TOKEN" $CI_REGISTRY && echo $FRONTEND_IMG &&
docker service update ${SUBDOMAIN}_frontend ${ARGS} --image $FRONTEND_IMG &&
docker service update ${SUBDOMAIN}_primus ${ARGS} --image $PRIMUS_IMG &&
docker service update ${SUBDOMAIN}_backend ${ARGS} --image $BACKEND_IMG &&
docker service update ${SUBDOMAIN}_rabbitmq ${ARGS} --image $RABBIT_IMG"
.prod_build_job: &prod_build_job
<<: *build_job
only:
- master
.prod_deploy_job: &prod_deploy_job
<<: *deploy_job
only:
- master
# ======== branch staging on staging domain ========
build-staging:
<<: *build_job
variables:
SUBDOMAIN: staging
only:
- staging
deploy-staging:
<<: *deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: staging
only:
- staging
# ======== branch dev-foundation on dev-foundation domain ========
build-dev-foundation:
<<: *build_job
variables:
SUBDOMAIN: dev-foundation
only:
- dev-foundation
deploy-dev-foundation:
<<: *deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: dev-foundation
only:
- dev-foundation
# ======== branch master-foundation on foundation domain ========
build-master-foundation:
<<: *build_job
variables:
SUBDOMAIN: foundation
only:
- master-foundation
deploy-master-foundation:
<<: *deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: foundation
only:
- master-foundation
# ======== branch connect on connect domain ========
build-connect:
<<: *build_job
variables:
SUBDOMAIN: connect
only:
- connect
deploy-connect:
<<: *deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: connect
only:
- connect
# ======== PROD ========
# app
build-app:
<<: *prod_build_job
variables:
SUBDOMAIN: app
deploy-app:
<<: *prod_deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: app
# try
build-try:
<<: *prod_build_job
variables:
SUBDOMAIN: try
deploy-try:
<<: *prod_deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: try
# demo
build-demo:
<<: *prod_build_job
variables:
SUBDOMAIN: demo
deploy-demo:
<<: *prod_deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: demo
# workshop
build-workshop:
<<: *prod_build_job
variables:
SUBDOMAIN: workshop
deploy-workshop:
<<: *prod_deploy_job
variables:
<<: *deploy_var
SUBDOMAIN: workshop