Skip to content

Commit

Permalink
Improved main container layout
Browse files Browse the repository at this point in the history
Fixes #36 and Fixes #38
  • Loading branch information
mblaschke committed Apr 19, 2015
1 parent 02244da commit 1d577c6
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 87 deletions.
5 changes: 5 additions & 0 deletions docker/main/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM ubuntu:14.04

# Ensure UTF-8
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

COPY conf/php.ini /etc/php5/mods-available/docker-boilerplate.ini
COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY conf/locale.conf /opt/docker/locale.conf
Expand Down
4 changes: 2 additions & 2 deletions docker/main/bin/dnsmasq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function dnsmasq_start() {
## set dnsmasq to main nameserver
echo "nameserver 127.0.0.1" > /etc/resolv.conf

## wait for 6 hours
sleep 21600
## wait for 10 hours
sleep 36000
}

## Fetch IP from services
Expand Down
29 changes: 29 additions & 0 deletions docker/main/bin/init-mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

#############################
## Init MySQL
#############################

echo "[client]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
[mysql]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
database=\"$MYSQL_DATABASE\"
default-character-set=utf8
local-infile=1
show-warnings
auto-rehash
sigint-ignore
reconnect
[mysqldump]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
" | tee /root/.my.cnf > /home/.my.cnf
50 changes: 50 additions & 0 deletions docker/main/bin/init-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

#############################
## Init PHP
#############################
echo "
date.timezone = ${PHP_TIMEZONE}
" >> /etc/php5/mods-available/docker-boilerplate.ini

#############################
## Init PHP-FPM
#############################

# Backup original
if [ ! -f "/opt/docker/.fpm-www.conf" ]; then
cp /etc/php5/fpm/pool.d/www.conf /opt/docker/.fpm-www.conf
fi

## Remove old logs
rm -f -- /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log
touch -- /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log
chmod 666 /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log

# Restore original
cp /opt/docker/.fpm-www.conf /etc/php5/fpm/pool.d/www.conf
sed -i "s@listen = /var/run/php5-fpm.sock@listen = 9000@" /etc/php5/fpm/pool.d/www.conf

# Manipulate php-fpm configuration
echo "
; Server resource settings
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes
access.format = \"%R - %u %t \\\"%m %r%Q%q\\\" %s %f cpu:%C%% mem:%{megabytes}M reqTime:%d\"
access.log = /tmp/php.access.log
slowlog = /tmp/php.slow.log
request_slowlog_timeout = 30s
php_admin_value[error_log] = /tmp/php.error.log
php_admin_flag[log_errors] = on
env[TYPO3_CONTEXT] = ${TYPO3_CONTEXT}
env[FLOW_CONTEXT] = ${FLOW_CONTEXT}
env[FLOW_REWRITEURLS] = ${FLOW_REWRITEURLS}
" >> /etc/php5/fpm/pool.d/www.conf
8 changes: 8 additions & 0 deletions docker/main/bin/init-ssmtp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

#############################
## Init SSMTP
#############################

sed -i "s/mailhub=.*/mailhub=${MAIL_GATEWAY}/" /etc/ssmtp/ssmtp.conf
sed -i "s/#FromLineOverride=.*/FromLineOverride=YES/" /etc/ssmtp/ssmtp.conf
5 changes: 5 additions & 0 deletions docker/main/bin/init-system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

## Set uid/gid for www-data user
usermod --uid "${PHP_UID}" --shell /bin/bash --home /home www-data
groupmod --gid "${PHP_GID}" www-data
92 changes: 7 additions & 85 deletions docker/main/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,95 +1,17 @@
#!/bin/bash
set -e

#############################
## Init UID/GID
#############################

usermod --uid "${PHP_UID}" --shell /bin/bash --home /home www-data
groupmod --gid "${PHP_GID}" www-data

#############################
## Init MySQL
#############################

echo "[client]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
## Init system
source /opt/docker/init-system.sh

[mysql]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
database=\"$MYSQL_DATABASE\"
default-character-set=utf8
local-infile=1
show-warnings
auto-rehash
sigint-ignore
reconnect
## Init MySQL (client)
source /opt/docker/init-mysql.sh

[mysqldump]
host=mysql
user=\"$MYSQL_USER\"
password=\"$MYSQL_PASSWORD\"
" | tee /root/.my.cnf > /home/.my.cnf

#############################
## Init SSMTP
#############################
source /opt/docker/init-ssmtp.sh

sed -i "s/mailhub=.*/mailhub=${MAIL_GATEWAY}/" /etc/ssmtp/ssmtp.conf

#############################
## Init PHP
#############################
echo "
date.timezone = ${PHP_TIMEZONE}
" > /etc/php5/mods-available/docker-boilerplate.ini

#############################
## Init PHP-FPM
#############################

# Backup original
if [ ! -f "/opt/docker/.fpm-www.conf" ]; then
cp /etc/php5/fpm/pool.d/www.conf /opt/docker/.fpm-www.conf
fi

## Remove old logs
rm -f -- /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log
touch -- /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log
chmod 666 /tmp/php.access.log /tmp/php.slow.log /tmp/php.error.log

# Restore original
cp /opt/docker/.fpm-www.conf /etc/php5/fpm/pool.d/www.conf
sed -i "s@listen = /var/run/php5-fpm.sock@listen = 9000@" /etc/php5/fpm/pool.d/www.conf

# Manipulate php-fpm configuration
echo "
; Server resource settings
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes
access.format = \"%R - %u %t \\\"%m %r%Q%q\\\" %s %f cpu:%C%% mem:%{megabytes}M reqTime:%d\"
access.log = /tmp/php.access.log
slowlog = /tmp/php.slow.log
request_slowlog_timeout = 30s
php_admin_value[error_log] = /tmp/php.error.log
php_admin_flag[log_errors] = on
env[TYPO3_CONTEXT] = ${TYPO3_CONTEXT}
env[FLOW_CONTEXT] = ${FLOW_CONTEXT}
env[FLOW_REWRITEURLS] = ${FLOW_REWRITEURLS}
" >> /etc/php5/fpm/pool.d/www.conf
## Init SSMTP
source /opt/docker/init-php.sh

#############################
## COMMAND
Expand Down

0 comments on commit 1d577c6

Please sign in to comment.