diff --git a/apache/Dockerfile b/apache/Dockerfile index e3d2352028..852a62fa16 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,11 +1,18 @@ FROM php:5.6-apache +ARG php_ext +ARG wp_version=latest +ARG wp_locale=en_US + +ENV WP_BUILD_VERSION wp_version +ENV WP_BUILD_LOCALE wp_locale + RUN a2enmod rewrite expires # install the PHP extensions we need RUN apt-get update && apt-get install -y 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 + && docker-php-ext-install gd mysqli opcache $php_ext # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php @@ -20,18 +27,17 @@ RUN { \ VOLUME /var/www/html -ENV WORDPRESS_VERSION 4.6.1 -ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202 +RUN curl -o /usr/local/bin/wp -SL https://github.com/wp-cli/wp-cli/releases/download/v0.24.1/wp-cli-0.24.1.phar \ + && chmod +x /usr/local/bin/wp \ + && wp --info --allow-root -# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress -RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz \ - && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \ - && tar -xzf wordpress.tar.gz -C /usr/src/ \ - && rm wordpress.tar.gz \ +RUN wp core download --path=/usr/src/wordpress --locale=$wp_locale --version=$wp_version --allow-root \ && chown -R www-data:www-data /usr/src/wordpress COPY docker-entrypoint.sh /entrypoint.sh +WORKDIR /var/www/html + # grr, ENTRYPOINT resets CMD now ENTRYPOINT ["/entrypoint.sh"] CMD ["apache2-foreground"] diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 4f55ae3ae3..3e46e5415c 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +# Alias for WP-cli to include arguments that we want to use everywhere +shopt -s expand_aliases +alias wp="wp --path=$DOCUMENT_ROOT --allow-root" + if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then : "${WORDPRESS_DB_HOST:=mysql}" # if we're linked to MySQL and thus have credentials already, let's use them @@ -45,7 +49,24 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then 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 + # handle WordPress upgrades magically with wp-cli + # can be set through env on runtime or arg on build time + # defaults to WP_VERSION=latest + if [ wp core is-installed ]; then + wp core update --version=$WP_VERSION + + # update all plugins + wp plugin update --all + + # install plugins provided in the WORDPRESS_PLUGINS env variable + if [ "$WORDPRESS_PLUGINS" ]; then + for $plugin in $WORDPRESS_PLUGINS; do + if ! $(wp plugin is-installed ${plugin}); then + wp plugin install $plugin + fi + done + fi + fi # 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 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4f55ae3ae3..6846728ba3 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +# Alias for WP-cli to include arguments that we want to use everywhere +shopt -s expand_aliases +alias wp="wp --path=$DOCUMENT_ROOT --allow-root" + if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then : "${WORDPRESS_DB_HOST:=mysql}" # if we're linked to MySQL and thus have credentials already, let's use them @@ -45,8 +49,25 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then 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 - + # handle WordPress upgrades magically with wp-cli + # can be set through env on runtime or arg on build time + # defaults to WP_VERSION=latest + if [ wp core is-installed ]; then + wp core update --version=$WP_VERSION + + # update all plugins + wp plugin update --all + + # install plugins provided in the WORDPRESS_PLUGINS env variable + if [ "$WORDPRESS_PLUGINS" ]; then + for $plugin in $WORDPRESS_PLUGINS; do + if ! $(wp plugin is-installed ${plugin}); then + wp plugin install $plugin + fi + done + fi + fi + # 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 diff --git a/fpm/Dockerfile b/fpm/Dockerfile index 60d5467907..fc8d2dd3a4 100644 --- a/fpm/Dockerfile +++ b/fpm/Dockerfile @@ -1,9 +1,16 @@ FROM php:5.6-fpm +ARG php_ext +ARG wp_version=latest +ARG wp_locale=en_US + +ENV WP_BUILD_VERSION wp_version +ENV WP_BUILD_LOCALE wp_locale + # install the PHP extensions we need RUN apt-get update && apt-get install -y 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 + && docker-php-ext-install gd mysqli opcache $php_ext # set recommended PHP.ini settings # see https://secure.php.net/manual/en/opcache.installation.php @@ -18,18 +25,17 @@ RUN { \ VOLUME /var/www/html -ENV WORDPRESS_VERSION 4.6.1 -ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202 +RUN curl -o /usr/local/bin/wp -SL https://github.com/wp-cli/wp-cli/releases/download/v0.24.1/wp-cli-0.24.1.phar \ + && chmod +x /usr/local/bin/wp \ + && wp --info --allow-root -# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress -RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz \ - && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \ - && tar -xzf wordpress.tar.gz -C /usr/src/ \ - && rm wordpress.tar.gz \ +RUN wp core download --path=/usr/src/wordpress --locale=$wp_locale --version=$wp_version --allow-root \ && chown -R www-data:www-data /usr/src/wordpress COPY docker-entrypoint.sh /entrypoint.sh +WORKDIR /var/www/html + # grr, ENTRYPOINT resets CMD now ENTRYPOINT ["/entrypoint.sh"] CMD ["php-fpm"] diff --git a/fpm/docker-entrypoint.sh b/fpm/docker-entrypoint.sh index 4f55ae3ae3..6846728ba3 100755 --- a/fpm/docker-entrypoint.sh +++ b/fpm/docker-entrypoint.sh @@ -1,6 +1,10 @@ #!/bin/bash set -e +# Alias for WP-cli to include arguments that we want to use everywhere +shopt -s expand_aliases +alias wp="wp --path=$DOCUMENT_ROOT --allow-root" + if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then : "${WORDPRESS_DB_HOST:=mysql}" # if we're linked to MySQL and thus have credentials already, let's use them @@ -45,8 +49,25 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then 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 - + # handle WordPress upgrades magically with wp-cli + # can be set through env on runtime or arg on build time + # defaults to WP_VERSION=latest + if [ wp core is-installed ]; then + wp core update --version=$WP_VERSION + + # update all plugins + wp plugin update --all + + # install plugins provided in the WORDPRESS_PLUGINS env variable + if [ "$WORDPRESS_PLUGINS" ]; then + for $plugin in $WORDPRESS_PLUGINS; do + if ! $(wp plugin is-installed ${plugin}); then + wp plugin install $plugin + fi + done + fi + fi + # 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