Compare commits
2 commits
dbb45646d4
...
4f0be9919f
Author | SHA1 | Date | |
---|---|---|---|
4f0be9919f | |||
b8b83baa72 |
85 changed files with 669 additions and 255 deletions
13
.containerignore
Normal file
13
.containerignore
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
*
|
||||||
|
!db/src/
|
||||||
|
!db/pom.xml
|
||||||
|
!bot/src/
|
||||||
|
!bot/pom.xml
|
||||||
|
!migration/src/
|
||||||
|
!migration/pom.xml
|
||||||
|
!web/src/
|
||||||
|
!web/pom.xml
|
||||||
|
!pom.xml
|
||||||
|
web/src/ui/node_modules
|
||||||
|
web/src/ui/node
|
||||||
|
web/src/ui/dist
|
|
@ -1,13 +0,0 @@
|
||||||
*
|
|
||||||
!src/
|
|
||||||
!pom.xml
|
|
||||||
!ui/package*.json
|
|
||||||
!ui/postcss.config.js
|
|
||||||
!ui/tailwind.config.js
|
|
||||||
!ui/env.d..ts
|
|
||||||
!ui/vite.config.ts
|
|
||||||
!ui/tsconfig.json
|
|
||||||
!ui/tsconfig.node.json
|
|
||||||
!ui/index.html
|
|
||||||
!ui/public/
|
|
||||||
!ui/src/
|
|
43
Containerfile
Normal file
43
Containerfile
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Stage 1: Build bot
|
||||||
|
FROM docker.io/maven:3.9-eclipse-temurin-19 AS maven
|
||||||
|
WORKDIR /app
|
||||||
|
# Copy the dependency specifications
|
||||||
|
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 mvn -pl db -am dependency:go-offline
|
||||||
|
# Install the shared libraries in the local Maven repo (`.m2`)
|
||||||
|
# This will also install the `root` module.
|
||||||
|
COPY db db
|
||||||
|
RUN mvn -pl db -am install
|
||||||
|
# Resolve dependencies for modules without dependencies to each other
|
||||||
|
RUN mvn dependency:go-offline
|
||||||
|
# Build modules
|
||||||
|
COPY web web
|
||||||
|
RUN mvn -pl web package
|
||||||
|
COPY bot bot
|
||||||
|
RUN mvn -pl bot package
|
||||||
|
COPY migration migration
|
||||||
|
RUN mvn -pl migration package
|
||||||
|
|
||||||
|
# Stage 2: Create final web
|
||||||
|
FROM docker.io/eclipse-temurin:19-jdk-alpine AS web
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=maven /app/web/target/web-*-fat.jar /app/web.jar
|
||||||
|
EXPOSE 8080
|
||||||
|
CMD ["java", "-jar", "/app/web.jar"]
|
||||||
|
|
||||||
|
# Stage 2: Create final migration
|
||||||
|
FROM docker.io/eclipse-temurin:19-jdk-alpine AS migration
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=maven /app/migration/target/migration-*-fat.jar /app/migration.jar
|
||||||
|
CMD ["java", "-jar", "/app/migration.jar"]
|
||||||
|
|
||||||
|
# Stage 2: Create final bot
|
||||||
|
FROM docker.io/eclipse-temurin:19-jdk-alpine AS bot
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=maven /app/bot/target/bot-*-fat.jar /app/bot.jar
|
||||||
|
CMD ["java", "-jar", "/app/bot.jar"]
|
25
Dockerfile
25
Dockerfile
|
@ -1,25 +0,0 @@
|
||||||
# Stage 1: Build java application
|
|
||||||
FROM docker.io/maven:3.9-eclipse-temurin-19 AS maven
|
|
||||||
WORKDIR /app
|
|
||||||
COPY pom.xml .
|
|
||||||
RUN mvn dependency:go-offline
|
|
||||||
RUN mvn package
|
|
||||||
COPY src/ /app/src/
|
|
||||||
RUN mvn package
|
|
||||||
|
|
||||||
# Stage 2: Build vuejs application
|
|
||||||
FROM docker.io/node:18-slim AS vuejs
|
|
||||||
WORKDIR /app
|
|
||||||
COPY ./ui/package* .
|
|
||||||
RUN npm ci
|
|
||||||
COPY ./ui .
|
|
||||||
RUN npm run build-only
|
|
||||||
|
|
||||||
# Stage 3: Create the jlink app
|
|
||||||
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
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
CMD ["java", "--enable-preview", "-jar", "/app/dchat.jar"]
|
|
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>
|
39
build.sh
39
build.sh
|
@ -1,18 +1,16 @@
|
||||||
#!/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"
|
|
||||||
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"
|
build() {
|
||||||
|
CREATED=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
REVISION=$(git rev-parse HEAD)
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
IMAGE_LATEST="${REPO}:latest"
|
||||||
podman build \
|
# shellcheck disable=SC2086
|
||||||
|
podman build \
|
||||||
$DOCKER_BUILD_ARGS \
|
$DOCKER_BUILD_ARGS \
|
||||||
-t $IMAGE_LATEST \
|
-t $IMAGE_LATEST \
|
||||||
--label "org.opencontainers.image.revision=${REVISION}" \
|
--label "org.opencontainers.image.revision=${REVISION}" \
|
||||||
|
@ -25,7 +23,28 @@ podman build \
|
||||||
--label "org.opencontainers.image.description=${DESCRIPTION}" \
|
--label "org.opencontainers.image.description=${DESCRIPTION}" \
|
||||||
. || exit $?
|
. || exit $?
|
||||||
|
|
||||||
if [ "$PUSH_LATEST" == "1" ]; then
|
if [ "$PUSH_LATEST" == "1" ]; then
|
||||||
podman push "${IMAGE_LATEST}"
|
podman push "${IMAGE_LATEST}"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "start building bot"
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/bot"
|
||||||
|
TITLE="dchat-bot"
|
||||||
|
DESCRIPTION="A Discord bot to chat with ChatGPT from OpenAI"
|
||||||
|
DOCKER_BUILD_ARGS="--target bot"
|
||||||
|
build
|
||||||
|
|
||||||
|
echo "start building web"
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/web"
|
||||||
|
TITLE="dchat-web"
|
||||||
|
DESCRIPTION="A web API and UI for the dchat-bot configuration"
|
||||||
|
DOCKER_BUILD_ARGS="--target web"
|
||||||
|
build
|
||||||
|
|
||||||
|
echo "start building migration"
|
||||||
|
REPO="git.hhhammer.de/hamburghammer/dchat/migration"
|
||||||
|
TITLE="dchat-migration"
|
||||||
|
DESCRIPTION="A migration tool for the dchat database"
|
||||||
|
DOCKER_BUILD_ARGS="--target migration"
|
||||||
|
build
|
||||||
|
|
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>
|
145
pom.xml
145
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,40 +17,26 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- logging -->
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javacord</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>javacord</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>3.8.0</version>
|
|
||||||
<type>pom</type>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>2.15.0-rc2</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>annotations</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>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
@ -57,62 +46,82 @@
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.4.6</version>
|
<version>1.4.6</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>24.0.1</version>
|
<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>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
<build>
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>com.google.cloud.tools</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>jib-maven-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.3.2</version>
|
||||||
<configuration>
|
</plugin>
|
||||||
<compilerArgs>
|
|
||||||
<compilerArg>--enable-preview</compilerArg>
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
</compilerArgs>
|
<plugin>
|
||||||
</configuration>
|
<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>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.3</version>
|
<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>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
|
<modules>
|
||||||
|
<module>bot</module>
|
||||||
|
<module>db</module>
|
||||||
|
<module>web</module>
|
||||||
|
<module>migration</module>
|
||||||
|
</modules>
|
||||||
</project>
|
</project>
|
|
@ -1,12 +0,0 @@
|
||||||
*
|
|
||||||
!Caddyfile
|
|
||||||
!package*.json
|
|
||||||
!postcss.config.js
|
|
||||||
!tailwind.config.js
|
|
||||||
!env.d..ts
|
|
||||||
!vite.config.ts
|
|
||||||
!tsconfig.json
|
|
||||||
!tsconfig.node.json
|
|
||||||
!index.html
|
|
||||||
!public/
|
|
||||||
!src/
|
|
11
ui/Caddyfile
11
ui/Caddyfile
|
@ -1,11 +0,0 @@
|
||||||
{$SITE_ADDRESS} {
|
|
||||||
basicauth * {
|
|
||||||
{$AUTH_PASSWORD} {$AUTH_PASSWORD}
|
|
||||||
}
|
|
||||||
|
|
||||||
encode zstd gzip
|
|
||||||
|
|
||||||
root * /app
|
|
||||||
try_files {path} /index.html
|
|
||||||
file_server
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
FROM docker.io/node:18-slim AS build
|
|
||||||
WORKDIR /app
|
|
||||||
COPY ./package* .
|
|
||||||
RUN npm ci
|
|
||||||
COPY . .
|
|
||||||
RUN npm run build-only
|
|
||||||
|
|
||||||
FROM docker.io/caddy:2-alpine
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
COPY ./Caddyfile /
|
|
||||||
COPY --from=build /app/dist /app
|
|
||||||
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
CMD ["caddy", "run", "--config", "/Caddyfile"]
|
|
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