Add support for GraalVM

Note: This doesn't actually work yet. At the time of writing I'm seeing issues with Ktor not finding the application.conf file.
This commit is contained in:
William Brawner 2023-01-01 21:38:41 -07:00
parent 1d15b116c2
commit 73f113e33e
5 changed files with 56 additions and 7 deletions

View file

@ -1,4 +1,4 @@
FROM openjdk:17-jdk as builder
FROM ghcr.io/graalvm/graalvm-ce:ol9-java17-22.3.0-b2 as builder
MAINTAINER William Brawner <me@wbrawner.com>
RUN groupadd --system --gid 1000 gradle \
@ -6,12 +6,12 @@ RUN groupadd --system --gid 1000 gradle \
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN /home/gradle/src/gradlew --console=plain --no-daemon shadowJar
RUN /home/gradle/src/gradlew --console=plain --no-daemon nativeCompile
FROM openjdk:17-slim
FROM quay.io/centos/centos:stream9
EXPOSE 8080
RUN groupadd --system --gid 1000 twigs \
&& useradd --system --gid twigs --uid 1000 --create-home twigs
COPY --from=builder --chown=twigs:twigs /home/gradle/src/app/build/libs/twigs.jar twigs.jar
COPY --from=builder --chown=twigs:twigs /home/gradle/src/app/build/native/nativeCompile/twigs /usr/local/bin/twigs
USER twigs
CMD /usr/local/openjdk-17/bin/java $JVM_ARGS -jar /twigs.jar
CMD /usr/local/bin/twigs

View file

@ -1,11 +1,11 @@
import java.net.URI
import java.util.*
plugins {
java
kotlin("jvm")
application
alias(libs.plugins.shadow)
alias(libs.plugins.graalvm)
}
repositories {
@ -51,3 +51,20 @@ tasks.shadowJar {
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
graalvmNative {
binaries {
named("main") {
fallback.set(false)
verbose.set(true)
buildArgs.add("--initialize-at-build-time=io.ktor,kotlin")
buildArgs.add("-H:+InstallExitHandlers")
buildArgs.add("-H:+ReportUnsupportedElementsAtRuntime")
buildArgs.add("-H:+ReportExceptionStackTraces")
imageName.set("twigs")
}
}
}

View file

@ -0,0 +1,29 @@
[
{
"name": "kotlin.reflect.jvm.internal.ReflectionFactoryImpl",
"allDeclaredConstructors":true
},
{
"name": "kotlin.KotlinVersion",
"allPublicMethods": true,
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name": "kotlin.KotlinVersion[]"
},
{
"name": "kotlin.KotlinVersion$Companion"
},
{
"name": "kotlin.KotlinVersion$Companion[]"
},
{
"name": "kotlin.internal.jdk8.JDK8PlatformImplementations",
"allPublicMethods": true,
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
}
]

View file

@ -5,6 +5,7 @@ buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
dependencies {
@ -28,6 +29,6 @@ allprojects {
group = "com.wbrawner"
version = "0.0.1-SNAPSHOT"
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "16"
kotlinOptions.jvmTarget = "17"
}
}

View file

@ -1,5 +1,6 @@
[versions]
bcrypt = "0.9.0"
graalvm = "0.9.19"
hikari = "5.0.1"
junit = "5.8.2"
kotlin = "1.6.21"
@ -42,6 +43,7 @@ ktor-server = [
]
[plugins]
graalvm = { id = "org.graalvm.buildtools.native", version.ref = "graalvm" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }