From 0dbe6f91fee37b4cdfc750bd8f312075d911c769 Mon Sep 17 00:00:00 2001 From: wooffet Date: Tue, 5 Oct 2021 17:20:22 +0100 Subject: [PATCH 1/5] Add updated dockerfiles and compose files Add working ubuntu:latest dockerfile and compose file Add WIP alpine:latest dockerfile and compose file Add alpine specific masterserver shell script Remove init section from Dockerfile and replace with a build step in each service definition - will be gotten from cache after first build Change line endings in gameserver.sh and masterserver.sh from CRLF to LF (not sure if this would break in containers that run on non-windows systems?) Add some additional logging to masterserver.sh Add windows client files to .gitignore --- .gitignore | 4 +- Dockerfile.alpine-latest | 18 +++++++ Dockerfile.ubuntu-latest | 17 +++++++ docker-compose.alpine-latest.yml | 49 +++++++++++++++++++ docker-compose.ubuntu-latest.yml | 47 ++++++++++++++++++ docker-compose.yml | 12 ++--- setup/masterserver-alpinelatest.sh | 76 ++++++++++++++++++++++++++++++ setup/masterserver.sh | 10 +++- 8 files changed, 225 insertions(+), 8 deletions(-) create mode 100644 Dockerfile.alpine-latest create mode 100644 Dockerfile.ubuntu-latest create mode 100644 docker-compose.alpine-latest.yml create mode 100644 docker-compose.ubuntu-latest.yml create mode 100644 setup/masterserver-alpinelatest.sh diff --git a/.gitignore b/.gitignore index 141ad0f..de8b83e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ pwn3.tar.gz server client -postgres-data \ No newline at end of file +postgres-data +PwnAdventure3_Windows.zip +**/windowsclient diff --git a/Dockerfile.alpine-latest b/Dockerfile.alpine-latest new file mode 100644 index 0000000..2833c87 --- /dev/null +++ b/Dockerfile.alpine-latest @@ -0,0 +1,18 @@ +# Use the latest alpine linux docker image as a base to start with a tiny image +FROM alpine:latest + +ENV PWN3=/opt/pwn3 + +RUN apk add --no-cache \ + openrc \ + bash \ + libssl1.0 \ + nano \ + postgresql \ + && adduser pwn3 --system --shell /bin/bash --group + +EXPOSE 5432 + +ADD --chown=pwn3 server/MasterServer/initdb.sql $PWN3/initdb.sql +ADD --chown=pwn3 setup $PWN3/setup + diff --git a/Dockerfile.ubuntu-latest b/Dockerfile.ubuntu-latest new file mode 100644 index 0000000..e812aa5 --- /dev/null +++ b/Dockerfile.ubuntu-latest @@ -0,0 +1,17 @@ +# Use the latest alpine linux docker image as a base to start with a tiny image +FROM ubuntu:latest + +ENV PWN3=/opt/pwn3 + +RUN echo "deb http://security.ubuntu.com/ubuntu xenial-security main" >> /etc/apt/sources.list \ + && apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y nano postgresql libssl1.0.0 \ + && apt-get clean \ + && rm -rf /var/lib/apt \ + && adduser pwn3 --system --shell /bin/bash --group + +EXPOSE 5432 + +ADD --chown=pwn3 server/MasterServer/initdb.sql $PWN3/initdb.sql +ADD --chown=pwn3 setup $PWN3/setup + diff --git a/docker-compose.alpine-latest.yml b/docker-compose.alpine-latest.yml new file mode 100644 index 0000000..8b5799b --- /dev/null +++ b/docker-compose.alpine-latest.yml @@ -0,0 +1,49 @@ +version: '3.4' +services: + master: + build: + context: . + dockerfile: ./Dockerfile.alpine-latest + image: pwn3server-alpinelatest + container_name: master-alpinelatest.pwn3 + hostname: master.pwn3 + networks: + default: + aliases: + - "master.pwn3" + ports: + - "3333:3333" + volumes: + - type: bind + source: "./server" + target: "/opt/pwn3/server" + - type: bind + source: "./client" + target: "/opt/pwn3/client" + - type: bind + source: "./postgres-data" + target: "/opt/pwn3/postgres-data" + command: "/opt/pwn3/setup/masterserver-alpinelatest.sh" + game: + build: + context: . + dockerfile: ./Dockerfile.alpine-latest + image: pwn3server-alpinelatest + container_name: game-alpinelatest.pwn3 + hostname: game.pwn3 + networks: + default: + aliases: + - "master.pwn3" + ports: + - "3000-3010:3000-3010" + volumes: + - type: bind + source: "./server" + target: "/opt/pwn3/server" + - type: bind + source: "./client" + target: "/opt/pwn3/client" + command: "/opt/pwn3/setup/gameserver.sh" + depends_on: + - master \ No newline at end of file diff --git a/docker-compose.ubuntu-latest.yml b/docker-compose.ubuntu-latest.yml new file mode 100644 index 0000000..38b4790 --- /dev/null +++ b/docker-compose.ubuntu-latest.yml @@ -0,0 +1,47 @@ +version: '3.2' +services: + master: + build: + context: . + dockerfile: ./Dockerfile.ubuntu-latest + image: pwn3server-ubuntulatest + hostname: master.pwn3 + networks: + default: + aliases: + - "master.pwn3" + ports: + - "3333:3333" + volumes: + - type: bind + source: "./server" + target: "/opt/pwn3/server" + - type: bind + source: "./client" + target: "/opt/pwn3/client" + - type: bind + source: "./postgres-data" + target: "/opt/pwn3/postgres-data" + command: "/opt/pwn3/setup/masterserver.sh" + game: + build: + context: . + dockerfile: ./Dockerfile.ubuntu-latest + image: pwn3server-ubuntulatest + hostname: game.pwn3 + networks: + default: + aliases: + - "master.pwn3" + ports: + - "3000-3010:3000-3010" + volumes: + - type: bind + source: "./server" + target: "/opt/pwn3/server" + - type: bind + source: "./client" + target: "/opt/pwn3/client" + command: "/opt/pwn3/setup/gameserver.sh" + depends_on: + - master \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 21cdd0f..2c02d45 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ version: '3.2' services: - init: - build: . - image: pwn3server master: + build: + context: . + dockerfile: ./Dockerfile image: pwn3server hostname: master.pwn3 networks: @@ -23,9 +23,10 @@ services: source: "./postgres-data" target: "/opt/pwn3/postgres-data" command: "/opt/pwn3/setup/masterserver.sh" - depends_on: - - init game: + build: + context: . + dockerfile: ./Dockerfile image: pwn3server hostname: game.pwn3 networks: @@ -43,5 +44,4 @@ services: target: "/opt/pwn3/client" command: "/opt/pwn3/setup/gameserver.sh" depends_on: - - init - master \ No newline at end of file diff --git a/setup/masterserver-alpinelatest.sh b/setup/masterserver-alpinelatest.sh new file mode 100644 index 0000000..492095e --- /dev/null +++ b/setup/masterserver-alpinelatest.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +_term() { + if [ -z "$child" ] + then + return 0 + fi + echo "Caught SIGTERM signal!" + trap - SIGTERM SIGKILL # clear the trap + # kill sounds mean, but -s is graceful + kill -s -TERM "$child" 2>/dev/null + su postgres -c "pg_dump --schema=public --format=plain --file=/opt/pwn3/postgres-data/data.sql master" + exit 0 +} + +echo "Setup process kill trap" +trap _term SIGTERM SIGKILL + +echo "Start postgresql service" +/etc/init.d/postgresql start +rc-update add postgresql + +echo "Sleep 10" +sleep 10 + +echo "Setup postgresql using template $PWN3/setup/postgres_init.sql" +su postgres -c "psql -f $PWN3/setup/postgres_init.sql -d template1" + +echo "Cleanup previous logs" +# clean up +su pwn3 -c "rm /opt/pwn3/client/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Saved/Logs/*" + +if [ -f /opt/pwn3/postgres-data/data.sql ]; then + echo "Found data, making a backup now!" + cp -p /opt/pwn3/postgres-data/data.sql /opt/pwn3/postgres-data/data.sql."$(date +%Y%m%d_%H%M%S)" + echo "Restoring backup data!" + su postgres -c "psql -U postgres --dbname master -1 --file /opt/pwn3/postgres-data/data.sql" +else + echo "No backup data found!" + su pwn3 -c "psql master -f $PWN3/initdb.sql" + su pwn3 -c "psql master -f $PWN3/setup/postgres_master.sql" + su pwn3 -c "cd /opt/pwn3/server/MasterServer/ && ./MasterServer --create-admin-team Admin" +fi + +echo "Cleanup previous server creds using $PWN3/setup/postgres_cleanup.sql" +# cleanup all previous/old server master creds +su pwn3 -c "psql master -f $PWN3/setup/postgres_cleanup.sql" + +echo "Setup new server creds" +# get new master server creds +su pwn3 -c "cd /opt/pwn3/server/MasterServer/ && ./MasterServer --create-server-account > /opt/pwn3/server/creds" + +echo "Write new server creds to server.ini" +# write the new creds to the server.ini +USER=$(cat /opt/pwn3/server/creds | grep 'Username:' | cut -d ":" -f 2- | xargs) +PW=$(cat /opt/pwn3/server/creds | grep 'Password:' | cut -d ":" -f 2- | xargs) +cat >/opt/pwn3/client/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Content/Server/server.ini < /opt/pwn3/server/creds" +echo "Write new server creds to server.ini" # write the new creds to the server.ini USER=$(cat /opt/pwn3/server/creds | grep 'Username:' | cut -d ":" -f 2- | xargs) PW=$(cat /opt/pwn3/server/creds | grep 'Password:' | cut -d ":" -f 2- | xargs) @@ -58,7 +66,7 @@ Password=$PW Instances=5 EOL - +echo "Run the server" # run the server su pwn3 -c "cd /opt/pwn3/server/MasterServer/ && ./MasterServer" & From c7f4cf831ed1621ed48054a4564e6e1edcc0319a Mon Sep 17 00:00:00 2001 From: wooffet Date: Tue, 5 Oct 2021 21:02:26 +0100 Subject: [PATCH 2/5] Remove alpine files Remove alpine files due to too many unavailable dependencies for gameserver --- Dockerfile.alpine-latest | 18 ------- docker-compose.alpine-latest.yml | 49 ------------------- setup/masterserver-alpinelatest.sh | 76 ------------------------------ 3 files changed, 143 deletions(-) delete mode 100644 Dockerfile.alpine-latest delete mode 100644 docker-compose.alpine-latest.yml delete mode 100644 setup/masterserver-alpinelatest.sh diff --git a/Dockerfile.alpine-latest b/Dockerfile.alpine-latest deleted file mode 100644 index 2833c87..0000000 --- a/Dockerfile.alpine-latest +++ /dev/null @@ -1,18 +0,0 @@ -# Use the latest alpine linux docker image as a base to start with a tiny image -FROM alpine:latest - -ENV PWN3=/opt/pwn3 - -RUN apk add --no-cache \ - openrc \ - bash \ - libssl1.0 \ - nano \ - postgresql \ - && adduser pwn3 --system --shell /bin/bash --group - -EXPOSE 5432 - -ADD --chown=pwn3 server/MasterServer/initdb.sql $PWN3/initdb.sql -ADD --chown=pwn3 setup $PWN3/setup - diff --git a/docker-compose.alpine-latest.yml b/docker-compose.alpine-latest.yml deleted file mode 100644 index 8b5799b..0000000 --- a/docker-compose.alpine-latest.yml +++ /dev/null @@ -1,49 +0,0 @@ -version: '3.4' -services: - master: - build: - context: . - dockerfile: ./Dockerfile.alpine-latest - image: pwn3server-alpinelatest - container_name: master-alpinelatest.pwn3 - hostname: master.pwn3 - networks: - default: - aliases: - - "master.pwn3" - ports: - - "3333:3333" - volumes: - - type: bind - source: "./server" - target: "/opt/pwn3/server" - - type: bind - source: "./client" - target: "/opt/pwn3/client" - - type: bind - source: "./postgres-data" - target: "/opt/pwn3/postgres-data" - command: "/opt/pwn3/setup/masterserver-alpinelatest.sh" - game: - build: - context: . - dockerfile: ./Dockerfile.alpine-latest - image: pwn3server-alpinelatest - container_name: game-alpinelatest.pwn3 - hostname: game.pwn3 - networks: - default: - aliases: - - "master.pwn3" - ports: - - "3000-3010:3000-3010" - volumes: - - type: bind - source: "./server" - target: "/opt/pwn3/server" - - type: bind - source: "./client" - target: "/opt/pwn3/client" - command: "/opt/pwn3/setup/gameserver.sh" - depends_on: - - master \ No newline at end of file diff --git a/setup/masterserver-alpinelatest.sh b/setup/masterserver-alpinelatest.sh deleted file mode 100644 index 492095e..0000000 --- a/setup/masterserver-alpinelatest.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -_term() { - if [ -z "$child" ] - then - return 0 - fi - echo "Caught SIGTERM signal!" - trap - SIGTERM SIGKILL # clear the trap - # kill sounds mean, but -s is graceful - kill -s -TERM "$child" 2>/dev/null - su postgres -c "pg_dump --schema=public --format=plain --file=/opt/pwn3/postgres-data/data.sql master" - exit 0 -} - -echo "Setup process kill trap" -trap _term SIGTERM SIGKILL - -echo "Start postgresql service" -/etc/init.d/postgresql start -rc-update add postgresql - -echo "Sleep 10" -sleep 10 - -echo "Setup postgresql using template $PWN3/setup/postgres_init.sql" -su postgres -c "psql -f $PWN3/setup/postgres_init.sql -d template1" - -echo "Cleanup previous logs" -# clean up -su pwn3 -c "rm /opt/pwn3/client/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Saved/Logs/*" - -if [ -f /opt/pwn3/postgres-data/data.sql ]; then - echo "Found data, making a backup now!" - cp -p /opt/pwn3/postgres-data/data.sql /opt/pwn3/postgres-data/data.sql."$(date +%Y%m%d_%H%M%S)" - echo "Restoring backup data!" - su postgres -c "psql -U postgres --dbname master -1 --file /opt/pwn3/postgres-data/data.sql" -else - echo "No backup data found!" - su pwn3 -c "psql master -f $PWN3/initdb.sql" - su pwn3 -c "psql master -f $PWN3/setup/postgres_master.sql" - su pwn3 -c "cd /opt/pwn3/server/MasterServer/ && ./MasterServer --create-admin-team Admin" -fi - -echo "Cleanup previous server creds using $PWN3/setup/postgres_cleanup.sql" -# cleanup all previous/old server master creds -su pwn3 -c "psql master -f $PWN3/setup/postgres_cleanup.sql" - -echo "Setup new server creds" -# get new master server creds -su pwn3 -c "cd /opt/pwn3/server/MasterServer/ && ./MasterServer --create-server-account > /opt/pwn3/server/creds" - -echo "Write new server creds to server.ini" -# write the new creds to the server.ini -USER=$(cat /opt/pwn3/server/creds | grep 'Username:' | cut -d ":" -f 2- | xargs) -PW=$(cat /opt/pwn3/server/creds | grep 'Password:' | cut -d ":" -f 2- | xargs) -cat >/opt/pwn3/client/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Content/Server/server.ini < Date: Tue, 5 Oct 2021 21:53:08 +0100 Subject: [PATCH 3/5] Update Dockerfile.ubuntu-latest Add vim back to dockerfile --- Dockerfile.ubuntu-latest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.ubuntu-latest b/Dockerfile.ubuntu-latest index e812aa5..c7a48f0 100644 --- a/Dockerfile.ubuntu-latest +++ b/Dockerfile.ubuntu-latest @@ -5,7 +5,7 @@ ENV PWN3=/opt/pwn3 RUN echo "deb http://security.ubuntu.com/ubuntu xenial-security main" >> /etc/apt/sources.list \ && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y nano postgresql libssl1.0.0 \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y nano vim postgresql libssl1.0.0 \ && apt-get clean \ && rm -rf /var/lib/apt \ && adduser pwn3 --system --shell /bin/bash --group From 9d2df8507e40c82fecbc2a829be868d60260b979 Mon Sep 17 00:00:00 2001 From: wooffet Date: Tue, 5 Oct 2021 22:00:08 +0100 Subject: [PATCH 4/5] Add newlines at end of files --- Dockerfile.ubuntu-latest | 1 - docker-compose.ubuntu-latest.yml | 2 +- docker-compose.yml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile.ubuntu-latest b/Dockerfile.ubuntu-latest index c7a48f0..a2a9538 100644 --- a/Dockerfile.ubuntu-latest +++ b/Dockerfile.ubuntu-latest @@ -14,4 +14,3 @@ EXPOSE 5432 ADD --chown=pwn3 server/MasterServer/initdb.sql $PWN3/initdb.sql ADD --chown=pwn3 setup $PWN3/setup - diff --git a/docker-compose.ubuntu-latest.yml b/docker-compose.ubuntu-latest.yml index 38b4790..0244168 100644 --- a/docker-compose.ubuntu-latest.yml +++ b/docker-compose.ubuntu-latest.yml @@ -44,4 +44,4 @@ services: target: "/opt/pwn3/client" command: "/opt/pwn3/setup/gameserver.sh" depends_on: - - master \ No newline at end of file + - master diff --git a/docker-compose.yml b/docker-compose.yml index 2c02d45..2be7192 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,4 +44,4 @@ services: target: "/opt/pwn3/client" command: "/opt/pwn3/setup/gameserver.sh" depends_on: - - master \ No newline at end of file + - master From 72042026ada3be089c2a634b46fad4e31265af59 Mon Sep 17 00:00:00 2001 From: wooffet Date: Tue, 5 Oct 2021 22:03:54 +0100 Subject: [PATCH 5/5] Update Dockerfile.ubuntu-latest --- Dockerfile.ubuntu-latest | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.ubuntu-latest b/Dockerfile.ubuntu-latest index a2a9538..8093e97 100644 --- a/Dockerfile.ubuntu-latest +++ b/Dockerfile.ubuntu-latest @@ -1,4 +1,3 @@ -# Use the latest alpine linux docker image as a base to start with a tiny image FROM ubuntu:latest ENV PWN3=/opt/pwn3