Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
775d7e2
Base WP image
misterbisson Dec 7, 2015
75f6757
Adding WP skeleton
misterbisson Dec 7, 2015
0447cff
bring the default dockerfile and wp skeleton together
misterbisson Dec 12, 2015
0449f7b
add wp-cli
misterbisson Dec 12, 2015
d1f2794
adding hyperdb
misterbisson Dec 14, 2015
14e6ccf
rename config files to templates
misterbisson Dec 14, 2015
d6c5224
conform directory name to expectations in base image
misterbisson Dec 14, 2015
1312166
Add Containerbuddy and other sugar
misterbisson Jan 24, 2016
c42a1c0
Updating WordPress to 4.4.1
misterbisson Jan 24, 2016
9e4eb96
config templates
misterbisson Jan 24, 2016
feec386
git2consul
misterbisson Jan 25, 2016
58627b8
config file tweaks WIP
misterbisson Jan 25, 2016
00a9a0c
wip 03/16/2016
Mar 16, 2016
b0d2fe7
removing rando ipython files
Mar 16, 2016
eb58ebb
adding _env.example file
Mar 17, 2016
9746435
adding _env.example
Mar 17, 2016
e819ca3
starting to add nginx
Mar 21, 2016
ef22630
docker-entrypoint.py tweak
Mar 21, 2016
4f1e201
WIP 03212016
Mar 22, 2016
02c3b28
wip
Mar 22, 2016
1422c57
env test
Mar 22, 2016
0e4d512
onstart.sh script done, retiring the python version
Mar 22, 2016
19159bc
removing python dependancy and cleaning up Dockerfile
Mar 22, 2016
fdb2aed
Merge branch 'wordpress' into add-nginx
Mar 22, 2016
2f6edbc
nginx working
Mar 22, 2016
6fb103f
removing themes from repo
Mar 22, 2016
81882fc
post status call 03/29/2106
Mar 29, 2016
00798dd
consul in env var
Mar 29, 2016
4c4cf9c
switching over to tim's nginx image
Mar 29, 2016
2c9db30
wip - nginx from image
Mar 30, 2016
110cf3a
adding hyperdb
Mar 30, 2016
fc8944b
finally adding the WP uniques to the env and wp-config.php.ctmpl
Mar 30, 2016
05d8824
moving on up
misterbisson Mar 31, 2016
5bde084
forgot Containerbuddy
misterbisson Mar 31, 2016
c588382
Merge pull request #1 from autopilotpattern/move-back
misterbisson Mar 31, 2016
38c07ea
wip
Mar 31, 2016
bc363b5
Merge branch 'wordpress' of github.com:10up/triton-wordpress into wor…
Mar 31, 2016
1eeae3a
wip 04012016
Apr 1, 2016
16e2c55
nfs WIP 04/04/2106
Apr 4, 2016
01bbf79
Merge pull request #2 from 10up/nfs
misterbisson Apr 5, 2016
4e2a6ee
containerbuddy 1.3
misterbisson Apr 5, 2016
e4e4456
Merge pull request #3 from autopilotpattern/persnickety
misterbisson Apr 5, 2016
4045787
cleanup after renaming
misterbisson Apr 5, 2016
97dd89c
Merge pull request #4 from autopilotpattern/persnickety
misterbisson Apr 5, 2016
e56a3aa
WIP 04/05/2016
Apr 5, 2016
86a9746
New and improved onchange-nfs.sh script
Apr 6, 2016
4e8e85f
code tweaks to the mu-plugin from @stevegrunwell's code review
Apr 6, 2016
227d7d6
WIP 04132016
Apr 13, 2016
c2803f3
WIP 04142016
Apr 14, 2016
592eb8f
removed consul-templates directory
Apr 15, 2016
240a580
working on the readme
Apr 15, 2016
4458740
More work on readme, maybe a bit overly verbose?
Apr 19, 2016
46847ee
more readme, did not get updated in last commit
Apr 20, 2016
e8b982e
readme edits
Apr 20, 2016
92efb7d
wip
Apr 20, 2016
8f02db4
changes to setup.sh script to account for different versions of ssh-k…
Apr 20, 2016
6ec47df
setup.sh working with latest mysql container
Apr 22, 2016
3e24d6f
Revert "Edits"
misterbisson Apr 22, 2016
f376f82
Merge pull request #11 from autopilotpattern/revert-9-progress2
misterbisson Apr 22, 2016
7a0f03b
readme edits
misterbisson Apr 22, 2016
93580f6
reduced nginx duplication
misterbisson Apr 23, 2016
7fd6706
compose cleanup
misterbisson Apr 26, 2016
467c8dd
compose file cleanup
misterbisson Apr 26, 2016
04c79b1
purpose and placeholder images
misterbisson Apr 26, 2016
e65f7c7
Merge pull request #12 from autopilotpattern/progress-nginx
misterbisson Apr 26, 2016
a4d3979
cleaned up local compose as well
misterbisson Apr 26, 2016
4d32fc3
updated setup.sh
misterbisson Apr 26, 2016
5a46756
support older versions of ssh-keygen
misterbisson Apr 26, 2016
24603e5
tag all images, even if the tag is :latest
misterbisson Apr 26, 2016
65d6c40
add ssh-keygen note
misterbisson Apr 26, 2016
04593ad
add some random to the username
misterbisson Apr 26, 2016
db8a46b
copy edits
misterbisson Apr 26, 2016
d9bab48
removing the example, look to setup.sh for details
misterbisson Apr 26, 2016
c288d05
set valid active theme
misterbisson Apr 26, 2016
a937761
fixed contitionals in perstart.sh for WORDPRESS_ACTIVE_THEME and WORD…
Apr 27, 2016
176d89e
fixing perms on uploads after test data import
Apr 27, 2016
6344c3e
quoting the var
Apr 27, 2016
01d369f
Merge pull request #13 from 10up/progress2
misterbisson Apr 27, 2016
3cf9832
cleaner $WORDPRESS_TEST_DATA condition
misterbisson Apr 27, 2016
70a5cf3
copyedits
misterbisson Apr 27, 2016
301eeb0
copyedits
misterbisson Apr 28, 2016
cee119d
add contributing section
misterbisson Apr 28, 2016
bdad814
feedback
misterbisson Apr 28, 2016
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
**/.DS_Store
_env*
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# credentials
_env*
manta*

