forked from rtr-nettest/open-rmbt-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
227 lines (206 loc) · 7.25 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
225
226
227
variables:
SERVICE_NAME: backend
before_script:
- 'export MAVEN_OPTS="-Xms4g -Xmx4g -Dmaven.repo.local=${CI_PROJECT_DIR}/.m2/repository"'
stages:
- test
- sonar
- build
- deploy
.environment_dev:
environment:
name: dev
only:
- dev
.environment_merge:
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /(dev)/
.test:
image: maven:3.6-jdk-13-alpine
cache:
key: "${CI_COMMIT_REF_SLUG}"
untracked: true
script:
- apk add --no-cache zip unzip
- mkdir -p ${CI_PROJECT_DIR}/artifacts/ && cd ${CI_PROJECT_DIR}/artifacts
- 'curl --location --output ${CORE_ARTIFACT_DOWNLOAD}.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.martes-specure.com/api/v4/projects/${CORE_PROJECT_ID}/jobs/artifacts/${CORE_ARTIFACT_BRANCH}/download?job=${CORE_ARTIFACT_DOWNLOAD}"'
- ls -lsa
- unzip ${CORE_ARTIFACT_DOWNLOAD}.zip -d ${CORE_ARTIFACT_DOWNLOAD}
- mv -f ${CI_PROJECT_DIR}/artifacts/${CORE_ARTIFACT_DOWNLOAD}/target/${CORE_ARTIFACT_NAME} ${CI_PROJECT_DIR}/
- rm -f ${CORE_ARTIFACT_DOWNLOAD}.zip
- cd ${CI_PROJECT_DIR} && rm -rvf "${CI_PROJECT_DIR}/artifacts/"
- >-
mvn clean install:install-file
-Dfile=$CORE_ARTIFACT_NAME
-DgroupId=com.specure
-DartifactId=core
-Dversion=0.0.1-SNAPSHOT
-Dpackaging=jar
-DgeneratePom=true
- >-
mvn
org.jacoco:jacoco-maven-plugin:0.8.5:prepare-agent
test -B
org.jacoco:jacoco-maven-plugin:0.8.5:report
.sonar:
image: maven:3.6.3-jdk-11-slim
cache:
key: "${CI_COMMIT_REF_SLUG}"
untracked: true
policy: pull
script:
- |
apt-get update && apt-get -y upgrade && apt-get install -y apt-utils jq curl unzip zip
apt-get clean
rm -rf \
/var/lib/apt/lists/* \
/var/log/alternatives.log \
/var/log/apt/history.log \
/var/log/apt/term.log \
/var/log/dpkg.log
- >-
mvn sonar:sonar
-Dsonar.gitlab.project_id="${CI_PROJECT_PATH}"
-Dsonar.gitlab.commit_sha="${CI_COMMIT_SHA}"
-Dsonar.gitlab.ref_name="${CI_COMMIT_REF_NAME}"
-Dsonar.projectKey="${SONAR_PROJECT}"
-Dsonar.projectName="${SONAR_PROJECT}"
-Dsonar.host.url="${SONAR_URL}"
-Dsonar.login="${SONAR_KEY}"
-Dsonar.coverage.exclusions="src/main/java/at/rtr/rmbt/**/annotation/**,
src/main/java/at/rtr/rmbt/**/config/**,
src/main/java/at/rtr/rmbt/**/constant/**,
src/main/java/at/rtr/rmbt/**/enums/**,
src/main/java/at/rtr/rmbt/**/mapper/**,
src/main/java/at/rtr/rmbt/**/model/**,
src/main/java/at/rtr/rmbt/**/repository/**,
src/main/java/at/rtr/rmbt/**/request/**,
src/main/java/at/rtr/rmbt/**/response/**,
srс/main/resources/**,
**/*Application.java"
- |
URL="$(cat ./target/sonar/report-task.txt | grep ceTaskUrl | cut -c11-)"
sleep ${SONAR_WAIT}s
curl -# -k -u "${SONAR_KEY}":"" "${URL}" -o sonar_analysis.txt
export SONAR_STATUS=$(cat sonar_analysis.txt | jq -r '.task.status')
export SONAR_ANLYSIS_ID=$(cat sonar_analysis.txt | jq -r '.task.analysisId')
if [ "${SONAR_STATUS}" == "SUCCESS" ];then
echo -e "\e[93mSONAR ANALYSIS SUCCESSFULL...\e[0m ANALYSING RESULTS";
curl -# -k -u "${SONAR_KEY}":"" "${SONAR_URL}/api/qualitygates/project_status?analysisId=${SONAR_ANLYSIS_ID}" -o sonar_result.txt
export SONAR_RESULT=$(cat sonar_result.txt | jq -r '.projectStatus.status');
if [ "${SONAR_RESULT}" == "ERROR" ];then
echo -e "\e[91mSONAR RESULTS FAILED\e[0m";
echo "$(cat sonar_result.txt | jq -r '.projectStatus.conditions')"
exit 1
else
echo -e "\e[92mSONAR RESULTS SUCCESSFULL\e[0m";
echo "$(cat sonar_result.txt | jq -r '.projectStatus.conditions')"
exit 0
fi
else
echo -e "\e[91mSONAR ANALYSIS FAILED\e[0m"
exit 1
fi
.build:
image: maven:3.6-jdk-13-alpine
artifacts:
untracked: false
paths:
- target/*.jar
script:
- apk add --no-cache zip unzip
- mkdir -p ${CI_PROJECT_DIR}/artifacts/ && cd ${CI_PROJECT_DIR}/artifacts
- 'curl --location --output ${CORE_ARTIFACT_DOWNLOAD}.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.martes-specure.com/api/v4/projects/${CORE_PROJECT_ID}/jobs/artifacts/${CORE_ARTIFACT_BRANCH}/download?job=${CORE_ARTIFACT_DOWNLOAD}"'
- ls -lsa
- unzip ${CORE_ARTIFACT_DOWNLOAD}.zip -d ${CORE_ARTIFACT_DOWNLOAD}
- mv -f ${CI_PROJECT_DIR}/artifacts/${CORE_ARTIFACT_DOWNLOAD}/target/${CORE_ARTIFACT_NAME} ${CI_PROJECT_DIR}/
- rm -f ${CORE_ARTIFACT_DOWNLOAD}.zip
- cd ${CI_PROJECT_DIR} && rm -rvf "${CI_PROJECT_DIR}/artifacts/"
- >-
mvn clean install:install-file
-Dfile=$CORE_ARTIFACT_NAME
-DgroupId=com.specure
-DartifactId=core
-Dversion=0.0.1-SNAPSHOT
-Dpackaging=jar
-DgeneratePom=true
- mvn -D'maven.test.skip=true' clean install -B
.deploy:
image: alpine:3.11.3
variables:
CLUSTER_NAME: "${CI_COMMIT_REF_SLUG}"
before_script:
- 'which ssh-agent || ( apk update && apk add --no-cache openssh )'
- eval $(ssh-agent -s)
- echo "${SSH_KEY_PRIVATE}" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-add -l
- ssh-keyscan "${SSH_HOST}" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh -o StrictHostKeyChecking=no "${SSH_HOST}" "rm -rf /app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- ssh -o StrictHostKeyChecking=no "${SSH_HOST}" "mkdir -p /app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- scp -o stricthostkeychecking=no ${CI_PROJECT_DIR}/devops/Dockerfile "${SSH_HOST}":"/app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- scp -o stricthostkeychecking=no ${CI_PROJECT_DIR}/devops/docker-entrypoint.sh "${SSH_HOST}":"/app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- scp -o stricthostkeychecking=no ${CI_PROJECT_DIR}/devops/wait-for-it.sh "${SSH_HOST}":"/app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- scp -o stricthostkeychecking=no ${CI_PROJECT_DIR}/target/*.jar "${SSH_HOST}":"/app/rtr-${CLUSTER_NAME}/${SERVICE_NAME}"
- >-
ssh -o StrictHostKeyChecking=no "${SSH_HOST}" "cd /app/rtr-${CLUSTER_NAME}/ &&
docker-compose stop ${SERVICE_NAME} &&
docker-compose rm -f ${SERVICE_NAME} &&
docker-compose build ${SERVICE_NAME} &&
docker-compose up -d ${SERVICE_NAME}"
- ssh -o StrictHostKeyChecking=no "${SSH_HOST}" "docker system prune -f"
test:dev:
extends:
- .test
only:
- dev
stage: test
test:merge:
extends:
- .environment_merge
- .test
stage: test
test:other:
extends:
- .test
except:
- dev
stage: test
sonar:
extends:
- .sonar
environment:
name: "${CI_COMMIT_REF_SLUG}"
only:
- dev
stage: sonar
#sonar:merge:
# extends:
# - .environment_merge
# - .sonar
# stage: sonar
#
#sonar:other:
# extends:
# - .sonar
# except:
# - dev
# stage: sonar
build:dev:
extends:
- .environment_dev
- .build
stage: build
deploy:dev:
extends:
- .environment_dev
- .deploy
needs:
- build:dev
stage: deploy