-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
201 lines (172 loc) · 4.65 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
variables:
DOCKER_TLS_CERTDIR: "/certs"
BASE_DOMAIN: cct-ev.de
STACK_NAME: portal-frontend-$CI_ENVIRONMENT_SLUG
.install-ssh: &install-ssh
- "which ssh-agent || ( apk update && apk add openssh-client )"
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
.docker-stack-run: &docker-stack-run
- docker stack deploy -c docker-compose.yml --prune --resolve-image always --with-registry-auth $STACK_NAME
.docker-stack-stop: &docker-stack-stop
- docker stack rm $STACK_NAME
stages:
- lint
- test
- build
- deploy
lint:
image: node:lts
stage: lint
needs: []
cache:
paths:
- node_modules
script:
- npm install --progress=false
- VUE_APP_ENV=dev npm run lint
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_REF_PROTECTED == "true"
test:
image: node:lts
stage: test
needs: []
cache:
paths:
- node_modules
script:
- npm install --progress=false
- VUE_APP_ENV=dev npm run test:unit
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_REF_PROTECTED == "true"
build:
stage: build
image: docker@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
services:
- docker:dind@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
variables:
IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
script:
- |
cat <<EOF >.env
VUE_APP_GITLAB_TOKEN=$GITLAB_PRIVATE_TOKEN
EOF
- docker pull $IMAGE || true
- docker build --cache-from $IMAGE -t $IMAGE .
- docker push $IMAGE
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_REF_PROTECTED == "true"
deploy stag:
extends:
- .deploy base
environment:
name: stag
url: https://portal.stag.$BASE_DOMAIN
on_stop: stop stag
variables:
DOCKER_HOST: 'ssh://[email protected].${BASE_DOMAIN}:23'
DOMAIN: "portal.stag.${BASE_DOMAIN}"
only:
- master
stop stag:
only:
- master
extends:
- .stop base
environment:
name: stag
variables:
DOCKER_HOST: 'ssh://[email protected].${BASE_DOMAIN}:23'
DOMAIN: "portal.stag.${BASE_DOMAIN}"
deploy review:
extends:
- .deploy base
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_ENVIRONMENT_SLUG.portal.stag.$BASE_DOMAIN
on_stop: stop review
variables:
DOCKER_HOST: 'ssh://[email protected].${BASE_DOMAIN}:23'
DOMAIN: "$CI_ENVIRONMENT_SLUG.portal.stag.${BASE_DOMAIN}"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
stop review:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
extends:
- .stop base
environment:
name: review/$CI_COMMIT_REF_NAME
variables:
DOCKER_HOST: 'ssh://[email protected].${BASE_DOMAIN}:23'
DOMAIN: "$CI_ENVIRONMENT_SLUG.portal.stag.${BASE_DOMAIN}"
deploy production:
image: docker@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
stage: deploy
needs:
- job: build
artifacts: false
only:
- tags
environment:
name: prod
url: https://portal.$BASE_DOMAIN
on_stop: stop production
extends:
- .deploy base
variables:
DOCKER_HOST: 'ssh://gitlab-ci@portal.${BASE_DOMAIN}:23'
DOMAIN: "portal.${BASE_DOMAIN}"
IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
stop production:
only:
- tags
extends:
- .stop base
environment:
name: prod
variables:
DOCKER_HOST: 'ssh://gitlab-ci@portal.${BASE_DOMAIN}:23'
DOMAIN: "portal.${BASE_DOMAIN}"
# templates
.deploy base:
image: docker@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
stage: deploy
needs:
- job: build
artifacts: false
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_ENVIRONMENT_SLUG.$BASE_DOMAIN
on_stop: stop review
variables:
IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
before_script:
- *install-ssh
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- *docker-stack-run
.stop base:
image: docker@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
stage: deploy
needs:
- job: build
artifacts: false
environment:
action: stop
when: manual
variables:
IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
before_script:
- *install-ssh
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- *docker-stack-stop