# macos frustration
.DS_Store
91 changes: 91 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FROM php:5.6-apache

RUN a2enmod rewrite

# Install the PHP extensions we need, and other packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
jq \
less \
libjpeg-dev \
libmemcached-dev \
libpng12-dev \
nfs-common \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install memcached \
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-install gd mysqli opcache \
&& docker-php-ext-enable memcached

# Set recommended PHP.ini settings
# See https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini

# The our helper/glue scripts and configuration for this specific app
COPY bin /usr/local/bin
COPY etc /etc

# Add Containerpilot and its configuration
ENV CONTAINERPILOT_VER 2.0.1
ENV CONTAINERPILOT file:///etc/containerpilot.json

RUN export CONTAINERPILOT_CHECKSUM=a4dd6bc001c82210b5c33ec2aa82d7ce83245154 \
&& curl -Lso /tmp/containerpilot.tar.gz \
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
&& echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \
&& tar zxf /tmp/containerpilot.tar.gz -C /usr/local/bin \
&& rm /tmp/containerpilot.tar.gz

# Install Consul template
# Releases at https://releases.hashicorp.com/consul-template/
ENV CONSUL_TEMPLATE_VERSION 0.14.0
ENV CONSUL_TEMPLATE_SHA1 7c70ea5f230a70c809333e75fdcff2f6f1e838f29cfb872e1420a63cdf7f3a78
RUN curl --retry 7 -Lso /tmp/consul-template.zip "https://releases.hashicorp.com/consul-template/${CONSUL_TEMPLATE_VERSION}/consul-template_${CONSUL_TEMPLATE_VERSION}_linux_amd64.zip" \
&& echo "${CONSUL_TEMPLATE_SHA1} /tmp/consul-template.zip" | sha256sum -c \
&& unzip /tmp/consul-template.zip -d /usr/local/bin \
&& rm /tmp/consul-template.zip

