Dockerfile, docker-compose.yml and downloading of game in install.sh

This commit is contained in:
leca 2024-09-22 02:50:10 +03:00
parent 4b516a2b59
commit cc20da589e
6 changed files with 80 additions and 29 deletions

3
.env Normal file
View File

@ -0,0 +1,3 @@
SERVER_GAME="minetest"
SERVER_MODS="i3;animalia"
API_URL="https://content.minetest.net/api"

1
.gitignore vendored
View File

@ -1,2 +1 @@
data data
conf

View File

@ -1,5 +1,9 @@
FROM debian:12 FROM debian:12
ARG gameid
RUN echo "Building image with gameid: $gameid"
#Update #Update
RUN apt update -y && apt upgrade -y RUN apt update -y && apt upgrade -y
@ -19,29 +23,10 @@ USER root
WORKDIR /home/minetest/minetest-source/build WORKDIR /home/minetest/minetest-source/build
RUN make install RUN make install
#Install game & mods
#Planned to do script for game & mod installation
# USER minetest
# RUN mkdir /home/minetest/.minetest
# WORKDIR /home/minetest/.minetest
# RUN wget https://content.minetest.net/packages/Minetest/minetest_game/releases/27207/download/
# RUN mv index.html minetest_game.zip
# # RUN unzip minetest_game.zip
# # RUN rm minetest_game.zip
# USER root
# RUN mkdir -p /usr/local/share/minetest/games
# RUN mv /home/minetest/.minetest/minetest_game.zip /usr/local/share/minetest/games
# WORKDIR /usr/local/share/minetest/games
# RUN unzip minetest_game.zip
# RUN rm minetest_game.zip
RUN mkdir -p /usr/local/share/minetest/games RUN mkdir -p /usr/local/share/minetest/games
USER minetest USER minetest
EXPOSE 30000/udp EXPOSE 30000/udp
ENTRYPOINT ["/usr/local/bin/minetestserver", "--gameid", "minetest"] RUN echo "#!/bin/bash\n/usr/local/bin/minetestserver --gameid $gameid" > ./entrypoint.sh
# USER root RUN chmod +x entrypoint.sh
# ENTRYPOINT ["/bin/bash"] ENTRYPOINT ["./entrypoint.sh"]

View File

@ -1,10 +1,15 @@
services: services:
minetest_server: minetest_server:
build: . environment:
- SERVER_GAME
build:
context: .
args:
gameid: ${SERVER_GAME}
restart: always restart: always
network_mode: host network_mode: host
volumes: volumes:
- ./data:/use/local/share/minetest - ./data/games:/usr/local/share/minetest/games
ports: ports:
- "30000:30000/udp" - "30000:30000/udp"
- "127.0.0.1:30000:30000/tcp" - "127.0.0.1:30000:30000/tcp"

View File

@ -1,3 +1,64 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo 1 source ./server.env
# 1 = json of the game
download_and_install_game() {
download_url=$(echo "${1}" | jq ".url" | tr -d '"')
cd games
wget -O game.zip "${download_url}"
unzip game.zip
}
mkdir -p data/games
cd data
#Checking for input
if [[ $SERVER_MODS == "" || $SERVER_GAME == "" ]]; then
echo "Please, fill server.env file before launching this script!"
exit -1
fi
#Parsing mode names
oIFS="$IFS"
IFS=";"
SERVER_MODS=($SERVER_MODS)
IFS="$oIFS"
#Downloading game
results=$(curl --silent -X GET "$API_URL/packages/?type=game&q=$SERVER_GAME")
oIFS="$IFS"
IFS=$'\n'
authors=($(echo $results | jq '.[].author'))
IFS="$oIFS"
result_amount="${#authors[@]}"
for i in $(seq 0 $((${result_amount}-1))); do
author=$(echo $results | jq ".[${i}].author" | tr -d '"')
name=$(echo $results | jq ".[${i}].name" | tr -d '"')
desc=$(echo $results | jq ".[${i}].short_description" | tr -d '"')
echo "{${i}} [${author}] (${name}): ${desc}"
done
chosen=""
while [ true ]
do
read answer
chosen=$(echo $results | jq ".[${answer}]")
if [[ $chosen = null ]]; then
echo "Incorrect answer. Try again"
else
break
fi
done
chosen_author=$(echo $chosen | jq ".author" | tr -d '"')
chosen_packet_name=$(echo $chosen | jq ".name" | tr -d '"')
request_url="${API_URL}/packages/${chosen_author}/${chosen_packet_name}"
chosen=$(curl --silent -X GET $API_URL/packages/${chosen_author}/${chosen_packet_name}/)
download_and_install_game "${chosen}"

View File

@ -1,2 +0,0 @@
SERVER_GAME=""
SERVER_MODS=""