From f111df5905a48f71c878c3b26fe1acc410cff88f Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Wed, 1 Nov 2023 12:02:40 +0100 Subject: [PATCH] docs: update examples --- .examples/full/.env | 33 ++++ .examples/full/app/Dockerfile | 6 + .examples/full/docker-compose.yml | 105 ++++++++++++ .examples/full/web/Dockerfile | 9 + .examples/full/web/nginx.conf | 161 ++++++++++++++++++ .examples/maxsize/app/Dockerfile | 14 +- .examples/maxsize/docker-compose.yml | 2 +- .../app/Dockerfile | 2 + .../docker-compose.yml | 6 +- .examples/nginx-proxy/app/Dockerfile | 2 + .examples/nginx-proxy/docker-compose.yml | 6 +- .examples/readme.md | 7 +- .examples/simple/apache/docker-compose.yml | 2 +- .examples/simple/fpm/docker-compose.yml | 2 +- .../supervisor/apache/docker-compose.yml | 2 +- .../supervisor/fpm-alpine/docker-compose.yml | 2 +- .examples/supervisor/fpm/docker-compose.yml | 2 +- README.md | 8 +- 18 files changed, 343 insertions(+), 28 deletions(-) create mode 100644 .examples/full/.env create mode 100644 .examples/full/app/Dockerfile create mode 100644 .examples/full/docker-compose.yml create mode 100644 .examples/full/web/Dockerfile create mode 100644 .examples/full/web/nginx.conf diff --git a/.examples/full/.env b/.examples/full/.env new file mode 100644 index 0000000..b8378d9 --- /dev/null +++ b/.examples/full/.env @@ -0,0 +1,33 @@ +APP_ENV=production +APP_DEBUG=false + +# The URL of your application. +APP_URL=http://localhost + +# Set trusted proxy IP addresses. +# To trust all proxies that connect directly to your server, use a "*". +APP_TRUSTED_PROXIES=* + +# Database information +DB_CONNECTION=mysql +DB_HOST=db +DB_DATABASE=monica +DB_USERNAME=monica + +# Mail credentials used to send emails from the application. +MAIL_DRIVER=smtp +MAIL_HOST=smtp.domain.com +MAIL_PORT=587 +MAIL_USERNAME=username +MAIL_PASSWORD=password +MAIL_ENCRYPTION=tls +# Outgoing emails will be sent with these identity +MAIL_FROM_ADDRESS=email@example.com +MAIL_FROM_NAME="Monica instance" + +LOG_CHANNEL=stderr + +CACHE_DRIVER=redis +SESSION_DRIVER=database +QUEUE_DRIVER=redis +REDIS_HOST=redis diff --git a/.examples/full/app/Dockerfile b/.examples/full/app/Dockerfile new file mode 100644 index 0000000..586dfd2 --- /dev/null +++ b/.examples/full/app/Dockerfile @@ -0,0 +1,6 @@ +FROM monica:fpm-alpine + +# Use the default production configuration +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +ENV PHP_UPLOAD_LIMIT="10G" diff --git a/.examples/full/docker-compose.yml b/.examples/full/docker-compose.yml new file mode 100644 index 0000000..b8a1cfb --- /dev/null +++ b/.examples/full/docker-compose.yml @@ -0,0 +1,105 @@ +# Run Monica with fpm flavor, mariadb, cron, queue, redis, and nginx +# +# You first need to generate the secrets for the encryption key and db password: +# `{ echo -n 'base64:'; openssl rand -base64 32; } | docker secret create app_key -` +# `openssl rand -hex 24 | docker secret create mysql_password -` +# +# You might want to set these variables in you .env file: +#- APP_URL with your domain (https scheme) +# + +version: "3.9" + +services: + app: + build: ./app + image: monica-app + env_file: .env + environment: + - APP_KEY_FILE=/run/secrets/app_key + - DB_PASSWORD_FILE=/run/secrets/mysql_password + volumes: + - data:/var/www/html/storage + restart: always + depends_on: + - db + - redis + secrets: + - app_key + - mysql_password + + db: + image: mariadb:11 + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=true + - MYSQL_DATABASE=monica + - MYSQL_USER=monica + - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password + volumes: + - mysql:/var/lib/mysql + restart: always + secrets: + - mysql_password + + redis: + image: redis:alpine + restart: always + + cron: + build: ./app + image: monica-app + command: cron.sh + env_file: .env + environment: + - APP_KEY_FILE=/run/secrets/app_key + - DB_PASSWORD_FILE=/run/secrets/mysql_password + restart: always + volumes: + - data:/var/www/html/storage + depends_on: + - db + - redis + secrets: + - app_key + - mysql_password + + queue: + build: ./app + image: monica-app + command: queue.sh + env_file: .env + environment: + - APP_KEY_FILE=/run/secrets/app_key + - DB_PASSWORD_FILE=/run/secrets/mysql_password + restart: always + volumes: + - data:/var/www/html/storage + depends_on: + - db + - redis + secrets: + - app_key + - mysql_password + + web: + build: ./web + image: monica-web + restart: always + ports: + - 8081:80 + volumes: + - data:/var/www/html/storage:ro + depends_on: + - app + + +volumes: + data: + mysql: + + +secrets: + app_key: + external: true + mysql_password: + external: true diff --git a/.examples/full/web/Dockerfile b/.examples/full/web/Dockerfile new file mode 100644 index 0000000..d5a20c3 --- /dev/null +++ b/.examples/full/web/Dockerfile @@ -0,0 +1,9 @@ +FROM monica:fpm-alpine AS monica + +FROM nginx:alpine + +COPY nginx.conf /etc/nginx/nginx.conf + +# Copy content of monica image +COPY --from=monica /var/www/html /var/www/html +RUN ln -sf /var/www/html/storage/app/public /var/www/html/public/storage diff --git a/.examples/full/web/nginx.conf b/.examples/full/web/nginx.conf new file mode 100644 index 0000000..985ca53 --- /dev/null +++ b/.examples/full/web/nginx.conf @@ -0,0 +1,161 @@ +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + 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; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + set_real_ip_from 10.0.0.0/8; + set_real_ip_from 172.16.0.0/12; + set_real_ip_from 192.168.0.0/16; + real_ip_header X-Real-IP; + + # Connect to app service + upstream php-handler { + server app:9000; + } + + server { + listen 80; + + server_name monica; + + ## HSTS ## + # Add the 'Strict-Transport-Security' headers to enable HSTS protocol. + # WARNING: Only add the preload option once you read about the consequences: https://hstspreload.org/. + # This form will add the domain to a hardcoded list that is shipped in all major browsers and getting + # removed from this list could take several months. + # + #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;" always; + + add_header Referrer-Policy "no-referrer" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-Download-Options "noopen" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Permitted-Cross-Domain-Policies "none" always; + add_header X-Robots-Tag "none" always; + add_header X-XSS-Protection "1; mode=block" always; + + # Remove X-Powered-By, which is an information leak + fastcgi_hide_header X-Powered-By; + + root /var/www/html/public; + + index index.html index.htm index.php; + + charset utf-8; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ ^/(?:robots.txt|security.txt) { + allow all; + log_not_found off; + access_log off; + } + + error_page 404 500 502 503 504 /index.php; + + location ~ /\.well-known/(?:carddav|caldav) { + return 301 $scheme://$host/dav; + } + location = /.well-known/security.txt { + return 301 $scheme://$host/security.txt; + } + location ~ /\.(?!well-known).* { + deny all; + } + + # set max upload size + client_max_body_size 10G; + fastcgi_buffers 64 4K; + + # Enable gzip but do not remove ETag headers + gzip on; + gzip_vary on; + gzip_comp_level 4; + gzip_min_length 256; + gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; + gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; + + # Uncomment if your server is build with the ngx_pagespeed module + # This module is currently not supported. + #pagespeed off; + + location ~ \.php(/|$) { + # regex to split $uri to $fastcgi_script_name and $fastcgi_path + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + + fastcgi_pass php-handler; + fastcgi_index index.php; + + include fastcgi_params; + + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + # Bypass the fact that try_files resets $fastcgi_path_info + # see: http://trac.nginx.org/nginx/ticket/321 + set $path_info $fastcgi_path_info; + fastcgi_param PATH_INFO $path_info; + } + + # Adding the cache control header for js and css files + # Make sure it is BELOW the PHP block + location ~ \.(?:css|js|woff2?|svg|gif|json)$ { + try_files $uri /index.php$request_uri; + add_header Cache-Control "public, max-age=15778463"; + + ## HSTS ## + # Add the 'Strict-Transport-Security' headers to enable HSTS protocol. + # Note it is intended to have those duplicated to the ones above. + # WARNING: Only add the preload option once you read about the consequences: https://hstspreload.org/. + # This form will add the domain to a hardcoded list that is shipped in all major browsers and getting + # removed from this list could take several months. + # + #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;" always; + + add_header Referrer-Policy "no-referrer" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-Download-Options "noopen" always; + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Permitted-Cross-Domain-Policies "none" always; + add_header X-Robots-Tag "none" always; + add_header X-XSS-Protection "1; mode=block" always; + + # Optional: Don't log access to assets + access_log off; + } + + location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ { + try_files $uri /index.php$request_uri; + + # Optional: Don't log access to assets + access_log off; + } + + # deny access to .htaccess files + location ~ /\.ht { + deny all; + } + } +} diff --git a/.examples/maxsize/app/Dockerfile b/.examples/maxsize/app/Dockerfile index 47c3db8..242be63 100644 --- a/.examples/maxsize/app/Dockerfile +++ b/.examples/maxsize/app/Dockerfile @@ -3,12 +3,8 @@ FROM monica:fpm-alpine # Use the default production configuration RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" -RUN set -ex;\ - \ - { \ - echo '[www]'; \ - echo 'upload_max_filesize = 500M'; \ - echo 'post_max_size = 500M'; \ - echo 'max_execution_time = 600'; \ - } \ - > $PHP_INI_DIR/conf.d/uploads.ini +# Set the upload limit to 10G +ENV PHP_UPLOAD_LIMIT="10G" + +# Set the memory limit to 512M +ENV PHP_MEMORY_LIMIT="512M" diff --git a/.examples/maxsize/docker-compose.yml b/.examples/maxsize/docker-compose.yml index 879f5ea..a584246 100644 --- a/.examples/maxsize/docker-compose.yml +++ b/.examples/maxsize/docker-compose.yml @@ -41,7 +41,7 @@ services: - app db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/.examples/nginx-proxy-self-signed-ssl/app/Dockerfile b/.examples/nginx-proxy-self-signed-ssl/app/Dockerfile index 0201286..ae418bb 100644 --- a/.examples/nginx-proxy-self-signed-ssl/app/Dockerfile +++ b/.examples/nginx-proxy-self-signed-ssl/app/Dockerfile @@ -2,3 +2,5 @@ FROM monica:fpm # Use the default production configuration RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +ENV PHP_UPLOAD_LIMIT="10G" diff --git a/.examples/nginx-proxy-self-signed-ssl/docker-compose.yml b/.examples/nginx-proxy-self-signed-ssl/docker-compose.yml index 224a3b5..41eb3f0 100644 --- a/.examples/nginx-proxy-self-signed-ssl/docker-compose.yml +++ b/.examples/nginx-proxy-self-signed-ssl/docker-compose.yml @@ -37,7 +37,7 @@ services: - redis db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica @@ -54,11 +54,11 @@ services: cron: build: ./app image: monica-app + command: cron.sh env_file: .env restart: always volumes: - data:/var/www/html/storage - command: cron.sh depends_on: - db - redis @@ -66,11 +66,11 @@ services: queue: build: ./app image: monica-app + command: queue.sh env_file: .env restart: always volumes: - data:/var/www/html/storage - command: queue.sh depends_on: - db - redis diff --git a/.examples/nginx-proxy/app/Dockerfile b/.examples/nginx-proxy/app/Dockerfile index 0201286..ae418bb 100644 --- a/.examples/nginx-proxy/app/Dockerfile +++ b/.examples/nginx-proxy/app/Dockerfile @@ -2,3 +2,5 @@ FROM monica:fpm # Use the default production configuration RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +ENV PHP_UPLOAD_LIMIT="10G" diff --git a/.examples/nginx-proxy/docker-compose.yml b/.examples/nginx-proxy/docker-compose.yml index 9b48716..068904b 100644 --- a/.examples/nginx-proxy/docker-compose.yml +++ b/.examples/nginx-proxy/docker-compose.yml @@ -33,7 +33,7 @@ services: - redis db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica @@ -50,11 +50,11 @@ services: cron: build: ./app image: monica-app + command: cron.sh env_file: .env restart: always volumes: - data:/var/www/html/storage - command: cron.sh depends_on: - db - redis @@ -62,11 +62,11 @@ services: queue: build: ./app image: monica-app + command: queue.sh env_file: .env restart: always volumes: - data:/var/www/html/storage - command: queue.sh depends_on: - db - redis diff --git a/.examples/readme.md b/.examples/readme.md index 37487c9..1cd9b2c 100644 --- a/.examples/readme.md +++ b/.examples/readme.md @@ -5,6 +5,7 @@ In this section you will find some examples about how to use monica's docker ima | Example | Description | |---------|-------------| | [`simple`](simple) | simple example that run a container. +| [`full`](full) | example that run `fpm-alpine` with nginx, redis, separate cron and queue containers, and uses secrets. | [`supervisor`](supervisor) | uses supervisor to run a cron and a queue inside your container. | [`nginx-proxy-self-signed-ssl`](nginx-proxy-self-signed-ssl) | shows you how to run monica with a self signed ssl certificate. | [`nginx-proxy`](nginx-proxy) | shows you how to run monica with https and generate a [Let's Encrypt](https://letsencrypt.org/) certificate. @@ -19,7 +20,7 @@ In this section you will find some examples about how to use monica's docker ima First, download a copy of Monica example configuration file: ```sh -curl -sS https://raw.githubusercontent.com/monicahq/monica/main/.env.example -o .env +curl -sS https://raw.githubusercontent.com/monicahq/monica/4.x/.env.example -o .env ``` Open the file in an editor and update it for your own needs: @@ -33,7 +34,7 @@ Open the file in an editor and update it for your own needs: ### With supervisor The [`supervisor`](supervisor) examples shows you how to run monica with -- a db container (mysql:5.7) +- a db container (mariadb:11) - an app container, which run `supervisord` to handle a web server/fpm, a cron, and a queue. This let you use `QUEUE_CONNECTION=database` in your `.env` file. @@ -61,6 +62,6 @@ Don't forget to set: You may want to set `APP_ENV=production` to force the use of `https` scheme. This example add a `redis` container, that can be used too, adding these variables to your `.env` file: -- `REDIS_HOST=redis`: mandatory +- `REDIS_HOST=redis`: mandatory, where `redis` is the name of the redis container - `CACHE_DRIVER=redis`: to use redis as a cache table - `QUEUE_CONNECTION=redis`: to use redis as a queue table diff --git a/.examples/simple/apache/docker-compose.yml b/.examples/simple/apache/docker-compose.yml index 289e65b..d17ce11 100644 --- a/.examples/simple/apache/docker-compose.yml +++ b/.examples/simple/apache/docker-compose.yml @@ -24,7 +24,7 @@ services: restart: always db: - image: mysql:8.0 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/.examples/simple/fpm/docker-compose.yml b/.examples/simple/fpm/docker-compose.yml index ab2a245..5938a94 100644 --- a/.examples/simple/fpm/docker-compose.yml +++ b/.examples/simple/fpm/docker-compose.yml @@ -32,7 +32,7 @@ services: restart: always db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/.examples/supervisor/apache/docker-compose.yml b/.examples/supervisor/apache/docker-compose.yml index 8916ac8..fad0c2d 100644 --- a/.examples/supervisor/apache/docker-compose.yml +++ b/.examples/supervisor/apache/docker-compose.yml @@ -29,7 +29,7 @@ services: restart: always db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/.examples/supervisor/fpm-alpine/docker-compose.yml b/.examples/supervisor/fpm-alpine/docker-compose.yml index 0b65a8b..b484860 100644 --- a/.examples/supervisor/fpm-alpine/docker-compose.yml +++ b/.examples/supervisor/fpm-alpine/docker-compose.yml @@ -36,7 +36,7 @@ services: - app db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/.examples/supervisor/fpm/docker-compose.yml b/.examples/supervisor/fpm/docker-compose.yml index 7495bf8..da49094 100644 --- a/.examples/supervisor/fpm/docker-compose.yml +++ b/.examples/supervisor/fpm/docker-compose.yml @@ -38,7 +38,7 @@ services: - app db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica diff --git a/README.md b/README.md index f809119..dd5087d 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,14 @@ monica ### Connect to a mysql database -Monica needs a database connection, and currently supports mysql only. Run these to have a running environment: +Monica needs a database connection, and currently supports mysql/mariadb only. Run these to have a running environment: ```console mysqlCid="$(docker run -d \ -e MYSQL_RANDOM_ROOT_PASSWORD=true \ -e MYSQL_DATABASE=monica \ -e MYSQL_USER=homestead \ -e MYSQL_PASSWORD=secret \ - "mysql:5.7")" + "mariadb:11")" docker run -d \ --link "$mysqlCid":mysql \ -e DB_HOST=mysql \ @@ -146,7 +146,7 @@ services: restart: always db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica @@ -223,7 +223,7 @@ services: restart: always db: - image: mysql:5.7 + image: mariadb:11 environment: - MYSQL_RANDOM_ROOT_PASSWORD=true - MYSQL_DATABASE=monica