Compare commits
1 commit
4f0be9919f
...
dbb45646d4
Author | SHA1 | Date | |
---|---|---|---|
dbb45646d4 |
81 changed files with 616 additions and 175 deletions
81
bot/pom.xml
Normal file
81
bot/pom.xml
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<artifactId>dchat</artifactId>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bot</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>bot</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<artifactId>db</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.javacord</groupId>
|
||||||
|
<artifactId>javacord</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-to-slf4j</artifactId>
|
||||||
|
<version>2.20.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<compilerArgs>
|
||||||
|
<compilerArg>--enable-preview</compilerArg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<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.bot.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>
|
|
@ -1,29 +1,15 @@
|
||||||
package de.hhhammer.dchat;
|
package de.hhhammer.dchat.bot;
|
||||||
|
|
||||||
|
import de.hhhammer.dchat.bot.openai.ChatGPTService;
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
import de.hhhammer.dchat.migration.MigrationExecutor;
|
|
||||||
import de.hhhammer.dchat.openai.ChatGPTService;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Main.class);
|
|
||||||
private static final String DB_MIGRATION_PATH = "db/schema.sql";
|
|
||||||
private final DiscordBot discordBot;
|
|
||||||
private final WebAPI webAPI;
|
|
||||||
private final DBMigrator dbMigrator;
|
|
||||||
|
|
||||||
public Main(DiscordBot discordBot, WebAPI webAPI, DBMigrator dbMigrator) {
|
|
||||||
this.discordBot = discordBot;
|
|
||||||
this.webAPI = webAPI;
|
|
||||||
this.dbMigrator = dbMigrator;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String discordApiKey = System.getenv("DISCORD_API_KEY");
|
String discordApiKey = System.getenv("DISCORD_API_KEY");
|
||||||
|
@ -44,27 +30,11 @@ public class Main {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String apiPortStr = System.getenv("API_PORT") != null ? System.getenv("API_PORT") : "8080";
|
|
||||||
int apiPort = Integer.parseInt(apiPortStr);
|
|
||||||
|
|
||||||
var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient());
|
var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient());
|
||||||
var serverDBService = new ServerDBService(postgresUrl, postgresUser, postgresPassword);
|
var serverDBService = new ServerDBService(postgresUrl, postgresUser, postgresPassword);
|
||||||
var userDBService = new UserDBService(postgresUrl, postgresUser, postgresPassword);
|
var userDBService = new UserDBService(postgresUrl, postgresUser, postgresPassword);
|
||||||
|
|
||||||
var discordBot = new DiscordBot(serverDBService, userDBService, chatGPTService, discordApiKey);
|
var discordBot = new DiscordBot(serverDBService, userDBService, chatGPTService, discordApiKey);
|
||||||
var webAPI = new WebAPI(serverDBService, userDBService, apiPort);
|
discordBot.run();
|
||||||
var dbMigrator = new DBMigrator(new MigrationExecutor(postgresUrl, postgresUser, postgresPassword), DB_MIGRATION_PATH);
|
|
||||||
new Main(discordBot, webAPI, dbMigrator).run();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public void run() {
|
|
||||||
logger.info("Starting services...");
|
|
||||||
try (var executor = Executors.newFixedThreadPool(2)) {
|
|
||||||
executor.submit(dbMigrator).get(); // Waiting for migrations
|
|
||||||
executor.submit(discordBot);
|
|
||||||
executor.submit(webAPI);
|
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,11 @@
|
||||||
package de.hhhammer.dchat;
|
package de.hhhammer.dchat.bot;
|
||||||
|
|
||||||
|
import de.hhhammer.dchat.bot.discord.MessageCreateHandler;
|
||||||
|
import de.hhhammer.dchat.bot.discord.ServerMessageHandler;
|
||||||
|
import de.hhhammer.dchat.bot.discord.UserMessageHandler;
|
||||||
|
import de.hhhammer.dchat.bot.openai.ChatGPTService;
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
import de.hhhammer.dchat.discord.MessageCreateHandler;
|
|
||||||
import de.hhhammer.dchat.discord.ServerMessageHandler;
|
|
||||||
import de.hhhammer.dchat.discord.UserMessageHandler;
|
|
||||||
import de.hhhammer.dchat.openai.ChatGPTService;
|
|
||||||
import org.javacord.api.DiscordApi;
|
import org.javacord.api.DiscordApi;
|
||||||
import org.javacord.api.DiscordApiBuilder;
|
import org.javacord.api.DiscordApiBuilder;
|
||||||
import org.javacord.api.interaction.SlashCommand;
|
import org.javacord.api.interaction.SlashCommand;
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat.discord;
|
package de.hhhammer.dchat.bot.discord;
|
||||||
|
|
||||||
import org.javacord.api.entity.message.MessageType;
|
import org.javacord.api.entity.message.MessageType;
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
import org.javacord.api.event.message.MessageCreateEvent;
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat.discord;
|
package de.hhhammer.dchat.bot.discord;
|
||||||
|
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
import org.javacord.api.event.message.MessageCreateEvent;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package de.hhhammer.dchat.discord;
|
package de.hhhammer.dchat.bot.discord;
|
||||||
|
|
||||||
|
import de.hhhammer.dchat.bot.openai.ChatGPTRequestBuilder;
|
||||||
|
import de.hhhammer.dchat.bot.openai.ChatGPTService;
|
||||||
|
import de.hhhammer.dchat.bot.openai.ResponseException;
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
import de.hhhammer.dchat.db.models.server.ServerMessage;
|
import de.hhhammer.dchat.db.models.server.ServerMessage;
|
||||||
import de.hhhammer.dchat.openai.ChatGPTRequestBuilder;
|
|
||||||
import de.hhhammer.dchat.openai.ChatGPTService;
|
|
||||||
import de.hhhammer.dchat.openai.ResponseException;
|
|
||||||
import org.javacord.api.entity.DiscordEntity;
|
import org.javacord.api.entity.DiscordEntity;
|
||||||
import org.javacord.api.entity.message.Message;
|
import org.javacord.api.entity.message.Message;
|
||||||
import org.javacord.api.entity.message.MessageReference;
|
import org.javacord.api.entity.message.MessageReference;
|
|
@ -1,10 +1,10 @@
|
||||||
package de.hhhammer.dchat.discord;
|
package de.hhhammer.dchat.bot.discord;
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
import de.hhhammer.dchat.db.models.user.UserMessage;
|
import de.hhhammer.dchat.db.models.user.UserMessage;
|
||||||
import de.hhhammer.dchat.openai.ChatGPTRequestBuilder;
|
import de.hhhammer.dchat.bot.openai.ChatGPTRequestBuilder;
|
||||||
import de.hhhammer.dchat.openai.ChatGPTService;
|
import de.hhhammer.dchat.bot.openai.ChatGPTService;
|
||||||
import de.hhhammer.dchat.openai.ResponseException;
|
import de.hhhammer.dchat.bot.openai.ResponseException;
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
import org.javacord.api.event.message.MessageCreateEvent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
|
@ -1,7 +1,6 @@
|
||||||
package de.hhhammer.dchat.openai;
|
package de.hhhammer.dchat.bot.openai;
|
||||||
|
|
||||||
import de.hhhammer.dchat.openai.models.ChatGPTRequest;
|
|
||||||
|
|
||||||
|
import de.hhhammer.dchat.bot.openai.models.ChatGPTRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.hhhammer.dchat.openai;
|
package de.hhhammer.dchat.bot.openai;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import de.hhhammer.dchat.openai.models.ChatGPTRequest;
|
import de.hhhammer.dchat.bot.openai.models.ChatGPTRequest;
|
||||||
import de.hhhammer.dchat.openai.models.ChatGPTResponse;
|
import de.hhhammer.dchat.bot.openai.models.ChatGPTResponse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat.openai;
|
package de.hhhammer.dchat.bot.openai;
|
||||||
|
|
||||||
public class ResponseException extends Exception {
|
public class ResponseException extends Exception {
|
||||||
public ResponseException(String message) {
|
public ResponseException(String message) {
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat.openai.models;
|
package de.hhhammer.dchat.bot.openai.models;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat.openai.models;
|
package de.hhhammer.dchat.bot.openai.models;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
13
bot/src/main/resources/logback.xml
Normal file
13
bot/src/main/resources/logback.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="de.hhhammer.dchat" level="DEBUG"/>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
65
build.sh
65
build.sh
|
@ -1,31 +1,56 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
REPO="git.hhhammer.de/hamburghammer/dchat"
|
|
||||||
AUTHORS="Augusto Dwenger J. <dwenger@posteo.de>"
|
AUTHORS="Augusto Dwenger J. <dwenger@posteo.de>"
|
||||||
URL="https://${REPO}"
|
URL="https://${REPO}"
|
||||||
VENDOR="hamburghammer"
|
VENDOR="hamburghammer"
|
||||||
TITLE="dchat"
|
TITLE="dchat"
|
||||||
DESCRIPTION="A Discord bot to chat with ChatGPT from OpenAI"
|
DESCRIPTION="A Discord bot to chat with ChatGPT from OpenAI"
|
||||||
CREATED=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
||||||
REVISION=$(git rev-parse HEAD)
|
|
||||||
|
|
||||||
IMAGE_LATEST="${REPO}:latest"
|
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
build() {
|
||||||
podman build \
|
CREATED=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
$DOCKER_BUILD_ARGS \
|
REVISION=$(git rev-parse HEAD)
|
||||||
-t $IMAGE_LATEST \
|
|
||||||
--label "org.opencontainers.image.revision=${REVISION}" \
|
|
||||||
--label "org.opencontainers.image.version=${TAG}" \
|
|
||||||
--label "org.opencontainers.image.authors=${AUTHORS}" \
|
|
||||||
--label "org.opencontainers.image.created=${CREATED}" \
|
|
||||||
--label "org.opencontainers.image.source=${URL}" \
|
|
||||||
--label "org.opencontainers.image.vendor=${VENDOR}" \
|
|
||||||
--label "org.opencontainers.image.title=${TITLE}" \
|
|
||||||
--label "org.opencontainers.image.description=${DESCRIPTION}" \
|
|
||||||
. || exit $?
|
|
||||||
|
|
||||||
if [ "$PUSH_LATEST" == "1" ]; then
|
IMAGE_LATEST="${REPO}:latest"
|
||||||
podman push "${IMAGE_LATEST}"
|
# shellcheck disable=SC2086
|
||||||
fi
|
podman build \
|
||||||
|
$DOCKER_BUILD_ARGS \
|
||||||
|
-t $IMAGE_LATEST \
|
||||||
|
--label "org.opencontainers.image.revision=${REVISION}" \
|
||||||
|
--label "org.opencontainers.image.version=${TAG}" \
|
||||||
|
--label "org.opencontainers.image.authors=${AUTHORS}" \
|
||||||
|
--label "org.opencontainers.image.created=${CREATED}" \
|
||||||
|
--label "org.opencontainers.image.source=${URL}" \
|
||||||
|
--label "org.opencontainers.image.vendor=${VENDOR}" \
|
||||||
|
--label "org.opencontainers.image.title=${TITLE}" \
|
||||||
|
--label "org.opencontainers.image.description=${DESCRIPTION}" \
|
||||||
|
.. || exit $?
|
||||||
|
|
||||||
|
if [ "$PUSH_LATEST" == "1" ]; then
|
||||||
|
podman push "${IMAGE_LATEST}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "start building bot"
|
||||||
|
cd "./bot" || exit 1
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/bot"
|
||||||
|
TITLE="dchat-bot"
|
||||||
|
DESCRIPTION="A Discord bot to chat with ChatGPT from OpenAI"
|
||||||
|
build
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo "start building web"
|
||||||
|
cd "./web" || exit 1
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/web"
|
||||||
|
TITLE="dchat-web"
|
||||||
|
DESCRIPTION="A web API and UI for the dchat-bot configuration"
|
||||||
|
build
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo "start building migration"
|
||||||
|
cd "./migration" || exit 1
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/migration"
|
||||||
|
TITLE="dchat-migration"
|
||||||
|
DESCRIPTION="A migration tool for the dchat database"
|
||||||
|
build
|
||||||
|
cd ..
|
||||||
|
|
31
db/pom.xml
Normal file
31
db/pom.xml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<artifactId>dchat</artifactId>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>db</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>db</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.15.0-rc2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -2,8 +2,8 @@ version: "3"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
bot:
|
bot:
|
||||||
image: git.hhhammer.de/hamburghammer/dchat:latest
|
image: git.hhhammer.de/hamburghammer/dchat/bot:latest
|
||||||
build: .
|
build: ./bot/
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
@ -13,8 +13,30 @@ services:
|
||||||
- POSTGRES_USER=<postgres-user>
|
- POSTGRES_USER=<postgres-user>
|
||||||
- POSTGRES_PASSWORD=<postgres-password>
|
- POSTGRES_PASSWORD=<postgres-password>
|
||||||
- POSTGRES_URL=jdbc:postgresql://db:5432/dchat
|
- POSTGRES_URL=jdbc:postgresql://db:5432/dchat
|
||||||
- API_PORT=8080
|
|
||||||
- JDK_JAVA_OPTIONS="--enable-preview"
|
- JDK_JAVA_OPTIONS="--enable-preview"
|
||||||
|
|
||||||
|
web:
|
||||||
|
image: git.hhhammer.de/hamburghammer/dchat/web:latest
|
||||||
|
build: ./web/
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=<postgres-user>
|
||||||
|
- POSTGRES_PASSWORD=<postgres-password>
|
||||||
|
- POSTGRES_URL=jdbc:postgresql://db:5432/dchat
|
||||||
|
- JDK_JAVA_OPTIONS="--enable-preview"
|
||||||
|
|
||||||
|
migration:
|
||||||
|
image: git.hhhammer.de/hamburghammer/dchat/migration:latest
|
||||||
|
build: ./migration/
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=<postgres-user>
|
||||||
|
- POSTGRES_PASSWORD=<postgres-password>
|
||||||
|
- POSTGRES_URL=jdbc:postgresql://db:5432/dchat
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: docker.io/postgres:15-alpine
|
image: docker.io/postgres:15-alpine
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
60
migration/pom.xml
Normal file
60
migration/pom.xml
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<artifactId>dchat</artifactId>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>migration</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>migration</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
</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.migration.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>
|
25
migration/src/main/java/de/hhhammer/dchat/migration/App.java
Normal file
25
migration/src/main/java/de/hhhammer/dchat/migration/App.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package de.hhhammer.dchat.migration;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*/
|
||||||
|
public class App {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
|
private static final String DB_MIGRATION_PATH = "db/schema.sql";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String postgresUser = System.getenv("POSTGRES_USER");
|
||||||
|
String postgresPassword = System.getenv("POSTGRES_PASSWORD");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
var migrationExecutor = new MigrationExecutor(postgresUrl, postgresUser, postgresPassword);
|
||||||
|
var dbMigrator = new DBMigrator(migrationExecutor, DB_MIGRATION_PATH);
|
||||||
|
dbMigrator.run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package de.hhhammer.dchat;
|
package de.hhhammer.dchat.migration;
|
||||||
|
|
||||||
import de.hhhammer.dchat.migration.DBMigrationException;
|
|
||||||
import de.hhhammer.dchat.migration.MigrationExecutor;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
13
migration/src/main/resources/logback.xml
Normal file
13
migration/src/main/resources/logback.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="de.hhhammer.dchat" level="DEBUG"/>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
179
pom.xml
179
pom.xml
|
@ -7,6 +7,9 @@
|
||||||
<groupId>de.hhhammer.dchat</groupId>
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
<artifactId>dchat</artifactId>
|
<artifactId>dchat</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<!-- FIXME change it to the project's website -->
|
||||||
|
<url>http://www.example.com</url>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>19</maven.compiler.source>
|
<maven.compiler.source>19</maven.compiler.source>
|
||||||
|
@ -14,105 +17,111 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- logging -->
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.javacord</groupId>
|
|
||||||
<artifactId>javacord</artifactId>
|
|
||||||
<version>3.8.0</version>
|
|
||||||
<type>pom</type>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>2.15.0-rc2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
|
||||||
<version>2.14.2</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<version>42.6.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.javalin</groupId>
|
|
||||||
<artifactId>javalin</artifactId>
|
|
||||||
<version>5.5.0</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-to-slf4j</artifactId>
|
|
||||||
<version>2.20.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>2.0.7</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.4.6</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>24.0.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.11.0</version>
|
|
||||||
<configuration>
|
|
||||||
<compilerArgs>
|
|
||||||
<compilerArg>--enable-preview</compilerArg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.3</version>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<shadedClassifierName>fat</shadedClassifierName>
|
|
||||||
<transformers>
|
|
||||||
<transformer
|
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<manifestEntries>
|
|
||||||
<Main-Class>de.hhhammer.dchat.Main</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>
|
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>2.0.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.4.6</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>24.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.6.0</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.google.cloud.tools</groupId>
|
||||||
|
<artifactId>jib-maven-plugin</artifactId>
|
||||||
|
<version>3.3.2</version>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.11.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
<modules>
|
||||||
|
<module>bot</module>
|
||||||
|
<module>db</module>
|
||||||
|
<module>web</module>
|
||||||
|
<module>migration</module>
|
||||||
|
</modules>
|
||||||
</project>
|
</project>
|
155
web/pom.xml
Normal file
155
web/pom.xml
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<artifactId>dchat</artifactId>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>web</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>web</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<node.version>v18.16.0</node.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.hhhammer.dchat</groupId>
|
||||||
|
<artifactId>db</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.javalin</groupId>
|
||||||
|
<artifactId>javalin</artifactId>
|
||||||
|
<version>5.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.15.0-rc2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>2.14.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<compilerArgs>
|
||||||
|
<compilerArg>--enable-preview</compilerArg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<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.web.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>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.eirslett</groupId>
|
||||||
|
<artifactId>frontend-maven-plugin</artifactId>
|
||||||
|
<version>1.9.1</version>
|
||||||
|
<configuration>
|
||||||
|
<nodeVersion>${node.version}</nodeVersion>
|
||||||
|
<workingDirectory>src/ui</workingDirectory>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>Install node and npm</id>
|
||||||
|
<goals>
|
||||||
|
<goal>install-node-and-npm</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<configuration>
|
||||||
|
<nodeVersion>${node.version}</nodeVersion>
|
||||||
|
<npmVersion>${npm.version}</npmVersion>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>npm install</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<configuration>
|
||||||
|
<arguments>install</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>npm build</id>
|
||||||
|
<goals>
|
||||||
|
<goal>npm</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<configuration>
|
||||||
|
<arguments>run build-only</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>Copy Vue frontend into target static folder</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>target/classes/ui</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/ui/dist</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
37
web/src/main/java/de/hhhammer/dchat/web/App.java
Normal file
37
web/src/main/java/de/hhhammer/dchat/web/App.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package de.hhhammer.dchat.web;
|
||||||
|
|
||||||
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
|
import io.javalin.Javalin;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*/
|
||||||
|
public class App {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String postgresUser = System.getenv("POSTGRES_USER");
|
||||||
|
String postgresPassword = System.getenv("POSTGRES_PASSWORD");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverDBService = new ServerDBService(postgresUrl, postgresUser, postgresPassword);
|
||||||
|
var userDBService = new UserDBService(postgresUrl, postgresUser, postgresPassword);
|
||||||
|
|
||||||
|
String apiPortStr = System.getenv("API_PORT") != null ? System.getenv("API_PORT") : "8080";
|
||||||
|
int apiPort = Integer.parseInt(apiPortStr);
|
||||||
|
var uiLocation = System.getenv("UI_LOCATION");
|
||||||
|
if (uiLocation == null) {
|
||||||
|
logger.error("Missing environment variables: UI_LOCATION");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
var webApi = new WebAPI(serverDBService, userDBService, uiLocation, apiPort);
|
||||||
|
webApi.run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package de.hhhammer.dchat;
|
package de.hhhammer.dchat.web;
|
||||||
|
|
||||||
import de.hhhammer.dchat.db.ServerDBService;
|
import de.hhhammer.dchat.db.ServerDBService;
|
||||||
import de.hhhammer.dchat.db.UserDBService;
|
import de.hhhammer.dchat.db.UserDBService;
|
||||||
|
@ -17,11 +17,13 @@ public class WebAPI implements Runnable {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(WebAPI.class);
|
private static final Logger logger = LoggerFactory.getLogger(WebAPI.class);
|
||||||
private final ServerDBService serverDBService;
|
private final ServerDBService serverDBService;
|
||||||
private final UserDBService userDBService;
|
private final UserDBService userDBService;
|
||||||
|
private final String uiLocation;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
public WebAPI(ServerDBService serverDBService, UserDBService userDBService, int port) {
|
public WebAPI(ServerDBService serverDBService, UserDBService userDBService, String uiLocation, int port) {
|
||||||
this.serverDBService = serverDBService;
|
this.serverDBService = serverDBService;
|
||||||
this.userDBService = userDBService;
|
this.userDBService = userDBService;
|
||||||
|
this.uiLocation = uiLocation;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ public class WebAPI implements Runnable {
|
||||||
config.staticFiles.add(staticFileConfig -> {
|
config.staticFiles.add(staticFileConfig -> {
|
||||||
staticFileConfig.hostedPath = "/";
|
staticFileConfig.hostedPath = "/";
|
||||||
staticFileConfig.location = Location.EXTERNAL;
|
staticFileConfig.location = Location.EXTERNAL;
|
||||||
staticFileConfig.directory = "./ui/dist/";
|
staticFileConfig.directory = this.uiLocation;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
@ -6,7 +6,6 @@
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name="de.hhhammer.dchat" level="DEBUG"/>
|
<logger name="de.hhhammer.dchat" level="DEBUG"/>
|
||||||
<logger name="org.javacord.core" level="WARN"/>
|
|
||||||
<logger name="io.javalin.Javalin" level="INFO"/>
|
<logger name="io.javalin.Javalin" level="INFO"/>
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
2
ui/.gitignore → web/src/ui/.gitignore
vendored
2
ui/.gitignore → web/src/ui/.gitignore
vendored
|
@ -26,3 +26,5 @@ coverage
|
||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
|
node
|
0
ui/env.d.ts → web/src/ui/env.d.ts
vendored
0
ui/env.d.ts → web/src/ui/env.d.ts
vendored
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Loading…
Reference in a new issue