-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
224 lines (217 loc) · 7.7 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
include:
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/maven-building-microservice.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/license-listing.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/packaging.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/deployment.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/deployment-custom-image.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/deployment-external-service/backup-files.yml'
- project: 'redmic-project/gitlab-ci-templates'
ref: master
file: '/maintenance.yml'
stages:
- build
- license-list
- pre-package
- package
- post-package
- deploy
- deploy-external-service
- maintenance
variables:
PROJECT_PARENT_NAME: api
DEVELOPMENT_MAINTENANCE_DISABLED: 'true'
.maven-build:
variables:
POSTGRES_IMAGE_TAG: 10.13-alpine
POSTGRES_DB: redmic
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
OAUTH_IMAGE_NAME: registry.gitlab.com/redmic-project/server/oauth/master
OAUTH_IMAGE_TAG: latest
OAUTH_CLIENT_ID: oauth_id
OAUTH_CLIENT_SECRET: oauth_secret
USER_IMAGE_NAME: registry.gitlab.com/redmic-project/server/user/master
USER_IMAGE_TAG: latest
DIND_IMAGE_NAME: docker
DIND_IMAGE_TAG: dind
DOCKER_HOST: tcp://docker:2375
SPRING_DATASOURCE_URL: jdbc:postgresql://docker:5432/redmic?stringtype=unspecified
ELASTIC_ADDRESSES: docker
OAUTH_SERVER: http://docker:8081
PROPERTY_USER_API: http://docker:8082
ELASTICSEARCH_IMAGE_NAME: docker.elastic.co/elasticsearch/elasticsearch
ELASTICSEARCH_IMAGE_TAG: 6.6.2
ES_BOOTSTRAP_MEMORY_LOCK: 'true'
OLD_ELASTIC_ADMIN_PASS: changeme
ELASTIC_ADMIN_PASS: elastic_admin_pass
ELASTIC_USER: elastic_user
ELASTIC_USER_PASS: elastic_user_pass
ELASTIC_USER_ROLE: redmic_user
ES_JAVA_OPTS: '-Xms512m -Xmx512m -Djava.security.policy=file:///usr/share/elasticsearch/config/grovy-classes_whitelist.policy'
ES_CLUSTER_NAME: es_dev
ES_NODE_NAME: node-1
ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES: 1
ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS: es6-1
ES_XPACK_SECURITY_ENABLED: 'false'
ELASTIC_HOSTS: es6-1
GITLAB_REGISTRY_HOST: registry.gitlab.com
CI_DEPLOY_USER: ci_deploy_user
CI_DEPLOY_PASSWORD: ci_deploy_password
services:
- ${DIND_IMAGE_NAME}:${DIND_IMAGE_TAG}
before_script:
- >
mkdir -p sql;
chmod -R 755 sql;
docker network create test || true
- >
docker run -d --rm --name postgres \
-p 5432:5432 \
--network test \
--network-alias db \
-e POSTGRES_DB \
-e POSTGRES_USER \
-e POSTGRES_PASSWORD \
-v $(pwd)/sql:/sql \
postgres:${POSTGRES_IMAGE_TAG}
- >
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/oauth_database_structure_test.sql \
"https://gitlab.com/api/v4/snippets/${OAUTH_DATABASE_STRUCTURE_TEST_SNIPPET_ID}/raw";
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/oauth_database_data_test.sql \
"https://gitlab.com/api/v4/snippets/${OAUTH_DATABASE_DATA_TEST_SNIPPET_ID}/raw";
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/user_database_structure_test.sql \
"https://gitlab.com/api/v4/snippets/${USER_DATABASE_STRUCTURE_TEST_SNIPPET_ID}/raw";
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/user_database_data_test.sql \
"https://gitlab.com/api/v4/snippets/${USER_DATABASE_DATA_TEST_SNIPPET_ID}/raw"
- >
RETRIES=10;
until docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-c 'select 1' > /dev/null 2>&1 || [ $RETRIES -eq 0 ];
do
RETRIES=$((RETRIES-=1));
echo "Waiting for postgres server, ${RETRIES} remaining attempts...";
sleep 1;
done;
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-f /sql/oauth_database_structure_test.sql;
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-c "ALTER ROLE ${USER_SPRING_DATASOURCE_USERNAME} WITH PASSWORD '${USER_SPRING_DATASOURCE_PASSWORD}'";
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-f /sql/oauth_database_data_test.sql;
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-f /sql/user_database_structure_test.sql;
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-f /sql/user_database_data_test.sql
- >
docker run -d --rm --name oauth \
-p 8081:8081 \
--network test \
-e SPRING_PROFILES_ACTIVE=dev \
-e SPRING_DATASOURCE_USERNAME=${USER_SPRING_DATASOURCE_USERNAME} \
-e SPRING_DATASOURCE_PASSWORD=${USER_SPRING_DATASOURCE_PASSWORD} \
${OAUTH_IMAGE_NAME}:${OAUTH_IMAGE_TAG}
- >
docker run -d --rm --name user \
-p 8082:8082 \
--network test \
-e SPRING_PROFILES_ACTIVE=dev \
-e SPRING_DATASOURCE_USERNAME=${USER_SPRING_DATASOURCE_USERNAME} \
-e SPRING_DATASOURCE_PASSWORD=${USER_SPRING_DATASOURCE_PASSWORD} \
-e OAUTH_CLIENT_ID \
-e OAUTH_CLIENT_SECRET \
${USER_IMAGE_NAME}:${USER_IMAGE_TAG}
- >
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/api_database_structure_test.sql \
"https://gitlab.com/api/v4/snippets/${API_DATABASE_STRUCTURE_TEST_SNIPPET_ID}/raw";
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-f /sql/api_database_structure_test.sql;
docker exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-c "ALTER ROLE ${SPRING_DATASOURCE_USERNAME} WITH PASSWORD '${SPRING_DATASOURCE_PASSWORD}'"
- >
docker run -d --rm --name es6-1 \
-p 9300:9300 \
-p 9200:9200 \
--network test \
--ulimit memlock=-1:-1 \
-e ES_BOOTSTRAP_MEMORY_LOCK \
-e OLD_ELASTIC_ADMIN_PASS \
-e ELASTIC_ADMIN_PASS \
-e ELASTIC_USER \
-e ELASTIC_USER_PASS \
-e ELASTIC_USER_ROLE \
-e ES_JAVA_OPTS \
-e ES_CLUSTER_NAME \
-e ES_NODE_NAME \
-e ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES \
-e ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS \
-e ES_XPACK_SECURITY_ENABLED \
${ELASTICSEARCH_IMAGE_NAME}:${ELASTICSEARCH_IMAGE_TAG}
- >
sleep 20;
RETRIES=10;
RESPONSE="";
until [ "$RESPONSE" = "green" ] || [ "$RETRIES" -eq 0 ];
do
sleep 5;
RETRIES=$((RETRIES-=1));
RESPONSE="$(curl -sS -u ${ELASTIC_USER}:${ELASTIC_USER_PASS} docker:9200/_cat/health?h=status || :)";
echo "Waiting for elasticsearch server, ${RETRIES} remaining attempts... Last output:";
done;
if [ "$RESPONSE" != "green" ];
then
echo "Elasticsearch logs:"
docker logs -n 100 es6-1
fi;
after_script:
- rm -rf .m2/repository/es
- docker stop user oauth postgres es6-1
.docker-build:
variables:
DBLD_PARENT_IMAGE_NAME: ${REDMIC_SERVER_IMAGE_NAME}
DBLD_PARENT_IMAGE_TAG: ${REDMIC_SERVER_IMAGE_TAG}
.deploy:
variables:
STACK: ${PROJECT_PARENT_NAME}
STATUS_CHECK_DELAY: 300
environment:
url: https://${PUBLIC_HOSTNAME}/${CI_PROJECT_NAME}
.deploy-external-service:
variables:
STACK: ${PROJECT_PARENT_NAME}
.scheduled-run:
variables:
STACK: ${PROJECT_PARENT_NAME}
SERVICE: ${PROJECT_PARENT_NAME}_backup-files