Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Dockerfile for MusicBot hosting #1433

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.circleci
.github
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 12 additions & 8 deletions scripts/run_jmusicbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,38 @@

# 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}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding sane defaults for the script with overrides


# Sleep timer for backing off failures
SLEEP=${SLEEP:-"30"}

download() {
if [ $DOWNLOAD == true ]; then
if [ "$DOWNLOAD" = true ]; then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shellcheck changes

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
download
run
$LOOP
do
sleep "$SLEEP"
continue
done