From ca16107fe4dafd726de4c5199ca77d9398308ab5 Mon Sep 17 00:00:00 2001 From: Juan Carlos Ramirez Date: Wed, 13 Sep 2023 23:12:28 -0500 Subject: [PATCH 1/2] Create Dockerfile for MusicBot hosting --- .dockerignore | 3 +++ Dockerfile | 14 ++++++++++++++ scripts/run_jmusicbot.sh | 20 ++++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..edf7afd3c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.circleci +.github \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..5013d699e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM maven:3.9.1-amazoncorretto-19-debian-bullseye + +WORKDIR /app + +# It would be better to build the codebase and package new docker images. +# TODO: Consider this approach and either delete this line or the maven lines +#COPY scripts/run_jmusicbot.sh /app/run_jmusicbot.sh + +COPY . . + +# TODO: We should include the version here, but today it's based off of github actions. +RUN mvn --batch-mode --update-snapshots verify && mv target/*-All.jar JMusicBot-latest.jar + +ENTRYPOINT ["/app/scripts/run_jmusicbot.sh"] \ No newline at end of file diff --git a/scripts/run_jmusicbot.sh b/scripts/run_jmusicbot.sh index 70a6874fe..cf8bb91c4 100644 --- a/scripts/run_jmusicbot.sh +++ b/scripts/run_jmusicbot.sh @@ -2,28 +2,31 @@ # This will have this script check for a new version of JMusicBot every # startup (and download it if the latest version isn't currently downloaded) -DOWNLOAD=true +DOWNLOAD=${DOWNLOAD:-false} # This will cause the script to run in a loop so that the bot auto-restarts # when you use the shutdown command -LOOP=true +LOOP=${LOOP:-false} + +# Sleep timer for backing off failures +SLEEP=${SLEEP:-"30"} download() { - if [ $DOWNLOAD == true ]; then + if [ "$DOWNLOAD" = true ]; then URL=$(curl -s https://api.github.com/repos/jagrosh/MusicBot/releases/latest \ - | grep -i browser_download_url.*\.jar \ + | grep -i "browser_download_url.*\.jar" \ | sed 's/.*\(http.*\)"/\1/') - FILENAME=$(echo $URL | sed 's/.*\/\([^\/]*\)/\1/') - if [ -f $FILENAME ]; then + FILENAME=$(echo "$URL" | sed 's/.*\/\([^\/]*\)/\1/') + if [ -f "$FILENAME" ]; then echo "Latest version already downloaded (${FILENAME})" else - curl -L $URL -o $FILENAME + curl -L "$URL" -o "$FILENAME" fi fi } run() { - java -Dnogui=true -jar $(ls -t JMusicBot* | head -1) + java -Dnogui=true -jar "$(ls -t JMusicBot* | head -1)" } while @@ -31,5 +34,6 @@ while run $LOOP do + sleep "$SLEEP" continue done From ac65b7e38786e036ff0dc19020b4ce0e714ec889 Mon Sep 17 00:00:00 2001 From: Juan Carlos Ramirez Date: Wed, 13 Mar 2024 10:45:10 -0500 Subject: [PATCH 2/2] Upgrade dockerfile to java 11 --- Dockerfile | 7 ++++--- scripts/run_jmusicbot.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5013d699e..ebc6ddc15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ -FROM maven:3.9.1-amazoncorretto-19-debian-bullseye +FROM maven:3.9.6-amazoncorretto-11 WORKDIR /app # It would be better to build the codebase and package new docker images. # TODO: Consider this approach and either delete this line or the maven lines -#COPY scripts/run_jmusicbot.sh /app/run_jmusicbot.sh +COPY scripts/run_jmusicbot.sh /app/run_jmusicbot.sh COPY . . # TODO: We should include the version here, but today it's based off of github actions. -RUN mvn --batch-mode --update-snapshots verify && mv target/*-All.jar JMusicBot-latest.jar +# Getting errors on build due to missing dependencies +#RUN mvn --batch-mode --update-snapshots verify && mv target/*-All.jar JMusicBot-latest.jar ENTRYPOINT ["/app/scripts/run_jmusicbot.sh"] \ No newline at end of file diff --git a/scripts/run_jmusicbot.sh b/scripts/run_jmusicbot.sh index cf8bb91c4..e79193407 100644 --- a/scripts/run_jmusicbot.sh +++ b/scripts/run_jmusicbot.sh @@ -2,7 +2,7 @@ # This will have this script check for a new version of JMusicBot every # startup (and download it if the latest version isn't currently downloaded) -DOWNLOAD=${DOWNLOAD:-false} +DOWNLOAD=${DOWNLOAD:-true} # This will cause the script to run in a loop so that the bot auto-restarts # when you use the shutdown command