From 540ef5e084db2295d7ca476c980ec10fb90e9722 Mon Sep 17 00:00:00 2001 From: Fabien MEURILLON Date: Sat, 9 Jan 2016 14:47:32 +0100 Subject: [PATCH 1/3] Add basic docker-compose configuration --- .gitignore | 3 ++ docker-compose.yml | 17 ++++++++ docker/nginx/nginx.conf | 89 +++++++++++++++++++++++++++++++++++++++++ docker/php/Dockerfile | 10 +++++ 4 files changed, 119 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/nginx/nginx.conf create mode 100644 docker/php/Dockerfile diff --git a/.gitignore b/.gitignore index 9bde27dbc..0495cb17d 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ # Data for wallabag data/assets/* data/db/wallabag*.sqlite + +# Docker container logs +docker/logs/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..bc4694195 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +nginx: + image: nginx + ports: + - "8080:80" + volumes: + - ./docker/nginx/nginx.conf:/nginx.conf + - ./docker/logs/nginx:/var/log/nginx + - .:/var/www/html + links: + - php:php + command: nginx -c /nginx.conf +php: + build: docker/php + ports: + - "9000:9000" + volumes: + - .:/var/www/html diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 000000000..7e82a0f89 --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,89 @@ +user nginx; +worker_processes 1; +pid /var/run/nginx.pid; + +events { + worker_connections 2048; + multi_accept on; + use epoll; +} + +http { + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log off; + error_log off; + gzip on; + gzip_disable "msie6"; + open_file_cache max=100; + + + upstream php-upstream { + server php:9000; + } + + server { + #server_name domain.tld www.domain.tld; + root /var/www/html/web; + + location / { + # try to serve file directly, fallback to app.php + try_files $uri /app.php$is_args$args; + } + # DEV + # This rule should only be placed on your development environment + # In production, don't include this and don't deploy app_dev.php or config.php + location ~ ^/(app_dev|config)\.php(/|$) { + fastcgi_pass php-upstream; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + } + # PROD + location ~ ^/app\.php(/|$) { + fastcgi_pass php-upstream; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + # Prevents URIs that include the front controller. This will 404: + # http://domain.tld/app.php/some-path + # Remove the internal directive to allow URIs like this + internal; + } + + error_log /var/log/nginx/project_error.log; + access_log /var/log/nginx/project_access.log; + } + +} + +daemon off; diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 000000000..7c56ae573 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,10 @@ +FROM php:fpm + +RUN apt-get update && apt-get install -y \ + libmcrypt-dev libicu-dev libpq-dev libxml2-dev \ + && docker-php-ext-install \ + iconv mcrypt mbstring intl pdo pdo_mysql pdo_pgsql + +RUN usermod -u 1000 www-data + +CMD ["php-fpm"] From 1d41effebc613b91bb84404711fb555f050a1700 Mon Sep 17 00:00:00 2001 From: Fabien MEURILLON Date: Sat, 9 Jan 2016 17:27:21 +0100 Subject: [PATCH 2/3] Add Docker configuration for Postgres and MariaDB --- .gitignore | 3 ++- app/config/parameters.yml.dist | 10 ++++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ docker/mariadb/env | 10 ++++++++++ docker/php/env | 6 ++++++ docker/postgres/env | 9 +++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 docker/mariadb/env create mode 100644 docker/php/env create mode 100644 docker/postgres/env diff --git a/.gitignore b/.gitignore index 0495cb17d..f88370d78 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,6 @@ data/assets/* data/db/wallabag*.sqlite -# Docker container logs +# Docker container logs and data docker/logs/ +docker/data/ diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index a769bc663..0c0cbff1c 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -1,5 +1,15 @@ # This file is a "template" of what your parameters.yml file should look like parameters: + # Uncomment these settings or manually update your parameters.yml + # to use docker-compose + # + # database_driver: %env.database_driver% + # database_host: %env.database_host% + # database_port: %env.database_port% + # database_name: %env.database_name% + # database_user: %env.database_user% + # database_password: %env.database_password% + database_driver: pdo_sqlite database_host: 127.0.0.1 database_port: ~ diff --git a/docker-compose.yml b/docker-compose.yml index bc4694195..c774b6217 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,3 +15,28 @@ php: - "9000:9000" volumes: - .:/var/www/html + #links: + # - "postgres:rdbms" + # - "mariadb:rdbms" + env_file: + - ./docker/php/env + # Comment non-used DBMS lines + # If all DBMS are commented out, sqlite will be used as default + # - ./docker/postgres/env + # - ./docker/mariadb/env +#postgres: +# image: postgres:9 +# ports: +# - "5432:5432" +# volumes: +# - ./docker/data/pgsql:/var/lib/postgresql/data +# env_file: +# - ./docker/postgres/env +#mariadb: +# image: mariadb:10 +# ports: +# - "3306:3306" +# volumes: +# - ./docker/data/mariadb:/var/lib/mysql +# env_file: +# - ./docker/mariadb/env diff --git a/docker/mariadb/env b/docker/mariadb/env new file mode 100644 index 000000000..87556a15d --- /dev/null +++ b/docker/mariadb/env @@ -0,0 +1,10 @@ +MYSQL_ROOT_PASSWORD=wallaroot +MYSQL_USER=wallabag +MYSQL_PASSWORD=wallapass +MYSQL_DATABASE=wallabag +SYMFONY__ENV__DATABASE_DRIVER=pdo_mysql +SYMFONY__ENV__DATABASE_HOST=rdbms +SYMFONY__ENV__DATABASE_PORT=3306 +SYMFONY__ENV__DATABASE_NAME=wallabag +SYMFONY__ENV__DATABASE_USER=wallabag +SYMFONY__ENV__DATABASE_PASSWORD=wallapass diff --git a/docker/php/env b/docker/php/env new file mode 100644 index 000000000..935134fca --- /dev/null +++ b/docker/php/env @@ -0,0 +1,6 @@ +SYMFONY__ENV__DATABASE_DRIVER=pdo_sqlite +SYMFONY__ENV__DATABASE_HOST=127.0.0.1 +SYMFONY__ENV__DATABASE_PORT=~ +SYMFONY__ENV__DATABASE_NAME=symfony +SYMFONY__ENV__DATABASE_USER=root +SYMFONY__ENV__DATABASE_PASSWORD=~ diff --git a/docker/postgres/env b/docker/postgres/env new file mode 100644 index 000000000..80c78c2af --- /dev/null +++ b/docker/postgres/env @@ -0,0 +1,9 @@ +POSTGRES_USER=wallabag +POSTGRES_PASSWORD=wallapass +POSTGRES_DB=wallabag +export SYMFONY__ENV__DATABASE_DRIVER=pdo_pgsql +export SYMFONY__ENV__DATABASE_HOST=rdbms +export SYMFONY__ENV__DATABASE_PORT=5432 +export SYMFONY__ENV__DATABASE_NAME=wallabag +export SYMFONY__ENV__DATABASE_USER=wallabag +export SYMFONY__ENV__DATABASE_PASSWORD=wallapass From 8b909e7ea7773807fdcae6e1cc08b2e62084bfd9 Mon Sep 17 00:00:00 2001 From: Fabien MEURILLON Date: Sat, 9 Jan 2016 19:02:24 +0100 Subject: [PATCH 3/3] Add documentation to run docker-compose --- docs/en/developer/docker.rst | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/en/developer/docker.rst diff --git a/docs/en/developer/docker.rst b/docs/en/developer/docker.rst new file mode 100644 index 000000000..9ed9dde2f --- /dev/null +++ b/docs/en/developer/docker.rst @@ -0,0 +1,51 @@ +Run Wallabag in docker-compose +============================== + +In order to run your own development instance of wallabag, you may +want to use the pre-configured docker compose files. + +Requirements +------------ + +Make sure to have `Docker +`__ and `Docker +Compose `__ availables on +your system and up to date. + +Switch DBMS +----------- + +By default, Wallabag will start with a sqlite database. +Since Wallabag provide support for Postgresql and MySQL, docker +containers are also available for these ones. + +In ``docker-compose.yml``, for the chosen DBMS uncomment : + +- the container definition (``postgres`` or ``mariadb`` root level + block) +- the container link in the ``php`` container +- the container env file in the ``php`` container + +In order to keep running Symfony commands on your host (such as +``wallabag:install``), you also should : + +- source the proper env files on your command line, so variables + like ``SYMFONY__ENV__DATABASE_HOST`` will exist. +- create a ``127.0.0.1 rdbms`` on your system ``hosts`` file + +Run Wallabag +------------ + +#. Fork and clone the project +#. Edit ``app/config/parameters.yml`` to replace ``database_*`` + properties with commented ones (with values prefixed by ``env.``) +#. ``composer install`` the project dependencies +#. ``php app/console wallabag:install`` to create the schema +#. ``docker-compose up`` to run the containers +#. Finally, browse to http://localhost:8080/ to find your freshly + installed wallabag. + +At various step, you'll probably run into UNIX permission problems, +bad paths in generated cache, etc… +Operations like removing cache files or changing files owners might +be frequently required, so don't be afraid !