-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
141 lines (132 loc) · 4.73 KB
/
Jenkinsfile
File metadata and controls
141 lines (132 loc) · 4.73 KB
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
@Library('swarm-deploy') _
def DockerApp
def DockerAppDB
def DockerDB
def DockerDyalog
def Testfile = "/tmp/dcms-CI.log"
def Branch = env.BRANCH_NAME.toLowerCase()
def Home = "/app/home"
node ('Docker') {
stage ('Checkout') {
checkout scm
}
stage ('Build container') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
DockerDyalog = docker.build("dcms-build", "-f $WORKSPACE/Dockerfile .")
}
}
stage ('Update MariaDB') {
withDockerRegistry(credentialsId: '0435817a-5f0f-47e1-9dcc-800d85e5c335') {
DockerDB=docker.image('mariadb:10.8.2') // Until build machine is updated
DockerDB.pull()
}
}
stage ('Install dependencies') {
sh "mkdir -p $WORKSPACE/home"
try {
DockerDyalog.inside("-t -u 6203 -v $WORKSPACE:/app -e HOME=${Home} -e APP_DIR=/app -e DOTNET_ROOT=/opt/dotnet --entrypoint=''"){
sh "/app/CI/activate.apls"
sh "/app/CI/install.apls"
}
} catch(e) {
println 'Could not install Tatin or NuGet dependencies.'
sh "docker rmi dcms-build"
throw new Exception("${e}")
}
}
stage ('Test service') {
DockerAppDB = DockerDB.run ("-e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_DATABASE=dyalog_cms -e MYSQL_USER=dcms -e MYSQL_PASSWORD=apl")
def DBIP = sh (
script: "docker inspect ${DockerAppDB.id} | jq .[0].NetworkSettings.IPAddress | sed 's/\"//g'",
returnStdout: true
).trim()
sh "echo ${DBIP}"
sleep 10
withCredentials([file(credentialsId: '205bc57d-1fae-4c67-9aeb-44c1144f071c', variable: 'DCMS_SECRETS')]) {
try {
DockerApp = DockerDyalog.run ("-t -u 6203 -v $DCMS_SECRETS:$DCMS_SECRETS -e HOME=${Home} -e CONFIGFILE=/app/CI/test.dcfg -e APP_DIR=/app -e YOUTUBE=http://localhost:8088/ -e SECRETS=$DCMS_SECRETS -e SQL_SERVER=${DBIP} -e SQL_DATABASE=dyalog_cms -e SQL_USER=dcms -e SQL_PASSWORD=apl -e SQL_PORT=3306 -v $WORKSPACE:/app")
println(DockerApp.id)
sh "docker logs -f ${DockerApp.id}"
def out = sh script: "docker inspect ${DockerApp.id} --format='{{.State.ExitCode}}'", returnStdout: true
sh "exit ${out}"
}
catch (e) {
DockerAppDB.stop()
println 'DCMS tests failed - cleaning up.'
sh ("docker logs ${DockerApp.id}")
sh ('git rev-parse --short HEAD > .git/commit-id')
withCredentials([string(credentialsId: '250bdc45-ee69-451a-8783-30701df16935', variable: 'GHTOKEN')]) {
commit_id = readFile('.git/commit-id')
sh "${WORKSPACE}/CI/githubComment.sh ${DockerApp.id} ${commit_id}"
}
DockerApp.stop()
sh "docker rmi dcms-build"
echo "Throwing Exception..."
echo "Exception is: ${e}"
throw new Exception("${e}");
}
}
DockerApp.stop()
DockerAppDB.stop()
}
stage ('Publish DCMS') {
withCredentials([file(credentialsId: '205bc57d-1fae-4c67-9aeb-44c1144f071c', variable: 'DCMS_SECRETS')]) {
sh 'mkdir -p ${WORKSPACE}/secrets && cat $DCMS_SECRETS > ${WORKSPACE}/secrets/secrets.json5'
if (Branch == 'master') {
ftpPublisher alwaysPublishFromMaster: false, continueOnError: false, failOnError: false, publishers: [[
configName: 'DCMSWeb',
transfers: [[
asciiMode: false,
cleanRemote: false,
excludes: '',
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: "/${Branch}/",
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '**/*'
]],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true
]]
} else {
sh ("mkdir -p /DockerVolumes/ftp/dcmsweb/${Branch}/")
sh ("cp -R * /DockerVolumes/ftp/dcmsweb/${Branch}/")
}
}
sh 'rm ${WORKSPACE}/secrets/secrets.json5'
}
stage ('Create ENV file') {
// This will come from Jenkins data after testing
sh '''
echo HOME=/app/home >> ${WORKSPACE}/env
echo SQL_SERVER=db >> ${WORKSPACE}/env
echo SQL_DATABASE=dyalog_cms >> ${WORKSPACE}/env
echo SQL_USER=dcms >> ${WORKSPACE}/env
echo SQL_PASSWORD=apl >> ${WORKSPACE}/env
echo SQL_PORT=3306 >> ${WORKSPACE}/env
echo SECRETS=/app/secrets/secrets.json5 >> ${WORKSPACE}/env
echo MYSQL_DATABASE=dyalog_cms >> ${WORKSPACE}/env
echo MYSQL_USER=dcms >> ${WORKSPACE}/env
echo MYSQL_PASSWORD=apl >> ${WORKSPACE}/env
echo MYSQL_PORT=3306 >> ${WORKSPACE}/env
echo CONFIGFILE=/app/dcms.dcfg >> ${WORKSPACE}/env
echo APP_DIR=/app >> ${WORKSPACE}/env
echo YOUTUBE=https://www.googleapis.com/youtube/v3/ >> ${WORKSPACE}/env
echo MYSQL_RANDOM_ROOT_PASSWORD=1 >> ${WORKSPACE}/env
'''
stash includes: 'env,service.yml', name: 'swarmfiles'
}
}
if (env.BRANCH_NAME.contains('master')) {
node (label: 'swarm && gosport') {
stage('Deploying with Docker Swarm') {
unstash 'swarmfiles'
res1 = stopServices 'DCMS'
res2 = swarm 'DCMS'
}
}
}