Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Also prepare the filesystem when a command is given #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
51 changes: 51 additions & 0 deletions script/prepare.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
41 changes: 0 additions & 41 deletions script/start.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down