Skip to content

Commit 691461d

Browse files
committed
Merge branch '232-vagrant-provider-full' of https://github.com/tombh/deis into tombh-232-vagrant-provider-full
2 parents fd0faba + be45748 commit 691461d

18 files changed

Lines changed: 730 additions & 175 deletions

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,18 @@ htmlcov/
5050
.ruby-version
5151
venv/
5252
.vagrant
53+
Vagrantfile.local
5354
*.swp
55+
.bundle
5456

57+
# Chef setup
58+
.chef
59+
contrib/vagrant/knife-config/admin.pem
60+
contrib/vagrant/knife-config/chef-validator.pem
61+
contrib/vagrant/nodes/
62+
63+
# Broken symlinks that appear when mounting the codebase onto a vagrant VM
64+
# See Vagrantfile.local.example
65+
logs
66+
static
67+
venv

Berksfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
site :opscode
1+
source "http://api.berkshelf.com"
22

33
cookbook 'apt'
44
cookbook 'rsyslog'

Berksfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"sources": {
2+
"dependencies": {
33
"apt": {
44
"locked_version": "2.3.0"
55
},
@@ -10,9 +10,9 @@
1010
"locked_version": "2.2.2"
1111
},
1212
"deis": {
13-
"locked_version": "0.2.1",
13+
"locked_version": "0.1.2",
1414
"git": "https://github.com/opdemand/deis-cookbook.git",
15-
"ref": "617d5a2627fdee92ade9499b4a87c6ff85a99c66"
15+
"ref": "3277d069b61d261b6ebcab319041442fe38a2ae3"
1616
}
1717
}
1818
}

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
22

33
gem 'chef'
44
gem 'foodcritic'
5-
gem 'berkshelf'
5+
gem 'berkshelf', '3.0.0.beta3' # needed for --ssl-verify=false support
66

77
gem 'knife-ec2'
88
gem 'knife-rackspace'

Gemfile.lock

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (3.2.15)
5-
i18n (~> 0.6, >= 0.6.4)
6-
multi_json (~> 1.0)
74
addressable (2.3.5)
85
akami (1.2.0)
96
gyoku (>= 0.4.0)
107
nokogiri (>= 1.4.0)
11-
berkshelf (2.0.10)
12-
activesupport (~> 3.2.0)
8+
berkshelf (3.0.0.beta3)
139
addressable (~> 2.3.4)
10+
buff-config (~> 0.2)
11+
buff-extensions (~> 0.4)
1412
buff-shell_out (~> 0.1)
15-
chozo (>= 0.6.1)
1613
faraday (>= 0.8.5)
1714
hashie (>= 2.0.2)
1815
minitar (~> 0.5.4)
19-
rbzip2 (~> 0.2.0)
2016
retryable (~> 1.3.3)
21-
ridley (~> 1.5.0)
22-
solve (>= 0.5.0)
17+
ridley (~> 1.6)
18+
solve (>= 0.8.0)
2319
thor (~> 0.18.0)
2420
buff-config (0.4.0)
2521
buff-extensions (~> 0.3)
@@ -30,11 +26,11 @@ GEM
3026
buff-shell_out (0.1.1)
3127
buff-ruby_engine (~> 0.1.0)
3228
builder (3.2.2)
33-
celluloid (0.14.1)
34-
timers (>= 1.0.0)
35-
celluloid-io (0.14.1)
36-
celluloid (>= 0.14.1)
37-
nio4r (>= 0.4.5)
29+
celluloid (0.15.2)
30+
timers (~> 1.1.0)
31+
celluloid-io (0.15.0)
32+
celluloid (>= 0.15.0)
33+
nio4r (>= 0.5.0)
3834
chef (11.6.2)
3935
erubis (~> 2.7)
4036
highline (~> 1.6, >= 1.6.9)
@@ -49,10 +45,6 @@ GEM
4945
ohai (>= 0.6.0, < 7.0.0)
5046
rest-client (>= 1.0.4, < 1.7.0)
5147
yajl-ruby (~> 1.1)
52-
chozo (0.6.1)
53-
activesupport (>= 3.2.0)
54-
hashie (>= 2.0.2)
55-
multi_json (>= 1.3.0)
5648
digital_ocean (1.2.0)
5749
faraday (~> 0.8.7)
5850
faraday_middleware (~> 0.9.0)
@@ -92,7 +84,6 @@ GEM
9284
httpclient (2.3.4.1)
9385
httpi (0.9.7)
9486
rack
95-
i18n (0.6.5)
9687
ipaddress (0.8.0)
9788
json (1.7.7)
9889
knife-digital_ocean (0.2.0)
@@ -148,26 +139,24 @@ GEM
148139
rack (1.5.2)
149140
rash (0.4.0)
150141
hashie (~> 2.0.0)
151-
rbzip2 (0.2.0)
152142
rest-client (1.6.7)
153143
mime-types (>= 1.16)
154144
retryable (1.3.3)
155-
ridley (1.5.3)
145+
ridley (1.7.1)
156146
addressable
157147
buff-config (~> 0.2)
158148
buff-extensions (~> 0.3)
159149
buff-ignore (~> 1.1)
160150
buff-shell_out (~> 0.1)
161-
celluloid (~> 0.14.0)
162-
celluloid-io (~> 0.14.0)
151+
celluloid (~> 0.15)
152+
celluloid-io (~> 0.15)
163153
erubis
164154
faraday (>= 0.8.4)
165155
hashie (>= 2.0.2)
166156
json (>= 1.7.7)
167157
mixlib-authentication (>= 1.3.0)
168158
net-http-persistent (>= 2.8)
169159
net-ssh
170-
nio4r (>= 0.5.0)
171160
retryable
172161
solve (>= 0.4.4)
173162
varia_model (~> 0.1)
@@ -206,7 +195,7 @@ PLATFORMS
206195
ruby
207196

