create docker for the API

This commit is contained in:
2025-03-27 06:35:53 +01:00
parent 77be521627
commit e4ffd7792b
10 changed files with 83 additions and 46 deletions

12
.run/Compose up.run.xml Normal file
View File

@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Compose up" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="composeProjectName" value="event-demo" />
<option name="envFilePath" value="" />
<option name="sourceFilePath" value="docker/docker-compose.yaml" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>

View File

@@ -1,24 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="composeUp" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="composeUp" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@@ -1,7 +1,14 @@
Event demo Event demo
========== ==========
To run the stack:
```shell
docker compose -f docker\docker-compose.yaml -p event-demo up -d
```
Admin service URL: Admin service URL:
- [Traefik](http://pgadmin.traefik.me/) - [Traefik](http://pgadmin.traefik.me/)
- [Redis](http://pgadmin.traefik.me/) - [Redis](http://pgadmin.traefik.me/)
- [pgAdmin](http://pgadmin.traefik.me/) - [pgAdmin](http://pgadmin.traefik.me/)
- [API](http://api.traefik.me/)

View File

@@ -9,15 +9,15 @@ val kotlin_logging_version: String by project
val kotest_version: String by project val kotest_version: String by project
plugins { plugins {
application
kotlin("jvm") version "2.1.10" kotlin("jvm") version "2.1.10"
id("io.ktor.plugin") version "2.3.13" id("io.ktor.plugin") version "3.1.1"
id("org.jetbrains.kotlin.plugin.serialization") version "2.1.10" id("org.jetbrains.kotlin.plugin.serialization") version "2.1.10"
id("org.jlleitschuh.gradle.ktlint") version "12.2.0" id("org.jlleitschuh.gradle.ktlint") version "12.2.0"
id("com.avast.gradle.docker-compose") version "0.17.12" id("com.avast.gradle.docker-compose") version "0.17.12"
} }
group = "io.github.flecomte" group = "io.github.flecomte"
version = "0.0.1"
application { application {
mainClass.set("eventDemo.ApplicationKt") mainClass.set("eventDemo.ApplicationKt")
@@ -36,7 +36,7 @@ repositories {
java { java {
toolchain { toolchain {
languageVersion = JavaLanguageVersion.of(19) languageVersion = JavaLanguageVersion.of(21)
} }
} }

25
docker/Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME=/home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY .editorconfig /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle clean build -i -x test -x ktlintCheck -x ktlintKotlinScriptCheck
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM amazoncorretto:21 AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar /app/event-demo-all.jar
ENTRYPOINT ["java","-jar","/app/event-demo-all.jar"]

View File

@@ -1,3 +1,4 @@
name: event-demo
services: services:
traefik: traefik:
image: traefik:3.3.4 image: traefik:3.3.4
@@ -42,6 +43,7 @@ services:
volumes: volumes:
- ../migrations/events:/flyway/sql - ../migrations/events:/flyway/sql
- ./flyway.conf:/flyway/conf/flyway.conf - ./flyway.conf:/flyway/conf/flyway.conf
restart: no
postgresql: postgresql:
image: postgres:17.4 image: postgres:17.4
@@ -75,6 +77,21 @@ services:
- "traefik.http.routers.pgadmin.rule=Host(`pgadmin.traefik.me`)" - "traefik.http.routers.pgadmin.rule=Host(`pgadmin.traefik.me`)"
- "traefik.http.services.pgadmin.loadbalancer.server.port=80" - "traefik.http.services.pgadmin.loadbalancer.server.port=80"
app:
build:
context: ../
dockerfile: docker/Dockerfile
ports:
- "8080:8080"
depends_on:
flyway:
condition: service_completed_successfully
postgresql:
condition: service_healthy
labels:
- "traefik.http.routers.app.rule=Host(`api.traefik.me`)"
- "traefik.http.services.app.loadbalancer.server.port=8080"
secrets: secrets:
pgadmin_password: pgadmin_password:
file: pgadmin.secret file: pgadmin.secret

View File

@@ -1,16 +1,6 @@
package eventDemo package eventDemo
import eventDemo.configuration.configure import io.ktor.server.netty.EngineMain
import io.ktor.server.application.Application
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
fun main() { fun main(args: Array<String>): Unit =
embeddedServer( EngineMain.main(args)
factory = Netty,
port = 8080,
host = "0.0.0.0",
module = Application::configure,
watchPaths = listOf("classes"),
).start(wait = true)
}

View File

@@ -5,12 +5,12 @@ import io.ktor.server.application.install
import io.ktor.server.websocket.WebSockets import io.ktor.server.websocket.WebSockets
import io.ktor.server.websocket.pingPeriod import io.ktor.server.websocket.pingPeriod
import io.ktor.server.websocket.timeout import io.ktor.server.websocket.timeout
import java.time.Duration import kotlin.time.Duration.Companion.seconds
fun Application.configureWebSockets() { fun Application.configureWebSockets() {
install(WebSockets) { install(WebSockets) {
pingPeriod = Duration.ofSeconds(15) pingPeriod = 15.seconds
timeout = Duration.ofSeconds(15) timeout = 15.seconds
maxFrameSize = Long.MAX_VALUE maxFrameSize = Long.MAX_VALUE
masking = false masking = false
} }

View File

@@ -8,7 +8,7 @@ import org.koin.ktor.ext.get
fun Application.declareHttpGameRoute() { fun Application.declareHttpGameRoute() {
routing { routing {
readTheGameState(get()) readTheGameState(this@declareHttpGameRoute.get())
readGamesList(get()) readGamesList(this@declareHttpGameRoute.get())
} }
} }

View File

@@ -1,3 +1,13 @@
ktor {
deployment {
port = 8080
host = 0.0.0.0
}
application {
modules = [ eventDemo.configuration.ConfigureKt.configure ]
}
}
jwt { jwt {
secret = "secret" secret = "secret"
secret = ${?JWT_SECRET} secret = ${?JWT_SECRET}