From 293705da7216f948a5b150d1c36bac15b3d4e0f4 Mon Sep 17 00:00:00 2001 From: Project_IO Date: Mon, 2 Sep 2024 17:50:54 +0900 Subject: [PATCH] docker: support docker compose --- .dockerfile | 45 +++++++++++++++++++++ .env.example | 1 + .gitignore | 3 ++ Dockerfile | 15 ++++--- build.gradle.kts | 4 +- compose.yml | 17 +++++++- src/main/java/net/projecttl/p/x32/Px32.java | 2 +- 7 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 .dockerfile create mode 100644 .env.example diff --git a/.dockerfile b/.dockerfile new file mode 100644 index 0000000..a0edd36 --- /dev/null +++ b/.dockerfile @@ -0,0 +1,45 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +.fleet/ +.kotlin/ + +.env +!.env.example + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..46ef8b6 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +BOT_TOKEN= diff --git a/.gitignore b/.gitignore index 16e7a3f..b0cafb2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ build/ .fleet/ .kotlin/ +.env +!.env.example + ### IntelliJ IDEA ### .idea/ *.iws diff --git a/Dockerfile b/Dockerfile index ae2ff46..3afbdd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,17 @@ -FROM ghcr.io/graalvm/jdk:21 +FROM amazoncorretto:21-alpine3.20 -ARG TOKEN -ENV TOKEN=${TOKEN} +ARG BOT_TOKEN +ENV BOT_TOKEN=${BOT_TOKEN} -WORKDIR /opt/bot/src +WORKDIR /opt/bot/build COPY . . +RUN chmod a+x ./gradlew RUN ./gradlew shadowJar RUN cp ./build/libs/px32-bot.jar ../ -ENTRYPOINT ["BOT_TOKEN=${TOKEN}", "java", "-Xmx4096M", "-jar", "/opt/px32-bot.jar"] +WORKDIR /opt/bot +RUN rm -rf ./build +RUN export BOT_TOKEN=${BOT_TOKEN} + +ENTRYPOINT ["java", "-Xmx4096M", "-jar", "/opt/bot/px32-bot.jar"] diff --git a/build.gradle.kts b/build.gradle.kts index ee1cde0..ab3f554 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,8 +35,8 @@ dependencies { implementation("org.apache.logging.log4j:log4j-slf4j2-impl:$log4j_version") implementation("org.jetbrains.exposed:exposed-core:$exposed_version") implementation("org.jetbrains.exposed:exposed-jdbc:$exposed_version") - testImplementation(platform("org.junit:junit-bom:5.10.0")) - testImplementation("org.junit.jupiter:junit-jupiter") +// testImplementation(platform("org.junit:junit-bom:5.10.0")) +// testImplementation("org.junit.jupiter:junit-jupiter") } tasks { diff --git a/compose.yml b/compose.yml index e55704b..1a035ff 100644 --- a/compose.yml +++ b/compose.yml @@ -1,4 +1,17 @@ -version: "3.9" - services: + bot: + container_name: "P_x32-bot" + build: + context: . + dockerfile: "./Dockerfile" + env_file: + - ".env" + environment: + - BOT_TOKEN=${BOT_TOKEN} + networks: + - "bot" + volumes: + - "/etc/localtime:/etc/localtime:ro" + +networks: bot: {} diff --git a/src/main/java/net/projecttl/p/x32/Px32.java b/src/main/java/net/projecttl/p/x32/Px32.java index c09a8e6..7d6eb2e 100644 --- a/src/main/java/net/projecttl/p/x32/Px32.java +++ b/src/main/java/net/projecttl/p/x32/Px32.java @@ -18,7 +18,7 @@ public class Px32 { private void register() { commands.forEach(command -> { - jda.upsertCommand(command.getData()).queue(); + jda.updateCommands().addCommands(command.getData()).queue(); log.info("Registered command: {}", command.getData().getName()); }); }