This repository was archived by the owner on Oct 17, 2022. It is now read-only.
forked from rkourtz/nuodb-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
executable file
·182 lines (138 loc) · 5.03 KB
/
Jenkinsfile
File metadata and controls
executable file
·182 lines (138 loc) · 5.03 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
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
//def tag_prefix=env.BRANCH_NAME.replaceAll(/[^a-zA-Z0-9_]/,"_")
// This should really come from branch name
env.awsPushCredentials="build-jenkins-oa"
env.region="us-east-1"
env.dockerhubPushCredentials="docker.io-nuodb-push"
env.redhatPushCredentials="redhat.nuodb.push"
env.redhatRepo="https://registry.rhc4tp.openshift.com"
def suffix=env.SUFFIX
/** Build a list of tags from an array of version numbers.
*
* The array is built by concatenating as follows: (1,2,3) becomes
* ("1", "1.2", "1.2.3")
*
*/
def buildTags(array) {
def strings=[]
def last
array.each { s->
if(last) {
last = last + "-" + s
}
else {
last = s
}
strings << last
}
return strings.reverse()
}
/**
* standardPush -- push the given image to the given repository with
* all the usuall tags.
*/
def standardPush(imageName, repo, credentials, tags) {
def image = docker.image(imageName)
// Sometimes a docker push fails due to a server side issue. Work around docker's issue
retry (3) {
docker.withRegistry(repo, credentials) {
tags.each {
echo "docker push ${imageName} ${repo}/${imageName}:${it}${suffix}"
image.push("${it}${suffix}")
}
}
}
}
// On a node which has docker
node() {
stage('Read Configs') {
checkout scm
}
build_configs = findFiles(glob: 'build-params/*.properties')
buildinfo = []
def default_properties = [DOCKERFILE: 'Dockerfile', NODE_TYPE:'docker']
// You have to iterate this way in Jenkins to avoid a marshalling error
for(int i=0; i<build_configs.size(); i++) {
filename = build_configs[i]
props = readProperties defaults: default_properties, file: filename.toString()
buildinfo.add([ props.NODE_TYPE , filename ])
props = null
}
// echo "Build configs are: ${build_configs}"
echo "Build info are: ${buildinfo}"
}
builds=[:]
for(int i=0; i<buildinfo.size(); i++) {
echo "Calling dobuild on ${buildinfo[i]}"
filename = buildinfo[i][1]
label = buildinfo[i][0]
builds[filename]= makebuild(label, filename)
}
def makebuild(label, filename) {
return {
dobuild(label, filename)
}
}
echo "Parallel build: ${params.BUILD_IN_PARALLEL} ${params.BUILD_IN_PARALLEL.getClass()}"
if(!params.BUILD_IN_PARALLEL) {
builds.each { k, v->
echo "Calling ${k}"
v()
}
}
else {
// Actually perform the builds in parallel
parallel builds
}
def dobuild(nodelabel, filename) {
echo "Building from ${filename} on ${nodelabel}"
// TODO: if we can read and pass in the props, we can abstract the node type
node(nodelabel) {
checkout scm
def default_properties = [DOCKERFILE: 'Dockerfile', NODE_TYPE:'docker', PUSH_TO:'normal']
def props = readProperties defaults: default_properties, file: filename.toString()
/** A list of version numbers used to build tags. See #buildTags for details
*/
def VersionArray = [ props.RELEASE_BUILD, props.RELEASE_PACKAGE, props.BUILD, env.BUILD_NUMBER]
def fullVersion=VersionArray.join(".")
//////////////////////////////////////////////////////////////////////
//
// Build both the NuoDB (full) image and the NuoDB-CE image
//
//////////////////////////////////////////////////////////////////////
echo "Build stage"
def imageName=(filename.toString() =~ /\w+\/(.*)\.properties/)[0][1]
stage("Build ${imageName}") {
def buildargs = props.collect { k, v -> "'${k}=${v}'" }.join(" --build-arg ")
// echo "Command line is: ${buildargs}"
sh "docker build -t ${imageName}:${fullVersion} -f ${props.DOCKERFILE} --build-arg ${buildargs} . "
}
stage("Push ${imageName}") {
def tagSet = buildTags(VersionArray)
def image = docker.image(imageName)
//////////////////////////////////////////////////////////////////////
//
// The NuoDB (full) docker image can only go to AWS ECR
//
//////////////////////////////////////////////////////////////////////
if(props.VERSION.equals("nuodb")) {
if(props.PUSH_TO.equals("redhat")) {
error( "We're not currently pushing full NuoDB built on redhat")
}
else {
sh "docker tag ${imageName}:${fullVersion} nuodb:${fullVersion}"
standardPush("nuodb:${fullVersion}", env.REPOSITORY, "ecr:${env.region}:${env.awsPushCredentials}", tagSet)
}
}
else if(props.VERSION.equals("nuodb-ce")) {
if(props.PUSH_TO.equals("redhat")) {
sh "docker tag ${imageName}:${fullVersion} ${env.REDHAT_KEY}/nuodb-ce:${fullVersion}"
standardPush("${env.REDHAT_KEY}/nuodb-ce:${fullVersion}", env.redhatRepo, env.redhatPushCredentials, tagSet)
}
else {
sh "docker tag ${imageName}:${fullVersion} nuodb/nuodb-ce:${fullVersion}"
standardPush("nuodb/nuodb-ce:${fullVersion}", "", env.dockerhubPushCredentials, tagSet)
}
}
}
}
}