From faadfad22cce8187bacfac5fc9851c835a09b484 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Tue, 30 Aug 2022 14:22:29 +0800 Subject: [PATCH 1/5] Add docker support --- .dockerignore | 35 +++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ Dockerfile | 10 ++++++++++ README.md | 11 ++++++++++- docker-compose.yml | 27 +++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..57e20aafa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,35 @@ +.git +# Ignore data, log & temp directories +action_logs/ +!cache/ +cache/** +!cache/img +cache/img/** +!cache/img/signatures +cache/img/signatures/** +!cache/img/signatures/static +!cache/img/signatures/static/* +tmp/ + +# Ignore installation-related files +install/lock + +# Ignore PHP-related files & directories +vendor/ + +# Ignore app's instance configuration +config/** +!config/.gitkeep + +# Custom files that should not be comitted into the base code +language/**/rules.definitions.custom.lang + +# Files temporarily removed from further tracking +# (based on https://stackoverflow.com/a/11366713/951007) +config.php +includes/constants.php + +# Ignore JavaScript / Node.js -related files & directories +node_modules/ + +docker/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b9269a49..4faca6266 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ includes/constants.php # Ignore JavaScript / Node.js -related files & directories node_modules/ + +docker/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..630be7ee8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM php:7.3-apache +RUN apt-get update && apt-get install -y zip unzip libpng-dev libzip-dev && apt-get clean +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer +RUN docker-php-ext-configure gd && docker-php-ext-install gd mysqli zip +COPY . /var/www/html +WORKDIR /var/www/html +RUN chown -R www-data:www-data /var/www/html +USER www-data +RUN composer install --no-dev +USER root \ No newline at end of file diff --git a/README.md b/README.md index 2b9732193..de7e39d2a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ OGame-clone browser based game engine. ## Installation +### Bare Metal + 1. Setup a webserver capable of running PHP scripts. - ``php.ini`` file should have ``E_NOTICE`` reporting disabled, eg.: - ``error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT`` @@ -52,9 +54,16 @@ OGame-clone browser based game engine. 1. Move source files of the project to your webserver's directory. 1. Install PHP dependencies. - ``composer install --no-dev`` -1. Run installation wizard: http://your_server_address:port/install +1. Run installation wizard: ``http(s)://:/install`` 1. Remove ``install/`` directory +### Docker + +1. Build docker image ``docker-compose build`` +1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && chown 33:33 docker/*.php`` +1. Run services ``docker-compose up -d`` +1. Run installation wizard: ``http(s)://:/install`` + ## Updating from older versions 1. Check [__Releases__ section](https://github.com/mdziekon/UniEngine/releases) to see if migration scripts have been provided between your current version and the latest version you want to upgrade to. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..18983b836 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' +services: + app: + build: + context: . + dockerfile: Dockerfile + image: uniengine + restart: unless-stopped + depends_on: + - db + ports: + - 80:80 + volumes: + - ./docker/config.php:/var/www/html/config.php + - ./docker/constants.php:/var/www/html/includes/constants.php + - /etc/localtime:/etc/localtime:ro + + db: + image: mariadb:10 + restart: unless-stopped + command: + - --sql-mode= + environment: + MARIADB_ROOT_PASSWORD: uniengine + MARIADB_DATABASE: uniengine + volumes: + - ./docker/data:/var/lib/mysql From 5de2483c86636b22c06a430f623cc3669c39dd3f Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Fri, 2 Sep 2022 10:24:30 +0800 Subject: [PATCH 2/5] Use `php-fpm` and `nginx` instead of `php-apache` --- README.md | 3 +-- docker-compose.yml | 27 +++++++++++++++++++++++---- nginx.conf | 20 ++++++++++++++++++++ nginx.dockerfile | 11 +++++++++++ Dockerfile => php.dockerfile | 15 +++++++++------ 5 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 nginx.conf create mode 100644 nginx.dockerfile rename Dockerfile => php.dockerfile (64%) diff --git a/README.md b/README.md index de7e39d2a..59b30d690 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,8 @@ OGame-clone browser based game engine. ### Docker -1. Build docker image ``docker-compose build`` 1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && chown 33:33 docker/*.php`` -1. Run services ``docker-compose up -d`` +1. Build and run services ``docker-compose up -d --build`` 1. Run installation wizard: ``http(s)://:/install`` ## Updating from older versions diff --git a/docker-compose.yml b/docker-compose.yml index 18983b836..458cef2c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,34 @@ version: '3.8' services: - app: + nginx: build: context: . - dockerfile: Dockerfile - image: uniengine + dockerfile: nginx.dockerfile + image: uniengine/nginx restart: unless-stopped depends_on: - - db + - php ports: - 80:80 volumes: + - /etc/localtime:/etc/localtime:ro - ./docker/config.php:/var/www/html/config.php - ./docker/constants.php:/var/www/html/includes/constants.php + - shared_tmp:/var/www/html/tmp + + php: + build: + context: . + dockerfile: php.dockerfile + image: uniengine/php + restart: unless-stopped + depends_on: + - db + volumes: - /etc/localtime:/etc/localtime:ro + - ./docker/config.php:/var/www/html/config.php + - ./docker/constants.php:/var/www/html/includes/constants.php + - shared_tmp:/var/www/html/tmp db: image: mariadb:10 @@ -24,4 +39,8 @@ services: MARIADB_ROOT_PASSWORD: uniengine MARIADB_DATABASE: uniengine volumes: + - /etc/localtime:/etc/localtime:ro - ./docker/data:/var/lib/mysql + +volumes: + shared_tmp: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..57cfbf6a6 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,20 @@ +server { + listen 80; + server_name _; + + access_log /var/log/nginx/host.access.log main; + + root /var/www/html; + + location / { + try_files $uri /index.php$is_args$args; + } + + location ~ \.php$ { + root html; + fastcgi_pass php:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/nginx.dockerfile b/nginx.dockerfile new file mode 100644 index 000000000..b7ce447d2 --- /dev/null +++ b/nginx.dockerfile @@ -0,0 +1,11 @@ +FROM composer:latest as base +COPY . /var/www/html +RUN chown -R www-data:www-data /var/www/html +USER www-data +WORKDIR /var/www/html +RUN composer install --no-dev + +FROM nginx:stable +COPY --from=base /var/www/html /var/www/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +WORKDIR /var/www/html diff --git a/Dockerfile b/php.dockerfile similarity index 64% rename from Dockerfile rename to php.dockerfile index 630be7ee8..c464969a1 100644 --- a/Dockerfile +++ b/php.dockerfile @@ -1,10 +1,13 @@ -FROM php:7.3-apache -RUN apt-get update && apt-get install -y zip unzip libpng-dev libzip-dev && apt-get clean -COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer -RUN docker-php-ext-configure gd && docker-php-ext-install gd mysqli zip +FROM composer:latest as base COPY . /var/www/html -WORKDIR /var/www/html RUN chown -R www-data:www-data /var/www/html USER www-data +WORKDIR /var/www/html RUN composer install --no-dev -USER root \ No newline at end of file + +FROM php:7.3-fpm +RUN apt-get update && apt-get install -y zip unzip libpng-dev libzip-dev && apt-get clean +RUN docker-php-ext-configure gd && docker-php-ext-install gd mysqli zip +COPY --from=base /var/www/html /var/www/html +RUN chown -R www-data:www-data /var/www/html +WORKDIR /var/www/html From d1600b39b992b8d6d6d2b0c22916229e84e6ffa3 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Tue, 6 Sep 2022 10:39:53 +0800 Subject: [PATCH 3/5] minor changes --- .dockerignore | 6 ++---- .gitignore | 3 ++- README.md | 8 ++++++-- docker-compose.yml | 6 +++--- example.env | 3 +++ 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 example.env diff --git a/.dockerignore b/.dockerignore index 57e20aafa..fe2c45181 100644 --- a/.dockerignore +++ b/.dockerignore @@ -21,9 +21,6 @@ vendor/ config/** !config/.gitkeep -# Custom files that should not be comitted into the base code -language/**/rules.definitions.custom.lang - # Files temporarily removed from further tracking # (based on https://stackoverflow.com/a/11366713/951007) config.php @@ -32,4 +29,5 @@ includes/constants.php # Ignore JavaScript / Node.js -related files & directories node_modules/ -docker/ \ No newline at end of file +docker/ +.env \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4faca6266..36969b04b 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ includes/constants.php # Ignore JavaScript / Node.js -related files & directories node_modules/ -docker/ \ No newline at end of file +docker/ +.env \ No newline at end of file diff --git a/README.md b/README.md index 59b30d690..b560ecca2 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,13 @@ OGame-clone browser based game engine. ### Docker -1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && chown 33:33 docker/*.php`` +1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && chown 33:33 docker/*.php``\ +The user and group id 33 here is the `www-data` user from `nginx:stable` and `php:7.3-fpm`, because it may have a different name on some hosts (for example, on archlinux it is `http`), use its id here to make sure it is available +1. Prepare and edit environment config file ``cp example.env .env && vim .env`` 1. Build and run services ``docker-compose up -d --build`` -1. Run installation wizard: ``http(s)://:/install`` +1. Run installation wizard: ``http(s)://:/install``\ +The port number should already be defined in ``.env``, unless you are using a reverse proxy such as nginx or traefik, then this should match the configuration in your reverse proxy. +1. Initialize with the root user password and database name defined in the ``.env`` file, database host should be ``db`` ## Updating from older versions diff --git a/docker-compose.yml b/docker-compose.yml index 458cef2c9..b59100868 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: depends_on: - php ports: - - 80:80 + - ${WEB_PORT:-80}:80 volumes: - /etc/localtime:/etc/localtime:ro - ./docker/config.php:/var/www/html/config.php @@ -36,8 +36,8 @@ services: command: - --sql-mode= environment: - MARIADB_ROOT_PASSWORD: uniengine - MARIADB_DATABASE: uniengine + MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-uniengine} + MARIADB_DATABASE: ${MARIADB_DATABASE:-uniengine} volumes: - /etc/localtime:/etc/localtime:ro - ./docker/data:/var/lib/mysql diff --git a/example.env b/example.env new file mode 100644 index 000000000..1f226d1e9 --- /dev/null +++ b/example.env @@ -0,0 +1,3 @@ +WEB_PORT=80 +MARIADB_ROOT_PASSWORD=uniengine +MARIADB_DATABASE=uniengine \ No newline at end of file From e23f2492d4828af418a56e536ff85ec86a432351 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Tue, 13 Sep 2022 09:04:42 +0800 Subject: [PATCH 4/5] fix cache problem add sudo on readme --- README.md | 2 +- docker-compose.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b560ecca2..fa47defa8 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ OGame-clone browser based game engine. ### Docker -1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && chown 33:33 docker/*.php``\ +1. Prepare config file ``mkdir docker && cp config.php docker && cp includes/constants.php docker && sudo chown 33:33 docker/*.php``\ The user and group id 33 here is the `www-data` user from `nginx:stable` and `php:7.3-fpm`, because it may have a different name on some hosts (for example, on archlinux it is `http`), use its id here to make sure it is available 1. Prepare and edit environment config file ``cp example.env .env && vim .env`` 1. Build and run services ``docker-compose up -d --build`` diff --git a/docker-compose.yml b/docker-compose.yml index b59100868..f5d9050c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: - ./docker/config.php:/var/www/html/config.php - ./docker/constants.php:/var/www/html/includes/constants.php - shared_tmp:/var/www/html/tmp + - shared_cache:/var/www/html/cache php: build: @@ -29,6 +30,7 @@ services: - ./docker/config.php:/var/www/html/config.php - ./docker/constants.php:/var/www/html/includes/constants.php - shared_tmp:/var/www/html/tmp + - shared_cache:/var/www/html/cache db: image: mariadb:10 @@ -44,3 +46,4 @@ services: volumes: shared_tmp: + shared_cache: From 710040e8d9babad85e7e980e63dd0bc4f01d77e4 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Tue, 13 Sep 2022 10:00:26 +0800 Subject: [PATCH 5/5] fix cache --- generate_sig.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generate_sig.php b/generate_sig.php index 04db00934..b5f161599 100644 --- a/generate_sig.php +++ b/generate_sig.php @@ -86,6 +86,9 @@ function ReturnImage($ImagePath) { * to relax access requirements. This should also be changed to improve security. */ $UNIX_EVERYONE_WRITE_PERMISSION = 0x002; + if (!is_dir($CacheLangPath)) { + mkdir($CacheLangPath, 0755, true); + } $isCacheDirWriteable = fileperms($CacheLangPath) & $UNIX_EVERYONE_WRITE_PERMISSION; if (