-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from danthe1st/main
native-image compilation, disable member cache
- Loading branch information
Showing
29 changed files
with
604 additions
and
4,839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
FROM eclipse-temurin:21-jre | ||
RUN mkdir /work | ||
COPY build/libs/JavaBot-1.0.0-SNAPSHOT-all.jar /work/bot.jar | ||
FROM alpine:latest | ||
RUN apk add --no-cache libsm libxrender libxext libxtst libxi gcompat ttf-dejavu | ||
|
||
COPY build/native/nativeCompile /work | ||
WORKDIR /work | ||
|
||
RUN chown 1000:1000 /work | ||
USER 1000 | ||
ENV HOME=/work | ||
|
||
# https://github.com/openjdk/jdk/pull/20169 | ||
# need to create fake JAVA_HOME | ||
RUN mkdir -p /tmp/JAVA_HOME/conf/fonts | ||
RUN mkdir /tmp/JAVA_HOME/lib | ||
|
||
|
||
VOLUME "/work/config" | ||
VOLUME "/work/logs" | ||
VOLUME "/work/db" | ||
VOLUME "/work/purgeArchives" | ||
USER 1000 | ||
ENTRYPOINT [ "java", "-jar", "bot.jar" ] | ||
ENTRYPOINT [ "./javabot", "-Djava.home=/tmp/JAVA_HOME" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = "JavaBot" | ||
rootProject.name = "javabot" | ||
|
78 changes: 78 additions & 0 deletions
78
src/main/java/net/discordjug/javabot/RuntimeHintsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package net.discordjug.javabot; | ||
|
||
import java.nio.channels.Channel; | ||
|
||
import club.minnced.discord.webhook.send.WebhookEmbed; | ||
import net.discordjug.javabot.data.config.BotConfig; | ||
import net.discordjug.javabot.data.config.GuildConfig; | ||
import net.discordjug.javabot.data.config.GuildConfigItem; | ||
import net.discordjug.javabot.data.config.SystemsConfig; | ||
import net.discordjug.javabot.data.config.SystemsConfig.ApiConfig; | ||
import net.discordjug.javabot.data.config.guild.HelpConfig; | ||
import net.discordjug.javabot.data.config.guild.MessageCacheConfig; | ||
import net.discordjug.javabot.data.config.guild.MetricsConfig; | ||
import net.discordjug.javabot.data.config.guild.ModerationConfig; | ||
import net.discordjug.javabot.data.config.guild.QOTWConfig; | ||
import net.discordjug.javabot.data.config.guild.ServerLockConfig; | ||
import net.discordjug.javabot.data.config.guild.StarboardConfig; | ||
import net.dv8tion.jda.api.entities.Guild; | ||
import net.dv8tion.jda.api.entities.Member; | ||
import net.dv8tion.jda.api.entities.Role; | ||
import net.dv8tion.jda.api.entities.ScheduledEvent; | ||
import net.dv8tion.jda.api.entities.ThreadMember; | ||
import net.dv8tion.jda.api.entities.User; | ||
import net.dv8tion.jda.api.entities.channel.forums.ForumTag; | ||
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji; | ||
import net.dv8tion.jda.api.entities.sticker.GuildSticker; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import net.dv8tion.jda.api.managers.AudioManager; | ||
import net.dv8tion.jda.internal.entities.MemberPresenceImpl; | ||
import net.dv8tion.jda.internal.requests.restaction.PermOverrideData; | ||
import org.h2.server.TcpServer; | ||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportRuntimeHints; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
/** | ||
* Configure classes and resources to be accessible from native-image. | ||
*/ | ||
@Configuration | ||
@ImportRuntimeHints(RuntimeHintsConfiguration.class) | ||
@RegisterReflectionForBinding({ | ||
//register config classes for reflection | ||
BotConfig.class, GuildConfig.class, GuildConfigItem.class, SystemsConfig.class, ApiConfig.class, | ||
HelpConfig.class, MessageCacheConfig.class, MetricsConfig.class, ModerationConfig.class, QOTWConfig.class, ServerLockConfig.class, StarboardConfig.class, | ||
|
||
//ensure JDA can create necessary caches | ||
User[].class, Guild[].class, Member[].class, Role[].class, Channel[].class, AudioManager[].class, ScheduledEvent[].class, ThreadMember[].class, ForumTag[].class, RichCustomEmoji[].class, GuildSticker[].class, MemberPresenceImpl[].class, | ||
//needs to be serialized for channel managers etc | ||
PermOverrideData.class, | ||
//ensure that webhook embed authors can be serialized | ||
WebhookEmbed.EmbedAuthor.class | ||
}) | ||
public class RuntimeHintsConfiguration implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
|
||
//ensure resources are available in native-image | ||
hints.resources().registerPattern("assets/**"); | ||
hints.resources().registerPattern("database/**"); | ||
hints.resources().registerPattern("help_guidelines/**"); | ||
hints.resources().registerPattern("help_overview/**"); | ||
hints.resources().registerResource(new ClassPathResource("quartz.properties")); | ||
|
||
//allow H2 to create the TCP server (necessary for starting the DB) | ||
hints.reflection().registerType(TcpServer.class, MemberCategory.INVOKE_PUBLIC_METHODS); | ||
|
||
// JDA needs to be able to access listener methods | ||
hints.reflection().registerType(ListenerAdapter.class, MemberCategory.INVOKE_PUBLIC_METHODS); | ||
|
||
// caffeine | ||
hints.reflection().registerTypeIfPresent(getClass().getClassLoader(), "com.github.benmanes.caffeine.cache.SSW", MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.