-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
277 lines (228 loc) · 7.85 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* Gridify Server
* Copyright (C) 2019 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.regex.Pattern
String buildVersion() {
def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?")
String version = System.getenv('GRIDIFYD_BUILD_VERSION')
if (version == null || version.length() == 0) {
version = sourceVersion()
}
return versionPattern.matcher(version).matches() ? version.substring(1) : version
}
String sourceVersion() {
String version = System.getenv('GRIDIFYD_SOURCE_VERSION')
if (version != null && version.length() > 0) {
return version
}
ByteArrayOutputStream out = new ByteArrayOutputStream()
def o = exec {
commandLine = ['git', 'describe', '--tags', '--always', '--dirty']
standardOutput = out
errorOutput = out
ignoreExitValue = true
}
if (o.exitValue != 0) {
if (o.exitValue != 128) {
logger.lifecycle("Unable to determine git version: {}", out.toString())
}
return "UNKNOWN"
}
return out.toString().replace(System.lineSeparator(), '')
}
apply plugin: 'application'
group = 'io.kamax.gridify'
version = buildVersion()
mainClassName = 'io.kamax.gridify.server.MonolithHttpGridifyServerApplication'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
def appName = 'gridify'
def execName = "${appName}d"
def packName = "${appName}-server"
def appDirName = "${appName}/server"
def appPublisher = 'kamax'
def confFileName = "config.sample.yaml"
def distDir = "${project.buildDir}/${distsDirName}"
def distName = "${execName}-${buildVersion()}"
def distTarFile = "${distName}.tar"
def distTar = "${distDir}/${distTarFile}"
def debBinPath = "/usr/lib/${appDirName}"
def debConfPath = "/etc/${appDirName}"
def debDataPath = "/var/lib/${appDirName}"
def debSystemdPath = "/etc/systemd/system"
def debConfFileName = "config.yaml"
def debStartScriptFilename = appName
def debBuildBasePath = "${project.buildDir}/tmp/debian"
def debBuildDebianPath = "${debBuildBasePath}/DEBIAN"
def debBuildBinPath = "${debBuildBasePath}${debBinPath}"
def debBuildConfPath = "${debBuildBasePath}${debConfPath}"
def debBuildDataPath = "${debBuildBasePath}${debDataPath}"
def debBuildSystemdPath = "${debBuildBasePath}${debSystemdPath}"
def dockerBuildPath = "${project.buildDir}/tmp/docker"
def dockerImageName = "${appPublisher}/${packName}"
def dockerImageTag = "${dockerImageName}:${version}"
def dockerImageTagLatestDev = "${dockerImageName}:latest-dev"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// Logging
implementation 'org.slf4j:slf4j-simple:1.7.25'
// Various utilities
implementation 'org.apache.commons:commons-lang3:3.5'
implementation 'commons-io:commons-io:2.6'
implementation 'commons-codec:commons-codec:1.11'
implementation 'com.google.guava:guava:26.0-jre'
// JSON handling
implementation 'com.google.code.gson:gson:2.8.5'
// Config management
implementation 'org.yaml:snakeyaml:1.23'
// Connection Pool
implementation 'com.mchange:c3p0:0.9.5.2'
// PostgreSQL
implementation 'org.postgresql:postgresql:42.2.23'
// Crypto
implementation 'net.i2p.crypto:eddsa:0.3.0'
// Event bus
implementation 'net.engio:mbassador:1.3.1'
// DNS lookup
implementation 'dnsjava:dnsjava:2.1.8'
// HTTP Client
implementation 'org.apache.httpcomponents:httpclient:4.5.4'
// HTTP server
implementation 'io.undertow:undertow-core:2.2.10.Final'
// Crypto (BCrypt for password, TLS/SSL, etc.)
implementation 'org.bouncycastle:bcprov-jdk14:1.60'
// JWT for various access tokens
implementation 'com.auth0:java-jwt:3.7.0'
// ----------- Identity stores
// LDAP connector
implementation 'org.apache.directory.api:api-all:1.0.0'
testImplementation 'com.unboundid:unboundid-ldapsdk:4.0.11'
testImplementation 'junit:junit:4.12'
}
// For reproducible builds
// https://docs.gradle.org/5.2/userguide/working_with_files.html#sec:reproducible_archives
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
jar {
manifest {
attributes(
'Implementation-Title': execName,
'Implementation-Version': buildVersion(),
'Implementation-Vendor': appPublisher
)
}
}
task debBuild() {
doLast {
String debVersion = buildVersion()
logger.lifecycle('Version for package: {}', debVersion)
mkdir distDir
mkdir debBuildBasePath
mkdir debBuildDebianPath
mkdir debBuildBinPath
mkdir debBuildConfPath
mkdir debBuildDataPath
mkdir debBuildSystemdPath
copy {
from "${project.buildDir}/libs/${execName}.jar"
into debBuildBinPath
}
copy {
from "${project.file("build/scriptsShadow/" + execName)}"
into debBuildBinPath
}
copy {
from(project.file(confFileName)) {
rename confFileName, debConfFileName
}
into debBuildConfPath
}
ant.replaceregexp(
file: "${debBuildConfPath}/${debConfFileName}",
match: " data:(.*)",
replace: " data: '${debDataPath}'"
)
copy {
from project.file('src/main/debian')
into debBuildDebianPath
}
ant.replace(
file: "${debBuildDebianPath}/control",
token: 'Version: 0',
value: "Version: ${debVersion}"
)
ant.replace(
file: "${debBuildDebianPath}/postinst",
token: '%DEB_DATA_DIR%',
value: debDataPath
)
ant.chmod(
file: "${debBuildDebianPath}/postinst",
perm: 'a+x'
)
ant.chmod(
file: "${debBuildDebianPath}/prerm",
perm: 'a+x'
)
copy {
from "${project.file("src/main/systemd/${appName}.service")}"
into debBuildSystemdPath
}
exec {
commandLine(
'fakeroot',
'dpkg-deb',
'-b',
debBuildBasePath,
"${project.buildDir}/distributions"
)
}
}
}
task dockerBuildImage(type: Exec) {
commandLine 'docker', 'build', '-t', dockerImageTag, dockerBuildPath
doFirst {
copy {
from tarTree("${distDir}/${distName}.tar")
into layout.buildDirectory.dir("tmp/docker")
}
ant.move(
file: "${dockerBuildPath}/${distName}",
toFile: "${dockerBuildPath}/app"
)
copy {
from "${projectDir}/src/script/gcli"
into "${dockerBuildPath}/app/bin"
}
copy {
from "${projectDir}/src/main/docker/Dockerfile",
"${projectDir}/src/main/docker/entrypoint"
into dockerBuildPath
}
}
}
task dockerTagImage(type: Exec, dependsOn: 'dockerBuildImage') {
commandLine 'docker', 'tag', dockerImageTag, dockerImageTagLatestDev
}
task dockerBuild(dependsOn: 'dockerTagImage')