Skip to content

Commit c0e9bc5

Browse files
committed
Initial version without upstream artifacts
0 parents  commit c0e9bc5

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM debian:wheezy
2+
3+
RUN apt-get update && apt-get install -y \
4+
apache2 \
5+
curl \
6+
libapache2-mod-php5 \
7+
php5-curl \
8+
php5-gd \
9+
php5-mysql \
10+
rsync \
11+
wget
12+
RUN a2enmod rewrite
13+
14+
# copy a few things from apache's init script that it requires to be setup
15+
ENV APACHE_CONFDIR /etc/apache2
16+
ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars
17+
# and then a few more from $APACHE_CONFDIR/envvars itself
18+
ENV APACHE_RUN_USER www-data
19+
ENV APACHE_RUN_GROUP www-data
20+
ENV APACHE_RUN_DIR /var/run/apache2
21+
ENV APACHE_PID_FILE $APACHE_RUN_DIR/apache2.pid
22+
ENV APACHE_LOCK_DIR /var/lock/apache2
23+
ENV APACHE_LOG_DIR /var/log/apache2
24+
ENV LANG C
25+
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
26+
27+
# make CustomLog (access log) go to stdout instead of files
28+
# and ErrorLog to stderr
29+
RUN find "$APACHE_CONFDIR" -type f -exec sed -ri ' \
30+
s!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g; \
31+
s!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g; \
32+
' '{}' ';'
33+
34+
RUN rm -rf /var/www/html && mkdir /var/www/html
35+
VOLUME /var/www/html
36+
WORKDIR /var/www/html
37+
38+
ENV WORDPRESS_VERSION 3.9.2
39+
40+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
41+
RUN curl -SL http://wordpress.org/wordpress-$WORDPRESS_VERSION.tar.gz | tar -xzC /usr/src/
42+
43+
COPY docker-apache.conf /etc/apache2/sites-available/wordpress
44+
RUN a2dissite 000-default && a2ensite wordpress
45+
46+
COPY docker-entrypoint.sh /entrypoint.sh
47+
48+
ENTRYPOINT ["/entrypoint.sh"]
49+
EXPOSE 80
50+
CMD ["apache2", "-DFOREGROUND"]

docker-apache.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/html
3+
<Directory /var/www/html>
4+
AllowOverride all
5+
</Directory>
6+
</VirtualHost>
7+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

docker-entrypoint.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ -z "$MYSQL_PORT_3306_TCP" ]; then
5+
echo >&2 'error: missing MYSQL_PORT_3306_TCP environment variable'
6+
echo >&2 ' Did you forget to --link some_mysql_container:mysql ?'
7+
exit 1
8+
fi
9+
10+
# if we're linked to MySQL, and we're using the root user, and our linked
11+
# container has a default "root" password set up and passed through... :)
12+
: ${WORDPRESS_DB_USER:=root}
13+
if [ "$WORDPRESS_DB_USER" = 'root' ]; then
14+
: ${WORDPRESS_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
15+
fi
16+
: ${WORDPRESS_DB_NAME:=wordpress}
17+
18+
if [ -z "$WORDPRESS_DB_PASSWORD" ]; then
19+
echo >&2 'error: missing required WORDPRESS_DB_PASSWORD environment variable'
20+
echo >&2 ' Did you forget to -e WORDPRESS_DB_PASSWORD=... ?'
21+
echo >&2
22+
echo >&2 ' (Also of interest might be WORDPRESS_DB_USER and WORDPRESS_DB_NAME.)'
23+
exit 1
24+
fi
25+
26+
if ! [ -e index.php -a -e wp-includes/version.php ]; then
27+
echo >&2 "WordPress not found in $(pwd) - copying now..."
28+
if [ "$(ls -A)" ]; then
29+
echo >&2 "WARNING: $(pwd) is not empty - press Ctrl+C now if this is an error!"
30+
( set -x; ls -A; sleep 10 )
31+
fi
32+
rsync --archive --one-file-system --quiet /usr/src/wordpress/ ./
33+
echo >&2 "Complete! WordPress has been successfully copied to $(pwd)"
34+
if [ ! -e .htaccess ]; then
35+
cat > .htaccess <<-'EOF'
36+
RewriteEngine On
37+
RewriteBase /
38+
RewriteRule ^index\.php$ - [L]
39+
RewriteCond %{REQUEST_FILENAME} !-f
40+
RewriteCond %{REQUEST_FILENAME} !-d
41+
RewriteRule . /index.php [L]
42+
EOF
43+
fi
44+
fi
45+
46+
# TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version
47+
48+
if [ ! -e wp-config.php ]; then
49+
awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP'
50+
// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
51+
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
52+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
53+
$_SERVER['HTTPS'] = 'on';
54+
}
55+
56+
EOPHP
57+
fi
58+
59+
set_config() {
60+
key="$1"
61+
value="$2"
62+
php_escaped_value="$(php -r 'var_export($argv[1]);' "$value")"
63+
sed_escaped_value="$(echo "$php_escaped_value" | sed 's/[\/&]/\\&/g')"
64+
sed -ri "s/((['\"])$key\2\s*,\s*)(['\"]).*\3/\1$sed_escaped_value/" wp-config.php
65+
}
66+
67+
WORDPRESS_DB_HOST="${MYSQL_PORT_3306_TCP#tcp://}"
68+
69+
set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
70+
set_config 'DB_USER' "$WORDPRESS_DB_USER"
71+
set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
72+
set_config 'DB_NAME' "$WORDPRESS_DB_NAME"
73+
74+
# allow any of these "Authentication Unique Keys and Salts." to be specified via
75+
# environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
76+
UNIQUES=(
77+
AUTH_KEY
78+
SECURE_AUTH_KEY
79+
LOGGED_IN_KEY
80+
NONCE_KEY
81+
AUTH_SALT
82+
SECURE_AUTH_SALT
83+
LOGGED_IN_SALT
84+
NONCE_SALT
85+
)
86+
for unique in "${UNIQUES[@]}"; do
87+
eval unique_value=\$WORDPRESS_$unique
88+
if [ "$unique_value" ]; then
89+
set_config "$unique" "$unique_value"
90+
else
91+
# if not specified, let's generate a random value
92+
set_config "$unique" "$(head -c1M /dev/urandom | sha1sum | cut -d' ' -f1)"
93+
fi
94+
done
95+
96+
TERM=dumb php -- "$WORDPRESS_DB_HOST" "$WORDPRESS_DB_USER" "$WORDPRESS_DB_PASSWORD" "$WORDPRESS_DB_NAME" <<'EOPHP'
97+
<?php
98+
// database might not exist, so let's try creating it (just to be safe)
99+
100+
list($host, $port) = explode(':', $argv[1], 2);
101+
$mysql = new mysqli($host, $argv[2], $argv[3], '', (int)$port);
102+
103+
if ($mysql->connect_error) {
104+
file_put_contents('php://stderr', 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n");
105+
exit(1);
106+
}
107+
108+
if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($argv[4]) . '`')) {
109+
file_put_contents('php://stderr', 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n");
110+
$mysql->close();
111+
exit(1);
112+
}
113+
114+
$mysql->close();
115+
EOPHP
116+
117+
chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" .
118+
119+
exec "$@"

0 commit comments

Comments
 (0)