Skip to content

Instantly share code, notes, and snippets.

@erochest
Last active August 29, 2015 14:15
Show Gist options
  • Save erochest/3292ae2398c50c045a88 to your computer and use it in GitHub Desktop.
Save erochest/3292ae2398c50c045a88 to your computer and use it in GitHub Desktop.
Docker stuff to get WordPress/Ivanhoe running using Fig (http://www.fig.sh/wordpress.html). Excuse me, docker-compose.

A Glossary

The host: Your machine made out of metal and plastic and stuff. It runs Windows.

The VM: The Linux (CentOS) computer running inside your host machine.

vagrant: The software we're using to manage the VM. Run vagrant commands in the git bash window in your host computer.

docker and docker-compose: The software we're using to run the WordPress site. Run docker commands inside the Window in your VM.

tmux: A terminal multiplexer. This runs inside the VM. We're using it to save our session between work sessions. It will also allow us to start things running and then forget about them.

Xvfb: A windowing system without any display.

Commands

To start up the vagrant VM. You'll do this in a git bash window at the beginning of each work session.

vagrant up

To log into the VM from a git bash window (after running 'vagrant up').

vagrant ssh

To get back to a running tmux session after logging into the VM.

tmux attach

If it complains that there's no tmux sessions, skip down to Setting up a Session below, and then come back here.

Now, to run tests, from within tmux. (You can also run a specific spec file by passing it in as a full path name in place of specs/ below.)

xvfb-run ./rs specs/

Now, when you're done, you first need to detach from tmux. Do this by pressing <Ctrl-b d>.

Now, you're in the VM. Exit from the VM by pressing <Ctrl-d>.

Finally, you can suspend the VM.

vagrant suspend

Setting up a Session

You'll need to get the various servers running again. To do that, follow these instructions:

  1. Change into the Ivanhoe directory:

    cd /vagrant/wordpress/wp-content/themes/ivanhoe
  2. Start tmux

tmux
  1. We'll be creating new windows within this tmux session. First create a session with <Ctrl-b c>. Now start Xvfb.
Xvfb
  1. Create another session with <Ctrl-b c>. Now start the docker server and start the wordpress site and database.
sudo service docker start
docker-compose start
  1. Change back to the original tmux window with <Ctrl-b 0>. Now everything's running again, and you can go back to the previous instructions.
web:
build: .
command: php -S 0.0.0.0:8000 -t /code
ports:
- "8000:8000"
links:
- db
volumes:
- .:/code
db:
image: mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: "rootpass"
MYSQL_USER: ivanhoe
MYSQL_PASSWORD: ivanhoe
ports:
- "33306:3306"
FROM orchardup/php5
ADD . /code
sudo yum group install "Development Tools"
sudo yum install epel-release
sudo yum install docker tmux xorg-x11-server-Xvfb ruby ruby-devel rubygem-bundler zlib-devel qt-devel qtwebkit-devel mysql-devel mariadb
sudo ln -s /usr/lib64/qt4/bin/qmake /usr/bin/qmake
sudo service docker start
curl -L https://github.com/docker/compose/releases/download/1.1.0/docker-compose-`uname -s`-`uname -m` | sudo tee /usr/local/bin/docker-compose > /dev/null
sudo chmod +x /usr/local/bin/docker-compose
sudo usermod -a -G $(grep docker /etc/group | cut -d: -f 3) vagrant
# Log out and back in
cd /vagrant
git clone https://gist.github.com/3292ae2398c50c045a88.git
cp 3292ae2398c50c045a88/{Dockerfile,docker-compose.yml,router.php} .
echo 'create database test_ivanhoe;' > mysql -uroot -hvagrant_db_1 -P33306 -prootpass
echo "grant all on test_ivanhoe.* to 'ivanhoe'@'%' identified by 'ivanhoe';" > mysql -uroot -hvagrant_db_1 -P33306 -prootpass
## Edit wordpress/wp-config.php
# define('DB_NAME', 'wordpress');
# define('DB_USER', 'ivanhoe');
# define('DB_PASSWORD', 'ivanhoe');
# define('DB_HOST', 'db:3306');
## Edit .env with test-specific settings
# DB_HOST=vagrant_db_1
# WP_DB_HOST=db
# DB_USER=ivanhoe
# DB_PASSWORD=ivanhoe
# DB_PORT=33306
# WP_DB_PORT=3306
# URL_BASE=http://vagrantpress.dev:8000/wordpress
PATH=$PATH:/usr/local/bin
tmux
# pane 2
docker-compose up
# pane 3
Xvfb
# run tests with
xvfb-run ./rs specs/
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir($root);
$path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/');
set_include_path(get_include_path().':'.__DIR__);
if(file_exists($root.$path))
{
if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/')
$path = rtrim($path,'/').'/index.php';
if(strpos($path,'.php') === false) return false;
else {
chdir(dirname($root.$path));
require_once $root.$path;
}
}else include_once 'index.php';
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "puppetlabs/centos-7.0-64-puppet"
# allows running commands globally in shell for installed composer libraries
# config.vm.provision :shell, path: "files/scripts/setup.sh"
# setup virtual hostname and provision local IP
config.vm.hostname = "vagrantpress.dev"
config.vm.network :private_network, :ip => "192.168.50.4"
# Fix for slow external network connections
config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
vb.memory = 2048
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment