diff --git a/Dockerfile b/Dockerfile index 7b7d793..129b950 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,17 +66,18 @@ ADD logrotate/cron /etc/periodic/daily/logrotate-cron # Custom PHP configuration COPY php/php.ini /usr/local/etc/php/php.ini +COPY script/prepare.sh /opt/scripts/prepare.sh COPY script/start.sh /opt/scripts/start.sh COPY script/entry.sh /opt/scripts/entry.sh # Make sure every user can start the container RUN chown -R 1000:1000 /opt/scripts \ - && chmod 0777 /opt/scripts/start.sh /opt/scripts/entry.sh \ + && chmod 0777 /opt/scripts/{prepare,start,entry}.sh \ && chmod +x /etc/periodic/daily/logrotate-cron WORKDIR /var/www/html -ENTRYPOINT ["/opt/scripts/entry.sh"] +ENTRYPOINT ["/opt/scripts/prepare.sh", "/opt/scripts/entry.sh"] CMD ["/opt/scripts/start.sh"] diff --git a/script/prepare.sh b/script/prepare.sh new file mode 100644 index 0000000..0a1b626 --- /dev/null +++ b/script/prepare.sh @@ -0,0 +1,51 @@ +#!/bin/sh -e + +html_dir="/var/www/html" + +www_folder() { + mkdir -p "$1" + chown -R www-data "$1" +} + +www_file() { + touch "$1" + chown www-data "$1" +} + +php_logs() { + www_folder "/var/log/php" + www_file "/var/log/php/access.log" + www_file "/var/log/php/error.log" + + # The "c" supplementary letter is needed because the first letter will be cut + # at replacement. + sed -i \ + -e '/^;catch_workers_output/ccatch_workers_output = yes' \ + -e '/^;log_level/clog_level = debug' \ + -e '/^;listen/clisten = 9000' \ + -e '/^;access.log/caccess.log = /var/log/php/access.log' \ + -e '/^;php_flag\[display_errors\]/cphp_flag[display_errors] = off' \ + -e '/^;php_admin_value\[error_log\]/cphp_admin_value[error_log] = /var/log/php/error.log' \ + -e '/^;php_admin_flag\[log_errors\]/cphp_admin_flag[log_errors] = on' \ + -e '/^;clear_env/cclear_env = no' \ + "/usr/local/etc/php-fpm.d/www.conf" +} + +symfony_logs() { + www_folder "${html_dir}/var" +} + +symfony_vendor() { + www_folder "${html_dir}/vendor" +} + +symfony_public() { + www_folder "${html_dir}/public" +} + +php_logs +symfony_logs +symfony_vendor +symfony_public + +exec "$@" diff --git a/script/start.sh b/script/start.sh index 52f4365..d6adee3 100644 --- a/script/start.sh +++ b/script/start.sh @@ -1,47 +1,6 @@ #!/usr/bin/env bash set -o errexit -php_logs() { - local conf_file="/usr/local/etc/php-fpm.d/www.conf" - - local log_dir="/var/log/php" - local access_log_file="${log_dir}/access.log" - local error_log_file="${log_dir}/error.log" - - mkdir -p ${log_dir} \ - && touch ${access_log_file} \ - && touch ${error_log_file}; - - if [ ! -z "$UID" ] && [ ! -z "$GID" ]; then - chown -R $UID:$GID ${log_dir} - fi - - # The "c" supplementary letter is needed because the first letter will be cut at replacement. - sed -i '/^;catch_workers_output/ccatch_workers_output = yes' ${conf_file} \ - && sed -i '/^;log_level/clog_level = debug' ${conf_file} \ - && sed -i '/^;listen/clisten = 9000' ${conf_file} \ - && sed -i '/^;access.log/caccess.log = /var/log/php/access.log' ${conf_file} \ - && sed -i '/^;php_flag\[display_errors\]/cphp_flag[display_errors] = off' ${conf_file} \ - && sed -i '/^;php_admin_value\[error_log\]/cphp_admin_value[error_log] = /var/log/php/error.log' ${conf_file} \ - && sed -i '/^;php_admin_flag\[log_errors\]/cphp_admin_flag[log_errors] = on' ${conf_file} \ - && sed -i '/^;clear_env/cclear_env = no' ${conf_file} -} - -symfony_logs() { - local html_dir="/var/www/html" - local var_dir="${html_dir}/var" - - if [ ! -z "$UID" ] && [ ! -z "$GID" ]; then - # To avoid permissions issues, create directly the /var/www/html/var directory and give it to $UID:$GID - - mkdir -p ${var_dir} - chown -R $UID:$GID ${var_dir} - fi -} - -php_logs -symfony_logs - cron -L 15 # Add host ip as an alias in /etc/hosts to allow container to ping it without guessing it's ip everytime