From e835aadd0611a2d18b4a64f3a34dd205b36cd9c2 Mon Sep 17 00:00:00 2001 From: Hendrik Boll Date: Sat, 11 May 2019 16:09:58 +0200 Subject: [PATCH] Update and testing on docker builds --- Dockerfile | 19 ++-- docker-compose.yml | 1 + entrypoint.sh | 86 +++++++++++++++++++ .../GameData/Tracks/MatchSettings/default.txt | 2 +- xaseco/dedimania.xml | 4 +- 5 files changed, 100 insertions(+), 12 deletions(-) create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0228b79..8d04de8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,17 @@ FROM fanyx/php:5.6 -COPY /tmserver:/opt/tmserver -COPY /xaseco:/opt/xaseco +COPY /tmserver /opt/tmserver +COPY /xaseco /opt/xaseco +COPY ./entrypoint.sh / RUN apt update \ - && groupadd trackmania \ - && useradd -M -g trackmania trackmania \ - && chown -R trackmania:trackmania /opt/tmserver \ - && chown -R trackmania:trackmania /opt/xaseco + && apt install pwgen +RUN groupadd trackmania +RUN useradd -M -g trackmania trackmania +RUN chown -R trackmania:trackmania /opt/tmserver +RUN chown -R trackmania:trackmania /opt/xaseco +RUN chown trackmania:trackmania /entrypoint.sh USER trackmania WORKDIR /opt/tmserver - -ENTRYPOINT ["./tmserver"] -CMD ["start", "tmserver"] +CMD ["/bin/bash", "/entrypoint.sh", "start", "tmserver"] diff --git a/docker-compose.yml b/docker-compose.yml index ffe3662..cf2c39e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,7 @@ version: '3' - SERVER_ADMIN_PASSWORD= - SERVER_NAME=Trackmania Server - SERVER_COMMENT=This is a Trackmania Server + - SERVER_PASSWORD= volumes: - /xaseco:/opt/xaseco - /tmserver:/opt/tmserver diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..4a5a71f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,86 @@ +#!/bin/bash +# + +set -e + +# Evaluate all the available environment variables +if [[ -z "${SERVER_LOGIN}" ]]; then + echo "Server account login is missing. Server cannot start." + exit 9 +fi +if [[ -z "${SERVER_LOGIN_PASSWORD}" ]]; then + echo "Server account password is missing. Server cannot start." + exit 9 +fi +if [[ -z "${DB_HOST}" ]]; then + echo "MySQL database host was not set. Defaulting to 'db' for the docker-compose configuration" + DB_HOST="db" +fi +if [[ -z "${DB_NAME}" ]]; then + echo "No database name was set. Defaulting to 'trackmania' for the docker-compose configuration" + DB_NAME="trackmania" +fi +if [[ -z "${DB_LOGIN}" ]]; then + echo "No database user was set. Defaulting to 'trackmania' for th docker-compose configuration" + DB_LOGIN="trackmania" +fi +if [[ -z "${DB_LOGIN_PASSWORD}" ]]; then + echo "No database user password was set. The server cannot connect to the database. Aborting" + exit 9 +fi +if [[ -z "${SERVER_PORT}" ]]; then + echo "No server port was set. Defaulting to port 2350" + SERVER_PORT="2350" +fi +if [[ -z "${SERVER_P2P_PORT}" ]]; then + echo "No server peer2peer port was set. Defaulting to port 3450" + SERVER_P2P_PORT="3450" +fi +if [[ -z "${SERVER_SA_PASSWORD}" ]]; then + echo "No SuperAdmin password was set. Generating a random one. You can change it afterwards but it's also not that important" + echo "Might aswell leave it as randomly generated" + SERVER_SA_PASSWORD=$(pwgen -s 12) + echo "SuperAdmin password: ${SERVER_SA_PASSWORD}" +fi +if [[ -z "${SERVER_ADM_PASSWORD}" ]]; then + echo "No Admin password was set. Generating a random one. You can change it afterwards but it's also not that important" + echo "Might aswell leave it as randomly generated" + SERVER_ADM_PASSWORD=$(pwgen -s 12) + echo "Admin password: ${SERVER_ADM_PASSWORD}" +fi +if [[ -z "${SERVER_NAME}" ]]; then + echo "No server name was set. Defaulting to 'Trackmania Server'" + SERVER_NAME="Trackmania Server" +fi +if [[ -z "${SERVER_COMMENT}" ]]; then + echo "No server description was set. Defaulting to 'This is a Trackmania Server'" + SERVER_COMMENT="This is a Trackmania Server" +fi + +# Evaluation over +# Commencing substition in config files + +#Xaseco files +cd /opt/xaseco + +sed -i -e "s/--\$SERVER_SA_PASSWORD--/\${SERVER_SA_PASSWORD}/" /opt/xaseco/config.xml + +sed -i -e "s/--\$DB_HOST--/\${DB_HOST}/" \ + -e "s/--\$DB_LOGIN--/\${DB_LOGIN}/" \ + -e "s/--\$DB_LOGIN_PASSWORD--/\${DB_LOGIN_PASSWORD}/" \ + -e "s/--\$DB_NAME--/\${DB_NAME}/" \ + /opt/xaseco/localdatabase.xml + +#Trackmania Files +cd /opt/tmserver + +sed -i -e "s/--\$SERVER_SA_PASSWORD--/\${SERVER_SA_PASSWORD}/" \ + -e "s/--\$SERVER_ADM_PASSWORD--\/${SERVER_ADM_PASSWORD}/" \ + -e "s/--\$SERVER_LOGIN--/\${SERVER_LOGIN}/" \ + -e "s/--\$SERVER_LOGIN_PASSWORD--/\${SERVER_LOGIN_PASSWORD}/" \ + -e "s/--\$SERVER_NAME--/\${SERVER_NAME}/" \ + -e "s/--\$SERVER_COMMENT--/\${SERVER_COMMENT}/" \ + -e "s/--\$SERVER_PASSWORD--/\${SERVER_PASSWORD}/" \ + -e "s/--\$SERVER_PORT--/\${SERVER_PORT}/" \ + -e "s/--\$SERVER_P2P_PORT--/\${SERVER_P2P_PORT}/" \ + /opt/tmserver/GameData/Config/default.txt diff --git a/tmserver/GameData/Tracks/MatchSettings/default.txt b/tmserver/GameData/Tracks/MatchSettings/default.txt index d552672..97627e8 100644 --- a/tmserver/GameData/Tracks/MatchSettings/default.txt +++ b/tmserver/GameData/Tracks/MatchSettings/default.txt @@ -32,7 +32,7 @@ - 1 + 0 1 0 0 diff --git a/xaseco/dedimania.xml b/xaseco/dedimania.xml index 3d41e56..ad07c4d 100644 --- a/xaseco/dedimania.xml +++ b/xaseco/dedimania.xml @@ -39,8 +39,8 @@ - --$SERVER_LOGIN-- - --$SERVER_LOGIN_PASSWORD-- + +