Commit d0ff0fc2 authored by Fabio Montefuscolo's avatar Fabio Montefuscolo

add composer;

remove database setup from entrypoint;
add opcache conf to entrypoint
parent c9d441c0
FROM php:5.6-apache
FROM montefuscolo/php
MAINTAINER Fabio Montefuscolo <fabio.montefuscolo@gmail.com>
#
# It is based on official Wordpress Dockerfile, but I put
# files direct on /var/www/html instead /usr/src/wordpress.
# You can mount your wp-content, wp-config.php and .htaccess
# and the entrypoint script will not overwrte your files.
# It helps me on theme and plugin development.
#
RUN a2enmod rewrite expires ssl
# install the PHP extensions we need
RUN apt-get update && apt-get install -y unzip libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-install gd mysqli opcache
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN curl -o wp-cli.phar 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar?0.23.1' \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp
RUN curl -o installer.php "https://getcomposer.org/installer" \
&& php installer.php --install-dir=/usr/local/bin/ --filename=composer \
&& rm installer.php
RUN wp core download --path=/var/www/html/ --version=4.5.3 --allow-root
COPY docker-entrypoint.sh /entrypoint.sh
RUN chown -R root:root /var/www/html/ \
&& chown -R www-data:www-data /var/www/html/wp-content
COPY htaccess /var/www/html/.htaccess
COPY wp-config.php /var/www/html/wp-config.php
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt \
-subj "/C=BR/ST=SP/L=São Roque/O=Hacklab/OU=Development/CN=Dev/emailAddress=a@b.cd" \
&& mv localhost.key /etc/ssl/private/localhost.key \
&& mv localhost.crt /etc/ssl/certs/localhost.crt
COPY default-ssl.conf /etc/apache2/sites-enabled
RUN mkdir -p /docker-entrypoint-extra/
COPY docker-entrypoint.sh /entrypoint.sh
EXPOSE 80 443
......
......@@ -3,69 +3,27 @@
keygen() {
cat /dev/urandom | tr -dc '[:print:]' | tr "\\\\" "-" | tr "'" "-" | head -c64;
}
PHP=`which php`
DB_USER="${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}";
DB_NAME="${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-wordpress}}";
DB_PASSWORD="${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:$MYSQL_ENV_MYSQL_ROOT_PASSWORD}}";
DB_HOST="${WORDPRESS_DB_HOST:-mysql}";
export WORDPRESS_AUTH_KEY="${WORDPRESS_AUTH_KEY:-$(keygen)}"
export WORDPRESS_SECURE_AUTH_KEY="${WORDPRESS_SECURE_AUTH_KEY:-$(keygen)}"
export WORDPRESS_LOGGED_IN_KEY="${WORDPRESS_LOGGED_IN_KEY:-$(keygen)}"
export WORDPRESS_NONCE_KEY="${WORDPRESS_NONCE_KEY:-$(keygen)}"
export WORDPRESS_AUTH_SALT="${WORDPRESS_AUTH_SALT:-$(keygen)}"
export WORDPRESS_SECURE_AUTH_SALT="${WORDPRESS_SECURE_AUTH_SALT:-$(keygen)}"
export WORDPRESS_LOGGED_IN_SALT="${WORDPRESS_LOGGED_IN_SALT:-$(keygen)}"
export WORDPRESS_NONCE_SALT="${WORDPRESS_NONCE_SALT:-$(keygen)}"
#
# Create wp-config.php
#
if ! [ -e "/var/www/html/wp-config.php" ];
then
cat > /var/www/html/wp-config.php << EOF
<?php
define('DB_USER', '$DB_USER');
define('DB_NAME', '$DB_NAME');
define('DB_PASSWORD', '$DB_PASSWORD');
define('DB_HOST', '$DB_HOST');
define('DB_CHARSET', '${WORDPRESS_DB_CHARSET:-utf8}');
define('DB_COLLATE', '${WORDPRESS_DB_COLLATE}');
define('AUTH_KEY', '${WORDPRESS_AUTH_KEY:-$(keygen)}');
define('SECURE_AUTH_KEY', '${WORDPRESS_SECURE_AUTH_KEY:-$(keygen)}');
define('LOGGED_IN_KEY', '${WORDPRESS_LOGGED_IN_KEY:-$(keygen)}');
define('NONCE_KEY', '${WORDPRESS_NONCE_KEY:-$(keygen)}');
define('AUTH_SALT', '${WORDPRESS_AUTH_SALT:-$(keygen)}');
define('SECURE_AUTH_SALT', '${WORDPRESS_SECURE_AUTH_SALT:-$(keygen)}');
define('LOGGED_IN_SALT', '${WORDPRESS_LOGGED_IN_SALT:-$(keygen)}');
define('NONCE_SALT', '${WORDPRESS_NONCE_SALT:-$(keygen)}');
\$table_prefix = '${WORDPRESS_TABLE_PREFIX:-wp}_';
define('WP_DEBUG', ${WORDPRESS_WP_DEBUG:-false});
define('WP_DEBUG_LOG', ${WORDPRESS_WP_DEBUG_LOG:-false});
define('WP_DEBUG_DISPLAY', ${WORDPRESS_WP_DEBUG_DISPLAY:-true});
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
EOF
fi
#
# Create .htaccess
#
if ! [ -e "/var/www/html/.htaccess" ];
if [ "$WORDPRESS_WP_DEBUG" != "true" ] && [ "$OPCACHE" != "false" ];
then
cat > /var/www/html/.htaccess << EOF
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
cat > /usr/local/etc/php/conf.d/opcache-recommended.ini << EOF
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
EOF
if [ "$WORDPRESS_WP_DEBUG" = "true" ];
then
echo "php_flag opcache.enable Off" >> /var/www/html/.htaccess
fi
fi
......@@ -93,30 +51,15 @@ then
then
usermod -u "$uid" www-data
fi
else
uid=$(awk -F: '/^www-data/{ print $3 }' /etc/passwd)
fi
chown www-data:www-data /var/www/html/.htaccess
chown www-data:www-data /var/www/html/wp-config.php
chown -R www-data:www-data /var/www/html/wp-content
#
# Setup database and user
#
php << EOF
<?php
\$con = @new mysqli($DB_HOST, 'root', '$MYSQL_ENV_MYSQL_ROOT_PASSWORD');
if(\$con->connect_errno === 0) {
\$con->query("create database if not exists '$DB_NAME'");
\$con->query("grant all privileges on \`$DB_NAME\`.* to '$DB_USER'@'%' identified by '$DB_PASSWORD'");
\$con->query("flush privileges");
}
EOF
for f in /docker-entrypoint-extra/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.php) echo "$0: running $f"; "${PHP}" < "$f"; echo ;;
*.php) echo "$0: running $f"; "${PHP}" < "$f" ;;
*) echo "$0: ignoring $f" ;;
esac
echo
......
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<?php
define('DB_USER', getenv('DB_USER') ?: 'wordpress');
define('DB_NAME', getenv('DB_NAME') ?: 'wordpress');
define('DB_PASSWORD', getenv('DB_PASSWORD') ?: 'wordpress');
define('DB_HOST', getenv('DB_HOST') ?: 'mysql');
define('DB_CHARSET', getenv('WORDPRESS_DB_CHARSET') ?: 'utf8');
define('DB_COLLATE', getenv('WORDPRESS_DB_COLLATE') ?: '');
define('AUTH_KEY', getenv('WORDPRESS_AUTH_KEY') ?: 'secret');
define('SECURE_AUTH_KEY', getenv('WORDPRESS_SECURE_AUTH_KEY') ?: 'secret');
define('LOGGED_IN_KEY', getenv('WORDPRESS_LOGGED_IN_KEY') ?: 'secret');
define('NONCE_KEY', getenv('WORDPRESS_NONCE_KEY') ?: 'secret');
define('AUTH_SALT', getenv('WORDPRESS_AUTH_SALT') ?: 'secret');
define('SECURE_AUTH_SALT', getenv('WORDPRESS_SECURE_AUTH_SALT') ?: 'secret');
define('LOGGED_IN_SALT', getenv('WORDPRESS_LOGGED_IN_SALT') ?: 'secret');
define('NONCE_SALT', getenv('WORDPRESS_NONCE_SALT') ?: 'secret');
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
define('WP_DEBUG', getenv('WORDPRESS_WP_DEBUG') === 'true');
define('WP_DEBUG_LOG', getenv('WORDPRESS_WP_DEBUG_LOG') === 'true');
define('WP_DEBUG_DISPLAY', getenv('WORDPRESS_WP_DEBUG_DISPLAY') === 'true');
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment