diff --git a/.env b/.env index cef47e840fc5f9905bf7995a2ed2e04dd1d848cf..b20d5037bc9d7547e594767ea55bc1307f2b34c6 100644 --- a/.env +++ b/.env @@ -39,4 +39,4 @@ APP_BUILDINFO=unknown # a git hash or something identifying the build APP_BUILDINFO_URL='#' # Disable the webserver bundle (avoids deprecation warnings). Use docker instead. -DISABLE_DEV_SERVER=false \ No newline at end of file +DISABLE_DEV_SERVER=true \ No newline at end of file diff --git a/docker-compose/README.md b/docker-compose/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cbc07d2621503e10ac5572c42b4ec377bdf0776b --- /dev/null +++ b/docker-compose/README.md @@ -0,0 +1,31 @@ +# Running with Docker + +This is simple docker-compose setup using docker with php-fpm and nginx to serve +the symfony app. + +## Setup + +* `sudo apt install docker-compose` to install docker-compose on Debian/Ubuntu + +## Running the Server + +* `sudo docker-compose up -d` to start the server in the background +* `sudo docker-compose up` to start the server in the foreground with logs +* `sudo docker-compose stop` to stop the server +* `sudo docker-compose logs -f` to see the logs +* `sudo docker-compose restart messenger-worker` restart messenger worker for updating message handling code + +## Executing Symfony commands + +* `./run` to start a shell in the php-fpm container. +* After this you can run symfony/composer commands like: + * `./bin/console debug:config` + * `composer install` + * `composer test` +* You can also call `bin/console` commands directly from outside the container with `./console debug:config` + if you have all dependencies available on the host. + +## Links + +* Open <http://127.0.0.1:8000/> for the API Platform webpage +* Open <http://localhost:8101/> for redis commander diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..ce62bc6a6eabe43422ed7bfca47d3a13aba2d89c --- /dev/null +++ b/docker-compose/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3.1" + +services: + webserver: + image: nginx:alpine + working_dir: /application + volumes: + - ..:/application + - ./webserver/nginx.conf:/etc/nginx/conf.d/default.conf + ports: + - "8000:80" + + php-fpm: + environment: + - TERM_PROGRAM=Hyper # force colors for the symfony dumper + build: + context: php-fpm + working_dir: /application + volumes: + - ..:/application + - ./php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini + - ./php-fpm/php-fpm-overrides.conf:/etc/php/7.3/fpm/pool.d/z-overrides.conf + + messenger-worker: + environment: + - TERM_PROGRAM=Hyper # force colors for the symfony dumper + build: + context: php-fpm + working_dir: /application + entrypoint: ./bin/console messenger:consume async + volumes: + - ..:/application + - ./php-fpm/php-ini-overrides.ini:/etc/php/7.3/cli/conf.d/99-overrides.ini + + redis: + image: "redis" + + redis-commander: + image: "rediscommander/redis-commander" + environment: + - REDIS_HOST=redis + ports: + - "8101:8081" \ No newline at end of file diff --git a/docker-compose/php-fpm/Dockerfile b/docker-compose/php-fpm/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b2e792ce79e89b00fcbc22a0739158881c4911d0 --- /dev/null +++ b/docker-compose/php-fpm/Dockerfile @@ -0,0 +1,49 @@ +FROM debian:buster + +ENV DEBIAN_FRONTEND=noninteractive + +# Basics +RUN apt-get update && apt-get install -y wget lsb-release + +# Install PHP and the rest +# Debian Buster only has php-redis 4.2, we need 4.3 +RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \ + && echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list \ + && apt-get update \ + && apt-get -y --no-install-recommends install \ + ca-certificates \ + curl \ + unzip \ + sudo \ + git \ + php-apcu \ + php-apcu-bc \ + php7.3-cli \ + php7.3-curl \ + php7.3-soap \ + php7.3-json \ + php7.3-mbstring \ + php7.3-opcache \ + php7.3-readline \ + php7.3-xml \ + php7.3-zip \ + php7.3-redis \ + php7.3-fpm \ + php7.3-ldap \ + php7.3-gmp \ + php7.3-xdebug \ + composer \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +STOPSIGNAL SIGQUIT + +RUN useradd -u 1000 -ms /bin/bash user +RUN echo 'user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +USER user + +RUN git config --global url."https://gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:" + +CMD ["/usr/sbin/php-fpm7.3", "-O" ] +EXPOSE 9000 +WORKDIR "/application" \ No newline at end of file diff --git a/docker-compose/php-fpm/php-fpm-overrides.conf b/docker-compose/php-fpm/php-fpm-overrides.conf new file mode 100644 index 0000000000000000000000000000000000000000..8c9ddccdd5ea9e0786885609a38409f1d023f3c5 --- /dev/null +++ b/docker-compose/php-fpm/php-fpm-overrides.conf @@ -0,0 +1,32 @@ +[global] +; Override default pid file +pid = /home/user/.php-fpm.pid + +; Avoid logs being sent to syslog +error_log = /proc/self/fd/2 + +; Set this to php default's max_execution_time to allow children to stop gracefully when fpm is commanded to stop +; This helps avoiding 502's +process_control_timeout = 30 + +; Do not daemonize (eg send process to the background) +daemonize = no + +; Don't print anything when started +log_level = warning + +[www] +; Access from webserver container is via network, not socket file +listen = [::]:9000 + +; Redirect logs to stdout - FPM closes /dev/std* on startup +access.log = /proc/self/fd/2 +access.format = "[%{%Y-%m-%d %H:%M:%S}t] %m %{REQUEST_SCHEME}e://%{HTTP_HOST}e%{REQUEST_URI}e CODE=%s" + +catch_workers_output = yes + +; Remove "pool www" decoration from log output +decorate_workers_output = no + +; This option sets the limit on the number of simultaneous requests that will be served +pm.max_children = 10 \ No newline at end of file diff --git a/docker-compose/php-fpm/php-ini-overrides.ini b/docker-compose/php-fpm/php-ini-overrides.ini new file mode 100644 index 0000000000000000000000000000000000000000..6c3555f78559edd7813381c28991ea4988009c28 --- /dev/null +++ b/docker-compose/php-fpm/php-ini-overrides.ini @@ -0,0 +1,5 @@ +upload_max_filesize = 200M +post_max_size = 208M +memory_limit = 450M +zend.assertions = 1 +date.timezone = "Europe/Vienna" diff --git a/docker-compose/run b/docker-compose/run new file mode 100755 index 0000000000000000000000000000000000000000..79363b1c61f0fb60dde4422854ac6acf6ee3252b --- /dev/null +++ b/docker-compose/run @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run --rm --entrypoint bash php-fpm diff --git a/docker-compose/webserver/nginx.conf b/docker-compose/webserver/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..e6208614c875ba4740dbe9b0a29d70d291b2cd29 --- /dev/null +++ b/docker-compose/webserver/nginx.conf @@ -0,0 +1,26 @@ +server { + listen 80 default; + + client_max_body_size 108M; + + access_log /var/log/nginx/application.access.log; + + + root /application/public; + index index.php; + + if (!-e $request_filename) { + rewrite ^.*$ /index.php last; + } + + location ~ (\.php|/)$ { + fastcgi_pass php-fpm:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log"; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + include fastcgi_params; + } + +}