From bbcfe5e8a53a86d8ada9b440aaf28830e7c66932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VAN=20DER=20BIEST=20C=C3=A9lian?= Date: Mon, 20 Apr 2020 21:54:52 +0000 Subject: [PATCH 1/5] New readme to explain how to use PyPlanet in docker --- README.md | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0579336..a462d18 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,96 @@ -# Docker Compose for PyPlanet +# How to use [pyplanet/controller image](https://hub.docker.com/r/pyplanet/controller/) -## Installation +`docker run -d --name MySuperPyplanetController -e ... (available env variables below) pyplanet/controller` -... todo ... +## Environment Variables +------ + +### If you are using MySQL (or MariaDB, PerconaDB, etc). + +`MYSQL_DATABASE` ( default : pyplanet ) + +`MYSQL_HOST` + +`MYSQL_USER` ( default : pyplanet ) + +`MYSQL_PASSWORD` ( default : pyplanet ) + +### If you are using PostgreSQL. + +`POSTGRES_DB` ( default : pyplanet ) + +`POSTGRES_HOST` + +`POSTGRES_USER` ( default : pyplanet ) + +`POSTGRES_PASSWORD` ( default : pyplanet ) + + + +`MANIAPLANET_HOST` ( default : dedicated ) + +Address of the maniaplanet server. + +`MANIAPLANET_PORT` ( default : 5000 ) + +XML-RPC port. + +`MANIAPLANET_USER` ( default : SuperAdmin ) + +`MANIAPLANET_PASSWORD` ( default: SuperAdmin ) + +`MANIAPLANET_OWNER_LOGIN` + +The owner will get *ALL* the permissions in the system. + +# Docker Compose and PyPlanet + +This repository contain a docker-compose template that you can easily use and adapt according to your needs. +More templates will come in a near futur. + +### Full template + +This template provide a full setup, including Maniaplanet, PyPlanet, PHPMyAdmin, MariaDB and SFTP server. +Here is a litle schematic to describe the network : +``` + +--------+ + |NETWORKS| + +--------+ + +Back Network Front Network + + + + | | + | | + | +--------+ | + |----|PyPlanet| | + | +--------+ | + | | + | +-------+ | + 3306|----|MariaDB| | + | +-------+ | + | | + | +-----------+ | + 5000|----|Maniaplanet|---|2350,3450 + | +-----------+ | + | | + | +----------+ | + +----|PHPMyAdmin|----|8080 + +----------+ | + | + +----+ | + |SFTP|----+8022 + +----+ + +``` +This template use 4 named volumes : +* **maniaplanet** : Maniaplanet server folder. +* **maniaplanet_configs** : Config that is used at the first start of the Maniaplanet container. +* **pyplanet** : PyPlanet folder. +* **database** : /var/lib/mysql of mariadb container. + +This template is ready to use, you just need to fill the dedicated_vars.env.default and rename it dedicated_vars.env. + +### How to update ? + +To update, you just need to execute `docker-compose pull` then `docker-compose up -d`. \ No newline at end of file From 331a94504522895f9333b3faaa2480ba2408b6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VAN=20DER=20BIEST=20C=C3=A9lian?= Date: Mon, 20 Apr 2020 21:55:31 +0000 Subject: [PATCH 2/5] Remove useless/deprecated stuff --- Dockerfile | 33 ------------- base.py | 99 -------------------------------------- dedicated_vars.default.env | 7 --- docker-compose.yml | 43 ----------------- manage.py | 18 ------- requirements.txt | 5 -- 6 files changed, 205 deletions(-) delete mode 100644 Dockerfile delete mode 100644 base.py delete mode 100644 dedicated_vars.default.env delete mode 100644 docker-compose.yml delete mode 100755 manage.py delete mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 47aa0ce..0000000 --- a/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM python:3.7 -LABEL maintainer="Tom Valk " -ENV PROJECT_ROOT /app -ENV IS_DOCKER 1 - -# Create maniaplanet user/group -RUN addgroup --gid 1000 maniaplanet && \ - adduser -u 1000 --group maniaplanet --system - -RUN apt-get -q update \ -&& apt-get install -y build-essential libssl-dev libffi-dev zlib1g-dev \ - && rm -rf /var/lib/apt/lists/* - -# Create project root. -RUN mkdir -p $PROJECT_ROOT -WORKDIR $PROJECT_ROOT -COPY base.py $PROJECT_ROOT/base.py -RUN chown -R maniaplanet:maniaplanet $PROJECT_ROOT - -# Install PyPlanet. -RUN pip install pyplanet --upgrade - -USER maniaplanet - -# Init project. -RUN pyplanet init_project server -WORKDIR $PROJECT_ROOT/server/ -RUN cp ../base.py $PROJECT_ROOT/server/settings/base.py - -VOLUME $PROJECT_ROOT/server/ - -ENTRYPOINT [ "./manage.py" ] -CMD [ "start", "--pool=default", "--settings=settings" ] diff --git a/base.py b/base.py deleted file mode 100644 index df45755..0000000 --- a/base.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -This file contains the basic settings and overrides the default ones that are defined in the core. -Documentation: http://pypla.net/ - -If you want to use other configuration methods like YAML or JSON files, take a look at http://pypla.net/ and head to the -configuration pages. -""" -import os - -# Set the root_path to the root of our project. -ROOT_PATH = os.path.dirname(os.path.dirname(__file__)) - -# Set the temporary location for the project. -TMP_PATH = os.path.join(ROOT_PATH, 'tmp') - -# Create temporary folder if not exists. -if not os.path.exists(TMP_PATH): - os.mkdir(TMP_PATH) - -# Enable debug mode to get verbose output, not report any errors and dynamically use the DEBUG in your code -# for extra verbosity of logging/output. -DEBUG = bool(os.environ.get('PYPLANET_DEBUG', False)) - -# Add your pools (the controller instances per dedicated here) or leave as it is to use a single instance only. -POOLS = [ - 'default' -] - -# Owners are logins of the server owners, the owners always get *ALL* the permissions in the system. -OWNERS = { - 'default': [ - 'your-maniaplanet-login' - ] -} - -# Allow self-upgrading the installation. Disable on shared servers with one installation (hosting environment)! -SELF_UPGRADE = False - -# Databases configuration holds an dictionary with information of the database backend. -# Please refer to the documentation for all examples. http://pypla.net/ -DATABASES = { - 'default': { - 'ENGINE': 'peewee_async.MySQLDatabase', - 'NAME': 'pyplanet', - 'OPTIONS': { - 'host': 'db', - 'user': 'pyplanet', - 'password': 'pyplanet', - 'charset': 'utf8mb4', - } - } -} - -# Dedicated configuration holds the different dedicated servers that the instances will run on including the names of -# the instances. -DEDICATED = { - 'default': { - 'HOST': 'dedicated', - 'PORT': '5000', - 'USER': 'SuperAdmin', - 'PASSWORD': 'SuperAdmin', - } -} - -# Map configuration is a set of configuration options related to match settings etc. -# Matchsettings filename. -MAP_MATCHSETTINGS = { - 'default': 'maplist.txt', -} - -# Blacklist file is managed by the dedicated server and will be loaded and writen to by PyPlanet once a -# player gets blacklisted. The default will be the filename Maniaplanet always uses and is generic. -BLACKLIST_FILE = { - 'default': 'blacklist.txt' -} - -# The storage configuration contains the same instance mapping of the dedicated servers and is used -# to access the filesystem on the dedicated server location. -# Please refer to the documentation for more information. http://pypla.net/ -STORAGE = { - 'default': { - 'DRIVER': 'pyplanet.core.storage.drivers.local.LocalDriver', - 'OPTIONS': {}, - } -} - -# Define any cache backends that can be used by the core and the plugins to cache data. -# This is not yet implemented. As soon as it's implemented you can activate it with the documentation, available on -# http://pypla.net/ -# CACHE = { -# 'default': { -# -# } -# } - -# Songs is a list of URLs to .ogg files of songs to be played by the music server. -SONGS = { - 'default': [] -} \ No newline at end of file diff --git a/dedicated_vars.default.env b/dedicated_vars.default.env deleted file mode 100644 index 52ed18f..0000000 --- a/dedicated_vars.default.env +++ /dev/null @@ -1,7 +0,0 @@ -LOGIN=mp_dedicated_user -PASSWORD=mp_dedicated_pass -TITLE=TMStadium@nadeo -TITLE_PACK_URL=https://v4.live.maniaplanet.com/ingame/public/titles/download/TMStadium@nadeo.Title.Pack.gbx -TITLE_PACK_FILE=TMStadium@nadeo.Title.Pack.gbx -MATCH_SETTINGS=MatchSettings/default.txt -SERVER_NAME=DefaultName \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index a9a09ba..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: '3' -services: - controller: - image: pyplanet/pyplanet - build: . - restart: always - links: - - dedicated - - db - depends_on: - - dedicated - - db - volumes: - - ./settings:/app/settings - - ./apps:/app/apps - - ./dedicated/UserData:/dedicated/UserData - - dedicated: - image: pyplanet/maniaplanet-dedicated - restart: always - env_file: ./dedicated_vars.env - volumes: - - ./dedicated/UserData:/dedicated/UserData - - ./dedicated/Logs:/dedicated/Logs - expose: - - "5000" - ports: - - "2350" - - "2350/udp" - - "3450" - - "3450/udp" - - db: - image: mysql:5.7 - restart: always - environment: - MYSQL_DATABASE: pyplanet - MYSQL_USER: pyplanet - MYSQL_PASSWORD: pyplanet - MYSQL_ROOT_PASSWORD: pyplanet - command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --innodb-flush-log-at-trx-commit=0 - volumes: - - ./mysql:/var/lib/mysql diff --git a/manage.py b/manage.py deleted file mode 100755 index 219c6da..0000000 --- a/manage.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 -import os -import sys -import time - -if __name__ == '__main__': - time.sleep(3) - - os.environ.setdefault('PYPLANET_SETTINGS_MODULE', 'settings') - try: - from pyplanet.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - 'Couldn\'t import PyPlanet. Are you sure it\'s installed and ' - 'available on your PYTHONPATH environment variable? Did you ' - 'forget to activate a virtual environment?' - ) from exc - execute_from_command_line(sys.argv) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e85f091..0000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Change the numbers according to the major release. First read the release notes and upgrade notes on our site: -# http://pypla.net/ -pyplanet - -# Add your apps requirements here: From dd34038376fdcd605eecd08035ea4859beb558f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VAN=20DER=20BIEST=20C=C3=A9lian?= Date: Mon, 20 Apr 2020 21:55:53 +0000 Subject: [PATCH 3/5] Add the first docker-compose template --- full-template/dedicated_vars.env.default | 20 ++++++ full-template/docker-compose.yml | 84 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 full-template/dedicated_vars.env.default create mode 100644 full-template/docker-compose.yml diff --git a/full-template/dedicated_vars.env.default b/full-template/dedicated_vars.env.default new file mode 100644 index 0000000..a51b679 --- /dev/null +++ b/full-template/dedicated_vars.env.default @@ -0,0 +1,20 @@ +#Maniaplanet dedicated server IDs. See: https://maniaplanet.com/account/dedicated-servers +LOGIN= +PASSWORD= + +#Maniaplanet dedicated server config. +TITLE=TMStadium@nadeo +TITLE_PACK_URL=https://v4.live.maniaplanet.com/ingame/public/titles/download/TMStadium@nadeo.Title.Pack.gbx +TITLE_PACK_FILE=TMStadium@nadeo.Title.Pack.gbx +MATCH_SETTINGS=MatchSettings/default.txt +SERVER_NAME=DefaultName + +#Database config. Changes here will only be applied on the database container. +#This can be changed in "pyplanet" volume "/app/server/settings/base.py", file app.py, l56. <<-- That will be improve in the futur, it's on the TODO list. +MYSQL_USER=pyplanet +MYSQL_PASSWORD=pyplanet +MYSQL_DATABASE=pyplanet +MYSQL_ROOT_PASSWORD= + +#SFTP password of maniaplanet user. By default listening 0.0.0.0:8154 on your host. +SFTP_PASSWORD= diff --git a/full-template/docker-compose.yml b/full-template/docker-compose.yml new file mode 100644 index 0000000..1106404 --- /dev/null +++ b/full-template/docker-compose.yml @@ -0,0 +1,84 @@ +#Maintained by Célian "celianvdb" VAN DER BIEST +version: '3' +services: + controller: + image: pyplanet/controller + restart: always + + depends_on: + - dedicated + - db + volumes: + - pyplanet:/app/server/ + - maniaplanet:/app/dedicated/ + networks: + - back + + dedicated: + image: pyplanet/maniaplanet-dedicated + restart: always + env_file: ./dedicated_vars.env + + volumes: + - maniaplanet:/app/dedicated + - maniaplanet_configs:/app/dedicated-configs + networks: + - back + - front + expose: + - "5000" + ports: + - "2350:2350" + - "3450:3450" + + db: + image: mariadb:latest + restart: always + env_file: ./dedicated_vars.env + + environment: + MYSQL_INITDB_SKIP_TZINFO: 1 + volumes: + - database:/var/lib/mysql/ + networks: + - back + expose: + - "3306" + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + + pma: + image: phpmyadmin/phpmyadmin + restart: always + depends_on: + - db + env_file: ./dedicated_vars.env + + networks: + - front + - back + ports: + - "8080:80" + + sftp: + image: atmoz/sftp + restart: always + env_file: ./dedicated_vars.env + + volumes: + - maniaplanet:/home/maniaplanet/dedicated + - pyplanet:/home/maniaplanet/pyplanet + networks: + - front + ports: + - "8022:22" + command: ["sh", "-c", "./entrypoint maniaplanet:$${SFTP_PASSWORD}:1000"] + +volumes: + maniaplanet: + maniaplanet_configs: + pyplanet: + database: + +networks: + front: + back: From f4891c662c92b18cd7946f9d84e66e136739ed7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VAN=20DER=20BIEST=20C=C3=A9lian?= Date: Mon, 20 Apr 2020 23:30:10 +0000 Subject: [PATCH 4/5] Fix the full template --- full-template/dedicated_vars.env.default | 25 ++++++++++++++++-------- full-template/docker-compose.yml | 3 +++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/full-template/dedicated_vars.env.default b/full-template/dedicated_vars.env.default index a51b679..21f53ee 100644 --- a/full-template/dedicated_vars.env.default +++ b/full-template/dedicated_vars.env.default @@ -1,3 +1,19 @@ +#PyPlanet +MANIAPLANET_HOST=dedicated +MANIAPLANET_PORT=5000 +MANIAPLANET_USER=SuperAdmin +MANIAPLANET_PASSWORD=SuperAdmin +MANIAPLANET_OWNER_LOGIN= +MYSQL_HOST=db + +#Database config ( also applied in the pyplanet configuration ). +MYSQL_USER=pyplanet +MYSQL_PASSWORD=pyplanet +MYSQL_DATABASE=pyplanet +# You can define the root password if you need it or just keep it random. By default, it's random +#MYSQL_ROOT_PASSWORD= +MYSQL_RANDOM_ROOT_PASSWORD=yes + #Maniaplanet dedicated server IDs. See: https://maniaplanet.com/account/dedicated-servers LOGIN= PASSWORD= @@ -9,12 +25,5 @@ TITLE_PACK_FILE=TMStadium@nadeo.Title.Pack.gbx MATCH_SETTINGS=MatchSettings/default.txt SERVER_NAME=DefaultName -#Database config. Changes here will only be applied on the database container. -#This can be changed in "pyplanet" volume "/app/server/settings/base.py", file app.py, l56. <<-- That will be improve in the futur, it's on the TODO list. -MYSQL_USER=pyplanet -MYSQL_PASSWORD=pyplanet -MYSQL_DATABASE=pyplanet -MYSQL_ROOT_PASSWORD= - -#SFTP password of maniaplanet user. By default listening 0.0.0.0:8154 on your host. +#SFTP password of maniaplanet user. By default listening 0.0.0.0:8022 on your host. SFTP_PASSWORD= diff --git a/full-template/docker-compose.yml b/full-template/docker-compose.yml index 1106404..fe719e8 100644 --- a/full-template/docker-compose.yml +++ b/full-template/docker-compose.yml @@ -4,6 +4,7 @@ services: controller: image: pyplanet/controller restart: always + env_file: ./dedicated_vars.env depends_on: - dedicated @@ -29,7 +30,9 @@ services: - "5000" ports: - "2350:2350" + - "2350:2350/udp" - "3450:3450" + - "3450:3450/udp" db: image: mariadb:latest From 752fb5e15f71b134e2ffbbb01b6565a9af097e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?VAN=20DER=20BIEST=20C=C3=A9lian?= Date: Sun, 17 May 2020 12:03:02 +0000 Subject: [PATCH 5/5] Improvment on full template. --- .gitignore | 9 +++------ README.md | 8 ++++++-- full-template/docker-compose.yml | 2 ++ full-template/ssh_host_keygen.sh | 2 ++ 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100755 full-template/ssh_host_keygen.sh diff --git a/.gitignore b/.gitignore index 5476b13..5b299b9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,8 @@ *.iws *.iml -### Python -*.pyc - ### Docker -dedicated_vars.env +*dedicated_vars.env -/dedicated -/mysql +### ssh host keys +full-template/ssh_host_keys/* diff --git a/README.md b/README.md index a462d18..1e31b1d 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,12 @@ This template use 4 named volumes : * **pyplanet** : PyPlanet folder. * **database** : /var/lib/mysql of mariadb container. -This template is ready to use, you just need to fill the dedicated_vars.env.default and rename it dedicated_vars.env. +To use this template you only have two things to do : +* Rename dedicated_vars.env.default to dedicated_vars.env and fill it. +* Generate your ssh host key by executing the ssh_host_keygen.sh script. + +Then you are ready to use it ``docker-compose up -d``. ### How to update ? -To update, you just need to execute `docker-compose pull` then `docker-compose up -d`. \ No newline at end of file +To update, you just need to execute `docker-compose pull` then `docker-compose up -d`. diff --git a/full-template/docker-compose.yml b/full-template/docker-compose.yml index fe719e8..7cb7567 100644 --- a/full-template/docker-compose.yml +++ b/full-template/docker-compose.yml @@ -70,6 +70,8 @@ services: volumes: - maniaplanet:/home/maniaplanet/dedicated - pyplanet:/home/maniaplanet/pyplanet + - ./ssh_host_keys/ssh_host_ed25519_key:/etc/ssh/ssh_host_ed25519_key + - ./ssh_host_keys/ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key networks: - front ports: diff --git a/full-template/ssh_host_keygen.sh b/full-template/ssh_host_keygen.sh new file mode 100755 index 0000000..a9f67f2 --- /dev/null +++ b/full-template/ssh_host_keygen.sh @@ -0,0 +1,2 @@ +ssh-keygen -t ed25519 -f ssh_host_keys/ssh_host_ed25519_key -N "" < /dev/null +ssh-keygen -t rsa -b 4096 -f ssh_host_keys/ssh_host_rsa_key -N "" < /dev/null