bta dockerfiles

This commit is contained in:
Patrick Kuhs 2025-02-22 09:04:36 +01:00
commit 238bd49a14
5 changed files with 164 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
server/

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
FROM alpine:latest
ENV MINECRAFT_VERSION= \
PAPER_BUILD="latest" \
EULA="false" \
MC_RAM=""
RUN apk update && \
apk add openjdk21-jre && \
apk add bash && \
apk add curl && \
apk add jq
RUN addgroup -S servergrp
RUN adduser -S server -G servergrp -D -u 1000
USER server
RUN mkdir /home/server/instance
#RUN chown -hR server:servergrp /home/server/instance
COPY setup.sh /home/server/
CMD ["bash", "/home/server/setup.sh"]
EXPOSE 25565
VOLUME /home/server/instance

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
build:
docker build -t bta-docker .
run: build
docker run -it --name bta bta-docker
test-env: build
docker run -it -e EULA="true" -e WHITELIST="true" -e SEED="123" -e MAX_PALYERS="1" -e DIFFICULTY="normal" -e GAMEMODE="survival" -e "MOTD"="Local Docker Test" -p 25565:25565 -p 8100:8100 --volume ./server:/home/server/instance:z --name bta bta-docker
clean:
docker rm bta
docker image rm bta-docker
rm -r ./server
mkdir ./server
cp bta.v7.3_01.server.jar ./server/server.jar
echo "Holzhakker" > ./server/whitelist.prep
echo "Holzhakker" > ./server/op.prep
debug:
docker run --rm -it --entrypoint bash --name bta-debug bta-docker

21
docker-compose.yml Normal file
View File

@ -0,0 +1,21 @@
version: "3"
services:
server:
image: bta-docker
container_name: YOUR_CONTAINER_NAME
restart: always
volumes:
- "YOUR_SERVER_LOCATION":/home/server/instance:z
ports:
- "YOUR_PORT:25565"
environment:
SERVER_MEMORY: "2G"
EULA: "true"
SEED: "abc"
# provide a txt file with the usernames of the players to be whitelisted in the server folder to automatically add them to the whitelist
WHITELIST: "true"
MAX_PLAYERS: "20"
# Difficulty settings: 0 - peaceful, 1 - easy, 2 - normal, 3 - hard
DIFFICULTY: "easy"
MOTD: "A Dockerized Minecraft Server"

94
setup.sh Executable file
View File

@ -0,0 +1,94 @@
#!/bin/bash
SERVER_DIR=/home/server/instance
cd $SERVER_DIR
# prepare performance opts for java
JAVA_OPTS=""
echo "eula=${EULA:-false}" > eula.txt
if [[ -n $SERVER_MEMORY ]]
then
JAVA_OPTS="-Xms${SERVER_MEMORY} -Xmx${SERVER_MEMORY} $JAVA_OPTS"
fi
SERVER_PROPERTIES=$SERVER_DIR/server.properties
SERVER_WHITELIST=$SERVER_DIR/white-list.txt
SERVER_OPLIST=$SERVER_DIR/ops.txt
WHITELIST_PREP=$SERVER_DIR/whitelist.prep
OPLIST_PREP=$SERVER_DIR/op.prep
if [ -f $SERVER_PROPERTIES ]; then
mv $SERVER_PROPERTIES $SERVER_PROPERTIES.bkp
rm $SERVER_PROPERTIES
touch $SERVER_PROPERTIES
fi
if [ -f $WHITELIST_PREP ]; then
echo -n "" > $SERVER_WHITELIST
cat $WHITELIST_PREP | while read u
do
echo "Adding $u to whitelist"
# get uuid of user
uuid=$(curl -s https://api.mojang.com/users/profiles/minecraft/$u | jq -r '.id')
uuid=$(echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}")
if [[ $uuid == "null" ]]; then
echo "User $u not found. Skipping."
continue
fi
# write to whitelist.json
echo "$uuid" >> $SERVER_WHITELIST;
done
fi
if [ -f $OPLIST_PREP ]; then
echo -n "" > $SERVER_OPLIST
cat $OPLIST_PREP | while read u
do
echo "Adding $u to whitelist"
# get uuid of user
uuid=$(curl -s https://api.mojang.com/users/profiles/minecraft/$u | jq -r '.id')
uuid=$(echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}")
if [[ $uuid == "null" ]]; then
echo "User $u not found. Skipping."
continue
fi
# write to whitelist.json
echo "$uuid" >> $SERVER_OPLIST;
done
fi
if [[ -n $WHITELIST ]]; then
echo "white-list=$WHITELIST" >> $SERVER_PROPERTIES
fi
if [[ -n $SEED ]]; then
echo "seed=$SEED" >> $SERVER_PROPERTIES
fi
if [[ -n $MAX_PLAYERS ]]; then
echo "max-players=$MAX_PLAYERS" >> $SERVER_PROPERTIES
fi
if [[ -n $DIFFICULTY ]]; then
echo "difficulty=$DIFFICULTY" >> $SERVER_PROPERTIES
fi
if [[ -n $MOTD ]]; then
echo "motd=$MOTD" >> $SERVER_PROPERTIES
fi
# Start server
exec java $JAVA_OPTS -jar "server.jar" nogui