Building The Broadcast

We recently helped femcare startup LOLA launch their blog The Broadcast. This is a deployment story. It’s a WordPress blog but with a small DevOps twist. We are heavy consumers of Cloud66 and I wanted to have this LAMP stack to have Cloud66 manage it.

Docker

Cloud66 makes this all possible through it’s support for Docker. All that’s needed is a hosted image or a GitHub repository that contains a Dockerfile. I couldn’t use the official image so I copied it and made a simple modification:

- RUN curl -o wordpress.tar.gz …
+ WORKDIR /var/www/html
+ COPY . .
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

That’s it! Well more or less. Moving on. I kept their entrypoint shell script exactly the same. You can confirm that everything is working by starting the project on your local machine. This simple docker-compose config will get you going:

wordpress:
build: .
links:
- db:mysql

ports:
- 8080:80

db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: password

Visit this URL: (docker-machine ip):8080 and you should see the setup page.

Cloud66

Build a new docker stack. The gist of it is to provide the url of the GitHub repository. Name your stack, the environment, your service and chose a database, it has to be MySQL. In the following step you will need to pre fill some environment variables:

WORDPRESS_DB_HOST=_env(MYSQL_ADDRESS_INT)
WORDPRESS_DB_NAME=_env(MYSQL_DATABASE)
WORDPRESS_DB_PASSWORD=_env(MYSQL_PASSWORD)
WORDPRESS_DB_USER=_env(MYSQL_USERNAME)

Last but not least we have to prepare the host with an uploads folder and a .htaccess. This is what I did:

services:
wordpress:
volumes:
- "/var/www/html/uploads:/var/www/html/wp-content/uploads"
- "/var/www/html/.htaccess:/var/www/html/.htaccess:ro"

Reverse Proxy

One last chore. We opted to point the blog at a url from the main website.

http {
upstream blog {
server buffalo.lola-blog.c66.me;
}
  server {
location /blog {
rewrite ^/blog/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_pass http://blog;
proxy_redirect off;
}

location /wp-admin {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_pass http://blog;
proxy_redirect off;
}
}
}

We shy away from using WordPress for most things but with the requirements of this project it was a perfect fit. In other words, WordPress did everything we needed and accelerated the development quite a bit. Originally we did not consider deploying this to Cloud66 but I am glad we did. Cloud 66 BuildGrid makes deploying a wide variety of infrastructure easy.