Skip to content

Commit

Permalink
docs: update examples (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Nov 1, 2023
1 parent 9618978 commit d50bf7c
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 28 deletions.
33 changes: 33 additions & 0 deletions .examples/full/.env
Original file line number Diff line number Diff line change
@@ -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 protected]
MAIL_FROM_NAME="Monica instance"

LOG_CHANNEL=stderr

CACHE_DRIVER=redis
SESSION_DRIVER=database
QUEUE_DRIVER=redis
REDIS_HOST=redis
6 changes: 6 additions & 0 deletions .examples/full/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
105 changes: 105 additions & 0 deletions .examples/full/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .examples/full/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
161 changes: 161 additions & 0 deletions .examples/full/web/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
14 changes: 5 additions & 9 deletions .examples/maxsize/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .examples/maxsize/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
- app

db:
image: mysql:5.7
image: mariadb:11
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=true
- MYSQL_DATABASE=monica
Expand Down
2 changes: 2 additions & 0 deletions .examples/nginx-proxy-self-signed-ssl/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions .examples/nginx-proxy-self-signed-ssl/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
- redis

db:
image: mysql:5.7
image: mariadb:11
environment:
- MYSQL_RANDOM_ROOT_PASSWORD=true
- MYSQL_DATABASE=monica
Expand All @@ -54,23 +54,23 @@ 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

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
Expand Down
2 changes: 2 additions & 0 deletions .examples/nginx-proxy/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading

0 comments on commit d50bf7c

Please sign in to comment.