208197
DEPENDENCIES
209-
berkshelf
198+
berkshelf (= 3.0.0.beta3)
210199
chef
211200
foodcritic
212201
knife-digital_ocean

Vagrantfile

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
1-
# -*- mode: ruby -*-
2-
# vi: set ft=ruby :
31

4-
VAGRANTFILE_API_VERSION = "2"
5-
6-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7-
8-
# Give each controller and node additional memory
9-
config.vm.provider :virtualbox do |v|
10-
v.customize ["modifyvm", :id, "--memory", 2048]
11-
end
2+
Vagrant.configure("2") do |config|
3+
config.vm.box = "deis-node"
124

13-
# Deis Nodes
5+
# This is the vanilla Ubunutu 12.04 Precise box. It's about 350MB
146
config.vm.box_url = "https://s3-us-west-2.amazonaws.com/opdemand/deis-node.box"
15-
config.vm.box = "deis-node"
167

17-
# Deis Controller
18-
config.vm.define "deis-controller", primary: true do |controller|
19-
controller.vm.hostname = "deis-controller"
20-
controller.vm.network "private_network", ip: "192.168.61.100"
21-
end
8+
# This is a premade Deis controller box, probably 12.04, need to check. It's about 1.1GB
9+
# config.vm.box_url = "https://s3-us-west-2.amazonaws.com/opdemand/deis-controller.box"
2210

23-
# Node 1
24-
config.vm.define "deis-node-1" do |node1|
25-
node1.vm.hostname = "deis-node-1"
26-
node1.vm.network "private_network", ip: "192.168.61.101"
27-
end
11+
# Avahi-daemon will broadcast the server's address as deis-controller.local
12+
config.vm.host_name = "deis-controller"
2813

29-
# Node 2
30-
config.vm.define "deis-node-2" do |node2|
31-
node2.vm.hostname = "deis-node-2"
32-
node2.vm.network "private_network", ip: "192.168.61.102"
14+
# IP will be associated to 'deis-controller.local' using avahi-daemon
15+
config.vm.network :private_network, ip: "192.168.61.100"
16+
17+
# The Deis Controller requires at least 1G of RAM to install.
18+
# You may be able to run it with less once it's installed.
19+
config.vm.provider :virtualbox do |vb|
20+
vb.customize ["modifyvm", :id, "--memory", "1024"]
3321
end
3422

23+
# 'deis provider:discover' detects the host machine's user and IP address, however, that command cannot
24+
# be guareteed to run inside the deis codebase. Therefore we can't use that opportunity to discover
25+
# the path of the codebase on the host machine. Therefore we do it now as this Vagrantfile has to exist
26+
# inside the codebase.
27+
nodes_dir = File.dirname(__FILE__) + '/contrib/vagrant/nodes'
28+
29+
config.vm.provision :shell, inline: <<-SCRIPT
30+
# Avahi-daemon broadcasts the machine's hostname to local DNS.
31+
# Therefore 'deis-controller.local' in this case.
32+
sudo service avahi-daemon restart
33+
# Make a record of where the deis code base is on the host machine
34+
echo "#{nodes_dir}" > /home/vagrant/.host_nodes_dir
35+
SCRIPT
3536
end
37+
38+
# If you want to do some funky custom stuff to your box, but don't want those things tracked by git,
39+
# add a Vagrantfile.local and it will be included. You can use the exact same syntax as above. For
40+
# example you could mount your dev version of deis onto the VM and hack live on the VM;
41+
# `config.vm.share_folder "deis", "/opt/deis", "~/myworkspace/deis"
42+
# Or if you're low on RAM you can boot the VM with less RAM. Note that at least 1GB is needed for
43+
# installation, but you may be able to get away with 512MB once everything is installed.
44+
load "Vagrantfile.local" if File.exists? "Vagrantfile.local"

