-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
177 lines (173 loc) · 6.31 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
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'
stages:
- build
- license-list
- pre-package
- package
- post-package
- deploy
.maven-build:
variables:
POSTGRES_IMAGE_TAG: 10.13-alpine
POSTGRES_DB: redmic
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
DIND_IMAGE_NAME: docker
DIND_IMAGE_TAG: dind
DOCKER_HOST: tcp://docker:2375
SPRING_DATASOURCE_URL: jdbc:postgresql://docker:5432/redmic?stringtype=unspecified¤tSchema=sde
JOBS_DATASOURCE_URL: jdbc:postgresql://docker:5432/redmic?currentSchema=job
ELASTIC_ADDRESSES: docker
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
LOGGING_LEVEL_ROOT: error
LOGGING_LEVEL_ORG_SPRINGFRAMEWORK: error
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
- >
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"
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"
curl -s --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_READ_API}" \
-o sql/task_database_structure_test.sql \
"https://gitlab.com/api/v4/snippets/${TASK_DATABASE_STRUCTURE_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} \
-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 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} \
-f /sql/task_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 exec postgres psql -h localhost \
-d redmic \
-U ${POSTGRES_USER} \
-c "ALTER ROLE ${JOBS_DATASOURCE_USERNAME} WITH PASSWORD '${JOBS_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}
- >
RESPONSE="";
until [ "$RESPONSE" = "green" ];
do
sleep 15;
RESPONSE="$(curl -sS -u ${ELASTIC_USER}:${ELASTIC_USER_PASS} docker:9200/_cat/health?h=status || :)";
echo "Waiting for elasticsearch server, remaining attempts... Last output:";
echo $RESPONSE;
done
after_script:
- rm -rf .m2/repository/es
- docker stop 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: api
STATUS_CHECK_DELAY: 300