From 6b5acdb1bc84118580b58a7ae257a2d2a6b1c798 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Fri, 14 Apr 2023 23:13:24 +0200 Subject: [PATCH] feat: added dockerfile, added docker for readme, fixed folders for docker Signed-off-by: limited_dev --- README.md | 6 +++++ build.gradle.kts | 9 ++++++-- dockerfile | 15 ++++++++++++ .../botendo/util/CredentialManager.kt | 23 +++++++++++++++---- src/main/resources/simplelogger.properties | 2 -- 5 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 dockerfile diff --git a/README.md b/README.md index 951962a..53a1da5 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,9 @@ A Discord music bot, written in Kotlin using the kord library. Install IntellJ and import the project from git. Done. + +## Docker commands 4 me + +- docker run -it -m 2g -v/home/limited_dev/Documents/Code/Botendo/run/data/:/data/:rw limiteddev/botendo:x.x.x +- docker build -t limiteddev/botendo:x.x.x . +- docker push limiteddev/botendo:x.x.x diff --git a/build.gradle.kts b/build.gradle.kts index 1084309..73431e1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,7 +33,7 @@ val ownerID = 372703841151614976L group = "de.limited_dev.botendo" version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" } ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } - ?: "DevelopmentBuild" + ?: "6.1.0" val kordver = "1.5.6" val lavaver = "3.8.0" @@ -57,11 +57,16 @@ repositories { name = "Job-Token" value = System.getenv("CI_JOB_TOKEN") } - } else { + } else if (project.hasProperty("myGitlabToken")) { credentials(HttpHeaderCredentials::class) { name = "Private-Token" value = project.ext["myGitlabToken"] as String } + } else { + credentials(HttpHeaderCredentials::class) { + name = "none" + value = "" + } } } } diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..64da190 --- /dev/null +++ b/dockerfile @@ -0,0 +1,15 @@ +FROM openjdk:17-jdk-slim AS build + +WORKDIR /app + +ADD . /app + +RUN rm -rf /app/run + +RUN ./gradlew shadowJar + +FROM openjdk:17-jdk-slim AS run + +COPY --from=build /app/build/libs/*-all.jar app.jar + +CMD ["java", "-jar", "app.jar"] diff --git a/src/main/kotlin/de/limited_dev/botendo/util/CredentialManager.kt b/src/main/kotlin/de/limited_dev/botendo/util/CredentialManager.kt index 3ee45c8..d46b5ca 100644 --- a/src/main/kotlin/de/limited_dev/botendo/util/CredentialManager.kt +++ b/src/main/kotlin/de/limited_dev/botendo/util/CredentialManager.kt @@ -23,6 +23,7 @@ import java.io.* import java.util.* object CredentialManager { + private const val foldername = "data" private const val filename = "credentials.nils" var token: String = "empty" var linkip: String = "empty" @@ -30,13 +31,18 @@ object CredentialManager { ///Load the needed credentials, generate a config if there is none fun load() { - val configFile = File(filename) + val folder = File(foldername) + if (!folder.exists()) { + save() + return + } + val configFile = File(folder, filename) if (!configFile.exists()) { save() return } try { - val input: InputStream = FileInputStream(filename) + val input: InputStream = FileInputStream(foldername + File.separator + filename) val prop = Properties() prop.load(input) token = if (prop.getProperty("token").equals("empty")) "empty" else prop.getProperty("token") @@ -50,7 +56,15 @@ object CredentialManager { ///generate a new sample config private fun save() { - val configFile = File(filename) + val folder = File(foldername) + if (!folder.exists()) { + try { + folder.mkdirs() + } catch (e: IOException) { + e.printStackTrace() + } + } + val configFile = File(foldername + File.separator + filename) if (!configFile.exists()) { try { configFile.createNewFile() @@ -59,7 +73,7 @@ object CredentialManager { } } try { - val output: OutputStream = FileOutputStream(filename) + val output: OutputStream = FileOutputStream(foldername + File.separator + filename) val prop = Properties() prop.setProperty("token", "empty") prop.setProperty("lavaip", "empty") @@ -70,5 +84,4 @@ object CredentialManager { e.printStackTrace() } } - } diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties index 1a45d23..d92ae71 100644 --- a/src/main/resources/simplelogger.properties +++ b/src/main/resources/simplelogger.properties @@ -16,5 +16,3 @@ # along with this program. If not, see . # # -org.slf4j.simpleLogger.defaultLogLevel=trace -org.slf4j.simpleLogger.showDateTime=true