-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
158 lines (140 loc) · 4.34 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
image: maven:3-jdk-11
cache:
paths:
- target/
stages:
- build
- dockerify
- deploy
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
services:
- docker:dind
.deploy-template: &deploy-template
stage: deploy
script:
- mkdir -p ~/.ssh
- cp "$ssh_key" ~/.ssh/id_rsa
- chmod 700 ~/.ssh/id_rsa
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/id_rsa
- host0=`awk '{print $1}' <<< $host`
- scp -oStrictHostKeyChecking=no ./target/biostudies.war "$user"@"$host0":"$deployDirectory"
- cp "$application_properties" external.properties
- echo -e "\ngit.commit.id.abbrev=$CI_COMMIT_SHORT_SHA" >> external.properties
- scp external.properties "$user"@"$host0":"$deployDirectory"/external.properties
- >
for host in $host; do
ssh -oStrictHostKeyChecking=no "$user"@"$host" "$deployDirectory"/restart.sh
echo "Waiting 220 seconds"
sleep 220
done
build-develop:
stage: build
artifacts:
paths:
- target/biostudies.war
script:
- apt-get update
- apt install jq -y
- wget https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
- wget `jq -r '.channels.Stable.downloads.chrome[] | select(.platform == "linux64").url' last-known-good-versions-with-downloads.json`
- wget `jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform == "linux64").url' last-known-good-versions-with-downloads.json`
- unzip chrome-linux64.zip
- unzip chromedriver-linux64.zip
- apt install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y
- PATH=`pwd`/chrome-linux64:$PATH
- mv `pwd`/chromedriver-linux64/chromedriver `pwd`
- mvn clean install spring-boot:repackage
environment: dev
only:
- develop
build-master:
stage: build
artifacts:
paths:
- target/biostudies.war
script:
- mvn -Dmaven.test.skip=true clean install spring-boot:repackage
only:
- master
build-branch:
stage: build
artifacts:
paths:
- target/biostudies.war
script:
- mvn -Dmaven.test.skip=true clean install spring-boot:repackage
when: manual
push-docker-image:
image: docker
stage: dockerify
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --build-arg RUN_AS_USER=${RUN_AS_USER} --build-arg RUN_AS_GROUP=${RUN_AS_GROUP} -t ${DOCKER_IMAGE} -t ${CI_REGISTRY_IMAGE}:latest --no-cache .
- docker push ${DOCKER_IMAGE}
- docker push ${CI_REGISTRY_IMAGE}:latest
- docker rmi ${DOCKER_IMAGE}
- docker rmi ${CI_REGISTRY_IMAGE}:latest
- docker logout $CI_REGISTRY
only:
- master
.deploy-k8s:
stage: deploy
image: alpine:latest
script:
- apk add --no-cache curl gettext
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin/kubectl
- cd ci
- cat "$APP_CONFIG" | kubectl apply -f -
- envsubst < deployment.tmpl | kubectl apply -f -
- kubectl rollout restart statefulset "$LABEL" -n "$NAMESPACE"
deploy-branch:
<<: *deploy-template
environment: $TARGET_ENVIRONMENT
when: manual
dev:
<<: *deploy-template
environment: dev
only:
- develop
beta:
<<: *deploy-template
environment: beta
only:
- develop
when: manual
hx-k8s:
extends: .deploy-k8s
environment:
name: hx
only:
- master
hl-k8s:
extends: .deploy-k8s
environment:
name: hl
only:
- master
preview:
<<: *deploy-template
environment: preview
only:
- master
when: manual
prod-backup:
<<: *deploy-template
environment: prod-backup
only:
- master
when: manual
prod:
<<: *deploy-template
environment: prod
only:
- master
when: manual