This repository has been archived by the owner on Jun 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathbuild.gradle
206 lines (173 loc) · 6.03 KB
/
build.gradle
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
buildscript {
repositories {
maven {
url "http://dl.bintray.com/gesellix/gradle-plugins"
}
mavenCentral()
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.0.2'
classpath "de.gesellix:gradle-debian-plugin:16"
}
}
plugins {
id 'idea'
id "org.sonarqube" version "1.2"
id 'net.researchgate.release' version '2.3.5'
id 'com.bmuschko.docker-remote-api' version '3.0.1'
}
subprojects {
group = "com.containersol.minimesos"
version = rootProject.version.toString()
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'java'
apply plugin: 'com.bmuschko.docker-remote-api'
apply plugin: 'maven'
apply plugin: 'jacoco'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
task showDeps(type: DependencyReportTask) {}
test {
testLogging {
showStandardStreams = true
}
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled true
}
}
configurations {
//workaround for build problem using docker4mac (https://github.com/bmuschko/gradle-docker-plugin/issues/235#issuecomment-239982250)
dockerJava {
resolutionStrategy {
force 'de.gesellix:unix-socket-factory:2016-04-06T22-21-19'
}
}
}
docker {
url = 'unix:///var/run/docker.sock'
certPath = null
if (System.getenv("DOCKER_HOST")) {
url = System.getenv("DOCKER_HOST").replace("tcp", "https")
if (System.getenv("DOCKER_CERT_PATH")) {
certPath = new File(System.getenv("DOCKER_CERT_PATH").toString())
}
}
}
}
ext {
mesosVer = "1.0.0"
repository = 'containersol'
}
idea {
project {
languageLevel = '1.8'
vcs = 'Git'
}
}
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.jacoco.reportPath", "${buildDir}/jacoco/test.exec"
}
}
task checkDockerAuthentication << {
// command below return 1 when user is not logged in to Docker Hub
def command = "docker info | grep \"Username:\"; rc=\$?; if [[ \$rc != 0 ]]; then exit 1; fi"
// executing via bash, so we can make use of its interpreter of the parameters. Otherwise pipes do not work
exec {
commandLine "bash", "-c", command
}
}
task setVersionInBashScript << {
if (new File(project.rootDir, "bin/minimesos").text.contains('MINIMESOS_TAG="latest"')) {
// set explicit version in bash script
ant.replace(file: "bin/minimesos", token: 'MINIMESOS_TAG="latest"', value: "MINIMESOS_TAG=\"${project.version}\"")
// commit modified files
exec {
workingDir "${project.rootDir}"
commandLine "git", "commit", "-a", "-m", "[Release ${project.version}] pre-tag commit"
}
// push update to repository
exec {
workingDir "${project.rootDir}"
commandLine "git", "push"
}
}
}
task resetVersionInBashScript << {
// have to use regular expression because the project version has changed and the previous is not kept
ant.replaceregexp(file: "bin/minimesos", match: "MINIMESOS_TAG=\".*?\"", replace: "MINIMESOS_TAG=\"latest\"")
}
task releaseMinimesosCliImage << {
['dockerHubUsername', 'dockerHubPassword', 'dockerHubEmail'].each {
assert project.hasProperty(it): 'Undefined "' + it + '" property'
}
docker {
registryCredentials {
username = project.property('dockerHubUsername')
password = project.property('dockerHubPassword')
email = project.property('dockerHubEmail')
}
}
def minimesosCliImage = "containersol/minimesos-cli"
def command = "docker tag \$(docker images ${minimesosCliImage} | grep 'latest' | awk '{print \$3}') ${minimesosCliImage}:${project.version}"
// executing via bash, so we can make use of its interpreter of the parameters. Otherwise pipes do not work
exec {
commandLine "bash", "-c", command
}
println "Pushing ${minimesosCliImage}:${project.version} docker image to Docker Hub..."
exec {
commandLine "docker", "push", "${minimesosCliImage}:${project.version}"
}
println "Pushing ${minimesosCliImage}:latest docker image to Docker Hub..."
exec {
commandLine "docker", "push", "${minimesosCliImage}:latest"
}
}
task createGitHubRelease << {
// use GitHub API
exec {
commandLine "curl", "-H", "Content-Type: application/json", "-H", "Authorization: token ${githubAuthToken}", "-XPOST", "-d", "{\"tag_name\":\"${project.version}\"}", "https://api.github.com/repos/ContainerSolutions/minimesos/releases"
}
}
task updateReleaseDocs << {
// update online documentation
exec {
commandLine "curl", "-XPOST", "https://readthedocs.org/build/minimesos"
}
// trigger update of minimesos.org
exec {
commandLine "curl", "-H", "x-api-key: ${awsMinimesosOrgApiKey}", "https://kilt52ydsk.execute-api.us-east-1.amazonaws.com/prod/RunHugoGit"
}
}
// fail the build early if user is not logged in to docker
checkUpdateNeeded.dependsOn checkDockerAuthentication
// set explicit version in minimesos bash script
preTagCommit.dependsOn setVersionInBashScript
// project.version changes after execution of updateVersion. Time to tag and to push container
updateVersion.dependsOn releaseMinimesosCliImage, createGitHubRelease
// project.version changes after execution of updateVersion
commitNewVersion.dependsOn resetVersionInBashScript, updateReleaseDocs
// working around https://github.com/researchgate/gradle-release/issues/144
release {
buildTasks = ['releaseBuild']
}
task releaseBuild {
dependsOn(
'minimesos:clean',
'minimesos:build',
'cli:build'
)
}