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/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/README.md b/README.md index 0579336..1e31b1d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,100 @@ -# 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. + +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`. 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/full-template/dedicated_vars.env.default b/full-template/dedicated_vars.env.default new file mode 100644 index 0000000..21f53ee --- /dev/null +++ b/full-template/dedicated_vars.env.default @@ -0,0 +1,29 @@ +#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= + +#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 + +#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 new file mode 100644 index 0000000..7cb7567 --- /dev/null +++ b/full-template/docker-compose.yml @@ -0,0 +1,89 @@ +#Maintained by Célian "celianvdb" VAN DER BIEST +version: '3' +services: + controller: + image: pyplanet/controller + restart: always + env_file: ./dedicated_vars.env + + 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" + - "2350:2350/udp" + - "3450:3450" + - "3450:3450/udp" + + 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 + - ./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: + - "8022:22" + command: ["sh", "-c", "./entrypoint maniaplanet:$${SFTP_PASSWORD}:1000"] + +volumes: + maniaplanet: + maniaplanet_configs: + pyplanet: + database: + +networks: + front: + back: 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 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: