Skip to content

Commit

Permalink
configure graalvm
Browse files Browse the repository at this point in the history
  • Loading branch information
avan1235 committed Mar 24, 2024
1 parent e1bf902 commit e35ea4e
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Dockerfile
docker-compose.yml
.dockerignore
.gitignore
.git
.idea
.kotlin
.gradle
local.properties
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM amazoncorretto:17 AS builder
FROM container-registry.oracle.com/graalvm/native-image:17 AS builder
COPY . .
RUN microdnf install findutils
RUN chmod +x ./gradlew
RUN ./gradlew server:shadowJar
RUN ./gradlew server:nativeCompile

FROM amazoncorretto:17 as runner
FROM debian:12-slim as runner

ARG POSTGRES_PORT
ARG POSTGRES_DB
Expand Down Expand Up @@ -31,6 +32,8 @@ ENV CORS_SCHEME=${CORS_SCHEME}

EXPOSE ${PORT}

COPY --from=builder ./server/build/libs/server-all.jar ./server.jar
WORKDIR /home

ENTRYPOINT ["java", "-jar", "server.jar"]
COPY --from=builder /app/server/build/native/nativeCompile/server ./server

ENTRYPOINT ["/home/server"]
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinSerialization) apply false
alias(libs.plugins.buildKonfig) apply false
alias(libs.plugins.graalVM) apply false

alias(libs.plugins.dotenvGradle)
}
12 changes: 7 additions & 5 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ kotlin {
implementation(libs.kotlinx.coroutines.swing)
implementation(libs.ktor.client.java)
}
iosMain.dependencies {
api(libs.decompose)
api(libs.essenty.lifecycle)
api(libs.essenty.statekeeper)
if (currentOS().isMacOsX) {
iosMain.dependencies {
api(libs.decompose)
api(libs.essenty.lifecycle)
api(libs.essenty.statekeeper)

implementation(libs.ktor.client.darwin)
implementation(libs.ktor.client.darwin)
}
}
wasmJsMain.dependencies {
implementation(libs.ktor.client.js)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package `in`.procyk.shin.component

import `in`.procyk.shin.shared.Option
import `in`.procyk.shin.shared.Option.None
import `in`.procyk.shin.shared.Option.Some
import `in`.procyk.shin.shared.RedirectType
import `in`.procyk.shin.shared.SHORTEN_PATH
import `in`.procyk.shin.shared.ShinCbor
import `in`.procyk.shin.shared.Shorten
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.Value
import `in`.procyk.shin.createHttpClient
import `in`.procyk.shin.model.ShortenedProtocol
import `in`.procyk.shin.shared.*
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,38 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ports:
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
networks:
- backend
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER}" ]
interval: 5s
timeout: 5s
retries: 5

shin-dev-server:
build:
context: .
dockerfile: Dockerfile
environment:
- POSTGRES_HOST=shin-dev-postgres
- POSTGRES_PORT=${POSTGRES_PORT}
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- HOST=${HOST}
- PORT=${PORT}
- REDIRECT_BASE_URL=${REDIRECT_BASE_URL}
- CORS_PORT=${CORS_PORT}
- CORS_HOST=${CORS_HOST}
- CORS_SCHEME=${CORS_SCHEME}
ports:
- "${HOST}:${PORT}:${PORT}"
networks:
- backend
depends_on:
shin-dev-postgres:
condition: service_healthy
restart: always

networks:
backend:
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ decompose = "3.0.0-alpha09"
essenty = "2.0.0-alpha07"
dotenvGradle = "4.0.0"
buildKonfig = "0.15.1"
graalVM = "0.10.1"

[libraries]
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
Expand All @@ -34,7 +35,7 @@ ktor-shared-resources = { module = "io.ktor:ktor-resources", version.ref = "ktor
ktor-serialization-kotlinx-cbor = { module = "io.ktor:ktor-serialization-kotlinx-cbor", version.ref = "ktor-client" }
ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor-server" }
ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor-server" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor-server" }
ktor-server-cio = { module = "io.ktor:ktor-server-cio-jvm", version.ref = "ktor-server" }
ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor-server" }
ktor-server-resources = { module = "io.ktor:ktor-server-resources", version.ref = "ktor-server" }
ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor-server" }
Expand Down Expand Up @@ -69,3 +70,4 @@ ktor = { id = "io.ktor.plugin", version.ref = "ktor-server" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
dotenvGradle = { id = "co.uzzu.dotenv.gradle", version.ref = "dotenvGradle" }
buildKonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildKonfig" }
graalVM = { id = "org.graalvm.buildtools.native", version.ref = "graalVM" }
32 changes: 30 additions & 2 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.ktor)
alias(libs.plugins.graalVM)
application
}

Expand All @@ -18,7 +19,7 @@ dependencies {

implementation(libs.ktor.server.core)
implementation(libs.ktor.server.cors)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.resources)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.cbor)
Expand All @@ -34,4 +35,31 @@ dependencies {

testImplementation(libs.ktor.server.tests)
testImplementation(libs.kotlin.test.junit)
}
}

graalvmNative {
binaries {
named("main") {
resources.autodetect()
fallback.set(false)
verbose.set(true)

buildArgs(
"--initialize-at-build-time=ch.qos.logback",
"--initialize-at-build-time=io.ktor,kotlin",
"--initialize-at-build-time=org.slf4j.LoggerFactory",

"--initialize-at-build-time=kotlinx.serialization.modules.SerializersModuleKt",
"--initialize-at-build-time=kotlinx.serialization.cbor.Cbor\$Default",
"--initialize-at-build-time=kotlinx.serialization.cbor.Cbor",
"--initialize-at-build-time=kotlinx.serialization.cbor.CborImpl",

"-H:+InstallExitHandlers",
"-H:+ReportUnsupportedElementsAtRuntime",
"-H:+ReportExceptionStackTraces",
)

imageName.set("server")
}
}
}
4 changes: 2 additions & 2 deletions server/src/main/kotlin/in/procyk/shin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import `in`.procyk.shin.util.env
import io.github.cdimascio.dotenv.Dotenv
import io.github.cdimascio.dotenv.dotenv
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.cio.*
import org.koin.dsl.module


Expand All @@ -21,7 +21,7 @@ fun main() {
singleShortUrlService()
}
embeddedServer(
factory = Netty,
factory = CIO,
host = dotenv.env("HOST"),
port = dotenv.env("PORT")
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"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
},
{
"name": "in.procyk.shin.shared.RedirectType",
"fields": [
{
"name": "Companion"
}
]
},
{
"name": "in.procyk.shin.shared.RedirectType$Companion",
"methods": [
{
"name": "serializer",
"parameterTypes": []
}
]
},
{
"name": "in.procyk.shin.shared.Shorten",
"fields": [
{
"name": "Companion"
}
]
},
{
"name": "in.procyk.shin.shared.Shorten$Companion",
"methods": [
{
"name": "serializer",
"parameterTypes": []
}
]
},
{
"name": "in.procyk.shin.db.ShortUrl",
"allDeclaredConstructors": true
}
]
File renamed without changes.
4 changes: 4 additions & 0 deletions start-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker compose --file docker-compose.yml --env-file .env build shin-dev-postgres
docker compose --file docker-compose.yml --env-file .env up shin-dev-postgres

0 comments on commit e35ea4e

Please sign in to comment.