-
Notifications
You must be signed in to change notification settings - Fork 28
/
Jenkinsfile
125 lines (109 loc) · 6.71 KB
/
Jenkinsfile
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
node {
def SORMAS_VERSION=''
def SORMAS_VERSION_NIGHTLY=''
stage('checkout') {
git branch: '${BRANCH}', url: 'https://github.com/sormas-foundation/SORMAS-Docker.git'
}
stage('set variables') {
echo 'Setting variables'
SORMAS_VERSION_NIGHTLY= sh (
script: 'curl -s https://raw.githubusercontent.com/sormas-foundation/SORMAS-Project/development/sormas-base/pom.xml | grep SNAPSHOT | sed s/\\<version\\>// | sed s/\\<\\\\/version\\>// | sed \'s/[[:space:]]//g\'',
returnStdout: true
).trim()
if (params.BUILD_NIGHTLY != null && params.BUILD_NIGHTLY) {
echo 'Build NIGHTLY'
SORMAS_VERSION = SORMAS_VERSION_NIGHTLY
sh """
sed -i 's,SORMAS_URL=.*\$,SORMAS_URL=http://10.160.41.100/,' ./.env
sed -i 's,SORMAS_VERSION=.*\$,SORMAS_VERSION=${SORMAS_VERSION},' ./.env
"""
}
else {
if (params.VERSION_TO_BUILD != null) {
echo 'Build Version specified in parameters: ${params.VERSION_TO_BUILD}'
SORMAS_VERSION = params.VERSION_TO_BUILD
}
else {
echo 'Build Version from .env'
SORMAS_VERSION = sh (
script: "source ./.env &> /dev/null && echo \$SORMAS_VERSION",
returnStdout: true
).trim()
}
}
if (params.SORMAS_DOCKER_VERSION != null) {
echo 'Set SORMAS_DOCKER_VERSION to ${SORMAS_DOCKER_VERSION}'
sh """
sed -i 's,SORMAS_DOCKER_VERSION=.#*\$,SORMAS_DOCKER_VERSION=${SORMAS_DOCKER_VERSION},' ./.env
"""
}
sh """
sed -i "/^GEO_TEMPLATE/d " ./.env
cat ./.env
"""
echo "${SORMAS_VERSION}"
}
stage('Build SORMAS') {
echo 'Building SORMAS'
sh """
source ./.env
sudo docker build --build-arg SORMAS_URL=\$SORMAS_URL --build-arg SORMAS_VERSION=\$SORMAS_VERSION --pull --no-cache -t sormas-application:${SORMAS_DOCKER_VERSION} sormas/
sudo docker build --build-arg SORMAS_URL=\$SORMAS_URL --build-arg SORMAS_VERSION=\$SORMAS_VERSION --pull --no-cache -t sormas-postgres:${SORMAS_DOCKER_VERSION} postgres/
sudo docker build --build-arg SORMAS_URL=\$SORMAS_URL --build-arg SORMAS_VERSION=\$SORMAS_VERSION --pull --no-cache -t sormas-apache2:${SORMAS_DOCKER_VERSION} apache2/
sudo docker build --build-arg SORMAS_URL=\$SORMAS_URL --build-arg SORMAS_VERSION=\$SORMAS_VERSION --pull --no-cache -t sormas-pg-dump:${SORMAS_DOCKER_VERSION} pg_dump/
"""
}
stage('DEPLOY SORMAS') {
echo 'Deploying locally....'
withCredentials([ usernamePassword(credentialsId: 'registry.netzlink.com', usernameVariable: 'MY_SECRET_USER_NLI', passwordVariable: 'MY_SECRET_USER_PASSWORD_NLI' )]) {
sh """
sudo docker login -u '$MY_SECRET_USER_NLI' -p '$MY_SECRET_USER_PASSWORD_NLI' registry.netzlink.com
sudo docker tag sormas-application:${SORMAS_DOCKER_VERSION} registry.netzlink.com/hzibraunschweig/sormas-application:${SORMAS_DOCKER_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/sormas-application:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-postgres:${SORMAS_DOCKER_VERSION} registry.netzlink.com/hzibraunschweig/sormas-postgres:${SORMAS_DOCKER_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/sormas-postgres:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-apache2:${SORMAS_DOCKER_VERSION} registry.netzlink.com/hzibraunschweig/sormas-apache2:${SORMAS_DOCKER_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/sormas-apache2:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-pg-dump:${SORMAS_DOCKER_VERSION} registry.netzlink.com/hzibraunschweig/sormas-pg-dump:${SORMAS_DOCKER_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/sormas-pg-dump:${SORMAS_DOCKER_VERSION}
"""
}
echo 'Deploying to docker.io....'
withCredentials([ usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'MY_SECRET_USER_NLI', passwordVariable: 'MY_SECRET_USER_PASSWORD_NLI' )]) {
sh """
sudo docker login -u '$MY_SECRET_USER_NLI' -p '$MY_SECRET_USER_PASSWORD_NLI' docker.io
sudo docker tag sormas-application:${SORMAS_DOCKER_VERSION} docker.io/hzibraunschweig/sormas-application:${SORMAS_DOCKER_VERSION}
sudo docker push docker.io/hzibraunschweig/sormas-application:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-postgres:${SORMAS_DOCKER_VERSION} docker.io/hzibraunschweig/sormas-postgres:${SORMAS_DOCKER_VERSION}
sudo docker push docker.io/hzibraunschweig/sormas-postgres:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-apache2:${SORMAS_DOCKER_VERSION} docker.io/hzibraunschweig/sormas-apache2:${SORMAS_DOCKER_VERSION}
sudo docker push docker.io/hzibraunschweig/sormas-apache2:${SORMAS_DOCKER_VERSION}
sudo docker tag sormas-pg-dump:${SORMAS_DOCKER_VERSION} docker.io/hzibraunschweig/sormas-pg-dump:${SORMAS_DOCKER_VERSION}
sudo docker push docker.io/hzibraunschweig/sormas-pg-dump:${SORMAS_DOCKER_VERSION}
"""
}
}
stage('Build LBDS') {
echo 'Building....'
withCredentials([ usernamePassword(credentialsId: 'crowdcodeNexus', usernameVariable: 'CROWDCODE_NEXUS_USER', passwordVariable: 'CROWDCODE_NEXUS_PASSWORD' )]) {
sh """
source ./.env
cd lbds
sudo docker build --pull --no-cache --build-arg LBDS_JAR_FILE_VERSION=${LBDS_JAR_FILE_VERSION} --build-arg CROWDCODE_NEXUS_USER=${CROWDCODE_NEXUS_USER} --build-arg CROWDCODE_NEXUS_PASSWORD="${CROWDCODE_NEXUS_PASSWORD}" -t hzibraunschweig/lbds:${LBDS_JAR_FILE_VERSION} .
"""
}
}
stage('Deploy LBDS') {
echo 'Deploying....'
withCredentials([ usernamePassword(credentialsId: 'registry.netzlink.com', usernameVariable: 'MY_SECRET_USER_NLI', passwordVariable: 'MY_SECRET_USER_PASSWORD_NLI' )]) {
sh """
sudo docker login -u '$MY_SECRET_USER_NLI' -p '$MY_SECRET_USER_PASSWORD_NLI' registry.netzlink.com
sudo docker tag hzibraunschweig/lbds:${LBDS_JAR_FILE_VERSION} registry.netzlink.com/hzibraunschweig/lbds:${LBDS_JAR_FILE_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/lbds:${LBDS_JAR_FILE_VERSION}
sudo docker tag hzibraunschweig/lbds:${LBDS_JAR_FILE_VERSION} registry.netzlink.com/hzibraunschweig/lbds:${SORMAS_DOCKER_VERSION}
sudo docker push registry.netzlink.com/hzibraunschweig/lbds:${SORMAS_DOCKER_VERSION}
echo 'Finished'
"""
}
}
}