Тип сервиса
Сервис Kotlin
Среда выполнения JVM для веб-приложений, API и фоновых задач на Kotlin, собранных из исходного кода; основана на сервисе Java.
Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.
В StackMaster
Как Kotlin работает в StackMaster
Build and start
The service's Dockerfile copies the repository to /usr/src/app and builds it with the repository's own build setup:
- Maven, when
pom.xmlis at the root: the Maven wrapper (mvnw) when the repository has one, or else Maven from the image, runspackagewith-Dmaven.test.skip=true. The runnable jar is taken fromtarget/. - Gradle, when
build.gradleorbuild.gradle.ktsis at the root: the Gradle wrapper (gradlew) runsassemble. The runnable jar is taken frombuild/libs/. A Gradle project without the wrapper fails to build.
Tests are not compiled or run: run them in CI. Jars ending in -sources, -javadoc, -tests or -plain, and Maven's original-*.jar, are not counted. When the build leaves more than one other jar, add JAVA_BUILD_JAR to the service with the one to run, relative to the repository, such as app/target/app.jar for a multi-module build. JAVA_BUILD_COMMAND replaces the build command; JAVA_BUILD_ARGS adds arguments to Maven or Gradle. The build reads these three as build variables, so give them the build scope; a development workspace builds at runtime, so give them the runtime scope too.
The jar is copied to /home/wodby/app.jar; build output and downloaded dependencies are removed. The container starts java-app, which runs java $JAVA_OPTS -jar /home/wodby/app.jar. JAVA_OPTS is -XX:MaxRAMPercentage=75.0 by default, so the heap follows the container's memory limit; set the service's memory limit rather than -Xmx. A pipeline that passes a Dockerfile from the repository (wodby ci build java -f Dockerfile) uses that file instead; it must still end with a command that starts the server.
- The application must listen on port 8080, on all interfaces. That is the port of the service's HTTP endpoint.
- The service is ready when port 8080 answers HTTP with a status below 500 at
/. WithJAVA_READY_PATHset, such as/health, that path must answer 200 instead. - The service declares no volume of its own: files written inside the container are lost when it is replaced.
Linked services
Links to other services reach the application as environment variables. Nothing in the image reads them: the application reads them itself. Do not hardcode hosts or credentials.
| Link | Variables |
|---|---|
| Database (MariaDB, MySQL or PostgreSQL) | DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION), DATABASE_URL |
SMTP_HOST, SMTP_PORT | |
| Redis or Valkey | REDIS_HOST, REDIS_PORT, REDIS_PASSWORD |
| OpenTelemetry Collector | OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf), OTEL_EXPORTER_OTLP_HEADERS (the Collector's ingest token) |
DATABASE_URL is a URL such as postgresql://user:password@host:5432/db, not a JDBC URL: build the JDBC URL from the DB_* variables, such as jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}. All links are optional. A variable is present only while its link exists and the linked service is enabled. The mail link carries no credentials. The OpenTelemetry variables are the standard SDK settings: an application or agent that uses an OpenTelemetry SDK exports to the Collector without further configuration; set OTEL_SERVICE_NAME to name the application in traces.
Environment
WODBY_HOSTSis a JSON array of the environment's hosts, not a comma-separated string.WODBY_PRIMARY_HOSTandWODBY_PRIMARY_URLare the canonical ones for links generated outside a request.WODBY_APP_SERVICE_NAMEis this service's host name inside the environment. Other services reach the application at that name on port 8080.WODBY_ENV_TYPEtells a development environment from a production-like one.
In a development workspace
- The checkout is mounted at
/usr/src/app. It is built as above and the jar is run from.wodby-workspace/app.jar. The checkout is watched: when a file changes, it is built again and the application is restarted with the new build, in the same container, usually within a few seconds. Nothing has to be restarted or deployed for a code change. A build that fails leaves the previous build running; the build's errors are in the service's logs. When the first build fails, the container waits for a change instead of stopping. - Workspace setup downloads dependencies with
workspace-java prepare:mvn dependency:go-offline, orgradlew dependencies. Code that does not compile yet does not fail it. - Maven's local repository, the Maven wrapper's downloads and Gradle's home are kept in
.wodby-workspace/in the checkout, so a restart downloads nothing again. A-Dmaven.repo.localinMAVEN_OPTSor aGRADLE_USER_HOMEset on the service is kept. Maven and Gradle in a login shell in the workspace use the same locations. Gradle builds keep the Gradle daemon running between builds. target/,build/,.gradle/and.wodby-workspace/are kept out of Git status without touching.gitignore, and changes in them do not start a build.WORKSPACE_JAVA_WATCH=0turns watching off.WORKSPACE_JAVA_COMMANDon the service replaces the start command.- A change to variables or linked services still needs a deployment of the environment.
Check the result
java-ready && echo readyfrom the container shows whether the application answers as the service expects.mvn -q compileor./gradlew compileJavain the checkout shows compile errors at once; the service's logs show them too when a change does not appear.
Kotlin on Wodby
What this service adds to the Java service it is based on. The image, build, start command, links and development workspace are the Java service's; check its guidance for those.
Build a Kotlin project
Kotlin projects build with Gradle: the repository needs the Gradle wrapper (gradlew and gradle/wrapper/). Kotlin's version is the one the build pins with the Kotlin Gradle plugin; the service's versions (25 and 21) are Java versions. Compile for the oldest Java version the application must run on (jvmTarget and Java's targetCompatibility).
The service runs one self-contained jar with java -jar, so ./gradlew assemble must leave exactly one runnable jar in build/libs/, with the application's dependencies inside and Main-Class in its manifest:
- With the Shadow plugin (
com.gradleup.shadow), set the shadow jar's classifier to empty and the plain jar's toplain. Jars ending in-plainare not counted. CallmergeServiceFiles()so libraries found throughMETA-INF/services, such as Ktor's and Netty's, keep working. - With Ktor's Gradle plugin,
buildFatJarmakes such a jar; add it toassembleand mark the plain jar the same way. - A build with several jars needs
JAVA_BUILD_JAR, relative to the repository, such asserver/build/libs/server-all.jar. Add it to the service as a build variable; a development workspace builds at runtime, so give it the runtime scope too.
The application plugin's installDist layout (a start script and a lib/ folder) is not used. Skipping its distZip and distTar tasks keeps builds and workspace rebuilds shorter.
Run on Wodby
- Listen on port 8080 on all interfaces, reading
PORTwhen it is set. With Ktor'sembeddedServer, passhost = "0.0.0.0". - The service is ready when
/answers with a status below 500. SetJAVA_READY_PATH, such as/healthz, to check a health route instead; it must then answer 200. - Ktor's
embeddedServer(...).start(wait = true)stops on SIGTERM and finishes running requests; keep its shutdown timeout below the service's 30 second grace period. - Build a JDBC URL from the
DB_*variables, such asjdbc:postgresql://$DB_HOST:$DB_PORT/$DB_NAME, for Exposed, JDBI or plain JDBC.
Check the result
./gradlew compileKotlin in the checkout shows compile errors at once; ./gradlew test runs the tests, which the service's build skips.
Обзор
Технический профиль Kotlin
Версии
Основан на
Репозиторий исходного кода
Публичный Helm-чарт
Стеки
Стеки, в которые входит Kotlin
CI/CD
Сборка Kotlin из Git-репозитория
Kotlin boilerplate
Используйте его как есть или клонируйте в свой Git-аккаунт.
wodby/kotlin-boilerplateCI-провайдеры
StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.
Реестры контейнеров
Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.
Переменные окружения из интеграций
Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Kotlin, и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.
Конфигурация
Конфигурация сервиса Kotlin
Технические домены
Связи сервиса
Каждая связь — это подключение Kotlin к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.
db
Сервисы, которые подходят для этой связи
sendmail
Сервисы, которые подходят для этой связи
redis
Сервисы, которые подходят для этой связи
otel
Сервисы, которые подходят для этой связи