Compare commits

...

4 commits

Author SHA1 Message Date
1a7cb6f055 Add comment to explain blocking call while migration runs 2023-05-14 00:57:13 +02:00
9de90700c3 Switch to virtual thread for discord bot shutdown hook
Why use a system Thread?
2023-05-14 00:56:21 +02:00
9dc9f16c06 Add JDK_JAVA_OPTIONS env to enable preview features 2023-05-14 00:53:06 +02:00
9754e36c99 Switch back to JDK 19 for the final image
We use preview features while compiling so it won't run on JDK 20...
Waiting for NixOS to package JDK 20 :D
2023-05-14 00:51:55 +02:00
4 changed files with 4 additions and 4 deletions

View file

@ -16,7 +16,7 @@ COPY ./ui .
RUN npm run build-only
# Stage 3: Create the jlink app
FROM docker.io/eclipse-temurin:20-jdk-alpine
FROM docker.io/eclipse-temurin:19-jdk-alpine
WORKDIR /app
COPY --from=maven /app/target/dchat-*-fat.jar /app/dchat.jar
COPY --from=vuejs /app/dist /app/ui/dist

View file

@ -14,6 +14,7 @@ services:
- POSTGRES_PASSWORD=<postgres-password>
- POSTGRES_URL=jdbc:postgresql://db:5432/dchat
- API_PORT=8080
- JDK_JAVA_OPTIONS="--enable-preview"
db:
image: docker.io/postgres:15-alpine
restart: unless-stopped

View file

@ -36,7 +36,7 @@ public class DiscordBot implements Runnable {
.setToken(discordApiKey)
.login()
.join();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Runtime.getRuntime().addShutdownHook(Thread.ofVirtual().unstarted(() -> {
logger.info("Shutting down Discord application");
discordApi.disconnect();
}));

View file

@ -60,8 +60,7 @@ public class Main {
public void run() {
logger.info("Starting services...");
try (var executor = Executors.newFixedThreadPool(2)) {
var migrationResult = executor.submit(dbMigrator);
migrationResult.get();
executor.submit(dbMigrator).get(); // Waiting for migrations
executor.submit(discordBot);
executor.submit(webAPI);
} catch (ExecutionException | InterruptedException e) {