Vagrantfile.local.example

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=begin
2+
This file augments the standard Vagrantfile with some developer-specific settings.
3+
You can override any settings you want. This file is in .gitignore, so can be specific
4+
to your own environment.
5+
6+
By default this file mounts your local development version of the Deis codebase onto the
7+
Deis Controller. It does this by mounting your code onto the VM at /vagrant, then moving
8+
the original installed code base to /opt/deis/controller_ORIG and symlinking
9+
/opt/deis/controller to the mounted code at /vagrant.
10+
11+
Because the deployed environment creates some extra files, like /deis/local_settings.py
12+
for example, these need to be then symlinked into the symlinked mount. Sound complicated?
13+
Yo dawg, I heard you like symlinks.
14+
=end
15+
16+
HOST_CODE_PATH = '/opt/deis/controller'
17+
HOST_BAK_PATH = "#{HOST_CODE_PATH}_ORIG"
18+
19+
# These paths are either in .gitignore or created after installation.
20+
# Therefore they need to be linked into the dev codebase.
21+
symlinks = [
22+
'deis/local_settings.py',
23+
'.secret_key',
24+
'logs',
25+
'static',
26+
'venv'
27+
].map { |path|
28+
"ln -s #{HOST_BAK_PATH}/#{path} #{HOST_CODE_PATH}/#{path}"
29+
}.join("\n")
30+
31+
Vagrant.configure("2") do |config|
32+
33+
config.vm.provider :virtualbox do |vb|
34+
#vb.customize ["modifyvm", :id, "--memory", "512"]
35+
end
36+
37+
# Mount the entire Deis codebase onto the VM at /vagrant
38+
# The first param is relative to the location of this file
39+
config.vm.synced_folder ".", "/vagrant", owner: 'deis', group: 'deis'
40+
41+
config.vm.provision :shell, inline: <<-SCRIPT
42+
if [ ! -d #{HOST_BAK_PATH} ]; then
43+
mv #{HOST_CODE_PATH} #{HOST_BAK_PATH}
44+
ln -s /vagrant #{HOST_CODE_PATH}
45+
46+
# Paths added after installation need linking into the codebase
47+
#{symlinks}
48+
49+
chown -R deis:deis #{HOST_CODE_PATH}
50+
fi
51+
SCRIPT
52+
53+
end

api/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Provider(UuidAuditedModel):
110110
('rackspace', 'Rackspace Open Cloud'),
111111
('static', 'Static Node'),
112112
('digitalocean', 'Digital Ocean'),
113+
('vagrant', 'Local Vagrant VMs'),
113114
)
114115

115116
owner = models.ForeignKey(settings.AUTH_USER_MODEL)

client/deis.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ def providers(self, args):
16611661
"""
16621662
return self.providers_list(args)
16631663

1664-
def providers_create(self, args):
1664+
def providers_create(self, args): # noqa
16651665
"""
16661666
Create a provider for use by Deis
16671667
@@ -1691,7 +1691,7 @@ def providers_create(self, args):
16911691
else:
16921692
raise ResponseError(response)
16931693

1694-
def providers_discover(self, args):
1694+
def providers_discover(self, args): # noqa
16951695
"""
16961696
Discover and update provider credentials
16971697
@@ -1729,6 +1729,51 @@ def providers_discover(self, args):
17291729
else:
17301730
print("No {} credentials discovered.".format(provider))
17311731

1732+
# Check for locally booted Deis Controller VM
1733+
try:
1734+
running_vms = subprocess.check_output(
1735+
['vboxmanage', 'list', 'runningvms'],
1736+
stderr=subprocess.PIPE
1737+
)
1738+
except subprocess.CalledProcessError:
1739+
running_vms = ""
1740+
# Vagrant internally names a running VM using the folder name in which the Vagrantfile
1741+
# resides, eg; my-deis-code-folder_default_1383326629
1742+
deis_codebase_folder = self._session.git_root().split('/')[-1]
1743+
if deis_codebase_folder in running_vms:
1744+
print("Detected locally running Deis Controller VM")
1745+
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands
1746+
# on the host machine. It does this via an SSH server. In order to access that server
1747+
# we need to send the current user's name and host.
1748+
try:
1749+
user = subprocess.check_output(
1750+
"whoami",
1751+
stderr=subprocess.PIPE
1752+
).strip()
1753+
hostname = subprocess.check_output(
1754+
"hostname",
1755+
stderr=subprocess.PIPE,
1756+
shell=True
1757+
).strip()
1758+
except subprocess.CalledProcessError:
1759+
print("Error detecting username and host address.")
1760+
sys.exit(1)
1761+
creds = {
1762+
'user': user,
1763+
'host': hostname + ".local"
1764+
}
1765+
body = {'creds': json.dumps(creds)}
1766+
sys.stdout.write('Activating Vagrant as a provider... ')
1767+
sys.stdout.flush()
1768+
response = self._dispatch('patch', '/api/providers/vagrant',
1769+
json.dumps(body))
1770+
if response.status_code == requests.codes.ok: # @UndefinedVariable
1771+
print('done')
1772+
else:
1773+
raise ResponseError(response)
1774+
else:
1775+
print("No Vagrant VMs detected")
1776+
17321777
def providers_info(self, args):
17331778
"""
17341779
Print information about a specific provider

0 commit comments

Comments
 (0)