diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..fe2c4518 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,33 @@ +.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 + +# 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/ +.env \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b9269a4..36969b04 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ includes/constants.php # Ignore JavaScript / Node.js -related files & directories node_modules/ + +docker/ +.env \ No newline at end of file diff --git a/README.md b/README.md index 2b973219..fa47defa 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,19 @@ 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. 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`` +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 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 00000000..f5d9050c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +version: '3.8' +services: + nginx: + build: + context: . + dockerfile: nginx.dockerfile + image: uniengine/nginx + restart: unless-stopped + depends_on: + - php + ports: + - ${WEB_PORT:-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 + - shared_cache:/var/www/html/cache + + 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 + - shared_cache:/var/www/html/cache + + db: + image: mariadb:10 + restart: unless-stopped + command: + - --sql-mode= + environment: + MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-uniengine} + MARIADB_DATABASE: ${MARIADB_DATABASE:-uniengine} + volumes: + - /etc/localtime:/etc/localtime:ro + - ./docker/data:/var/lib/mysql + +volumes: + shared_tmp: + shared_cache: diff --git a/example.env b/example.env new file mode 100644 index 00000000..1f226d1e --- /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 diff --git a/generate_sig.php b/generate_sig.php index 04db0093..b5f16159 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 ( diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..57cfbf6a --- /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 00000000..b7ce447d --- /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/php.dockerfile b/php.dockerfile new file mode 100644 index 00000000..c464969a --- /dev/null +++ b/php.dockerfile @@ -0,0 +1,13 @@ +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 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