From dee24bb4accca1c2649749e2badd9584b61d3545 Mon Sep 17 00:00:00 2001 From: Charly Ghislain Date: Thu, 21 Feb 2019 15:17:28 +0000 Subject: [PATCH] Add dockerfile & docker-compose --- docker-compose.yml | 20 +++++++++++++ docker/Dockerfile | 38 ++++++++++++++++++++++++ docker/scripts/install-spads.sh | 47 ++++++++++++++++++++++++++++++ docker/scripts/run-spads.sh | 9 ++++++ docker/scripts/spads-entrypoint.sh | 15 ++++++++++ 5 files changed, 129 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile create mode 100644 docker/scripts/install-spads.sh create mode 100644 docker/scripts/run-spads.sh create mode 100644 docker/scripts/spads-entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f42c9ef --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.6' + +services: + + spads: + image: spads + environment: + - "SPADS_LOBBY_LOGIN=" + - "SPADS_LOBBY_PASSWORD=" + - "SPADS_OWNER_LOBBY_LOGIN=" + volumes: + - spads-config:/opt/spads/etc + - spads-data:/opt/spads/var + network_mode: host + restart: always + +volumes: + spads-config: {} + spads-data: {} + diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..18ded32 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,38 @@ +FROM ubuntu:rolling + +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install --no-install-recommends -y \ + curl \ + perl \ + swig \ + g++ \ + ca-certificates \ + libcurl4 \ + libsdl2-2.0-0 \ + net-tools \ + python \ + python-pycurl \ + && apt-get autoremove \ + && rm -rf /var/run/apt \ + && useradd -m spads \ + && chown -R spads /opt + + +COPY scripts/*.sh /opt/ +RUN mkdir -p /opt/spads \ + && cd /opt/spads \ + && curl -L -O http://planetspads.free.fr/spads/installer/spadsInstaller.tar \ + && tar -xvf spadsInstaller.tar \ + && chmod +x /opt/*.sh \ + && chown -R spads /opt/spads + +USER spads +WORKDIR /opt/spads/ + +RUN /opt/install-spads.sh + + +ENTRYPOINT [ "/opt/spads-entrypoint.sh" ] +CMD [ "/opt/run-spads.sh" ] + diff --git a/docker/scripts/install-spads.sh b/docker/scripts/install-spads.sh new file mode 100644 index 0000000..bdd4139 --- /dev/null +++ b/docker/scripts/install-spads.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# put build args in a file that will be fed to the installer which only accept values from STDIN + +# Which SPADS release do you want to install (stable,testing,unstable,contrib) [testing] +# Please choose the directory where SPADS configuration files will be stored [etc] +# Please choose the directory where SPADS dynamic data will be stored [var] ? +# Please choose the directory where SPADS will write the logs [log] ? +# Do you want to use official Spring binary files (auto-managed by SPADS), or a custom Spring installation already existing on the system? (official,custom) [official] ? +# Which Spring version do you want to use (104.0,104.0.1-1463-g9b63660,stable,testing,unstable,...) [104.0] +#Please enter the absolute path of the Spring data directory containing the games and maps hosted by the autohost, or press enter to use a new directory instead [new] ? +# Which game do you want to download to initialize the autohost "games" directory (ba,bac,evo,jauria,metalfactions,nota,phoenix,s44,swiw,tard,tc,techa,xta,zk,none) [ba] ? +# Do you want to download a minimal set of 3 maps to initialize the autohost "maps" directory (yes,no) [yes] ? +#Which type of server do you want to use ("headless" requires much more CPU/memory and doesn't support "ghost maps", but it allows running AI bots and LUA scripts on server side)? (dedicated,headless) [dedicated] ? +#Do you want to enable new game auto-detection to always host the latest version of the game available in your "games" and "packages" folders? (yes,no) [yes] ? +# Please enter the autohost lobby login (the lobby account must already exist) ? +# Please enter the autohost lobby password ? +# Please enter the lobby login of the autohost owner ? + +SPADS_RELEASE="${SPADS_RELEASE:-testing}" +SPADS_SPRING_FLAVOUR="${SPADS_SPRING_FLAVOUR:-official}" +SPADS_SPRING_VERSION="${SPADS_SPRING_VERSION:-maintenance}" + +cat << EOF > /tmp/spads-installer-args +$SPADS_RELEASE +etc +var +log +$SPADS_SPRING_FLAVOUR +stable +new +none +no +dedicated +%SPADS_LOBBY_LOGIN% +%SPADS_LOBBY_PASSWORD% +%SPADS_OWNER_LOBBY_LOGIN% +EOF + +perl ./spadsInstaller.pl < /tmp/spads-installer-args + +# autoManagedSpringVersion supports maintenance, but not the installer +sed -i "s/^autoManagedSpringVersion.*/autoManagedSpringVersion:$SPADS_SPRING_VERSION/" etc/spads.conf + + + + diff --git a/docker/scripts/run-spads.sh b/docker/scripts/run-spads.sh new file mode 100644 index 0000000..928ced1 --- /dev/null +++ b/docker/scripts/run-spads.sh @@ -0,0 +1,9 @@ +#!/bin/bash +pushd /opt/spads &>/dev/null + set -x + perl ./spads.pl etc/spads.conf \ + "SPADS_LOBBY_LOGIN=$SPADS_LOBBY_LOGIN" \ + "SPADS_LOBBY_PASSWORD=$SPADS_LOBBY_PASSWORD" \ + "SPADS_OWNER_LOBBY_LOGIN=$SPADS_OWNER_LOBBY_LOGIN" \ + $@ +popd &>/dev/null diff --git a/docker/scripts/spads-entrypoint.sh b/docker/scripts/spads-entrypoint.sh new file mode 100644 index 0000000..5875b58 --- /dev/null +++ b/docker/scripts/spads-entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +SPADS_LOBBY_LOGIN="${SPADS_LOBBY_LOGIN:-}" +SPADS_LOBBY_PASSWORD="${SPADS_LOBBY_PASSWORD:-}" +SPADS_LOBBY_PASSWORD_FILE="${SPADS_LOBBY_PASSWORD_FILE:-}" +SPADS_OWNER_LOBBY_LOGIN="${SPADS_OWNER_LOBBY_LOGIN:-}" + +[[ -z "$SPADS_LOBBY_PASSWORD" && -f "$SPADS_LOBBY_PASSWORD_FILE" ]] && SPADS_LOBBY_PASSWORD="$(head -n 1 $SPADS_LOBBY_PASSWORD_FILE)" + +[ -z "$SPADS_LOBBY_LOGIN" ] && echo "WARN: SPADS_LOBBY_LOGIN missing" +[ -z "$SPADS_LOBBY_PASSWORD" ] && echo "WARN: SPADS_LOBBY_PĂ„SSWORD missing" +[ -z "$SPADS_OWNER_LOBBY_LOGIN" ] && echo "WARN: SPADS_OWNER_LOBBY_LOGIN missing" + +exec $@ +