Initial commit
This commit is contained in:
commit
2258a6bb5b
5 changed files with 116 additions and 0 deletions
1
.dockerignore
Normal file
1
.dockerignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Makefile
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
FROM ghcr.io/archlinux/archlinux:latest
|
||||||
|
LABEL org.opencontainers.image.authors="JeremyStarTM <jeremystartm@staropensource.de>"
|
||||||
|
|
||||||
|
RUN pacman -Syu --noconfirm jre17-openjdk jre11-openjdk jre8-openjdk
|
||||||
|
RUN mkdir /app
|
||||||
|
RUN useradd -U -m mcserver
|
||||||
|
ADD entrypoint.sh /app/entrypoint.sh
|
||||||
|
|
||||||
|
STOPSIGNAL SIGTERM
|
||||||
|
EXPOSE 25565 25565/tcp
|
||||||
|
USER mcserver:mcserver
|
||||||
|
ENTRYPOINT ["/sbin/bash", "/app/entrypoint.sh"]
|
14
Makefile
Normal file
14
Makefile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
.PHONY: dist help build test
|
||||||
|
|
||||||
|
dist: help
|
||||||
|
help:
|
||||||
|
@echo "make help [Displays help]"
|
||||||
|
@echo " build [Builds the docker image]"
|
||||||
|
@echo " test [Tests the docker image]"
|
||||||
|
@echo " clean [Cleans the docker build cache]"
|
||||||
|
build:
|
||||||
|
docker buildx build --progress tty --tag mcserverdocker:repobuild .
|
||||||
|
clean:
|
||||||
|
docker buildx prune --all --force
|
||||||
|
test:
|
||||||
|
docker run mcserverdocker:repobuild
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# MCServerDocker
|
||||||
|
Runs a Minecraft Server inside a docker container.
|
||||||
|
|
||||||
|
# Java Edition only
|
||||||
|
This only supports the true version of Minecraft, not that phone and console spinoff named "Bedrock Edition".
|
84
entrypoint.sh
Executable file
84
entrypoint.sh
Executable file
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/sbin/env bash
|
||||||
|
# Disables warning about echo not expanding escape sequences
|
||||||
|
# shellcheck disable=SC2028
|
||||||
|
|
||||||
|
function print_banner() {
|
||||||
|
echo " ____ ____ ____ __"
|
||||||
|
echo " /'\\_/\`\\/\\ _\`\\ /\\ _\`\\ /\\ _\`\\ /\\ \\"
|
||||||
|
echo "/\\ \\ \\ \\/\\_\\\\ \\,\\L\\_\\ __ _ __ __ __ __ _ __\\ \\ \\/\\ \\ ___ ___\\ \\ \\/'\\ __ _ __"
|
||||||
|
echo "\\ \\ \\__\\ \\ \\ \\/_/_\\/_\\__ \\ /'__\`\\/\\\`'__\\/\\ \\/\\ \\ /'__\`\\/\\\`'__\\ \\ \\ \\ \\ / __\`\\ /'___\\ \\ , < /'__\`\\/\\\`'__\\"
|
||||||
|
echo " \\ \\ \\_/\\ \\ \\ \\L\\ \\ /\\ \\L\\ \\/\\ __/\\ \\ \\/ \\ \\ \\_/ |/\\ __/\\ \\ \\/ \\ \\ \\_\\ \\/\\ \\L\\ \\/\\ \\__/\\ \\ \\\\\`\\ /\\ __/\\ \\ \\/"
|
||||||
|
echo " \\ \\_\\\\ \\_\\ \\____/ \\ \`\\____\\ \\____\\\\ \\_\\ \\ \\___/ \\ \\____\\\\ \\_\\ \\ \\____/\\ \\____/\\ \\____\\\\ \\_\\ \\_\\ \\____\\\\ \\_\\"
|
||||||
|
echo " \\/_/ \\/_/\\/___/ \\/_____/\\/____/ \\/_/ \\/__/ \\/____/ \\/_/ \\/___/ \\/___/ \\/____/ \\/_/\\/_/\\/____/ \\/_/"
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
echo ":: Initializing MCSD"
|
||||||
|
export "ARGS=--nogui "
|
||||||
|
if [ -z "${MCSD_ENFORCE_FRESH_CACHES}" ]; then
|
||||||
|
export "ARGS=${ARGS}--eraseCache "
|
||||||
|
fi
|
||||||
|
if [ -z "${MCSD_FORCE_UPGRADE}" ]; then
|
||||||
|
export "ARGS=${ARGS}--forceUpgrade "
|
||||||
|
fi
|
||||||
|
if [ -z "${MCSD_SAFEMODE}" ]; then
|
||||||
|
export "ARGS=${ARGS}--safeMode "
|
||||||
|
fi
|
||||||
|
if [ ! "${MCSD_AUTO_RESTART}" == "true" ] && [ ! "${MCSD_AUTO_RESTART}" == "false" ]; then
|
||||||
|
echo ":: Warning: No/Invalid auto restart value supplied, defaulting to false"
|
||||||
|
export "MCSD_AUTO_RESTART=false"
|
||||||
|
fi
|
||||||
|
if [ ! "${MCSD_JAVA_VERSION}" == "17" ] && [ ! "${MCSD_JAVA_VERSION}" == "11" ] && [ ! "${MCSD_JAVA_VERSION}" == "8" ]; then
|
||||||
|
echo ":: Warning: No/Invalid java version supplied, defaulting to java version 17"
|
||||||
|
export "MCSD_JAVA_VERSION=17"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
echo ":: Checking environment"
|
||||||
|
if [ ! -d "/data" ]; then
|
||||||
|
echo ":: Error: Could not locate /data directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -f "/data/server.jar" ]; then
|
||||||
|
echo ":: Error: Could not locate server.jar"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
echo ":: Starting server"
|
||||||
|
# We want to use ${ARGS} without using parenthesis
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
"/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" -jar "/data/server.jar" ${ARGS}
|
||||||
|
export "exitcode=${?}"
|
||||||
|
# yes it is assigned you idiot
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
if [ "${exitcode}" == "0" ]; then
|
||||||
|
echo ":: The server was shut down successfully"
|
||||||
|
else
|
||||||
|
echo ":: The server was forcefully shut down (code ${exitcode})"
|
||||||
|
fi
|
||||||
|
case "${MCSD_AUTO_RESTART}" in
|
||||||
|
"true")
|
||||||
|
echo ":: Restarting server after shutdown"
|
||||||
|
run
|
||||||
|
;;
|
||||||
|
"false")
|
||||||
|
echo ":: Ending execution"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo ":: An internal error occured (run function, can't decide MCSD_AUTO_RESTART)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
print_banner
|
||||||
|
initialize
|
||||||
|
check
|
||||||
|
run
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
Loading…
Reference in a new issue