From 6d86873eb009b6254e3d104f867c8f0ead9631be Mon Sep 17 00:00:00 2001 From: lionax Date: Thu, 6 Oct 2016 14:43:28 +0200 Subject: [PATCH 1/5] Use wp-cli for download and add build-args for version and locale conf --- apache/Dockerfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apache/Dockerfile b/apache/Dockerfile index e3d2352028..f26b42a811 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,5 +1,11 @@ FROM php:5.6-apache +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 @@ -20,18 +26,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"] From aee4c2feffef8a266410afac1e012ab9214895b9 Mon Sep 17 00:00:00 2001 From: lionax Date: Thu, 6 Oct 2016 15:14:31 +0200 Subject: [PATCH 2/5] Add ARG for supplying additional php-extensions for wp plugins --- apache/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apache/Dockerfile b/apache/Dockerfile index f26b42a811..852a62fa16 100644 --- a/apache/Dockerfile +++ b/apache/Dockerfile @@ -1,5 +1,6 @@ FROM php:5.6-apache +ARG php_ext ARG wp_version=latest ARG wp_locale=en_US @@ -11,7 +12,7 @@ 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 From 68413f5357c8f958662ce4f7fe89cec58c26cbf3 Mon Sep 17 00:00:00 2001 From: lionax Date: Thu, 6 Oct 2016 15:24:46 +0200 Subject: [PATCH 3/5] handle core updates with wp-cli --- apache/docker-entrypoint.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index 4f55ae3ae3..f70ee5e82d 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,13 @@ 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 + # TODO handle plugin updates + 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 From f76e227471ef9cc0700cbb156256bc108191425a Mon Sep 17 00:00:00 2001 From: lionax Date: Thu, 6 Oct 2016 15:37:16 +0200 Subject: [PATCH 4/5] Install plugins through env config and update all installed ones --- apache/docker-entrypoint.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apache/docker-entrypoint.sh b/apache/docker-entrypoint.sh index f70ee5e82d..3e46e5415c 100755 --- a/apache/docker-entrypoint.sh +++ b/apache/docker-entrypoint.sh @@ -54,7 +54,18 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then # defaults to WP_VERSION=latest if [ wp core is-installed ]; then wp core update --version=$WP_VERSION - # TODO handle plugin updates + + # 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 From 33bce12d8078b5c8f501c3efbe55548117130699 Mon Sep 17 00:00:00 2001 From: lionax Date: Thu, 6 Oct 2016 17:20:49 +0200 Subject: [PATCH 5/5] Apply changes to fpm version aswell --- docker-entrypoint.sh | 25 +++++++++++++++++++++++-- fpm/Dockerfile | 22 ++++++++++++++-------- fpm/docker-entrypoint.sh | 25 +++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 12 deletions(-) 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