Commit 047ee95e authored by pierreozoux's avatar pierreozoux

Initial commit

parent b6bf1c17
.vagrant
\ No newline at end of file
## Prerequisites to work on this project:
- [vagrant](http://www.vagrantup.com/)
- [virtualbox](https://www.virtualbox.org/)
- optional: [vagrant-hostsupdater](https://github.com/cogitatio/vagrant-hostsupdater)
## Get started:
```bash
vagrant up
```
Wait the provisionning to finish (~40mins), and go to your browser: http://coreos.dev
### If you want to start another wordpress:
```bash
vagrant ssh
sudo systemctl start wordpress@myuser.service
```
Update haproxy configuration in ``/data/server-wide/haproxy/haproxy.cfg`.
Check in your bowser!
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.5.0"
# Size of the CoreOS cluster created by Vagrant
$num_instances=1
# Official CoreOS channel from which updates should be downloaded
$update_channel='stable'
# Setting for VirtualBox VMs
$vb_memory = 1024
$vb_cpus = 1
BASE_IP_ADDR = ENV['BASE_IP_ADDR'] || "192.168.65"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "coreos-%s" % $update_channel
config.vm.box_version = ">= 308.0.1"
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel
(1..$num_instances).each do |i|
config.vm.define "core-#{i}" do |core|
config.vm.provider :virtualbox do |vb|
vb.memory = $vb_memory
vb.cpus = $vb_cpus
end
core.vm.hostname = "coreos.dev"
core.vm.network :private_network, ip: "#{BASE_IP_ADDR}.#{i+1}"
config.vm.synced_folder ".", "/data/infrastructure"
core.vm.provision :file, source: "./config/user-data", destination: "/tmp/vagrantfile-user-data"
core.vm.provision :shell, path: "./scripts/vagrant.sh"
end
end
end
#cloud-config
coreos:
update:
reboot-strategy: best-effort
#!/bin/bash
if [ ! -d "/data/per-user/$USER/mysql/data" ]; then
mkdir -p /data/per-user/$USER/mysql/data
echo MYSQL_PASS=`echo $RANDOM ${date} | md5sum | base64 | cut -c-10` > /data/per-user/$USER/mysql/.env
fi
#!/bin/bash
if [ ! -d "/data/per-user/$USER/wordpress/data" ]; then
cd /data/per-user/$USER/
tar xvzf /data/infrastructure/blueprints/wordpress.tgz
cat /data/per-user/$USER/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > /data/per-user/$USER/wordpress/.env
fi
#!/bin/bash -eux
# Install cloud-config file
mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/
# Install unit-files
cp /data/infrastructure/unit-files/* /etc/systemd/system
systemctl daemon-reload
# Pull relevant docker images
docker pull tutum/mysql
docker pull tutum/wordpress-stackable
# Start wordpress service for user coreos (and create the user)
systemctl enable wordpress@coreos.service
systemctl start wordpress@coreos.service
# Configure and start HAproxy
docker pull dockerfile/haproxy
mkdir -p /data/server-wide/haproxy
IP=`docker inspect --format {{.NetworkSettings.IPAddress}} wordpress-coreos`
sed s/%IP%/$IP/ /data/infrastructure/templates/haproxy.cfg > /data/server-wide/haproxy/haproxy.cfg
systemctl enable haproxy.service
systemctl start haproxy.service
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend http-in
bind *:80
acl is_core hdr_end(host) -i coreos.dev
use_backend core if is_core
backend core
cookie SERVERID insert nocache indirect
option httpclose
option forwardfor
server Server %IP%:80 cookie Server
[Unit]
Description=%p
After=docker.service
Requires=docker.service
[Service]
Restart=always
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill %p
ExecStartPre=-/usr/bin/docker rm %p
ExecStart=/usr/bin/docker run\
--name %p\
-p 80:80\
-v /data/server-wide/%p:/haproxy-override\
dockerfile/haproxy
ExecReload=/usr/bin/docker restart %p
ExecStop=/usr/bin/docker stop %p
[Install]
WantedBy=multi-user.target
[Unit]
Description=MySQL importer
Before=mysql@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
Environment=USER=%i
ExecStart=/data/infrastructure/importers/mysql.sh
[Install]
WantedBy=mysql@%i.service
[Unit]
Description=%p-%i
After=docker.service
After=%p-importer@%i.service
Requires=docker.service
Requires=%p-importer@%i.service
[Service]
Restart=always
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStart=/usr/bin/docker run\
--name %p-%i\
-v /data/per-user/%i/%p/data:/var/lib/mysql\
--env-file /data/per-user/%i/%p/.env\
tutum/mysql
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
[Install]
WantedBy=multi-user.target
[Unit]
Description=WordPress importer
After=mysql-importer@%i.service
Before=wordpress@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
Environment=USER=%i
ExecStart=/data/infrastructure/importers/wordpress.sh
[Install]
WantedBy=wordpress@%i.service
[Unit]
Description=%p-%i
After=docker.service
Requires=docker.service
Requires=mysql@%i.service
After=mysql@%i.service
Requires=%p-importer@%i.service
After=%p-importer@%i.service
[Service]
Restart=always
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStart=/usr/bin/docker run\
--name %p-%i\
--link mysql-%i:db\
-v /data/per-user/%i/%p/data/wp-content:/app/wp-content\
-v /data/per-user/%i/%p/data/.htaccess:/app/.htaccess\
--env-file /data/per-user/%i/%p/.env\
tutum/wordpress-stackable
ExecReload=/usr/bin/docker restart %p-%i
ExecStop=/usr/bin/docker stop %p-%i
[Install]
WantedBy=multi-user.target
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment