Skip to content

Commit

Permalink
2.3 backport (#88)
Browse files Browse the repository at this point in the history
* Version v2.3.0-RC2

* fix DB connect test message (#87)

* Rename docker dir to conf, closes #85

* Backport recent image changes to master
  • Loading branch information
djdefi committed Jun 1, 2016
1 parent 6de3691 commit 13a3310
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ RUN DEBIAN_FRONTEND=noninteractive \
apt-get clean && apt-get autoremove -q && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /tmp/*

COPY docker/php-fpm-pool.conf /etc/php5/fpm/pool.d/www.conf
COPY docker/supervisord.conf /etc/supervisor/supervisord.conf
COPY conf/php-fpm-pool.conf /etc/php5/fpm/pool.d/www.conf
COPY conf/supervisord.conf /etc/supervisor/supervisord.conf

RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php5/fpm/php-fpm.conf
RUN mkdir -p /var/www/html && \
chown -R www-data /var/www

COPY docker/crontab /etc/cron.d/artisan-schedule
COPY docker/entrypoint.sh /sbin/entrypoint.sh
COPY conf/crontab /etc/cron.d/artisan-schedule
COPY conf/entrypoint.sh /sbin/entrypoint.sh

RUN chmod 0644 /etc/cron.d/artisan-schedule && \
touch /var/log/cron.log
Expand All @@ -46,7 +46,7 @@ RUN wget https://github.com/cachethq/Cachet/archive/${cachet_ver}.tar.gz && \
rm -r ${cachet_ver}.tar.gz && \
php composer.phar install --no-dev -o

COPY docker/.env.docker /var/www/html/.env
COPY conf/.env.docker /var/www/html/.env

VOLUME /var/www
EXPOSE 8000
Expand Down
26 changes: 26 additions & 0 deletions conf/.env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
APP_ENV="{{APP_ENV}}"
APP_DEBUG="{{APP_DEBUG}}"
APP_URL="{{APP_URL}}"
APP_KEY={{APP_KEY}}

DB_DRIVER="{{DB_DRIVER}}"
DB_HOST="{{DB_HOST}}"
DB_DATABASE="{{DB_DATABASE}}"
DB_USERNAME="{{DB_USERNAME}}"
DB_PASSWORD="{{DB_PASSWORD}}"

CACHE_DRIVER="{{CACHE_DRIVER}}"
SESSION_DRIVER="{{SESSION_DRIVER}}"
QUEUE_DRIVER="{{QUEUE_DRIVER}}"

MAIL_DRIVER="{{MAIL_DRIVER}}"
MAIL_HOST="{{MAIL_HOST}}"
MAIL_PORT="{{MAIL_PORT}}"
MAIL_USERNAME="{{MAIL_USERNAME}}"
MAIL_PASSWORD="{{MAIL_PASSWORD}}"
MAIL_ADDRESS="{{MAIL_ADDRESS}}"
MAIL_NAME="{{MAIL_NAME}}"

REDIS_HOST="{{REDIS_HOST}}"
REDIS_DATABASE="{{REDIS_DATABASE}}"
REDIS_PORT="{{REDIS_PORT}}"
2 changes: 2 additions & 0 deletions conf/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#minute hour mday month wday who command
* * * * * www-data php /var/www/html/artisan schedule:run >> /dev/null 2>&1
127 changes: 127 additions & 0 deletions conf/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash
set -eo pipefail

[[ $DEBUG == true ]] && set -x

check_database_connection() {
case ${DB_DRIVER} in
mysql)
prog="mysqladmin -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} status"
;;
pgsql)
prog=$(find /usr/lib/postgresql/ -name pg_isready)
prog="${prog} -h ${DB_HOST} -U ${DB_USERNAME} -d ${DB_DATABASE} -t 1"
;;
esac
timeout=60
while ! ${prog} >/dev/null 2>&1
do
timeout=$(( $timeout - 1 ))
if [[ $timeout -eq 0 ]]; then
echo
echo "Could not connect to database server. Aborting..."
return 1
fi
echo -n "."
sleep 1
done
echo
}

initialize_system() {
APP_ENV=${APP_ENV:-development}
APP_DEBUG=${APP_DEBUG:-true}
APP_URL=${APP_URL:-http://localhost}
APP_KEY=${APP_KEY:-SECRET}

DB_DRIVER=${DB_DRIVER:-pgsql}
DB_HOST=${DB_HOST:-postgres}
DB_DATABASE=${DB_DATABASE:-cachet}
DB_USERNAME=${DB_USERNAME:-postgres}
DB_PASSWORD=${DB_PASSWORD:-postgres}
DB_PORT=${DB_PORT:-5432}

CACHE_DRIVER=${CACHE_DRIVER:-apc}
SESSION_DRIVER=${SESSION_DRIVER:-apc}
QUEUE_DRIVER=${QUEUE_DRIVER:-database}

MAIL_DRIVER=${MAIL_DRIVER:-smtp}
MAIL_HOST=${MAIL_HOST:-mailtrap.io}
MAIL_PORT=${MAIL_PORT:-2525}
MAIL_USERNAME=${MAIL_USERNAME:-null}
MAIL_PASSWORD=${MAIL_PASSWORD:-null}
MAIL_ADDRESS=${MAIL_ADDRESS:-null}
MAIL_NAME=${MAIL_NAME:-null}

REDIS_HOST=${REDIS_HOST:-null}
REDIS_DATABASE=${REDIS_DATABASE:-null}
REDIS_PORT=${REDIS_PORT:-null}

# configure env file

sed 's,{{APP_ENV}},'"${APP_ENV}"',g' -i /var/www/html/.env
sed 's,{{APP_DEBUG}},'"${APP_DEBUG}"',g' -i /var/www/html/.env
sed 's,{{APP_URL}},'"${APP_URL}"',g' -i /var/www/html/.env
sed 's,{{APP_KEY}},'${APP_KEY}',g' -i /var/www/html/.env

sed 's,{{DB_DRIVER}},'"${DB_DRIVER}"',g' -i /var/www/html/.env
sed 's,{{DB_HOST}},'"${DB_HOST}"',g' -i /var/www/html/.env
sed 's,{{DB_DATABASE}},'"${DB_DATABASE}"',g' -i /var/www/html/.env
sed 's,{{DB_USERNAME}},'"${DB_USERNAME}"',g' -i /var/www/html/.env
sed 's,{{DB_PASSWORD}},'"${DB_PASSWORD}"',g' -i /var/www/html/.env

sed 's,{{CACHE_DRIVER}},'"${CACHE_DRIVER}"',g' -i /var/www/html/.env
sed 's,{{SESSION_DRIVER}},'"${SESSION_DRIVER}"',g' -i /var/www/html/.env
sed 's,{{QUEUE_DRIVER}},'"${QUEUE_DRIVER}"',g' -i /var/www/html/.env

sed 's,{{MAIL_DRIVER}},'"${MAIL_DRIVER}"',g' -i /var/www/html/.env
sed 's,{{MAIL_HOST}},'"${MAIL_HOST}"',g' -i /var/www/html/.env
sed 's,{{MAIL_PORT}},'"${MAIL_PORT}"',g' -i /var/www/html/.env
sed 's,{{MAIL_USERNAME}},'"${MAIL_USERNAME}"',g' -i /var/www/html/.env
sed 's,{{MAIL_PASSWORD}},'"${MAIL_PASSWORD}"',g' -i /var/www/html/.env
sed 's,{{MAIL_ADDRESS}},'"${MAIL_ADDRESS}"',g' -i /var/www/html/.env
sed 's,{{MAIL_NAME}},'"${MAIL_NAME}"',g' -i /var/www/html/.env

sed 's,{{REDIS_HOST}},'"${REDIS_HOST}"',g' -i /var/www/html/.env
sed 's,{{REDIS_DATABASE}},'"${REDIS_DATABASE}"',g' -i /var/www/html/.env
sed 's,{{REDIS_PORT}},'"${REDIS_PORT}"',g' -i /var/www/html/.env

php composer.phar install --no-dev -o
php artisan app:install
rm -rf bootstrap/cache/*
touch /var/www/.cachet-installed
start_system
}

start_system() {
check_database_connection
[ -f "/var/www/.cachet-installed" ] && echo "Starting Cachet" || initialize_system
php artisan config:cache
sudo /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
}

case ${1} in
init|start)

case ${1} in
start)
start_system
;;
init)
initialize_system
;;
esac
;;
help)
echo "Available options:"
echo " start - Starts the Cachet server (default)"
echo " init - Initialize the Cachet server (e.g. create databases, compile assets)."
echo " help - Displays the help"
echo " [command] - Execute the specified command, eg. bash."
;;
*)
exec "$@"
;;
esac

exit 0
30 changes: 30 additions & 0 deletions conf/nginx-site.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
server {
listen 8000 default; ## Listen for ipv4; this line is default and implied

# Make site accessible from http://localhost/
server_name localhost;
root /var/www/html/public;

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_pass cachet:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_keep_conn on;
}

location ~ /\.ht {
deny all;
}

}
24 changes: 24 additions & 0 deletions conf/php-fpm-pool.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[www]
user = www-data
group = www-data

listen = 9000

request_terminate_timeout = 120s

pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 10s
pm.max_requests = 500
chdir = /

env[DB_DRIVER] = $DB_DRIVER
env[DB_HOST] = $DB_HOST
env[DB_DATABASE] = $DB_DATABASE
env[DB_USERNAME] = $DB_USERNAME
env[DB_PASSWORD] = $DB_PASSWORD
env[CACHE_DRIVER] = $CACHE_DRIVER


[global]
daemonize = no
22 changes: 22 additions & 0 deletions conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[supervisord]
logfile=/dev/null ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=0 ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=0 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket

[program:php-fpm]
command=/usr/sbin/php5-fpm -c /etc/php5/fpm

[program:cron]
command=/usr/sbin/cron -f
4 changes: 2 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eo pipefail

[[ $DEBUG == true ]] && set -x

Expand All @@ -16,7 +16,7 @@ check_database_connection() {
timeout=60
while ! ${prog} >/dev/null 2>&1
do
timeout=$(expr $timeout - 1)
timeout=$(( $timeout - 1 ))
if [[ $timeout -eq 0 ]]; then
echo
echo "Could not connect to database server. Aborting..."
Expand Down
2 changes: 1 addition & 1 deletion docker/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket

[program:php-fpm7.0]
[program:php-fpm]
command=/usr/sbin/php5-fpm -c /etc/php5/fpm

[program:cron]
Expand Down

0 comments on commit 13a3310

Please sign in to comment.