-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.gitlab-ci.yml
143 lines (126 loc) · 4.38 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
variables:
SERVICE_NAME: backend
before_script:
- 'export MAVEN_OPTS="-Xms4g -Xmx4g -Dmaven.repo.local=${CI_PROJECT_DIR}/.m2/repository"'
stages:
- test
- 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
.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
build:dev:
extends:
- .environment_dev
- .build
stage: build
deploy:dev:
extends:
- .environment_dev
- .deploy
needs:
- build:dev
stage: deploy