refactor!: refactoring log settings

BREAKING CHANGE: delete environment variables LOG_TO_STDOUT in Dockerfile
pull/87/head
xxxxxliil 2021-05-26 10:49:39 +08:00
parent a47a8ab49e
commit 1b24029729
5 changed files with 51 additions and 18 deletions

View File

@ -16,7 +16,7 @@ ENV GID=991 \
DB_PORT=3306 \
FLARUM_TITLE=Docker-Flarum \
DEBUG=false \
LOG_TO_STDOUT=false \
LOG_OUTPUT=file \
GITHUB_TOKEN_AUTH=false \
FLARUM_PORT=8888
@ -56,13 +56,15 @@ RUN apk add --no-progress --no-cache \
&& curl -s http://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& sed -i 's/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/' /etc/php8/php.ini \
&& chmod +x /usr/local/bin/composer \
&& mkdir -p /run/php /flarum/app \
&& mkdir -p /flarum/app /run/php /var/log/flarum \
&& COMPOSER_CACHE_DIR="/tmp" composer create-project flarum/flarum:$VERSION /flarum/app \
&& composer clear-cache \
&& rm -rf /flarum/.composer /tmp/* \
&& rm -rf /flarum/.composer /tmp/* /flarum/app/storage/logs \
&& cd /flarum/app/storage/ \
&& ln -s /var/log/flarum logs \
&& setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/nginx
COPY rootfs /
RUN chmod +x /usr/local/bin/* /etc/s6.d/*/run /etc/s6.d/.s6-svscan/*
VOLUME /etc/nginx/flarum /flarum/app/extensions /flarum/app/public/assets /flarum/app/storage/logs
VOLUME /etc/nginx/flarum /flarum/app/extensions /flarum/app/public/assets /var/log
CMD ["/usr/local/bin/startup"]

View File

@ -34,10 +34,10 @@
### Volume
- **/etc/nginx/flarum** : Nginx location directory
- **/flarum/app/extensions** : Flarum extension directory
- **/flarum/app/public/assets** : Flarum assets directory
- **/flarum/app/storage/logs** : Flarum logs directory
- **/etc/nginx/flarum** : Nginx location directory
- **/var/log** : Flarum & Nginx & PHP-FPM log directory
### Environment variables
@ -57,7 +57,8 @@
| **UPLOAD_MAX_SIZE** | The maximum size of an uploaded file | *optional* | 50M
| **PHP_MEMORY_LIMIT** | PHP memory limit | *optional* | 128M |
| **OPCACHE_MEMORY_LIMIT** | OPcache memory size in megabytes | *optional* | 128
| **LOG_TO_STDOUT** | Enable nginx and php error logs to stdout | *optional* | false
| **LOG_TO_STDOUT** | Enable nginx and php error logs to stdout (abandoned in the future)| *optional* | false
| **LOG_OUTOUT** | Set nginx and php log output (value: file/stdio) | *optional* | file
| **GITHUB_TOKEN_AUTH** | Github token to download private extensions | *optional* | false
| **PHP_EXTENSIONS** | Install additional php extensions | *optional* | none
@ -96,7 +97,7 @@ services:
volumes:
- /mnt/docker/flarum/assets:/flarum/app/public/assets
- /mnt/docker/flarum/extensions:/flarum/app/extensions
- /mnt/docker/flarum/storage/logs:/flarum/app/storage/logs
- /mnt/docker/flarum/log:/var/log
- /mnt/docker/flarum/nginx:/etc/nginx/flarum
ports:
- 80:8888
@ -170,7 +171,7 @@ services:
volumes:
- /mnt/docker/flarum/assets:/flarum/app/public/assets
- /mnt/docker/flarum/extensions:/flarum/app/extensions
- /mnt/docker/flarum/storage/logs:/flarum/app/storage/logs
- /mnt/docker/flarum/log:/var/log
- /mnt/docker/flarum/nginx:/etc/nginx/flarum
```

View File

@ -1,6 +1,7 @@
worker_processes auto;
pid /tmp/nginx.pid;
daemon off;
error_log <path-to-nginx-error_log> warn;
pid /tmp/nginx.pid;
worker_processes auto;
events {
worker_connections 1024;
@ -11,8 +12,7 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log /tmp/ngx_error.log error;
access_log <path-to-nginx-access_log>;
sendfile on;
keepalive_timeout 15;

View File

@ -4,10 +4,11 @@
[global]
daemonize = no
error_log = /tmp/php_error.log
error_log = <path-to-php-fpm-error_log>
[www]
listen = /run/php/php8-fpm.sock
access.log = <path-to-php-fpm-access_log>
pm = ondemand
pm.max_children = 30
pm.process_idle_timeout = 10s

View File

@ -30,14 +30,43 @@ done
find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \+
find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \+
# Set log output to STDOUT if wanted (LOG_TO_STDOUT=true)
# Set log output to STDOUT if wanted (LOG_TO_STDOUT=true) (abandoned in the future)
#echo "[WARN] Environment variables LOG_TO_STDOUT will be abandoned in the future"
if [ "${LOG_TO_STDOUT}" = true ]; then
echo "[INFO] Logging to stdout activated"
chmod o+w /dev/stdout
sed -i "s/.*error_log.*$/error_log \/dev\/stdout warn;/" /etc/nginx/nginx.conf
sed -i "s/.*error_log.*$/error_log = \/dev\/stdout/" /etc/php8/php-fpm.d/www.conf
LOG_OUTPUT='stdio'
else
LOG_OUTPUT='file'
fi
# Set log output
set_log_to_stdio(){
# by https://serverfault.com/questions/658367/how-to-get-php-fpm-to-log-to-stdout-stderr-when-running-in-a-docker-container
sed -i 's,<path-to-nginx-access_log>,/proc/self/fd/1,' /etc/nginx/nginx.conf
sed -i 's,<path-to-nginx-error_log>,/proc/self/fd/2,' /etc/nginx/nginx.conf
sed -i 's,<path-to-php-fpm-access_log>,/proc/self/fd/1,' /etc/php8/php-fpm.d/www.conf
sed -i 's,<path-to-php-fpm-error_log>,/proc/self/fd/2,' /etc/php8/php-fpm.d/www.conf
}
chown -R "${UID}":"${GID}" /var/log/*
case "${LOG_OUTPUT}" in
'file')
sed -i 's,<path-to-nginx-access_log>,/var/log/nginx/nginx-access.log,' /etc/nginx/nginx.conf
sed -i 's,<path-to-nginx-error_log>,/var/log/nginx/nginx-error.log,' /etc/nginx/nginx.conf
sed -i 's,<path-to-php-fpm-access_log>,/var/log/php8/fpm-access.log,' /etc/php8/php-fpm.d/www.conf
sed -i 's,<path-to-php-fpm-error_log>,/var/log/php8/fpm-error.log,' /etc/php8/php-fpm.d/www.conf
;;
'stdio')
set_log_to_stdio
;;
*)
echo "[WARN] The environment variable LOG_OUTPUT has an incorrect value or is not set, use stdio"
set_log_to_stdio
;;
esac
# Install additional php extensions
if [ -n "${PHP_EXTENSIONS}" ]; then
for php_extension in ${PHP_EXTENSIONS}; do