-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.gradle
236 lines (194 loc) · 7.16 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
buildscript {
dependencies {
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:${jfrogBuildExtractorVersion}")
}
repositories {
mavenCentral()
jcenter()
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "${kotlinVersion}"
id "com.adarshr.test-logger" version "${testLoggerPluginVersion}" apply false
id 'com.github.johnrengelman.shadow' version "${shadowPluginVersion}" apply false
id "com.palantir.graal" version "${palantirGraalNativeVersion}" apply false
id 'com.bmuschko.docker-remote-api' version "${bmuschkoDockerPluginVersion}" apply false
id 'com.google.cloud.tools.jib' version "${jibPluginVersion}" apply false
}
apply plugin: 'idea'
subprojects {
apply plugin: 'com.adarshr.test-logger'
apply plugin: 'kotlin'
group = "com.omarsmak.kafka.consumer.lag.monitoring"
version = '0.1.3'
ext {
libraryName = "kafka-consumer-lag-monitoring"
libraryVersion = version
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
test {
useJUnitPlatform()
}
dependencies {
compile "io.github.microutils:kotlin-logging:$kotlinLoggingVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
}
}
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerTagImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
// these tasks only applicable for any component
configure(subprojects.findAll { it.name.contains("component") }) {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.palantir.graal'
apply plugin: 'com.bmuschko.docker-remote-api'
apply plugin: 'com.google.cloud.tools.jib'
afterEvaluate {
ext {
componentFullName = libraryName + "-" + project.componentName
componentFullNameWithVersion = componentFullName + "-" + version
componentDockerName = "omarsmak/" + componentFullName
componentDockerNativeName = componentDockerName + "-native"
}
shadowJar {
zip64 = true
archiveBaseName.set(componentFullName)
}
jar {
manifest {
attributes(
"Multi-Release": true
)
}
}
graal {
graalVersion graalNativeImageVersion
outputName componentFullNameWithVersion
mainClass project.mainClassName
javaVersion '11'
option '--no-fallback'
option '--report-unsupported-elements-at-runtime'
option '--allow-incomplete-classpath'
}
docker {
registryCredentials {
username = System.getenv('DOCKERHUB_USER')
password = System.getenv('DOCKERHUB_PASSWORD')
email = 'omarsmak@gmail.com'
}
}
jib {
from.image 'gcr.io/distroless/java:11'
to{
image = componentDockerName
tags = [libraryVersion, "latest"]
auth {
username = System.getenv('DOCKERHUB_USER')
password = System.getenv('DOCKERHUB_PASSWORD')
}
}
container {
if (dockerExposedPort) {
ports = [dockerExposedPort.toString()]
}
jvmFlags = [
"-XX:+UseCompressedOops",
"-XX:MaxRAMPercentage=80",
"-Dfile.encoding=UTF-8",
"-Djava.security.egd=file:/dev/./urandom"
]
}
}
task createNativeDockerfile(type: Dockerfile) {
// First stage: build our native image inside a docker image
from new Dockerfile.From("ghcr.io/graalvm/graalvm-ce:${graalNativeImageVersion}").withStage("build")
workingDir "/app"
copyFile componentFullName + "*all.jar", "/app/jar/application.jar"
runCommand "gu install native-image"
runCommand "native-image -jar jar/application.jar --no-fallback --report-unsupported-elements-at-runtime --allow-incomplete-classpath"
// Second stage: Create our application docker image
from "frolvlad/alpine-glibc"
runCommand "apk update && apk add libstdc++"
workingDir "/work/"
copyFile new Dockerfile.CopyFile("/app/application", "/work/application").withStage("build")
if (project.dockerExposedPort) {
exposePort project.dockerExposedPort
}
entryPoint("./application")
}
task copyShadowJarToDockerContext(type: Copy) {
dependsOn shadowJar
from "$buildDir/libs"
include componentFullName + "*all.jar"
into "$buildDir/docker"
}
/**
* Build a Docker image with native application
*/
task buildNativeApplicationDockerImage(type: DockerBuildImage) {
dependsOn copyShadowJarToDockerContext, createNativeDockerfile
remove = true
noCache = false
images.add(componentDockerNativeName + ":latest")
images.add(componentDockerNativeName + ":$version")
}
/**
* Build and push a Docker image with native application
*/
task buildAndPushNativeApplicationDockerImage(type: DockerPushImage) {
dependsOn buildNativeApplicationDockerImage
images.set(buildNativeApplicationDockerImage.images)
}
/**
* Build a native application using Graal Native Image
*/
task buildNativeApplication(type: Tar) {
dependsOn nativeImage
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
def osName = "generic"
if (os.linux) {
osName = "linux"
} else if (os.macOsX) {
osName = "mac"
} else if (os.windows) {
osName = "windows"
}
archiveFileName = "$componentFullNameWithVersion-${osName}.tar.gz"
destinationDirectory = file("$buildDir/dist")
compression = Compression.GZIP
from "$buildDir/graal/$componentFullNameWithVersion"
}
/**
* Build a Docker image with jar application
*/
task buildDockerImage {
dependsOn jibDockerBuild
}
/**
* Build and push a Docker image with jar application
*/
task buildAndPushDockerImage {
dependsOn jib
}
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
}