feat: added dockerfile, added docker for readme, fixed folders for docker

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-04-14 23:13:24 +02:00
parent 2cc635d2d0
commit 6b5acdb1bc
5 changed files with 46 additions and 9 deletions

View file

@ -44,3 +44,9 @@ A Discord music bot, written in Kotlin using the kord library.
Install IntellJ and import the project from git. Install IntellJ and import the project from git.
Done. 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

View file

@ -33,7 +33,7 @@ val ownerID = 372703841151614976L
group = "de.limited_dev.botendo" group = "de.limited_dev.botendo"
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" } version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
?: "DevelopmentBuild" ?: "6.1.0"
val kordver = "1.5.6" val kordver = "1.5.6"
val lavaver = "3.8.0" val lavaver = "3.8.0"
@ -57,11 +57,16 @@ repositories {
name = "Job-Token" name = "Job-Token"
value = System.getenv("CI_JOB_TOKEN") value = System.getenv("CI_JOB_TOKEN")
} }
} else { } else if (project.hasProperty("myGitlabToken")) {
credentials(HttpHeaderCredentials::class) { credentials(HttpHeaderCredentials::class) {
name = "Private-Token" name = "Private-Token"
value = project.ext["myGitlabToken"] as String value = project.ext["myGitlabToken"] as String
} }
} else {
credentials(HttpHeaderCredentials::class) {
name = "none"
value = ""
}
} }
} }
} }

15
dockerfile Normal file
View file

@ -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"]

View file

@ -23,6 +23,7 @@ import java.io.*
import java.util.* import java.util.*
object CredentialManager { object CredentialManager {
private const val foldername = "data"
private const val filename = "credentials.nils" private const val filename = "credentials.nils"
var token: String = "empty" var token: String = "empty"
var linkip: String = "empty" var linkip: String = "empty"
@ -30,13 +31,18 @@ object CredentialManager {
///Load the needed credentials, generate a config if there is none ///Load the needed credentials, generate a config if there is none
fun load() { fun load() {
val configFile = File(filename) val folder = File(foldername)
if (!folder.exists()) {
save()
return
}
val configFile = File(folder, filename)
if (!configFile.exists()) { if (!configFile.exists()) {
save() save()
return return
} }
try { try {
val input: InputStream = FileInputStream(filename) val input: InputStream = FileInputStream(foldername + File.separator + filename)
val prop = Properties() val prop = Properties()
prop.load(input) prop.load(input)
token = if (prop.getProperty("token").equals("empty")) "empty" else prop.getProperty("token") token = if (prop.getProperty("token").equals("empty")) "empty" else prop.getProperty("token")
@ -50,7 +56,15 @@ object CredentialManager {
///generate a new sample config ///generate a new sample config
private fun save() { 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()) { if (!configFile.exists()) {
try { try {
configFile.createNewFile() configFile.createNewFile()
@ -59,7 +73,7 @@ object CredentialManager {
} }
} }
try { try {
val output: OutputStream = FileOutputStream(filename) val output: OutputStream = FileOutputStream(foldername + File.separator + filename)
val prop = Properties() val prop = Properties()
prop.setProperty("token", "empty") prop.setProperty("token", "empty")
prop.setProperty("lavaip", "empty") prop.setProperty("lavaip", "empty")
@ -70,5 +84,4 @@ object CredentialManager {
e.printStackTrace() e.printStackTrace()
} }
} }
} }

View file

@ -16,5 +16,3 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# #
# #
org.slf4j.simpleLogger.defaultLogLevel=trace
org.slf4j.simpleLogger.showDateTime=true