# Install wp-cli, http://wp-cli.org
ENV WP_CLI_CONFIG_PATH /var/www/html/wp-cli.yml
RUN curl -Ls -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp \
&& wp --info --allow-root

# Copy the WordPress skeleton from this repo into the container
# This includes any themes and/or plugins we've added to the content/themes and content/plugins directories.
COPY /var/www/html /var/www/html
RUN chown -R www-data:www-data /var/www/html/*

# Install WordPress via wp-cli & move the default themes to our content dir
ENV WORDPRESS_VERSION 4.5
RUN wp --allow-root core download --version=${WORDPRESS_VERSION} \
&& mv /var/www/html/wordpress/wp-content/themes/* /var/www/html/content/themes/

# Install HyperDB, https://wordpress.org/plugins/hyperdb
# Releases at https://wordpress.org/plugins/hyperdb/developers/ , though no SHA1 fingerprints are published
ENV HYPERDB_VERSION 1.1
RUN curl -Ls -o /var/www/html/hyperdb.zip https://downloads.wordpress.org/plugin/hyperdb.${HYPERDB_VERSION}.zip \
&& unzip hyperdb.zip \
&& chown -R www-data:www-data /var/www/html/hyperdb \
&& mv hyperdb/db.php /var/www/html/content/. \
&& rm -rf /var/www/html/hyperdb.zip /var/www/html/hyperdb \
&& touch /var/www/html/content/db-config.php

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need an SMTP plugin, since we don't have a mail daemon locally. This will require adding email config details in wp-config.json as well. See #1 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the SMTP plugin I'd used previously: https://wordpress.org/plugins/wp-smtp/

# Install ztollman's object-cache.php or object caching to memcached
RUN curl -Ls -o /var/www/html/content/object-cache.php https://raw.githubusercontent.com/tollmanz/wordpress-pecl-memcached-object-cache/master/object-cache.php

# The volume is defined after we install everything
VOLUME /var/www/html

CMD ["/usr/local/bin/containerpilot", \
"apache2-foreground"]
182 changes: 181 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,181 @@
# triton-wordpress
# AutoPilot Pattern WordPress

*A robust and highly-scalable implementation of WordPress in Docker using the Autopilot Pattern*

[![DockerPulls](https://img.shields.io/docker/pulls/autopilotpattern/wordpress.svg)](https://registry.hub.docker.com/u/autopilotpattern/wordpress/)
[![DockerStars](https://img.shields.io/docker/stars/autopilotpattern/wordpress.svg)](https://registry.hub.docker.com/u/autopilotpattern/wordpress/)
[![ImageLayers](https://badge.imagelayers.io/autopilotpattern/wordpress:latest.svg)](https://imagelayers.io/?images=autopilotpattern/wordpress:latest)
[![Join the chat at https://gitter.im/autopilotpattern/general](https://badges.gitter.im/autopilotpattern/general.svg)](https://gitter.im/autopilotpattern/general)

---

### Containerized and easily scalable

This project uses the Autopilot Pattern to automate operations, including discovery and configuration, for easy scaling to any size. All component containers use [ContainerPilot](https://www.joyent.com/containerpilot) and [Consul](https://consul.io/) to configure themselves. This also allows each service to be scaled independently to handle incoming traffic and as more services are added, the containers that consume these services will reconfigure themselves accordingly.

### Project Architecture

A running cluster includes the following components:

- [ContainerPilot](https://www.joyent.com/containerpilot): included in our MySQL containers to orchestrate bootstrap behavior and coordinate replication using keys and checks stored in Consul in the `preStart`, `health`, and `onChange` handlers.
- [MySQL](https://github.com/autopilotpattern/mysql/): we're using the [Autopilot Pattern implementation of MySQL](https://www.joyent.com/blog/dbaas-simplicity-no-lock-in) for automatic backups and self-clustering so that we can deploy and scale easily
- [HyperDB](https://wordpress.org/plugins/hyperdb/): an "advanced database class that replaces a few of the WordPress built-in database functions" to support the MySQL cluster that's necessary for scaling WordPress; everything is automatically configured so running a scalable WordPress site is no more complex than running without the scaling features
- [Memcached](https://github.com/autpilotpattern/memcached/): improves performance by keeping frequently accessed data in memory so WordPress doesn't have to query the database for every request; the images include [tollmanz's Memcached plugin](https://github.com/tollmanz/wordpress-pecl-memcached-object-cache) pre-installed, and ContainerPilot automatically configures it as we scale
- [Nginx](https://github.com/autopilotpattern/nginx): the front-end load balancer for the WordPress environment; passes traffic from users to the WordPress containers on the back-end
- [NFS](https://github.com/autpilotpattern/nfsserver/): stores user uploaded files so these files can be shared between many WordPress containers
- [Consul](https://www.consul.io/): used to coordinate replication and failover
- [Manta](https://www.joyent.com/object-storage): the Joyent object store, for securely and durably storing our MySQL snapshots
- [WP-CLI](http://wp-cli.org/): to make managing WordPress easier

### How do I use this thing?

Pick the answer that fits:

1. For the hello world experience: follow the directions below for configuration, then `docker-compose up -d` and you're done.
1. For building your own WordPress in Docker: clone this repository and place the WordPress theme you want to use into the `var/www/html/content/themes` directory. Develop locally using the `local-compose.yml` file, then build your Docker image and run those in the cloud with your own `docker-compose.yml` file that specifies your custom image.

The instructions below will get you set up to run containers on [Triton](https://www.joyent.com/), or anywhere that supports the Autopilot Pattern.

### Getting started on Triton

1. [Get a Joyent account](https://my.joyent.com/landing/signup/) and [add your SSH key](https://docs.joyent.com/public-cloud/getting-started).
1. Install the [Docker Toolbox](http://docker.com/toolbox) (including `docker` and `docker-compose`) on your laptop or other environment, as well as the [Joyent Triton CLI](https://www.joyent.com/blog/introducing-the-triton-command-line-tool)
1. [Configure Docker and Docker Compose for use with Joyent](https://docs.joyent.com/public-cloud/api-access/docker):

```bash
curl -O https://raw.githubusercontent.com/joyent/sdc-docker/master/tools/sdc-docker-setup.sh && chmod +x sdc-docker-setup.sh
./sdc-docker-setup.sh -k us-east-1.api.joyent.com <ACCOUNT> ~/.ssh/<PRIVATE_KEY_FILE>
```

### Configure your environment

Check that everything is configured correctly by running `./setup.sh`. You'll need an SSH key that has access to Manta, the object store where the MySQL backups are stored. Pass the path of that SSH key as `./setup.sh ~/path/to/MANTA_SSH_KEY`. The script will create an `_env` file that names the variables that you will need to run your WordPress environment.

#### Manta Settings

The script will set defaults for almost every config variable, but the Manta config is required and must be set manually. The two most important variables there are:

```
MANTA_BUCKET= # an existing Manta bucket
MANTA_USER= # a user with access to that bucket
```

The MySQL container will take a backup during its `preStart` handler and periodically while running. Configure these Manta settings to specify how and where this backup is stored. Here you need to specify the `MANTA_USER`, and also the `MANTA_BUCKET` where the backups will be stored.

#### WordPress configuration

The setup script will set working defaults for the entire WordPress configuration. The defaults will work for a quick "hello world" experience, but you'll probably want to set your own values for many fields.

```
# Environment variables for for WordPress site
WORDPRESS_URL=http://my-site.example.org/
WORDPRESS_SITE_TITLE=My Blog
WORDPRESS_ADMIN_EMAIL=user@example.net
WORDPRESS_ADMIN_USER=admin
WORDPRESS_ADMIN_PASSWORD=<random string>
WORDPRESS_ACTIVE_THEME=twentysixteen
WORDPRESS_CACHE_KEY_SALT=<random string>
#WORDPRESS_TEST_DATA=true # uncomment to import a collection of test content on start

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should should add a note about the source of the test data in the text below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added at the bottom of the section

```

This block is the typical information you must provide when installing WordPress. The URL of the site, the site title and admin user information are all straightforward. `WORDPRESS_ACTIVE_THEME` is the theme that will be activated automatically when the container starts. This will typically be theme that you are developing in this repo, or one of the default themes. `WORDPRESS_CACHE_KEY_SALT` should be set to a unique string, the object caching in WordPress will use this salt to determine the cache keys for information it sets on the Memcached container.

If you are not bringing your own theme in this repo, you can choose from these default themes for the `WORDPRESS_ACTIVE_THEME` variable:

- `twentyfifteen`
- `twentyfourteen`
- `twentysixteen`

The script will set a `WORDPRESS_URL` value for Triton users using [Container Name Service](https://www.joyent.com/blog/introducing-triton-container-name-service) that will make it easy to test the containers without setting any DNS information. You can [`CNAME` your site DNS](https://www.joyent.com/blog/introducing-triton-container-name-service#example-global-dns) to that to make it easy to scale and replace the Nginx containers at the front of your site without ever needing to update the DNS configuration.

Setting `WORDPRESS_TEST_DATA` will download the [manovotny/wptest](https://github.com/manovotny/wptest) content library when the WordPress container starts.

#### MySQL settings

The setup script will set default values for the MySQL configuration, including randomly generated passwords.

```
# Environment variables for MySQL service
# WordPress database/WPDB information
MYSQL_USER=wpdbuser
MYSQL_PASSWORD=<random string>
MYSQL_DATABASE=wp
# MySQL replication user, should be different from above
MYSQL_REPL_USER=repluser
MYSQL_REPL_PASSWORD=<random string>
```

These values will be automatically set in the `wp-config.php`. The last two options are used by the Autopilot Pattern MySQL container to set up its replication when scaled up to more than a single container. You can keep `repluser`, but set a unique password for your environment.

#### WordPress unique salts

As with most of the other configuration blocks, the setup script will set reasonable defaults for these values.

```
# Wordpress security salts
# These must be unique for your install to ensure the security of the site
WORDPRESS_AUTH_KEY=<random string>
WORDPRESS_SECURE_AUTH_KEY=<random string>
WORDPRESS_LOGGED_IN_KEY=<random string>
WORDPRESS_NONCE_KEY=<random string>
WORDPRESS_AUTH_SALT=<random string>
WORDPRESS_SECURE_AUTH_SALT=<random string>
WORDPRESS_LOGGED_IN_SALT=<random string>
WORDPRESS_NONCE_SALT=<random string>
```

These variables are how WordPress secures your logins and other secret info. These should be unique for your site. You can set your own values, or use [this WordPress tool](https://api.wordpress.org/secret-key/1.1/salt/) to generate a new set of random values.

#### Consul

Finally we need to configure an environment variable with the location of our Consul service. The setup script will pre-set this for Triton users.

```
CONSUL=<IP or DNS to Consul>
```

For local development, we use Docker links and simply set this to `CONSUL=consul`, but on Triton we use [Container Name Service](https://www.joyent.com/blog/introducing-triton-container-name-service) so that we can have a raft of Consul instances operating as a highly available service ([see example](https://www.joyent.com/blog/introducing-triton-container-name-service#example-consul-bootstrapping)).

### A note on Nginx

This project also builds it's own Nginx container that is based on the [AutoPilot Pattern Nginx](https://github.com/autopilotpattern/nginx). We build a custom Nginx container to more easily inject our custom configurations. The configs located in the `/nginx` directory should work well for most use cases of this project, but they can be customized and baked into the Nginx image if the need arises.

### Start the containers!

After configuring everything, we are now ready to start the containers. To do that simply execute `docker-compose up -d` to spin everything up on Triton. Open your browser to the `WORDPRESS_URL` and enjoy your new site!

For local development, use `docker-compose -f local-compose.yml up -d`.

### Going big

To scale, use `docker-compose scale...`. For example, the following will set the scale of the WordPress, Memcached, Nginx, and MySQL services to three instances each:

```bash
docker-compose scale wordpress=3 memcached=3 nginx=3 mysql=3
```

If there are few instances running for any of those services, more will be added to meet the specified count. As you scale, the application will automatically reconfigure itself so that everything is connected. All the Nginx instances will connect to all the WordPress instances, and those will connect to all the Memcached and MySQL instances. If an instance should unexpectedly crash, the other instances will automatically reconfigure to re-route requests around the failed instance.

To scale back down, simply run `docker-compose scale...` and specify a smaller number of instances.

### Compatibility

This project has been fully tested and documented to run in Docker in local development environments and on [Joyent Triton](https://www.joyent.com), however it has been demonstrated on, or is believe compatible with container environments including:

- [Mantl](http://mantl.io)
- [DC/OS](https://dcos.io)
- [Docker Swarm](https://www.docker.com/products/docker-swarm)
- [Kubernetes](http://kubernetes.io)
- Others

Discussion about support for these and other container platforms is welcome on [Gitter](https://gitter.im/autopilotpattern/general).

### Contributing

- Please [report bugs in Github](https://github.com/autopilotpattern/wordpress/issues) (and check the bug list for known bugs)
- Join us in [Gitter](https://gitter.im/autopilotpattern/general) to discuss features
- It's open source, [pull requests welcome](https://github.com/autopilotpattern/wordpress/pulls)!

### Sponsors

Initial development of this project was sponsored by [Joyent](https://www.joyent.com) and [10up](http://10up.com).
5 changes: 5 additions & 0 deletions bin/health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

/usr/local/bin/wp --allow-root core is-installed \
&& /usr/local/bin/wp --allow-root option get siteurl \
&& /usr/bin/curl --fail -s -o /dev/null http://localhost/
9 changes: 9 additions & 0 deletions bin/onchange-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

/usr/local/bin/onchange-wp-config.sh

consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/db-config.php.ctmpl:/var/www/html/content/db-config.php"
7 changes: 7 additions & 0 deletions bin/onchange-memcached.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/memcached-config.php.ctmpl:/var/www/html/memcached-config.php"
38 changes: 38 additions & 0 deletions bin/onchange-nfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

if [[ `curl -s ${CONSUL}:8500/v1/health/state/passing | grep nfs` ]]
then
echo "nfs is healthy, mounting uploads directory...."
NFS=$(curl -s http://${CONSUL}:8500/v1/catalog/service/nfs?passing | jq -r '.[0] | .ServiceAddress')
mount -t nfs -v -o nolock,vers=3 ${NFS}:/exports /var/www/html/content/uploads
echo "removing no-uploads.php mu-plugin"
rm /var/www/html/content/mu-plugins/no-uploads.php
# check 'wp core is-installed' here to prevent errors in the log on first run
# before WP gets installed into the database
if $(wp --allow-root core is-installed)
then
echo "adding 'upload_files' capability back to default roles"
# only these roles have 'upload_files' cap by default
for role in administrator editor author
do
if [ "$role" != 'role' ]
then
wp --allow-root cap add ${role} upload_files
fi
done
fi
else
echo "nfs is not healthly, umounting uploads directory..."
umount -f -l /var/www/html/content/uploads
echo "creating mu-plugin for NFS error in wp-admin"
cp /var/www/html/inactive-plugins/no-uploads.php /var/www/html/content/mu-plugins/

echo "removing 'upload_files' capability from all roles..."
for role in $(wp --allow-root role list --fields=role --format=csv)
do
if [ "$role" != 'role' ]
then
wp --allow-root cap remove ${role} upload_files
fi
done
fi
7 changes: 7 additions & 0 deletions bin/onchange-wp-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# The WordPress config file
consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/wp-config.php.ctmpl:/var/www/html/wp-config.php"
Loading