Compare commits

...

1 commit

Author SHA1 Message Date
78dfaff61a WIP
Some checks failed
ci/woodpecker/push/java/1 Pipeline was successful
ci/woodpecker/push/java/2 Pipeline was successful
ci/woodpecker/push/java/3 Pipeline was successful
ci/woodpecker/push/java/4 Pipeline was successful
ci/woodpecker/push/java/5 Pipeline was successful
ci/woodpecker/push/nodejs Pipeline was successful
ci/woodpecker/push/oci-image-cache-build Pipeline was successful
ci/woodpecker/push/oci-image-build/1 Pipeline failed
ci/woodpecker/push/oci-image-build/2 Pipeline failed
ci/woodpecker/push/oci-image-build/3 Pipeline was successful
ci/woodpecker/push/oci-image-build/4 Pipeline was successful
ci/woodpecker/push/oci-image-build/5 Pipeline was successful
ci/woodpecker/push/cleanup unknown status
2024-03-26 23:51:26 +01:00
14 changed files with 49 additions and 269 deletions

View file

@ -9,6 +9,8 @@
!web/pom.xml
!monolith/src/
!monolith/pom.xml
!monolith/image.sh
!monolith/ListScript.java
!pom.xml
!ui/
ui/node_modules

View file

@ -8,22 +8,25 @@ FROM docker.io/maven:3.9-eclipse-temurin-21 AS setup-image
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/root/.m2/ \
mvn ${MAVEN_CLI_OPTS} package
mvn ${MAVEN_CLI_OPTS} install
RUN --mount=type=cache,target=/root/.m2/ \
mvn ${MAVEN_CLI_OPTS} dependency:copy-dependencies -DoutputDirectory=monolith/deps
FROM ${SETUP_IMAGE} as setup
FROM docker.io/maven:3.9-eclipse-temurin-21 AS custom-runtime
WORKDIR /app
COPY --from=setup /app .
WORKDIR /app/monolith
RUN ./image.sh
# Create final monolith
FROM docker.io/eclipse-temurin:21-jdk-jammy AS monolith
WORKDIR /app
COPY --from=custom-runtime /app/monolith/custom-runtime-image/ /app/custom-runtime-image/
COPY --from=custom-runtime /app/monolith/deps/ /app/deps/
COPY --from=setup /app/monolith/target/monolith-*-fat.jar /app/monolith.jar
CMD ["java", "-jar", "/app/monolith.jar"]
# Create final web
FROM docker.io/eclipse-temurin:21-jdk-jammy AS web
WORKDIR /app
COPY --from=setup /app/web/target/web-*-fat.jar /app/web.jar
EXPOSE 8080
CMD ["java", "-jar", "/app/web.jar"]
CMD ["/app/custom-runtime-image/bin/java", "-jar", "/app/monolith.jar"]
# Create final migration
FROM docker.io/eclipse-temurin:21-jdk-jammy AS migration
@ -31,12 +34,6 @@ WORKDIR /app
COPY --from=setup /app/migration/target/migration-*-fat.jar /app/migration.jar
CMD ["java", "-jar", "/app/migration.jar"]
# Create final bot
FROM docker.io/eclipse-temurin:21-jdk-jammy AS bot
WORKDIR /app
COPY --from=setup /app/bot/target/bot-*-fat.jar /app/bot.jar
CMD ["java", "-jar", "/app/bot.jar"]
# Build the ui
FROM docker.io/node:18-alpine AS ui-build
WORKDIR /ui

View file

@ -37,43 +37,4 @@
<artifactId>jackson-databind</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.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>

View file

@ -1,51 +0,0 @@
package de.hhhammer.dchat.bot;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.hhhammer.dchat.bot.openai.ChatGPTService;
import de.hhhammer.dchat.db.PostgresServerDBService;
import de.hhhammer.dchat.db.PostgresUserDBService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.http.HttpClient;
public final class App {
private static final Logger logger = LoggerFactory.getLogger(App.class);
public static void main(final 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 var chatGPTService = new ChatGPTService(openaiApiKey, HttpClient.newHttpClient(), new ObjectMapper());
final var config = new HikariConfig();
config.setJdbcUrl(postgresUrl);
config.setUsername(postgresUser);
config.setPassword(postgresPassword);
try (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);
discordBot.run();
}
}
}

View file

@ -1,13 +0,0 @@
<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>

View file

@ -24,8 +24,4 @@
<artifactId>jackson-annotations</artifactId>
</dependency>
</dependencies>
<build>
</build>
</project>

View file

@ -19,43 +19,4 @@
<scope>runtime</scope>
</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>

19
monolith/ListScript.java Normal file
View file

@ -0,0 +1,19 @@
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ListScript {
public static void main(String[] args) throws IOException {
var inputFile = new File("./aggregated-module-list.txt");
var inputPath = Paths.get(inputFile.toURI());
try (Stream<String> lineStream = Files.lines(inputPath)) {
String joinedLines = lineStream.map(String::trim).collect(Collectors.joining(","));
System.out.println(joinedLines);
var outputFile = new File("./comma-module-list.txt");
var outputPath = Paths.get(outputFile.toURI());
Files.write(outputPath, joinedLines.getBytes());
}
}
}

16
monolith/image.sh Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
#for jar in deps/*.jar; do
# jdeps --list-deps --ignore-missing-deps --multi-release 21 $jar >> module-list.txt
#done
#
#set -euo pipefail
#
#sort -u module-list.txt > aggregated-module-list.txt
#
#java ListScript.java
jdeps --print-module-deps --ignore-missing-deps --multi-release 21 -q --recursive -cp 'deps/*.jar' target/monolith-1.0-SNAPSHOT.jar > module-list.txt
jlink --module-path $JAVA_HOME/jmods:deps --add-modules $(cat module-list.txt) --output custom-runtime-image

View file

@ -51,14 +51,6 @@
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View file

@ -164,10 +164,6 @@
<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>

View file

@ -35,43 +35,4 @@
<artifactId>jackson-datatype-jsr310</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.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>
</plugins>
</build>
</project>

View file

@ -1,43 +0,0 @@
package de.hhhammer.dchat.web;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.hhhammer.dchat.db.PostgresServerDBService;
import de.hhhammer.dchat.db.PostgresUserDBService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hello world!
*/
public final class App {
private static final Logger logger = LoggerFactory.getLogger(App.class);
public static void main(final String[] args) {
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 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 appConfig = new AppConfig(apiPort, debug);
final var webApi = new WebAPI(serverDBService, userDBService, appConfig);
webApi.run();
}
}
}

View file

@ -1,14 +0,0 @@
<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"/>
<logger name="io.javalin.Javalin" level="INFO"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>