master
Thibault Coupin 7 years ago
parent bcb5e39abb
commit a2618615b8
  1. 25
      Dockerfile
  2. 25
      Dockerfile.arm32v7
  3. 25
      Dockerfile.arm64v8
  4. 22
      README.md
  5. 169
      docker-entrypoint.sh

@ -0,0 +1,25 @@
FROM wordpress:4-php7.2-apache
# install the PHP extensions we need
RUN set -ex; \
\
apt-get update; \
apt-get install -y \
libsqlite3-dev \
unzip \
; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install gd pdo pdo_sqlite
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
ADD https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip /usr/src/wordpress/wp-content/plugins/
RUN unzip /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip -d /usr/src/wordpress/wp-content/plugins/ && \
rm /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip && \
cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content/
COPY docker-entrypoint.sh /usr/local/bin/
ENV WORDPRESS_DB_FILE=database.sqlite

@ -0,0 +1,25 @@
FROM arm32v7/wordpress:4-php7.2-apache
# install the PHP extensions we need
RUN set -ex; \
\
apt-get update; \
apt-get install -y \
libsqlite3-dev \
unzip \
; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install gd pdo pdo_sqlite
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
ADD https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip /usr/src/wordpress/wp-content/plugins/
RUN unzip /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip -d /usr/src/wordpress/wp-content/plugins/ && \
rm /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip && \
cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content/
COPY docker-entrypoint.sh /usr/local/bin/
ENV WORDPRESS_DB_FILE=database.sqlite

@ -0,0 +1,25 @@
FROM arm64v8/wordpress:4-php7.2-apache
# install the PHP extensions we need
RUN set -ex; \
\
apt-get update; \
apt-get install -y \
libsqlite3-dev \
unzip \
; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install gd pdo pdo_sqlite
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages
ADD https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip /usr/src/wordpress/wp-content/plugins/
RUN unzip /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip -d /usr/src/wordpress/wp-content/plugins/ && \
rm /usr/src/wordpress/wp-content/plugins/sqlite-integration.1.8.1.zip && \
cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content/
COPY docker-entrypoint.sh /usr/local/bin/
ENV WORDPRESS_DB_FILE=database.sqlite

@ -1,2 +1,22 @@
# docker-wordpress-sqlite
Fork from official wordpress-php7-apache, with sqlite plugin. For dev purpose or small memory device like Raspberrypi
Fork from official wordpress4-php7.2-apache, with [sqlite plugin](https://wordpress.org/plugins/sqlite-integration/). For dev purpose or small memory device like Raspberrypi.
### Tags
- `latest`: amd64
- `arm32v7`: Raspberry Pi v2 (not tested)
- `arm64v8`: Raspberry Pi v3 (not tested)
### How to use this image ?
Read [official Readme](https://hub.docker.com/r/_/wordpress/).
Deleted environment variables: `WORDPRESS_DB_*`
Added environment variables:
- `WORDPRESS_DB_DIR`: location of sqlite file, relative to /var/www/html (default to "database", ie "/var/www/html/database")
- `WORDPRESS_DB_FILE`: name of sqlite file (default to "database.sqlite")
### MySQL vs SQLite
Read this article https://darryldias.me/12/my-experience-with-wordpress-sqlite/

@ -0,0 +1,169 @@
#!/bin/bash
set -euo pipefail
##########################################################################################################
## COPY FROM https://github.com/docker-library/wordpress/blob/master/php7.2/apache/docker-entrypoint.sh ##
##########################################################################################################
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
if ! [ -e index.php -a -e wp-includes/version.php ]; then
echo >&2 "WordPress not found in $PWD - copying now..."
if [ "$(ls -A)" ]; then
echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!"
( set -x; ls -A; sleep 10 )
fi
tar cf - --one-file-system -C /usr/src/wordpress . | tar xf -
echo >&2 "Complete! WordPress has been successfully copied to $PWD"
if [ ! -e .htaccess ]; then
# NOTE: The "Indexes" option is disabled in the php:apache base image
cat > .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
EOF
chown www-data:www-data .htaccess
fi
fi
# 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
# allow any of these "Authentication Unique Keys and Salts." to be specified via
# environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
uniqueEnvs=(
AUTH_KEY
SECURE_AUTH_KEY
LOGGED_IN_KEY
NONCE_KEY
AUTH_SALT
SECURE_AUTH_SALT
LOGGED_IN_SALT
NONCE_SALT
)
envs=(
WORDPRESS_DB_DIR
WORDPRESS_DB_FILE
"${uniqueEnvs[@]/#/WORDPRESS_}"
WORDPRESS_DEBUG
)
haveConfig=
for e in "${envs[@]}"; do
file_env "$e"
if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then
haveConfig=1
fi
done
# only touch "wp-config.php" if we have environment-supplied configuration values
if [ "$haveConfig" ]; then
: "${WORDPRESS_DB_DIR:=database}"
: "${WORDPRESS_DB_FILE:=database.sqlite}"
# version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
# https://github.com/docker-library/wordpress/issues/116
# https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
sed -ri -e 's/\r$//' wp-config*
if [ ! -e wp-config.php ]; then
awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP'
// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
EOPHP
chown www-data:www-data wp-config.php
fi
# see http://stackoverflow.com/a/2705678/433558
sed_escape_lhs() {
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
}
sed_escape_rhs() {
echo "$@" | sed -e 's/[\/&]/\\&/g'
}
php_escape() {
local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
fi
echo "$escaped"
}
set_config() {
key="$1"
value="$2"
var_type="${3:-string}"
start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
end="\);"
if [ "${key:0:1}" = '$' ]; then
start="^(\s*)$(sed_escape_lhs "$key")\s*="
end=";"
fi
sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
if (! grep "'$key'" wp-config.php) > /dev/null ; then
SETTINGS_LINE=$(grep wp-settings wp-config.php)
sed -i "s/$SETTINGS_LINE/define('$key',$(sed_escape_rhs "$(php_escape "$value" "$var_type")"));\n$SETTINGS_LINE/g" wp-config.php
fi
}
set_config 'DB_DIR' "$WORDPRESS_DB_DIR"
set_config 'DB_FILE' "$WORDPRESS_DB_FILE"
set_config 'USE_MYSQL' "0" "integer"
for unique in "${uniqueEnvs[@]}"; do
uniqVar="WORDPRESS_$unique"
if [ -n "${!uniqVar}" ]; then
set_config "$unique" "${!uniqVar}"
else
# if not specified, let's generate a random value
currentVal="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
if [ "$currentVal" = 'put your unique phrase here' ]; then
set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
fi
fi
done
if [ "$WORDPRESS_DEBUG" ]; then
set_config 'WP_DEBUG' 1 boolean
fi
fi
# now that we're definitely done writing configuration, let's clear out the relevant envrionment variables (so that stray "phpinfo()" calls don't leak secrets from our code)
for e in "${envs[@]}"; do
unset "$e"
done
fi
exec "$@"
Loading…
Cancel
Save