forked from deepjavalibrary/djl-serving
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
205 lines (182 loc) · 7.37 KB
/
build.gradle.kts
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
@file:Suppress("UNCHECKED_CAST")
import com.netflix.gradle.plugins.deb.Deb
plugins {
ai.djl.javaProject
ai.djl.publish
application
id("com.netflix.nebula.ospackage") version "11.4.0"
}
dependencies {
api(platform("ai.djl:bom:${version}"))
api(project(":wlm"))
api("io.netty:netty-codec-http:${libs.versions.netty.get()}")
api("io.netty:netty-transport-native-epoll:${libs.versions.netty.get()}:linux-aarch_64")
api("io.netty:netty-transport-native-epoll:${libs.versions.netty.get()}:linux-x86_64")
api("io.netty:netty-transport-native-kqueue:${libs.versions.netty.get()}:osx-aarch_64")
api("io.netty:netty-transport-native-kqueue:${libs.versions.netty.get()}:osx-x86_64")
//noinspection GradlePackageUpdate
implementation(libs.commons.cli)
implementation(project(":prometheus"))
runtimeOnly(libs.apache.log4j.slf4j)
runtimeOnly(libs.disruptor)
runtimeOnly("ai.djl:model-zoo")
runtimeOnly("ai.djl.tensorflow:tensorflow-model-zoo")
runtimeOnly("ai.djl.pytorch:pytorch-model-zoo")
runtimeOnly("ai.djl.huggingface:tokenizers")
runtimeOnly("ai.djl.tensorrt:tensorrt")
runtimeOnly(project(":engines:python"))
testRuntimeOnly("org.bouncycastle:bcpkix-jdk18on:1.78")
testRuntimeOnly("org.bouncycastle:bcprov-jdk18on:1.78")
testRuntimeOnly(libs.snakeyaml)
testImplementation(libs.testng) {
exclude(group = "junit", module = "junit")
}
testImplementation(libs.mockito.core)
}
tasks {
jar {
manifest {
attributes["Main-Class"] = "ai.djl.serving.ModelServer"
}
includeEmptyDirs = false
exclude("META-INF/maven/**")
exclude("META-INF/INDEX.LIST")
exclude("META-INF/MANIFEST*")
}
test {
dependsOn(
":plugins:kserve:jar",
":plugins:management-console:jar",
":plugins:plugin-management-plugin:jar",
":plugins:static-file-plugin:jar"
)
workingDir(projectDir)
systemProperty("SERVING_PROMETHEUS", "true")
systemProperty("log4j.configurationFile", "${projectDir}/src/main/conf/log4j2.xml")
}
application {
mainClass = System.getProperty("main", "ai.djl.serving.ModelServer")
applicationDistribution.into("conf") {
from("src/main/conf/")
}
applicationDistribution.into("plugins") {
from(projectDir / "plugins")
}
}
distTar {
dependsOn(
":plugins:cache:copyJar",
":plugins:kserve:copyJar",
":plugins:management-console:copyJar",
":plugins:plugin-management-plugin:copyJar",
":plugins:static-file-plugin:copyJar",
":plugins:secure-mode:copyJar"
)
}
distZip {
dependsOn(
":plugins:cache:copyJar",
":plugins:kserve:copyJar",
":plugins:management-console:copyJar",
":plugins:plugin-management-plugin:copyJar",
":plugins:static-file-plugin:copyJar",
":plugins:secure-mode:copyJar"
)
}
run.configure {
dependsOn(
":plugins:kserve:jar",
":plugins:management-console:jar",
":plugins:static-file-plugin:jar"
)
environment("TF_CPP_MIN_LOG_LEVEL", "1") // turn off TensorFlow print out
environment("MXNET_ENGINE_TYPE", "NaiveEngine")
environment("OMP_NUM_THREADS", "1")
environment("MODEL_SERVER_HOME", "$projectDir")
systemProperties = System.getProperties().toMap() as Map<String, Any>
systemProperties.remove("user.dir")
systemProperty("SERVING_PROMETHEUS", "true")
systemProperty("log4j.configurationFile", "${projectDir}/src/main/conf/log4j2.xml")
application.applicationDefaultJvmArgs =
listOf("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4000")
workingDir(projectDir)
}
clean {
doFirst {
delete("plugins")
delete("docker/distributions")
delete("logs")
}
}
startScripts {
doLast {
unixScript.text = unixScript.text.replace(
"exec \"\$JAVACMD\" \"\$@\"",
"if [ -f \"/opt/djl/bin/telemetry.sh\" ]; then\n" +
" /opt/djl/bin/telemetry.sh\n" +
"fi\n" +
"if [ \"\${OMP_NUM_THREADS}\" = \"\" ] && [ \"\${NO_OMP_NUM_THREADS}\" = \"\" ] ; then\n" +
" export OMP_NUM_THREADS=1\n" +
"fi\n" +
"if [ \"\${TF_CPP_MIN_LOG_LEVEL}\" = \"\" ] ; then\n" +
" export TF_CPP_MIN_LOG_LEVEL=1\n" +
"fi\n" +
"if [ \"\${TF_NUM_INTRAOP_THREADS}\" = \"\" ] ; then\n" +
" export TF_NUM_INTRAOP_THREADS=1\n" +
"fi\n" +
"export APP_HOME\n" +
"exec env MXNET_ENGINE_TYPE=\"NaiveEngine\" \"\$JAVACMD\" \"\$@\""
).replace(
"DEFAULT_JVM_OPTS=\"\"",
"if [ \"\${MODEL_SERVER_HOME}\" = \"\" ] ; then\n" +
" export MODEL_SERVER_HOME=\${APP_HOME}\n" +
"fi\n" +
"if [ -f \"/opt/ml/.sagemaker_infra/endpoint-metadata.json\" ]; then\n" +
" export JAVA_OPTS=\"\$JAVA_OPTS -XX:-UseContainerSupport\"\n" +
" DEFAULT_JVM_OPTS=\"\${DEFAULT_JVM_OPTS:--Dlog4j.configurationFile=\${APP_HOME}/conf/log4j2-plain.xml}\"\n" +
"else\n" +
" DEFAULT_JVM_OPTS=\"\${DEFAULT_JVM_OPTS:--Dlog4j.configurationFile=\${APP_HOME}/conf/log4j2.xml}\"\n" +
"fi\n"
).replace(Regex("CLASSPATH=\\\$APP_HOME/lib/.*"), "CLASSPATH=\\\$APP_HOME/lib/*")
}
}
open class Cmd @Inject constructor(@Internal val execOperations: ExecOperations) : DefaultTask()
register<Cmd>("prepareDeb") {
dependsOn(distTar)
doFirst {
execOperations.exec {
workingDir = projectDir
commandLine(
"tar",
"xvf",
"${buildDirectory}/distributions/serving-${version}.tar",
"-C",
"$buildDirectory"
)
}
}
}
register<Deb>("createDeb") {
dependsOn("prepareDeb")
packageName = "djl-serving"
archiveVersion = "$project.version"
release = "1"
maintainer = "Deep Java Library <[email protected]>"
summary = "djl-serving is a general model server that can serve both Deep Learning models" +
"and traditional machine learning models."
postInstall(
"mkdir -p /usr/local/djl-serving-${project.version}/models" +
" && mkdir -p /usr/local/djl-serving-${project.version}/plugins"
)
from(buildDirectory / "serving-${project.version}") {
into("/usr/local/djl-serving-${project.version}")
}
link("/usr/bin/djl-serving", "/usr/local/djl-serving-${project.version}/bin/serving")
}
register<Copy>("dockerDeb") {
dependsOn("createDeb")
from(buildDirectory / "distributions")
include("*.deb")
into(projectDir / "docker/distributions")
}
}