forked from SODALITE-EU/semantic-reasoner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
233 lines (228 loc) · 8.54 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
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
228
229
230
231
232
233
pipeline {
options {
disableConcurrentBuilds()
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '30', daysToKeepStr: '', numToKeepStr: '')
}
agent { label 'docker-slave' }
environment {
// OPENSTACK SETTINGS
ssh_key_name = "jenkins-opera"
image_name = "centos7"
vm_name = "semantic-web"
network_name = "orchestrator-network"
security_groups = "default,sodalite-remote-access,sodalite-uc,sodalite-graphdb"
flavor_name = "m1.large"
// DOCKER SETTINGS
docker_network = "sodalite"
dockerhub_user = " "
dockerhub_pass = " "
docker_registry_cert_country_name = "SI"
docker_registry_cert_organization_name = "XLAB"
docker_public_registry_url = "registry.hub.docker.com"
docker_registry_cert_email_address = "[email protected]"
//KB DEPLOYMENT SETTINGS
KB_USERNAME = credentials('kb-username')
KB_PASSWORD = credentials('kb-password')
//KEYCLOAK SETTINGS
KEYCLOAK_URL = credentials('keycloak-url')
KEYCLOAK_CLIENT_ID = credentials('keycloak-client-id')
KEYCLOAK_CLIENT_SECRET = credentials('keycloak-client-secret')
// OPENSTACK DEPLOYMENT FALLBACK SETTINGS
OS_PROJECT_DOMAIN_NAME = "Default"
OS_USER_DOMAIN_NAME = "Default"
OS_PROJECT_NAME = "orchestrator"
OS_TENANT_NAME = "orchestrator"
OS_USERNAME = credentials('os-username')
OS_PASSWORD = credentials('os-password')
OS_AUTH_URL = credentials('os-auth-url')
OS_INTERFACE = "public"
OS_IDENTITY_API_VERSION = "3"
OS_REGION_NAME = "RegionOne"
OS_AUTH_PLUGIN = "password"
// ROOT X.509 CERTIFICATES
ca_crt_file = credentials('xopera-ca-crt')
ca_key_file = credentials('xopera-ca-key')
// CI-CD vars
// When triggered from git tag, $BRANCH_NAME is actually tag_name
TAG_SEM_VER_COMPLIANT = """${sh(
returnStdout: true,
script: './validate_tag.sh SemVar $BRANCH_NAME'
)}"""
TAG_MAJOR_RELEASE = """${sh(
returnStdout: true,
script: './validate_tag.sh MajRel $BRANCH_NAME'
)}"""
TAG_PRODUCTION = """${sh(
returnStdout: true,
script: './validate_tag.sh production $BRANCH_NAME'
)}"""
}
stages {
stage ('Pull repo code from github') {
steps {
checkout scm
}
}
stage('Inspect GIT TAG'){
steps {
sh """ #!/bin/bash
echo 'TAG: $BRANCH_NAME'
echo 'Tag is compliant with SemVar 2.0.0: $TAG_SEM_VER_COMPLIANT'
echo 'Tag is Major release: $TAG_MAJOR_RELEASE'
echo 'Tag is production: $TAG_PRODUCTION'
"""
}
}
stage ('Build the code with Maven') {
steps {
sh """ #!/bin/bash
cd "source code/semantic-reasoner"
mvn clean install -Ddefault.min.distinct.threshold=32428800
"""
//archiveArtifacts artifacts: '**/*.war, **/*.jar', onlyIfSuccessful: true
}
}
stage('SonarQube analysis'){
environment {
scannerHome = tool 'SonarQubeScanner'
}
steps {
withSonarQubeEnv('SonarCloud') {
sh """ #!/bin/bash
cd "source code/semantic-reasoner"
${scannerHome}/bin/sonar-scanner
"""
}
}
}
stage ('Trigger a build of defect-prediction') {
when {
not {
triggeredBy 'UpstreamCause'
}
}
steps {
build job: 'defect-prediction/master', wait: false
}
}
stage('Build reasoner docker image') {
when { // Only on production tags
// branch "master"
allOf {
expression{tag "*"}
expression{
TAG_PRODUCTION == 'true'
}
}
}
steps {
sh "cd source\\ code/semantic-reasoner; docker build -t semantic_web -f ./docker/web/Dockerfile ."
}
}
stage('Build graphdb docker image') {
when { // Only on production tags
// branch "master"
allOf {
expression{tag "graphdb-*"}
}
}
steps {
sh "cd source\\ code/semantic-reasoner; docker build -t graph_db -f ./docker/graph-db/Dockerfile ."
}
}
stage('Push Reasoner to DockerHub') {
when { // Only on production tags
allOf {
expression{tag "*"}
expression{
TAG_PRODUCTION == 'true'
}
}
//branch "master"
}
steps {
withDockerRegistry(credentialsId: 'jenkins-sodalite.docker_token', url: '') {
sh """#!/bin/bash
docker tag semantic_web sodaliteh2020/semantic_web:${BRANCH_NAME}
docker tag semantic_web sodaliteh2020/semantic_web
docker push sodaliteh2020/semantic_web:${BRANCH_NAME}
docker push sodaliteh2020/semantic_web:latest
"""
}
}
}
stage('Push graphdb to DockerHub') {
when {
tag "graphdb-*"
}
steps {
withDockerRegistry(credentialsId: 'jenkins-sodalite.docker_token', url: '') {
sh """#!/bin/bash
docker tag graph_db sodaliteh2020/graph_db:${BRANCH_NAME}
docker tag graph_db sodaliteh2020/graph_db
docker push sodaliteh2020/graph_db:${BRANCH_NAME}
docker push sodaliteh2020/graph_db:latest
"""
}
}
}
stage('Install dependencies') {
when { // Only on production tags
allOf {
expression{tag "*"}
expression{
TAG_PRODUCTION == 'true'
}
}
//branch "master"
}
steps {
sh """#!/bin/bash
rm -rf venv
python3 -m venv venv
. venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install opera[openstack]==0.6.4 docker
ansible-galaxy install -r openstack-blueprint/requirements.yml --force
rm -r -f openstack-blueprint/modules/
git clone -b 3.5.0 https://github.com/SODALITE-EU/iac-modules.git openstack-blueprint/modules/
cp ${ca_crt_file} openstack-blueprint/modules/docker/artifacts/ca.crt
cp ${ca_crt_file} openstack-blueprint/modules/misc/tls/artifacts/ca.crt
cp ${ca_key_file} openstack-blueprint/modules/docker/artifacts/ca.key
cp ${ca_key_file} openstack-blueprint/modules/misc/tls/artifacts/ca.key
"""
}
}
stage('Deploy to openstack') {
when { // Only on production tags
allOf {
expression{tag "*"}
expression{
TAG_PRODUCTION == 'true'
}
}
// branch "master"
}
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'xOpera_ssh_key', keyFileVariable: 'xOpera_ssh_key_file', usernameVariable: 'xOpera_ssh_username')]) {
sh """#!/bin/bash
# create input.yaml file from template
envsubst < openstack-blueprint/input.yaml.tmpl > openstack-blueprint/input.yaml
. venv/bin/activate
cd openstack-blueprint
rm -rf .opera
opera deploy service.yaml -i input.yaml
"""
}
}
}
}
post {
failure {
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
fixed {
slackSend (color: '#6d3be3', message: "FIXED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
}