Reduce image size
This commit is contained in:
parent
82214d327a
commit
724f1c87b1
@ -1,6 +1,6 @@
|
||||
FROM openjdk:14-alpine as jdkbuilder
|
||||
RUN apk add --no-cache binutils
|
||||
ENV MODULES java.base,java.desktop,java.instrument,java.logging,java.management,java.naming,java.security.jgss,java.sql,java.xml
|
||||
ENV MODULES java.base,java.xml,jdk.httpserver
|
||||
RUN jlink --output /myjdk --module-path $JAVA_HOME/jmods --add-modules $MODULES --no-header-files --no-man-pages --strip-debug --compress=2
|
||||
RUN strip -p --strip-unneeded /myjdk/lib/server/libjvm.so
|
||||
|
||||
@ -22,4 +22,4 @@ COPY --from=jdkbuilder /myjdk /myjdk
|
||||
COPY config.toml /app/config.toml
|
||||
WORKDIR /app
|
||||
EXPOSE 7000
|
||||
CMD ["/myjdk/bin/java", "-server", "-jar", "app.jar"]
|
||||
CMD ["/myjdk/bin/java", "-server", "-Xmx64m", "-XX:+UseG1GC", "-XX:+UseStringDeduplication", "-jar", "app.jar"]
|
||||
|
||||
37
pom.xml
37
pom.xml
@ -26,11 +26,6 @@
|
||||
<artifactId>pebble</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.electronwill.night-config</groupId>
|
||||
<artifactId>toml</artifactId>
|
||||
@ -42,9 +37,9 @@
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.javalin</groupId>
|
||||
<artifactId>javalin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<groupId>org.http4k</groupId>
|
||||
<artifactId>http4k-core</artifactId>
|
||||
<version>3.260.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -74,13 +69,35 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>starter.KotlinStarterKt</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>com.electronwill.night-config:*</artifact>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/maven/**</exclude>
|
||||
<exclude>META-INF/proguard/**</exclude>
|
||||
<exclude>META-INF/*.kotlin_module</exclude>
|
||||
<exclude>META-INF/DEPENDENCIES*</exclude>
|
||||
<exclude>META-INF/NOTICE*</exclude>
|
||||
<exclude>META-INF/LICENSE*</exclude>
|
||||
<exclude>LICENSE*</exclude>
|
||||
<exclude>META-INF/README*</exclude>
|
||||
<exclude>META-INF/native-image/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@ -117,4 +134,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@ -1,6 +1,17 @@
|
||||
package starter
|
||||
|
||||
import io.javalin.Javalin
|
||||
import org.http4k.core.HttpHandler
|
||||
import org.http4k.core.Method
|
||||
import org.http4k.core.Response
|
||||
import org.http4k.core.Status
|
||||
import org.http4k.core.body.form
|
||||
import org.http4k.core.body.formAsMap
|
||||
import org.http4k.routing.ResourceLoader
|
||||
import org.http4k.routing.bind
|
||||
import org.http4k.routing.routes
|
||||
import org.http4k.routing.static
|
||||
import org.http4k.server.SunHttp
|
||||
import org.http4k.server.asServer
|
||||
import starter.utils.sanitizeFilename
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
@ -9,23 +20,18 @@ class Server(
|
||||
private val conf: StarterConfig,
|
||||
private val projectZip: ProjectZip,
|
||||
) {
|
||||
|
||||
fun run() {
|
||||
val app = Javalin.create {
|
||||
it.addStaticFiles("/assets")
|
||||
}.start(7000)
|
||||
|
||||
app.get("/") { ctx ->
|
||||
ctx.result(views.index(conf.dependencies, conf.inputs))
|
||||
ctx.contentType("text/html")
|
||||
val indexHandler: HttpHandler = {
|
||||
Response(Status.OK).body(views.index(conf.dependencies, conf.inputs)).header("Content-Type", "text/html")
|
||||
}
|
||||
|
||||
app.post("/") { ctx ->
|
||||
val zipHandler: HttpHandler = { req ->
|
||||
val deps = conf.dependencies.filter {
|
||||
ctx.formParam(it.name) != null
|
||||
req.form(it.name) != null
|
||||
}
|
||||
|
||||
val inputKeys = conf.inputs.map { it.name }
|
||||
val inputs = ctx.formParamMap()
|
||||
val inputs = req.formAsMap()
|
||||
.filter { it.key in inputKeys }
|
||||
.map { (name, value) ->
|
||||
conf.inputs.find { it.name == name }!!.copy(value = value.first())
|
||||
@ -35,21 +41,28 @@ class Server(
|
||||
val basePackage = inputs.find { it.name == "basePackage" }!!.value!!
|
||||
|
||||
if (basePackage.contains("/") || basePackage.contains("..")) {
|
||||
ctx.status(400)
|
||||
ctx.result("Invalid Base Package")
|
||||
return@post
|
||||
Response(Status.BAD_REQUEST).body("Invalid Base Package")
|
||||
} else {
|
||||
val repositories = conf.repositories
|
||||
.filter { repo -> repo.name in deps.mapNotNull { it.repository } }
|
||||
|
||||
val project = Project(projectName, basePackage, inputs, deps, repositories)
|
||||
val outputStream = projectZip.createZip(project)
|
||||
|
||||
Response(Status.OK).header("Content-Type", "application/zip")
|
||||
.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
||||
.body(ByteArrayInputStream(outputStream.toByteArray()))
|
||||
}
|
||||
|
||||
val repositories = conf.repositories
|
||||
.filter { repo -> repo.name in deps.mapNotNull { it.repository } }
|
||||
|
||||
val project = Project(projectName, basePackage, inputs, deps, repositories)
|
||||
|
||||
ctx.contentType("application/zip")
|
||||
ctx.header("Content-Disposition", "attachment; filename=\"${sanitizeFilename(projectName)}.zip\"")
|
||||
|
||||
val outputStream = projectZip.createZip(project)
|
||||
ctx.result(ByteArrayInputStream(outputStream.toByteArray()))
|
||||
}
|
||||
|
||||
val app = routes(
|
||||
"/" bind Method.GET to indexHandler,
|
||||
"/" bind Method.POST to zipHandler,
|
||||
static(ResourceLoader.Classpath("/assets"))
|
||||
)
|
||||
|
||||
app.asServer(SunHttp(7000)).start()
|
||||
println("Started on http://localhost:7000")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<withJansi>true</withJansi>
|
||||
<encoder>
|
||||
<pattern>%cyan(%d{YYYY-MM-dd HH:mm:ss.SSS}) [%thread] %highlight(%-5level) %green(%logger{36}) - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="com.mitchellbosecke.pebble" level="INFO"/>
|
||||
<logger name="org.eclipse.jetty" level="INFO"/>
|
||||
</configuration>
|
||||
Loading…
x
Reference in New Issue
Block a user