Skip to content

Commit

Permalink
Merge pull request #251 from KagurazakaNyaa/master
Browse files Browse the repository at this point in the history
Add docker support
  • Loading branch information
mdziekon authored Sep 17, 2022
2 parents 80ca681 + 710040e commit 77f8090
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ includes/constants.php

# Ignore JavaScript / Node.js -related files & directories
node_modules/

docker/
.env
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand All @@ -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)://<your_server_address>:<port>/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)://<your_server_address>:<port>/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.
Expand Down
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WEB_PORT=80
MARIADB_ROOT_PASSWORD=uniengine
MARIADB_DATABASE=uniengine
3 changes: 3 additions & 0 deletions generate_sig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
20 changes: 20 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions nginx.dockerfile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions php.dockerfile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 77f8090

Please sign in to comment.