-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile.dist
164 lines (138 loc) · 7.53 KB
/
Jenkinsfile.dist
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
pipeline {
agent any
stages {
stage('Preparation') {
steps {
sh 'rm -rf ${WORKSPACE}/data'
sh 'rm -rf ${WORKSPACE}/build'
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'ssh-jenkins-master', url: 'ssh://[email protected]:7999/doc/db-databuilder.git']]
])
sh 'mkdir ${WORKSPACE}/data && chmod 0777 ${WORKSPACE}/data'
sh 'mkdir ${WORKSPACE}/build && chmod 0777 ${WORKSPACE}/build'
}
}
stage('Set Dotenv config') {
steps {
sh 'rm -f .env'
sh '''
printf "DATABASE_ROOT_PASSWORD=root\n" >> .env
printf "IMPORT_TIMEOUT_SECONDS=0\n" >> .env
printf "BASE_IMAGE=mysql:5.6\n" >> .env
printf "SQL_PATH_VOLUME=./examples/01-simple/sql\n" >> .env
printf "TARGET_IMAGE=registry.deubert.it:5000/db-databuilder/db-preloaded-01\n" >> .env
'''
}
}
stage('Build docker env') {
steps {
sh 'docker-compose -f docker-compose.01-import.yml build'
}
}
stage('Start docker env') {
steps {
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import up -d'
}
}
stage('Validate docker env') {
steps {
sh 'docker ps | grep "${JOB_NAME}_import_db"'
sh 'printenv'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db printenv'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db bash -c "printenv"'
}
}
stage('Wait for import completion') {
steps {
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db bash -c "chmod +x /tmp/*.sh"'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db bash -c "/tmp/wait-for-it.sh --timeout=$IMPORT_TIMEOUT_SECONDS --host=localhost --port=3306 -- /tmp/save-dbinfo.sh && /tmp/show-dbinfo.sh"'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db chmod -R 0777 /var/lib/mysql'
}
}
stage('Validate output') {
steps {
sh 'rm -rf ${WORKSPACE}/build/export'
sh 'mkdir -p ${WORKSPACE}/build/export'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date mysql user" > ${WORKSPACE}/build/export/mysql-users.sql'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date test01" > ${WORKSPACE}/build/export/test01.sql'
}
}
stage('Stop docker env') {
steps {
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import stop'
}
}
stage('Build data container') {
steps {
sh 'rm -rf ${WORKSPACE}/etc/data'
sh 'mv ${WORKSPACE}/data ${WORKSPACE}/etc/'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build build'
}
}
stage('Start data container') {
steps {
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build up -d'
}
}
stage('Validate preloaded output') {
steps {
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build exec -T db-preloaded bash -c "chmod +x /tmp/*.sh"'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build exec -T db-preloaded bash -c "/tmp/wait-for-it.sh --timeout=$IMPORT_TIMEOUT_SECONDS --host=localhost --port=3306 -- /tmp/show-dbinfo.sh"'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build exec -T db-preloaded sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date mysql user" > ${WORKSPACE}/build/export/mysql-users_PRELOADED.sql'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build exec -T db-preloaded sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date test01" > ${WORKSPACE}/build/export/test01_PRELOADED.sql'
sh 'diff ${WORKSPACE}/build/export/mysql-users_PRELOADED.sql ${WORKSPACE}/build/export/mysql-users.sql'
sh 'diff ${WORKSPACE}/build/export/test01_PRELOADED.sql ${WORKSPACE}/build/export/test01.sql'
}
}
stage('Stop data container') {
steps {
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build stop'
}
}
stage('Push data container to registry') {
steps {
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build push'
}
}
stage('Start test container') {
steps {
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test up -d'
}
}
stage('Validate test output') {
steps {
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test exec -T db-preloaded bash -c "chmod +x /tmp/*.sh"'
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test exec -T db-preloaded bash -c "/tmp/wait-for-it.sh --timeout=$IMPORT_TIMEOUT_SECONDS --host=localhost --port=3306 -- /tmp/show-dbinfo.sh"'
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test exec -T db-preloaded sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date mysql user" > ${WORKSPACE}/build/export/mysql-users_TEST.sql'
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test exec -T db-preloaded sh -c "/usr/bin/mysqldump -uroot -proot --skip-dump-date test01" > ${WORKSPACE}/build/export/test01_TEST.sql'
sh 'diff ${WORKSPACE}/build/export/mysql-users_TEST.sql ${WORKSPACE}/build/export/mysql-users.sql'
sh 'diff ${WORKSPACE}/build/export/test01_TEST.sql ${WORKSPACE}/build/export/test01.sql'
}
}
stage('Stop test container') {
steps {
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test stop'
}
}
}
post {
failure {
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import logs db'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import exec -T db chmod -R 0777 /var/lib/mysql'
sh 'docker-compose -f docker-compose.01-import.yml -p ${JOB_NAME}_import stop'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build logs db-preloaded'
sh 'docker-compose -f docker-compose.02-build.yml -p ${JOB_NAME}_build stop'
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test logs db-preloaded'
sh 'docker-compose -f docker-compose.03-test.yml -p ${JOB_NAME}_test stop'
}
always {
sh 'rm -rf data'
sh 'rm -rf build'
}
}
}