Skip to content

Commit 57cde57

Browse files
carmstrongMatthew Fisher
authored andcommitted
feat(contrib/vagrant): support multiple-VM environment
This commit modifies the Vagrantfile and Makefile in contrib/vagrant to support an arbitrary number of Deis cluster machines.
1 parent cfafc0d commit 57cde57

9 files changed

Lines changed: 134 additions & 472 deletions

File tree

contrib/vagrant/Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Deis Makefile
3+
#
4+
5+
ifndef $(DEIS_NUM_INSTANCES)
6+
DEIS_NUM_INSTANCES = 3
7+
endif
8+
9+
define ssh_all
10+
i=1 ; while [[ $$i -le $(DEIS_NUM_INSTANCES) ]] ; do \
11+
vagrant ssh deis-$$i -c $(1) ; \
12+
((i = i + 1)) ; \
13+
done
14+
endef
15+
16+
# ordered list of deis components
17+
COMPONENTS=registry logger database cache controller builder router
18+
19+
all: build run
20+
21+
test_client:
22+
python -m unittest discover client.tests
23+
24+
pull:
25+
$(call ssh_all,'for c in $(COMPONENTS); do docker pull deis/$$c; done')
26+
27+
build:
28+
$(call ssh_all,'cd share && for c in $(COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')
29+
30+
install:
31+
for c in $(COMPONENTS); do fleetctl enable ../../$$c/systemd/*; done
32+
33+
uninstall: stop
34+
for c in $(COMPONENTS); do fleetctl disable ../../$$c/systemd/*; done
35+
36+
start:
37+
for c in $(COMPONENTS); do fleetctl start ../../$$c/systemd/*; done
38+
39+
stop:
40+
for c in $(COMPONENTS); do fleetctl stop ../../$$c/systemd/*; done
41+
42+
restart:
43+
for c in $(COMPONENTS); do fleetctl restart ../../$$c/systemd/*; done
44+
45+
run: install restart
46+
47+
clean: uninstall
48+
$(call ssh_all,'cd share && for c in $(COMPONENTS); do docker rm -f deis-$$c; done')
49+
50+
full-clean: clean
51+
$(call ssh_all,'cd share && for c in $(COMPONENTS); do docker rmi deis-$$c; done')

contrib/vagrant/README.md

Lines changed: 39 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,39 @@
1-
Local development workflow for Deis
2-
================================================================
3-
4-
This document suggests some ways that might make developing Deis easier and cheaper. You don't have to follow
5-
them all.
6-
7-
1. You'll need VirtualBox >= `4.2.18`. We recommend installing Vagrant with their binary installer from http://downloads.vagrantup.com
8-
Vagrant 1.3.5 has support for VirtualBox 4.3
9-
10-
2. Firstly you need to decide whether to use your own Chef Server or the free tier of the hosted enterprise
11-
service from Opscode. The free tier has a limit of 5 nodes which is more then enough for development. Also
12-
bear in mind that a local Chef Server VM will take up at least 1GB of RAM.
13-
14-
**Local Chef Server**
15-
* `cd [DEIS_DIR] && ln -s contrib/vagrant/knife-config .chef`
16-
* `vagrant up` the chef server Vagrantfile.
17-
* copy the admin.pem and validation.pem files for your own knife client
18-
`scp -r root@chefserver.local:/etc/chef-server/admin.pem [DEIS_DIR]/contrib/vagrant/knife-config/`
19-
`scp -r root@chefserver.local:/etc/chef-server/chef-validator.pem [DEIS_DIR]/contrib/vagrant/knife-config/`
20-
21-
**Hosted Chef Server**
22-
* Goto https://getchef.opscode.com/signup and fill in your details.
23-
* Goto https://manage.opscode.com/login and sign in to your Chef Server.
24-
* Click on the 'Administration' tab and choose your organisation. There should be a tab in the sidebar that says
25-
'Starter Kit'. Click it and it will start a small download.
26-
* Inside the Starter Kit there is a '.chef' folder. Copy it to the root of your Deis codebase.
27-
28-
3. Now you can follow the standard deis setup:
29-
* If you're running a local chef server, you should adjust the `Gemfile` and make sure the version of berkshelf is 3.0.x. This is needed for the `--ssl-verify` option to work correctly.
30-
```bash
31-
bundle install # Installs gem files like the knife tool
32-
berks install # Downloads the relevant cookbooks
33-
# '--ssl-verify' is only needed when using a local Chef Server
34-
berks upload [--ssl-verify=false] # Upload the cookbooks to the Chef Server
35-
```
36-
37-
4. The Controller needs to be able to run Vagrant commands on your host machine. It does this via SSH. Therefore
38-
you will need a running SSH server open on port 22 and a means to broadcast your hostname to local DNS.
39-
* On Debian-flavoured Linux you just need to;
40-
`sudo apt-get install openssh-server`
41-
* On Mac OSX you just need to go to **System Preferences -> Sharing** and enable 'Remote Login'.
42-
* [Mac OSX user's should already be broadcasting their hostname](http://support.apple.com/kb/ht3473).
43-
* Linux user's will need to install avahi-daemon, so that their machine is accessible via
44-
[hostname].local. Eg; `sudo apt-get install avahi-daemon`.
45-
46-
5. Creating the Deis Controller.
47-
* Run `./contrib/vagrant/provision-vagrant-controller.sh`
48-
* You may need to prepend the command with `bundle exec` depending on your Ruby setup.
49-
* When running for the first time you will be asked to add the Controller's SSH key to your local SSH server.
50-
This will allow the Controller to run vagrant commands on your machine to bootstrap new nodes.
51-
* You need to tell the Chef Server that your new Controller has permission to create
52-
and delete nodes. Use:
53-
* For a local Chef Server just type `knife client edit deis-controller` and your default text
54-
editor will launch, you need to set 'admin' to 'true'.
55-
* For Hosted Chef, log in to https://manage.opscode.com/. Go to the
56-
Administration tab, click on the "Groups" entry to the left, then the "admins" entry
57-
under "All Groups". Choose the "Permissions" tab and click the "+ Add" button, then
58-
type in "deis-controller" and add it. Assign all permissions to the "deis-controller"
59-
client object.
60-
61-
6. If you want to hack on the command line client (`client/deis.py`), install your local dev version rather than
62-
the one from Pip.
63-
* `cd deis && make install` This installs the client into your executables path.
64-
* `sudo rm /usr/local/bin/deis && sudo ln ./deis.py /usr/local/bin/deis` This will symlink the dev version to your executables path.
65-
* Your deis controller is available at http://deis-controller.local:8000 so you can register with;
66-
`deis register http://deis-controller.local:8000`
67-
68-
7. Right, time to boot up some nodes!
69-
* Create a formation with a vagrant flavour, 512MB, 1024MB and 2048MB are available.
70-
`deis formations:create dev --flavor=vagrant-512 --domain=deisapp.local`
71-
* Scale a node with `deis nodes:scale dev runtime=1` Be patient, this is the command that runs vagrant commands. Scaling a single node
72-
can take over 15 mins.
73-
* Then create and push your app as per the usual documentation.
74-
75-
## Useful development commands
76-
* To get a shell session to a running container use the `dsh` command on the VM. Usage:
77-
* `dsh deis-builder`
78-
* `dsh deis-builder /bin/ls` Note the absolute path
79-
* `echo 'ls' | dsh deis-builder` Note no need for path when piping
80-
81-
* To use Django's manage.py:
82-
* SSH in to the VM with `vagrant ssh`
83-
* Use `dsh deis-controller`
84-
* Get into the Django server's path `cd /app/deis/controller`
85-
* Get a list of commands with; `./manage.py help`
86-
87-
* Django's native web admin interface is available at http://deis-controller.local:8000/admin/
88-
You can add and update all of the models from there.
89-
90-
* To reset the DB:
91-
* There is a script at contrib/vagrant/util/reset-db.sh that resets the DB and installs some basic fixtures.
92-
It should be run from your host machine.
93-
* It installs a formation named 'dev' and a super user with username 'devuser' and password 'devpass'.
94-
95-
* This is useful for uploading your own local version of the cookbooks, rather than the Github versions:
96-
* `knife cookbook upload deis --cookbook-path [deis-cookbook path] --force`
97-
* You need to change directory structure though as knife gets the cookbook name from the folder name. So, for example I use;
98-
99-
```bash
100-
deis
101-
|__ code
102-
|__ api
103-
|__ bin
104-
|__ client
105-
|__ cm
106-
|__ ... and so on
107-
|__ cookbooks
108-
|__ deis
109-
|__ attributes
110-
|__ definitions
111-
|__ recipes
112-
|__ ... and so on
113-
```
114-
115-
* Resolving submodule conflicts when merging master into your dev branch can be troublesome.
116-
You might have luck with `git submodule foreach git checkout master && git submodule foreach git pull --rebase`
117-
118-
* There is a sample `Vagrantfile.local.example` that can be useful if you want any personal customisations
119-
to your vagrant setup, like using less RAM for post-installation boots.
120-
121-
Notes
122-
-----
123-
124-
Mac OS X: if you see an error such as
125-
'failed to open /dev/vboxnetctl', try restarting VirtualBox:
126-
sudo /Library/StartupItems/VirtualBox/VirtualBox restart
1+
# Deis cluster local test environment
2+
3+
The Vagrantfile and Makefile provided in this directory will launch a multi-host Deis CoreOS cluster that runs locally.
4+
5+
## Prerequisites
6+
On your workstation:
7+
* Install [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
8+
* Install [Go](http://golang.org/doc/install) and configure your GOPATH, if necessary
9+
* Install the fleetctl client: `go get github.com/coreos/fleetctl`
10+
* Set the `DEIS_NUM_INSTANCES` environment variable if you'd like more (or less) than the default of 3 machines to test:
11+
* `export DEIS_NUM_INSTANCES=5`
12+
* Configure the fleetctl client to tunnel through one of the VMs:
13+
* `export FLEETCTL_TUNNEL=172.17.8.100`
14+
* (Note that IP addressing for the VMs starts at .100, but you can connect to any VM in the cluster)
15+
16+
## Launching Deis
17+
Follow the normal instructions in the [README](../../README.md) for launching and using Deis, with the caveat that
18+
commands should be run in this directory to ensure that the proper Vagrantfile and Makefile is used. In this directory
19+
pull/build commands are run in each VM, and service starting/stopping are run with `fleetctl` and affect the entire cluster.
20+
21+
## Testing ideas
22+
### Stop a container service
23+
Logging into one of the CoreOS machines and stopping a container service should cause the same component on another CoreOS
24+
host to take over as master
25+
26+
### Stop a VM
27+
Similarly, bringing down a VM should enable the services on another VM to take over as master
28+
29+
## Useful references
30+
### systemd services
31+
These systemd services run the various containers which compose Deis, and can be stopped on a machine with `sudo systemctl stop servicename`.
32+
* deis-builder.service
33+
* deis-cache.service
34+
* deis-controller.service
35+
* deis-database.service
36+
* deis-discovery.service
37+
* deis-logger.service
38+
* deis-registry.service
39+
* deis-router.service

contrib/vagrant/Vagrantfile

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,53 @@
1-
Vagrant.configure("2") do |config|
2-
config.vm.box = "deis-server"
1+
# -*- mode: ruby -*-
2+
# # vi: set ft=ruby :
33

4-
# Ubuntu 12.04.3 LTS base with 3.8 kernel (ready for Docker)
5-
config.vm.box_url = "https://s3-us-west-2.amazonaws.com/opdemand/ubuntu-12.04.3-amd64-vbox.box"
4+
require_relative '../coreos/override-plugin.rb'
65

7-
# Avahi-daemon will broadcast the server's address as deis-controller.local
8-
config.vm.host_name = "deis-controller"
6+
DEIS_NUM_INSTANCES = (ENV['DEIS_NUM_INSTANCES'].to_i > 0 && ENV['DEIS_NUM_INSTANCES'].to_i) || 3
97

10-
# IP will be associated to 'deis-controller.local' using avahi-daemon
11-
config.vm.network :private_network, ip: "192.168.61.100"
8+
Vagrant.configure("2") do |config|
9+
config.vm.box = "coreos-alpha"
10+
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/alpha/coreos_production_vagrant.box"
1211

13-
config.vm.provider :virtualbox do |vb|
14-
# The Deis Controller requires at least 2G of RAM to install.
15-
vb.customize ["modifyvm", :id, "--memory", "2048"]
16-
17-
# Displays a friendly name in the VirtualBox GUI
18-
vb.name = "deis-controller"
12+
config.vm.provider :vmware_fusion do |vb, override|
13+
override.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/alpha/coreos_production_vagrant_vmware_fusion.box"
1914
end
2015

21-
config.vm.synced_folder "../../", "/vagrant"
16+
config.vm.provider :virtualbox do |vb, override|
17+
vb.customize ["modifyvm", :id, "--memory", "4096"]
18+
# Fix docker not being able to resolve private registry in VirtualBox
19+
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
20+
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
21+
end
2222

23-
config.vm.provision :shell, inline: <<-SCRIPT
24-
# Avahi-daemon broadcasts the machine's hostname to local DNS.
25-
# Therefore 'deis-controller.local' in this case.
26-
sudo apt-get install -yq avahi-daemon
27-
SCRIPT
23+
# plugin conflict
24+
if Vagrant.has_plugin?("vagrant-vbguest") then
25+
config.vbguest.auto_update = false
26+
end
2827

29-
end
28+
(1..DEIS_NUM_INSTANCES).each do |i|
29+
config.vm.define vm_name = "deis-#{i}" do |config|
30+
config.vm.hostname = vm_name
31+
32+
ip = "172.17.8.#{i+99}"
33+
config.vm.network :private_network, ip: ip
34+
35+
# Enable NFS for sharing the host machine into the coreos-vagrant VM.
36+
config.vm.synced_folder "../..", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
3037

31-
# If you want to do some funky custom stuff to your box, but don't want those things tracked by git,
32-
# add a Vagrantfile.local and it will be included. You can use the exact same syntax as above. For
33-
# example if you're low on RAM you can boot the VM with less RAM. Note that 2GB is recommended
34-
# for installation, but you may be able to get away with 1GB once everything is installed.
35-
load "Vagrantfile.local" if File.exists? "Vagrantfile.local"
38+
# workaround missing /etc/hosts
39+
config.vm.provision :shell, :inline => "echo #{ip} #{vm_name} > /etc/hosts", :privileged => true
40+
41+
# workaround missing /etc/environment
42+
config.vm.provision :shell, :inline => "touch /etc/environment", :privileged => true
43+
44+
# disable update-engine to prevent reboots
45+
config.vm.provision :shell, :inline => "systemctl disable update-engine && systemctl mask update-engine", :privileged => true
46+
47+
# user-data bootstrapping
48+
config.vm.provision :file, :source => "../coreos/user-data", :destination => "/tmp/user-data"
49+
config.vm.provision :shell, :inline => "mkdir -p /var/lib/coreos-vagrant && mv /tmp/user-data /var/lib/coreos-vagrant", :privileged => true
50+
end
51+
end
52+
53+
end

contrib/vagrant/Vagrantfile.local.example

Lines changed: 0 additions & 13 deletions
This file was deleted.

contrib/vagrant/chef-server/Vagrantfile

Lines changed: 0 additions & 45 deletions
This file was deleted.

contrib/vagrant/knife-config/knife.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)