-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
217 lines (186 loc) · 4.8 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
stages:
- setup
- test
- build
- release
- deploy
cache:
untracked: true
key: "$CI_PROJECT_NAME"
paths:
- node_modules/
variables:
TEST_PATH: envs/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}
QUAL_PATH: envs/qualities/${CI_PROJECT_NAME}
PROD_PATH: envs/productions/${CI_PROJECT_NAME}
ENV_TEST_URL: ${CI_BUILD_REF_NAME}.rust-admin.com
ENV_QUAL_URL: quality.rust-admin.com
ENV_PROD_URL: rust-admin.com
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE
#https://gitlab.com/gitlab-org/gitlab-ce/issues/17861#note_12991518
DOCKER_DRIVER: aufs
DOCKERHUB_RELEASE: cgarnier/rust-admin
setup:
stage: setup
image: node:latest
script:
- npm i
tags:
- dind
test:
stage: test
image: node:latest
script:
- npm test
tags:
- dind
build:
stage: build
image: node:latest
script:
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
only:
- branches
tags:
- dind
.release_env: &release_env
stage: release
image: "docker:git"
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
tags:
- dind
release:
<<: *release_env
script:
- docker build -t $CONTAINER_TEST_IMAGE -f Dockerfile .
- docker push $CONTAINER_TEST_IMAGE
except:
- master
- tags
release_master_gitlab:
<<: *release_env
script:
- docker build -t $CONTAINER_TEST_IMAGE -f Dockerfile .
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_IMAGE:latest
- docker push $CONTAINER_IMAGE:latest
only:
- master
release_master_dockerhub:
<<: *release_env
before_script:
- docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
script:
- docker build -t $CONTAINER_TEST_IMAGE -f Dockerfile .
- docker tag $CONTAINER_TEST_IMAGE $DOCKERHUB_RELEASE:latest
- docker push $DOCKERHUB_RELEASE:latest
only:
- master
release_tags_gitlab:
<<: *release_env
before_script:
- docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
script:
- docker build -t $CONTAINER_TEST_IMAGE -f Dockerfile .
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_IMAGE:$CI_BUILD_TAG
- docker push $CONTAINER_IMAGE:$CI_BUILD_TAG
only:
- tags
release_tags_dockerhub:
<<: *release_env
before_script:
- docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
script:
- docker build -t $CONTAINER_TEST_IMAGE -f Dockerfile .
- docker tag $CONTAINER_TEST_IMAGE $DOCKERHUB_RELEASE:$CI_BUILD_TAG
- docker push $DOCKERHUB_RELEASE:$CI_BUILD_TAG
only:
- tags
# release_master:
# stage: release
# script:
# - docker pull $CONTAINER_TEST_IMAGE
# - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_IMAGE:latest
# - docker push $CONTAINER_IMAGE:latest
# # release docker hub
# - docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
# - docker tag $CONTAINER_TEST_IMAGE $DOCKERHUB_RELEASE:latest
# - docker push $DOCKERHUB_RELEASE:latest
# only:
# - master
# tags:
# - dind
# release_tags:
# stage: release
# script:
# - docker pull $CONTAINER_TEST_IMAGE
# - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_IMAGE:$CI_BUILD_TAG
# - docker push $CONTAINER_IMAGE:$CI_BUILD_TAG
# # release docker hub
# - docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
# - docker tag $CONTAINER_TEST_IMAGE $DOCKERHUB_RELEASE:$CI_BUILD_TAG
# - docker push $DOCKERHUB_RELEASE:$CI_BUILD_TAG
# only:
# - tags
# tags:
# - dind
deploy-testing:
stage: deploy
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- mkdir -p ${HOME}/${TEST_PATH}
- cat docker-compose-test.yml | envsubst > ${HOME}/${TEST_PATH}/docker-compose.yml
- cd ${HOME}/${TEST_PATH}
- docker-compose stop
- docker-compose pull
- docker-compose rm -f
- docker-compose up -d
except:
- master
- tags
tags:
- dev3host
environment:
name: review/$CI_BUILD_REF_NAME
url: http://$CI_BUILD_REF_NAME.rust-admin.com
on_stop: stop_review_app
stop_review_app:
stage: deploy
script:
- cd ${HOME}/${TEST_PATH}
- docker-compose stop
- docker-compose rm -f
- rm -rf ${HOME}/${TEST_PATH}
when: manual
environment:
name: review/$CI_BUILD_REF_NAME
action: stop
tags:
- dev3host
deploy-prod:
stage: deploy
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
script:
- mkdir -p ${HOME}/${PROD_PATH}
- cat docker-compose-prod.yml | envsubst > ${HOME}/${PROD_PATH}/docker-compose.yml
- cd ${HOME}/${PROD_PATH}/
- docker-compose stop
- docker-compose pull
- docker-compose rm -f
- docker-compose up -d
only:
- master
tags:
- dev3host
environment:
name: production
url: https://rust-admin.com