Skip to content

Using wp-cli to easily handle updates and other features #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
23 changes: 22 additions & 1 deletion apache/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
25 changes: 23 additions & 2 deletions fpm/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down