diff --git a/gmod/Dockerfile b/Dockerfile similarity index 56% rename from gmod/Dockerfile rename to Dockerfile index 0ebf797..5f83f34 100644 --- a/gmod/Dockerfile +++ b/Dockerfile @@ -1,6 +1,73 @@ -ARG SUFFIX="" +FROM debian:buster-slim as lgsm -FROM jusito/docker-ttt:lgsm_debian${SUFFIX} +# Const \\ Overwrite Env \\ Configs possible \\ Configs needed +# C.UTF-8 -> en_US.UTF-8 +ENV STEAM_PATH="/home/steam" \ + SERVER_PATH="/home/steam/serverfiles" \ + STEAM_CMD="/home/steam/.steam/steamcmd" \ + GROUP_ID=10000 \ + USER_ID=10000 \ + DOCKER_USER=steam \ + SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.9/supercronic-linux-amd64 \ + SUPERCRONIC=supercronic-linux-amd64 \ + SUPERCRONIC_SHA1SUM=5ddf8ea26b56d4a7ff6faecdd8966610d5cb9d85 \ + \ + \ + DEBIAN_FRONTEND=noninteractive \ + LANG=C.UTF-8 \ + TERM=xterm \ + \ + \ + DEBUGGING=false \ + CRON_MONITOR="*/5 * * * *" \ + CRON_UPDATE="*/30 * * * *" \ + CRON_FORCE_UPDATE="0 10 * * 0" \ + CRON_LOG_ROTATE="0 0 * * 0" \ + \ + \ + SERVER_EXECUTABLE="" \ + SERVER_GAME="" \ + TZ="Europe/Berlin" +#https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + +ENTRYPOINT ["./home/entrypoint.sh"] + +#WORKDIR "$STEAM_PATH" + +COPY ["lgsm/entrypoint.sh", "lgsm/initCron.sh", "lgsm/createAlias.sh", "/home/"] + +# procps needed for ps command +# iproute2 needed because of "-slim" +RUN dpkg --add-architecture i386 && \ + apt-get update -y && \ + apt-get install -y mailutils postfix curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates \ + binutils bc jq tmux lib32gcc1 libstdc++6 lib32stdc++6 libtinfo5:i386 netcat libsdl2-2.0-0:i386 \ + procps iproute2 && \ + \ + groupadd -g $GROUP_ID $DOCKER_USER && \ + useradd -d "$STEAM_PATH" -g $GROUP_ID -u $USER_ID -m $DOCKER_USER && \ + chown "$DOCKER_USER:$DOCKER_USER" /home/entrypoint.sh && \ + chown "$DOCKER_USER:$DOCKER_USER" /home/initCron.sh && \ + mkdir -p "$SERVER_PATH" && \ + chown -R "$DOCKER_USER:$DOCKER_USER" "$STEAM_PATH" && \ + chmod a=rx /home/entrypoint.sh && \ + chmod a=rx /home/initCron.sh && \ + chmod a=rx /home/createAlias.sh && \ + \ + ulimit -n 2048 && \ + \ + wget -O "$STEAM_PATH/linuxgsm.sh" "https://linuxgsm.sh" && \ + chown "$DOCKER_USER:$DOCKER_USER" "$STEAM_PATH/linuxgsm.sh" && \ + chmod +x "$STEAM_PATH/linuxgsm.sh" && \ + \ + \ + wget -O "${SUPERCRONIC}" "$SUPERCRONIC_URL" && \ + echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - && \ + chmod +x "$SUPERCRONIC" && \ + mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" && \ + ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic + +FROM lgsm as gmod # Const \\ Overwrite Env \\ Configs optional ENV CSS_PATH="/home/steam/addons/css" \ @@ -74,7 +141,7 @@ ENV CSS_PATH="/home/steam/addons/css" \ USE_MY_REPLACER_CONFIG=false -COPY ["prepareServer.sh", "initConfig.sh", "forceWorkshopDownload.sh", "installAndMountAddons.sh", "common.cfg", "/home/"] +COPY ["gmod/prepareServer.sh", "gmod/initConfig.sh", "gmod/forceWorkshopDownload.sh", "gmod/installAndMountAddons.sh", "gmod/common.cfg", "/home/"] RUN chown "$DOCKER_USER:$DOCKER_USER" /home/prepareServer.sh && \ chown "$DOCKER_USER:$DOCKER_USER" /home/initConfig.sh && \ @@ -100,3 +167,13 @@ RUN chown "$DOCKER_USER:$DOCKER_USER" /home/prepareServer.sh && \ /home/createAlias.sh "update" '/home/steam/gmodserver update' && \ /home/createAlias.sh "update-lgsm" '/home/steam/gmodserver update-lgsm' && \ /home/createAlias.sh "validate" '/home/steam/gmodserver validate' + +FROM gmod as TTT + +ENV SERVER_GAMEMODE="terrortown" + +COPY "TTT/server.cfg.default" "/home/server.cfg.default" + +USER "$USER_ID:$GROUP_ID" + +VOLUME "$SERVER_PATH" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dd32e90 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +volumes: + TTTDev: + +services: + ttt: + build: . + ports: + - 27015:27015/tcp + - 27015:27015/udp + environment: + INSTALL_CSS: "true" + SERVER_DEFAULT_MAP: ttt_lttp_kakariko_a4 + SERVER_PORT: 27015 + SERVER_NAME: "Example Name" + SERVER_PASSWORD: securePassword + SERVER_VOICE_ENABLE: 0 + SERVER_MAX_PLAYERS: 20 + SERVER_RCON_PASSWORD: securePassword + WORKSHOP_COLLECTION_ID: 1895900191 + volumes: + - TTTDev:/home/steam/serverfiles diff --git a/hooks/pre_push b/hooks/pre_push new file mode 100644 index 0000000..50918a5 --- /dev/null +++ b/hooks/pre_push @@ -0,0 +1,14 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +imageSuffix="" +if [ "$SOURCE_BRANCH" != "master" ]; then + imageSuffix="-$(echo "$SOURCE_BRANCH" | sed 's/\//-/g')" +fi + +echo "current directory:" +echo "$(pwd)" +ls -lA . +bash test/testBuild.sh "$imageSuffix" --skip-ttt --push diff --git a/lgsm/Dockerfile b/lgsm/Dockerfile deleted file mode 100644 index cd17247..0000000 --- a/lgsm/Dockerfile +++ /dev/null @@ -1,69 +0,0 @@ -FROM debian:buster-slim - -# Const \\ Overwrite Env \\ Configs possible \\ Configs needed -# C.UTF-8 -> en_US.UTF-8 -ENV STEAM_PATH="/home/steam" \ - SERVER_PATH="/home/steam/serverfiles" \ - STEAM_CMD="/home/steam/.steam/steamcmd" \ - GROUP_ID=10000 \ - USER_ID=10000 \ - DOCKER_USER=steam \ - SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.9/supercronic-linux-amd64 \ - SUPERCRONIC=supercronic-linux-amd64 \ - SUPERCRONIC_SHA1SUM=5ddf8ea26b56d4a7ff6faecdd8966610d5cb9d85 \ - \ - \ - DEBIAN_FRONTEND=noninteractive \ - LANG=C.UTF-8 \ - TERM=xterm \ - \ - \ - DEBUGGING=false \ - CRON_MONITOR="*/5 * * * *" \ - CRON_UPDATE="*/30 * * * *" \ - CRON_FORCE_UPDATE="0 10 * * 0" \ - CRON_LOG_ROTATE="0 0 * * 0" \ - \ - \ - SERVER_EXECUTABLE="" \ - SERVER_GAME="" \ - TZ="Europe/Berlin" -#https://en.wikipedia.org/wiki/List_of_tz_database_time_zones - -ENTRYPOINT ["./home/entrypoint.sh"] - -#WORKDIR "$STEAM_PATH" - -COPY ["entrypoint.sh", "initCron.sh", "createAlias.sh", "/home/"] - -# procps needed for ps command -# iproute2 needed because of "-slim" -RUN dpkg --add-architecture i386 && \ - apt-get update -y && \ - apt-get install -y mailutils postfix curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates \ - binutils bc jq tmux lib32gcc1 libstdc++6 lib32stdc++6 libtinfo5:i386 netcat \ - procps iproute2 && \ - \ - groupadd -g $GROUP_ID $DOCKER_USER && \ - useradd -d "$STEAM_PATH" -g $GROUP_ID -u $USER_ID -m $DOCKER_USER && \ - chown "$DOCKER_USER:$DOCKER_USER" /home/entrypoint.sh && \ - chown "$DOCKER_USER:$DOCKER_USER" /home/initCron.sh && \ - mkdir -p "$SERVER_PATH" && \ - chown -R "$DOCKER_USER:$DOCKER_USER" "$STEAM_PATH" && \ - chmod a=rx /home/entrypoint.sh && \ - chmod a=rx /home/initCron.sh && \ - chmod a=rx /home/createAlias.sh && \ - \ - ulimit -n 2048 && \ - \ - wget -O "$STEAM_PATH/linuxgsm.sh" "https://linuxgsm.sh" && \ - chown "$DOCKER_USER:$DOCKER_USER" "$STEAM_PATH/linuxgsm.sh" && \ - chmod +x "$STEAM_PATH/linuxgsm.sh" && \ - \ - \ - wget -O "${SUPERCRONIC}" "$SUPERCRONIC_URL" && \ - echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - && \ - chmod +x "$SUPERCRONIC" && \ - mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" && \ - ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic - diff --git a/lgsm/entrypoint.sh b/lgsm/entrypoint.sh index 1d3ae57..68f67ce 100644 --- a/lgsm/entrypoint.sh +++ b/lgsm/entrypoint.sh @@ -18,7 +18,7 @@ set -e # --- Install / Update --- cd "$STEAM_PATH" -if [ -n "$SERVER_EXECUTABLE" ] && [ -e "${STEAM_PATH}/$SERVER_EXECUTABLE" ]; then +if [ -n "$SERVER_EXECUTABLE" ] && [ -e "${STEAM_PATH}/$SERVER_EXECUTABLE" ] && [ -d "$STEAM_CMD" ]; then echo "[entrypoint.sh]updating..." ./"$SERVER_EXECUTABLE" update-lgsm ./"$SERVER_EXECUTABLE" update diff --git a/lgsm/hooks/pre_push b/lgsm/hooks/pre_push deleted file mode 100644 index c274c60..0000000 --- a/lgsm/hooks/pre_push +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -o errexit -#set -o pipefail -set -o nounset - -imageSuffix="" -if [ "$SOURCE_BRANCH" != "master" ]; then - imageSuffix="-$(echo "$SOURCE_BRANCH" | sed 's/\//-/g')" -fi - -#docker build -t "$DOCKER_REPO:lgsm_debian${imageSuffix}" "lgsm/" -cd .. - -bash test/testBuild.sh "$imageSuffix" true - -docker push "$DOCKER_REPO:gmod_debian${imageSuffix}" -docker push "$DOCKER_REPO:gmod_ttt_debian${imageSuffix}" -docker push "$DOCKER_REPO:latest${imageSuffix}" diff --git a/test/testBuild.sh b/test/testBuild.sh index e813ebd..9df967f 100644 --- a/test/testBuild.sh +++ b/test/testBuild.sh @@ -1,7 +1,9 @@ #!/bin/bash readonly SUFFIX="$1" -readonly SKIP_LGSM="$2" +readonly BUILD_TTT="$(grep -qF -e '--skip-ttt' <<< "$@" && echo false || echo true)" +readonly PUSH="$(grep -qF -e '--push' <<< "$@" && echo true || echo false)" +readonly repository="${DOCKER_REPO:-jusito/docker-ttt}" if [ "${DEBUGGING}" = "true" ]; then set -o xtrace @@ -13,18 +15,30 @@ set -o errexit set -o nounset set -o pipefail -echo "[testBuild][INFO]build" +function process() { + tag_prefix="$1" + target="$2" + cache_option="$(grep -qF -e '--no-cache' <<< "$@" && echo "--no-cache" || echo "")" -if [ "$SKIP_LGSM" = true ]; then - docker rmi "jusito/docker-ttt:lgsm_debian${SUFFIX}" || true - docker build --no-cache -t "jusito/docker-ttt:lgsm_debian${SUFFIX}" "lgsm/" + docker rmi "$repository:$tag_prefix${SUFFIX}" || true + docker build --target "$target" $cache_option -t "$repository:$tag_prefix${SUFFIX}" . + if "$PUSH"; then + docker push "$repository:$tag_prefix${SUFFIX}" + fi +} + +echo "[testBuild][INFO] build" + +process "lgsm_debian" "lgsm" --no-cache +process "gmod_debian" "gmod" +if "$BUILD_TTT"; then + process "gmod_ttt_debian" "TTT" fi -docker rmi "jusito/docker-ttt:gmod_debian${SUFFIX}" || true -docker build --no-cache -t "jusito/docker-ttt:gmod_debian${SUFFIX}" "gmod/" +docker rmi "$repository:latest${SUFFIX}" || true +docker tag "$repository:gmod_ttt_debian${SUFFIX}" "$repository:latest${SUFFIX}" +if "$PUSH"; then + docker push "$repository:latest${SUFFIX}" +fi -docker rmi "jusito/docker-ttt:gmod_ttt_debian${SUFFIX}" || true -docker build --no-cache -t "jusito/docker-ttt:gmod_ttt_debian${SUFFIX}" "TTT/" - -docker rmi "$DOCKER_REPO:latest${SUFFIX}" || true -docker tag "$DOCKER_REPO:gmod_ttt_debian${SUFFIX}" "$DOCKER_REPO:latest${SUFFIX}" \ No newline at end of file +echo "[testBuild][INFO] build done!"