create docker for the API
This commit is contained in:
12
.run/Compose up.run.xml
Normal file
12
.run/Compose up.run.xml
Normal 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>
|
||||
@@ -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>
|
||||
@@ -1,7 +1,14 @@
|
||||
Event demo
|
||||
==========
|
||||
|
||||
To run the stack:
|
||||
|
||||
```shell
|
||||
docker compose -f docker\docker-compose.yaml -p event-demo up -d
|
||||
```
|
||||
|
||||
Admin service URL:
|
||||
- [Traefik](http://pgadmin.traefik.me/)
|
||||
- [Redis](http://pgadmin.traefik.me/)
|
||||
- [pgAdmin](http://pgadmin.traefik.me/)
|
||||
- [pgAdmin](http://pgadmin.traefik.me/)
|
||||
- [API](http://api.traefik.me/)
|
||||
@@ -9,15 +9,15 @@ val kotlin_logging_version: String by project
|
||||
val kotest_version: String by project
|
||||
|
||||
plugins {
|
||||
application
|
||||
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.jlleitschuh.gradle.ktlint") version "12.2.0"
|
||||
id("com.avast.gradle.docker-compose") version "0.17.12"
|
||||
}
|
||||
|
||||
group = "io.github.flecomte"
|
||||
version = "0.0.1"
|
||||
|
||||
application {
|
||||
mainClass.set("eventDemo.ApplicationKt")
|
||||
@@ -36,7 +36,7 @@ repositories {
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(19)
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
docker/Dockerfile
Normal file
25
docker/Dockerfile
Normal 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"]
|
||||
@@ -1,3 +1,4 @@
|
||||
name: event-demo
|
||||
services:
|
||||
traefik:
|
||||
image: traefik:3.3.4
|
||||
@@ -42,6 +43,7 @@ services:
|
||||
volumes:
|
||||
- ../migrations/events:/flyway/sql
|
||||
- ./flyway.conf:/flyway/conf/flyway.conf
|
||||
restart: no
|
||||
|
||||
postgresql:
|
||||
image: postgres:17.4
|
||||
@@ -75,6 +77,21 @@ services:
|
||||
- "traefik.http.routers.pgadmin.rule=Host(`pgadmin.traefik.me`)"
|
||||
- "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:
|
||||
pgadmin_password:
|
||||
file: pgadmin.secret
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
package eventDemo
|
||||
|
||||
import eventDemo.configuration.configure
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.netty.Netty
|
||||
import io.ktor.server.netty.EngineMain
|
||||
|
||||
fun main() {
|
||||
embeddedServer(
|
||||
factory = Netty,
|
||||
port = 8080,
|
||||
host = "0.0.0.0",
|
||||
module = Application::configure,
|
||||
watchPaths = listOf("classes"),
|
||||
).start(wait = true)
|
||||
}
|
||||
fun main(args: Array<String>): Unit =
|
||||
EngineMain.main(args)
|
||||
|
||||
@@ -5,12 +5,12 @@ import io.ktor.server.application.install
|
||||
import io.ktor.server.websocket.WebSockets
|
||||
import io.ktor.server.websocket.pingPeriod
|
||||
import io.ktor.server.websocket.timeout
|
||||
import java.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
fun Application.configureWebSockets() {
|
||||
install(WebSockets) {
|
||||
pingPeriod = Duration.ofSeconds(15)
|
||||
timeout = Duration.ofSeconds(15)
|
||||
pingPeriod = 15.seconds
|
||||
timeout = 15.seconds
|
||||
maxFrameSize = Long.MAX_VALUE
|
||||
masking = false
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.koin.ktor.ext.get
|
||||
|
||||
fun Application.declareHttpGameRoute() {
|
||||
routing {
|
||||
readTheGameState(get())
|
||||
readGamesList(get())
|
||||
readTheGameState(this@declareHttpGameRoute.get())
|
||||
readGamesList(this@declareHttpGameRoute.get())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
ktor {
|
||||
deployment {
|
||||
port = 8080
|
||||
host = 0.0.0.0
|
||||
}
|
||||
application {
|
||||
modules = [ eventDemo.configuration.ConfigureKt.configure ]
|
||||
}
|
||||
}
|
||||
|
||||
jwt {
|
||||
secret = "secret"
|
||||
secret = ${?JWT_SECRET}
|
||||
|
||||
Reference in New Issue
Block a user