Skip to content
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

Wordpress #5

Merged
merged 4 commits into from
Apr 19, 2016
Merged
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
42 changes: 20 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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 \
libpng12-dev \
libjpeg-dev \
unzip \
curl \
nfs-common \
libmemcached-dev \
vim \
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 \
Expand All @@ -35,29 +35,26 @@ RUN { \
COPY bin /usr/local/bin
COPY etc /etc

# Add Containerbuddy and its configuration
ENV CONTAINERBUDDY_VER 1.3.0
ENV CONTAINERBUDDY file:///etc/containerbuddy.json
# Add Containerpilot and its configuration
ENV CONTAINERPILOT_VER 2.0.1
ENV CONTAINERPILOT file:///etc/containerpilot.json

RUN export CONTAINERBUDDY_CHECKSUM=c25d3af30a822f7178b671007dcd013998d9fae1 \
&& curl -Lso /tmp/containerbuddy.tar.gz \
"https://github.com/joyent/containerbuddy/releases/download/${CONTAINERBUDDY_VER}/containerbuddy-${CONTAINERBUDDY_VER}.tar.gz" \
&& echo "${CONTAINERBUDDY_CHECKSUM} /tmp/containerbuddy.tar.gz" | sha1sum -c \
&& tar zxf /tmp/containerbuddy.tar.gz -C /usr/local/bin \
&& rm /tmp/containerbuddy.tar.gz
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.12.2
ENV CONSUL_TEMPLATE_SHA1 a8780f365bf5bfad47272e4682636084a7475ce74b336cdca87c48a06dd8a193
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

# Make the WP uploads directory writeable by the web server
#RUN chown -R www-data:www-data /var/www/html/content/uploads

# 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 \
Expand All @@ -68,12 +65,13 @@ RUN curl -Ls -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp
# 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, etc, directories.
COPY /var/www/html /var/www/html
RUN chown -R www-data:www-data /var/www/html/*


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


# install HyperDB, https://wordpress.org/plugins/hyperdb
Expand All @@ -93,5 +91,5 @@ RUN curl -Ls -o /var/www/html/content/object-cache.php https://raw.githubusercon
# the volume is defined after we install everything
VOLUME /var/www/html

CMD ["/usr/local/bin/containerbuddy", \
CMD ["/usr/local/bin/containerpilot", \
"apache2-foreground"]
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# triton-wordpress
# autopilot-wordpress
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Autopilot Pattern WordPress

...and the set of badges shown in autopilotpattern/mysql#15 would be great too:

[![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)

*a Docker Compose leveraging services from many containers to create an robust WordPress envrionment*

### Containerized and discoverable via Consul
This project uses Consul for service discovery, and all component containers announce themselves to Consul and get the information they need about other services from Consul. This allows each container to configure itself once the services it depends on are online. It also allows each service to be scaled up to handle incoming traffic and as more services are added, the containers that consume these services will reconfigure themselves accordingly.

### Project Architecure
A running cluster includes the following components:

- [Consul](https://www.consul.io/): used to coordinate replication and failover
- [Autopilot-MySQL](https://github.com/autopilotpattern/mysql/): we're using the Autopilot-MySQL project to leverage the great features built into this container. It users MySQL5.6 via [Percona Server](https://www.percona.com/software/mysql-database/percona-server), and [`xtrabackup`](https://www.percona.com/software/mysql-database/percona-xtrabackup) for running hot snapshots.
- [Manta](https://www.joyent.com/object-storage): the Joyent object store, for securely and durably storing our MySQL snapshots.
- [ContainerPilot](http://containerpilot.io): included in our MySQL containers orchestrate bootstrap behavior and coordinate replication using keys and checks stored in Consul in the `onStart`, `health`, and `onChange` handlers.
Copy link
Contributor Author

@misterbisson misterbisson Apr 17, 2016

Choose a reason for hiding this comment

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

https://www.joyent.com/containerpilot

Also note that onStart is deprecated.

Edit, you're probably on both of those, as this was copypasta from elsewhere.

- [NFS](https://github.com/autpilotpattern/nfsserver/): Stores user uploaded files so these files can be shared between many WordPress containers and served to the world
- [Memcached](https://github.com/autpilotpattern/memcached/): Caches often accessed data in memory so WordPress doesn't always have to access the database
- [Nginx](https://github.com/autopilotpattern/nginx): Front-end load balancer for the WordPress envrionment, passes traffic from users to the WordPress containers on the back-end.

### Getting started

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](https://docs.docker.com/installation/mac/) (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) (`triton` replaces our old `sdc-*` CLI tools)
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>
```
### Joyent Manta configuration
```
write this:
needs ssh keys for manta
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started work on improving the MySQL configuration in autopilotpattern/mysql#14

```



Check that everything is configured correctly by running `./setup.sh`. If it returns without an error you're all set. This script will create and `_env` file that includes the Triton CNS name for the Consul service. You'll want to edit this file to update the username and password for Couchbase.
2 changes: 1 addition & 1 deletion _env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ WORDPRESS_SECURE_AUTH_SALT=
WORDPRESS_LOGGED_IN_SALT=
WORDPRESS_NONCE_SALT=

CONSUL=consul
CONSUL=consul.svc.{your-account-uuid}.{target-data-center}.cns.joyent.com
2 changes: 1 addition & 1 deletion bin/onchange-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/consul-templates/db-config.php.ctmpl:/var/www/html/content/db-config.php"
-template "/var/www/html/db-config.php.ctmpl:/var/www/html/content/db-config.php"
2 changes: 1 addition & 1 deletion bin/onchange-memcached.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/consul-templates/memcached-config.php.ctmpl:/var/www/html/memcached-config.php"
-template "/var/www/html/memcached-config.php.ctmpl:/var/www/html/memcached-config.php"
41 changes: 17 additions & 24 deletions bin/onchange-nfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,29 @@
if [[ `curl -s ${CONSUL}:8500/v1/health/state/passing | grep nfs` ]]
then
echo "nfs is healthy, mounting uploads directory...."
mount -t nfs -v -o nolock,vers=3 nfs:/exports /var/www/html/content/uploads
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
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
# 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"
echo "<?php
/**
* Display an error when the NFS container is unavailable.
*/
function nfs_error_notice() {
?>

<div class="error notice">
<p><?php esc_html_e( 'The NFS container is not present, media uploads have been disabled'); ?></p>
</div>

<?php
}
add_action( 'admin_notices', 'nfs_error_notice' );" > /var/www/html/content/mu-plugins/no-uploads.php
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)
Expand Down
2 changes: 1 addition & 1 deletion bin/onchange-wp-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ consul-template \
-once \
-dedup \
-consul ${CONSUL}:8500 \
-template "/var/www/html/consul-templates/wp-config.php.ctmpl:/var/www/html/wp-config.php"
-template "/var/www/html/wp-config.php.ctmpl:/var/www/html/wp-config.php"
8 changes: 8 additions & 0 deletions bin/prestart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ else
# wp option update for siteurl REQUIRES http://, need to determine will we handle that here
# or ask for it in the _env file or test for it above
wp --allow-root option update siteurl `wp --allow-root option get siteurl`/wordpress
# set a nice default permalink structure
wp --allow-root option update permalink_structure '/%year%/%monthnum%/%postname%/'
# set theme
if [ $WORDPRESS_ACTIVE_THEME ]
then
wp --allow-root theme activate $WORDPRESS_ACTIVE_THEME
fi

if [ $WORDPRESS_TEST_DATA ]
then
echo "installing WP test content"
Expand Down
70 changes: 0 additions & 70 deletions common-compose.yml

This file was deleted.

Loading