Compare commits
3 commits
d4486664e0
...
56a68bc867
Author | SHA1 | Date | |
---|---|---|---|
56a68bc867 | |||
f0d6c40e65 | |||
4135d7e57e |
8 changed files with 166 additions and 67 deletions
|
@ -7,6 +7,8 @@
|
||||||
!migration/pom.xml
|
!migration/pom.xml
|
||||||
!web/src/
|
!web/src/
|
||||||
!web/pom.xml
|
!web/pom.xml
|
||||||
|
!monolith/src/
|
||||||
|
!monolith/pom.xml
|
||||||
!pom.xml
|
!pom.xml
|
||||||
!ui/
|
!ui/
|
||||||
ui/node_modules
|
ui/node_modules
|
||||||
|
|
|
@ -4,6 +4,7 @@ matrix:
|
||||||
- bot
|
- bot
|
||||||
- web
|
- web
|
||||||
- migration
|
- migration
|
||||||
|
- monolith
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
- &image 'docker.io/maven:3.9-eclipse-temurin-21'
|
- &image 'docker.io/maven:3.9-eclipse-temurin-21'
|
||||||
|
|
|
@ -4,6 +4,7 @@ matrix:
|
||||||
- web
|
- web
|
||||||
- migration
|
- migration
|
||||||
- ui
|
- ui
|
||||||
|
- monolith
|
||||||
PLATFORM:
|
PLATFORM:
|
||||||
# - linux/amd64
|
# - linux/amd64
|
||||||
- linux/arm64
|
- linux/arm64
|
||||||
|
|
52
Dockerfile
52
Dockerfile
|
@ -5,63 +5,33 @@ ARG MAVEN_CLI_OPTS="--batch-mode --no-transfer-progress -Dmaven.test.skip"
|
||||||
# Copy all project files
|
# Copy all project files
|
||||||
FROM docker.io/maven:3.9-eclipse-temurin-21 AS setup
|
FROM docker.io/maven:3.9-eclipse-temurin-21 AS setup
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Copy the dependency specifications
|
COPY . .
|
||||||
COPY pom.xml .
|
|
||||||
COPY db/pom.xml db/
|
|
||||||
COPY bot/pom.xml bot/
|
|
||||||
COPY migration/pom.xml migration/
|
|
||||||
COPY web/pom.xml web/
|
|
||||||
# Resolve dependencies for shared libraries
|
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
RUN --mount=type=cache,target=/root/.m2/ \
|
||||||
mvn ${MAVEN_CLI_OPTS} -pl db -am dependency:go-offline
|
mvn ${MAVEN_CLI_OPTS} package
|
||||||
# Install the shared libraries in the local Maven repo (`.m2`)
|
|
||||||
# This will also install the `root` module.
|
|
||||||
|
|
||||||
# Build db dependency
|
# Create final monolith
|
||||||
FROM setup AS db-build
|
FROM docker.io/eclipse-temurin:21-jdk-jammy AS monolith
|
||||||
COPY db db
|
WORKDIR /app
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
COPY --from=setup /app/monolith/target/monolith-*-fat.jar /app/monolith.jar
|
||||||
mvn ${MAVEN_CLI_OPTS} -pl db -am install
|
CMD ["java", "-jar", "/app/monolith.jar"]
|
||||||
# Resolve dependencies for modules without dependencies to each other
|
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
|
||||||
mvn ${MAVEN_CLI_OPTS} dependency:go-offline
|
|
||||||
|
|
||||||
# Build modules
|
|
||||||
FROM db-build AS web-build
|
|
||||||
COPY web web
|
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
|
||||||
--mount=type=cache,target=/app/web/src/ui/dist/ \
|
|
||||||
--mount=type=cache,target=/app/web/src/ui/node/ \
|
|
||||||
--mount=type=cache,target=/app/web/src/ui/node_modules/ \
|
|
||||||
mvn ${MAVEN_CLI_OPTS} -pl web package
|
|
||||||
|
|
||||||
FROM db-build AS bot-build
|
|
||||||
COPY bot bot
|
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
|
||||||
mvn ${MAVEN_CLI_OPTS} -pl bot package
|
|
||||||
|
|
||||||
FROM db-build AS migration-build
|
|
||||||
COPY migration migration
|
|
||||||
RUN --mount=type=cache,target=/root/.m2/ \
|
|
||||||
mvn ${MAVEN_CLI_OPTS} -pl migration package
|
|
||||||
|
|
||||||
# Create final web
|
# Create final web
|
||||||
FROM docker.io/eclipse-temurin:21-jdk-jammy AS web
|
FROM docker.io/eclipse-temurin:21-jdk-jammy AS web
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=web-build /app/web/target/web-*-fat.jar /app/web.jar
|
COPY --from=setup /app/web/target/web-*-fat.jar /app/web.jar
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD ["java", "-jar", "/app/web.jar"]
|
CMD ["java", "-jar", "/app/web.jar"]
|
||||||
|
|
||||||
# Create final migration
|
# Create final migration
|
||||||
FROM docker.io/eclipse-temurin:21-jdk-jammy AS migration
|
FROM docker.io/eclipse-temurin:21-jdk-jammy AS migration
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=migration-build /app/migration/target/migration-*-fat.jar /app/migration.jar
|
COPY --from=setup /app/migration/target/migration-*-fat.jar /app/migration.jar
|
||||||
CMD ["java", "-jar", "/app/migration.jar"]
|
CMD ["java", "-jar", "/app/migration.jar"]
|
||||||
|
|
||||||
# Create final bot
|
# Create final bot
|
||||||
FROM docker.io/eclipse-temurin:21-jdk-jammy AS bot
|
FROM docker.io/eclipse-temurin:21-jdk-jammy AS bot
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=bot-build /app/bot/target/bot-*-fat.jar /app/bot.jar
|
COPY --from=setup /app/bot/target/bot-*-fat.jar /app/bot.jar
|
||||||
CMD ["java", "-jar", "/app/bot.jar"]
|
CMD ["java", "-jar", "/app/bot.jar"]
|
||||||
|
|
||||||
# Build the ui
|
# Build the ui
|
||||||
|
@ -86,7 +56,7 @@ RUN <<EOF cat > /etc/caddy/Caddyfile
|
||||||
|
|
||||||
:8080 {
|
:8080 {
|
||||||
route {
|
route {
|
||||||
reverse_proxy /api/* web:8080
|
reverse_proxy /api/* monolith:8080
|
||||||
reverse_proxy ui:80
|
reverse_proxy ui:80
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +1,24 @@
|
||||||
version: "3"
|
version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
bot:
|
monolith:
|
||||||
image: git.hhhammer.de/hamburghammer/dchat/bot:latest
|
image: git.hhhammer.de/hamburghammer/dchat/monolith:latest
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
build:
|
build:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
context: .
|
context: .
|
||||||
target: bot
|
target: monolith
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
|
||||||
- db
|
|
||||||
user: 1000:1000
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
- migration
|
|
||||||
|
|
||||||
web:
|
|
||||||
image: git.hhhammer.de/hamburghammer/dchat/web:latest
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
build:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: .
|
|
||||||
target: web
|
|
||||||
restart: unless-stopped
|
|
||||||
user: 1000:1000
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
- migration
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
networks:
|
networks:
|
||||||
- db
|
- db
|
||||||
- web
|
- web
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
user: 1000:1000
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- migration
|
||||||
|
|
||||||
migration:
|
migration:
|
||||||
image: git.hhhammer.de/hamburghammer/dchat/migration:latest
|
image: git.hhhammer.de/hamburghammer/dchat/migration:latest
|
||||||
|
@ -72,7 +56,7 @@ services:
|
||||||
user: 1000:1000
|
user: 1000:1000
|
||||||
depends_on:
|
depends_on:
|
||||||
- ui
|
- ui
|
||||||
- web
|
- monolith
|
||||||
ports:
|
ports:
|
||||||
- 8082:8080
|
- 8082:8080
|
||||||
networks:
|
networks:
|
||||||
|
|
65
monolith/pom.xml
Normal file
65
monolith/pom.xml
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<artifactId>dchat</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>monolith</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>monolith</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<artifactId>bot</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<artifactId>web</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
|
<shadedClassifierName>fat</shadedClassifierName>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>de.hhhammer.dchat.monolith.App</Main-Class>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.SF</exclude>
|
||||||
|
<exclude>META-INF/*.DSA</exclude>
|
||||||
|
<exclude>META-INF/*.RSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
75
monolith/src/main/java/de/hhhammer/dchat/monolith/App.java
Normal file
75
monolith/src/main/java/de/hhhammer/dchat/monolith/App.java
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
package de.hhhammer.dchat.monolith;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import de.hhhammer.dchat.bot.DiscordBot;
|
||||||
|
import de.hhhammer.dchat.bot.openai.ChatGPTService;
|
||||||
|
import de.hhhammer.dchat.db.PostgresServerDBService;
|
||||||
|
import de.hhhammer.dchat.db.PostgresUserDBService;
|
||||||
|
import de.hhhammer.dchat.web.AppConfig;
|
||||||
|
import de.hhhammer.dchat.web.WebAPI;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final String discordApiKey = System.getenv("DISCORD_API_KEY");
|
||||||
|
if (discordApiKey == null) {
|
||||||
|
logger.error("Missing environment variables: DISCORD_API_KEY");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
final String openaiApiKey = System.getenv("OPENAI_API_KEY");
|
||||||
|
if (openaiApiKey == null) {
|
||||||
|
logger.error("Missing environment variables: OPENAI_API_KEY");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
final String postgresUser = System.getenv("POSTGRES_USER");
|
||||||
|
final String postgresPassword = System.getenv("POSTGRES_PASSWORD");
|
||||||
|
final String postgresUrl = System.getenv("POSTGRES_URL");
|
||||||
|
if (postgresUser == null || postgresPassword == null || postgresUrl == null) {
|
||||||
|
logger.error("Missing environment variables: POSTGRES_USER and/or POSTGRES_PASSWORD and/or POSTGRES_URL");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
final String apiPortStr = System.getenv("API_PORT") != null ? System.getenv("API_PORT") : "8080";
|
||||||
|
final int apiPort = Integer.parseInt(apiPortStr);
|
||||||
|
final boolean debug = "true".equals(System.getenv("API_DEBUG"));
|
||||||
|
|
||||||
|
final var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient(), new ObjectMapper());
|
||||||
|
|
||||||
|
final var config = new HikariConfig();
|
||||||
|
config.setJdbcUrl(postgresUrl);
|
||||||
|
config.setUsername(postgresUser);
|
||||||
|
config.setPassword(postgresPassword);
|
||||||
|
|
||||||
|
try (final var ds = new HikariDataSource(config)) {
|
||||||
|
final var serverDBService = new PostgresServerDBService(ds);
|
||||||
|
final var userDBService = new PostgresUserDBService(ds);
|
||||||
|
|
||||||
|
final var discordBot = new DiscordBot(serverDBService, userDBService, chatGPTService, discordApiKey);
|
||||||
|
final var appConfig = new AppConfig(apiPort, debug);
|
||||||
|
final var webApi = new WebAPI(serverDBService, userDBService, appConfig);
|
||||||
|
run(discordBot, webApi);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.error("Application failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void run(Runnable... apps) throws InterruptedException {
|
||||||
|
List<Callable<Void>> callableApps = Arrays.stream(apps).sequential().map(runnable -> (Callable<Void>) () -> {
|
||||||
|
runnable.run();
|
||||||
|
return null;
|
||||||
|
}).toList();
|
||||||
|
try (var executorService = Executors.newFixedThreadPool(apps.length)) {
|
||||||
|
executorService.invokeAll(callableApps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
pom.xml
1
pom.xml
|
@ -176,5 +176,6 @@
|
||||||
<module>db</module>
|
<module>db</module>
|
||||||
<module>web</module>
|
<module>web</module>
|
||||||
<module>migration</module>
|
<module>migration</module>
|
||||||
|
<module>monolith</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
Loading…
Reference in a new issue