Skip to content

Commit da153a6

Browse files
author
Gabriel Monroy
committed
Merge pull request #257 from opdemand/232-vagrant-dev
232 vagrant dev
2 parents 1381fe0 + 878e769 commit da153a6

8 files changed

Lines changed: 331 additions & 18 deletions

File tree

Gemfile.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ GEM
88
thread_safe (~> 0.1)
99
tzinfo (~> 0.3.37)
1010
addressable (2.3.5)
11+
akami (1.2.0)
12+
gyoku (>= 0.4.0)
13+
nokogiri (>= 1.4.0)
1114
atomic (1.1.14)
1215
berkshelf (1.2.1)
1316
activesupport
@@ -47,10 +50,17 @@ GEM
4750
activesupport (>= 3.2.0)
4851
hashie (>= 2.0.2)
4952
multi_json (>= 1.3.0)
53+
em-winrm (0.5.4)
54+
eventmachine (= 1.0.0.beta.3)
55+
mixlib-log (>= 1.3.0)
56+
uuidtools (~> 2.1.1)
57+
winrm (~> 1.1.0)
5058
erubis (2.7.0)
59+
eventmachine (1.0.0.beta.3)
5160
excon (0.25.3)
5261
faraday (0.8.8)
5362
multipart-post (~> 1.2.0)
63+
ffi (1.9.0)
5464
fog (1.15.0)
5565
builder
5666
excon (~> 0.25.0)
@@ -63,14 +73,31 @@ GEM
6373
ruby-hmac
6474
foodcritic (0.2.0)
6575
formatador (0.2.4)
76+
gssapi (1.0.3)
77+
ffi (>= 1.0.1)
78+
gyoku (1.1.0)
79+
builder (>= 2.1.2)
6680
hashie (2.0.5)
6781
highline (1.6.19)
82+
httpclient (2.3.4.1)
83+
httpi (0.9.7)
84+
rack
6885
i18n (0.6.5)
6986
ipaddress (0.8.0)
7087
json (1.7.7)
7188
knife-ec2 (0.6.4)
7289
chef (>= 0.10.10)
7390
fog (~> 1.6)
91+
knife-rackspace (0.8.1)
92+
chef (>= 0.10.10)
93+
fog (~> 1.12)
94+
knife-windows
95+
knife-windows (0.5.12)
96+
em-winrm (= 0.5.4)
97+
little-plugger (1.1.3)
98+
logging (1.8.1)
99+
little-plugger (>= 1.1.3)
100+
multi_json (>= 1.3.6)
74101
mime-types (1.25)
75102
mini_portile (0.5.1)
76103
minitar (0.5.4)
@@ -95,6 +122,7 @@ GEM
95122
net-ssh-gateway (>= 0.99.0)
96123
nokogiri (1.6.0)
97124
mini_portile (~> 0.5.0)
125+
nori (1.1.5)
98126
ohai (6.18.0)
99127
ipaddress
100128
mixlib-cli
@@ -103,6 +131,7 @@ GEM
103131
mixlib-shellout
104132
systemu
105133
yajl-ruby
134+
rack (1.5.2)
106135
rest-client (1.6.7)
107136
mime-types (>= 1.16)
108137
retryable (1.3.3)
@@ -124,13 +153,33 @@ GEM
124153
retryable
125154
solve (>= 0.4.1)
126155
ruby-hmac (0.4.0)
156+
rubyntlm (0.1.1)
157+
savon (0.9.5)
158+
akami (~> 1.0)
159+
builder (>= 2.1.2)
160+
gyoku (>= 0.4.0)
161+
httpi (~> 0.9)
162+
nokogiri (>= 1.4.0)
163+
nori (~> 1.0)
164+
wasabi (~> 1.0)
127165
solve (0.8.1)
128166
systemu (2.5.2)
129167
thor (0.16.0)
130168
thread_safe (0.1.3)
131169
atomic
132170
timers (1.1.0)
133171
tzinfo (0.3.37)
172+
uuidtools (2.1.4)
173+
wasabi (1.0.0)
174+
nokogiri (>= 1.4.0)
175+
winrm (1.1.3)
176+
gssapi (~> 1.0.0)
177+
httpclient (~> 2.2, >= 2.2.0.2)
178+
logging (~> 1.6, >= 1.6.1)
179+
nokogiri (~> 1.5)
180+
rubyntlm (~> 0.1.1)
181+
savon (= 0.9.5)
182+
uuidtools (~> 2.1.2)
134183
yajl-ruby (1.1.0)
135184

136185
PLATFORMS
@@ -141,3 +190,4 @@ DEPENDENCIES
141190
chef
142191
foodcritic
143192
knife-ec2
193+
knife-rackspace

Vagrantfile

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
# -*- mode: ruby -*-
22
# vi: set ft=ruby :
33

4-
Vagrant.configure("2") do |config|
4+
VAGRANTFILE_API_VERSION = "2"
55

6-
config.vm.box = "deis-controller"
7-
config.vm.hostname = "deis-controller"
6+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
87

8+
# Give each controller and node additional memory
99
config.vm.provider :virtualbox do |v|
1010
v.customize ["modifyvm", :id, "--memory", 2048]
1111
end
12-
13-
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
1412

15-
config.vm.network :public_network, :bridge => 'en0: Wi-Fi (AirPort)' #, :mac => "08002769c9a0"
13+
# Deis Nodes
14+
config.vm.box_url = "https://s3-us-west-2.amazonaws.com/opdemand/deis-node.box"
15+
config.vm.box = "deis-node"
16+
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
22+
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
28+
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"
33+
end
1634

17-
config.vm.provision :shell, :inline => "echo Bootstrap with: knife bootstrap `/sbin/ifconfig eth1|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'` -x vagrant -P vagrant -N deis-controller -r role[deis-controller] --sudo"
18-
1935
end

api/fixtures/initial_data.json

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

bin/pre-push-hook

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/opt/deis/controller/venv/bin/python
2+
#
3+
# Musters data needed before `git push deis master`.
4+
#
5+
import json
6+
import os
7+
import sys
8+
import urllib2 as urllib
9+
10+
11+
# An incomplete list of domains we won't use to access the controller
12+
IGNORE = [
13+
'example.com',
14+
'127.0.0.1',
15+
'127.0.1.1',
16+
'0.0.0.0',
17+
'localhost',
18+
]
19+
20+
21+
if __name__ == '__main__':
22+
# Set up Django so it can find deis/settings.py
23+
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
24+
sys.path.insert(0, base_path)
25+
os.environ['DJANGO_SETTINGS_MODULE'] = 'deis.settings'
26+
27+
# Find the current Django Site object and see if the user has updated
28+
# it to reference a useable domain
29+
from django.contrib.sites.models import Site
30+
site = Site.objects.get_current()
31+
if not any(site.domain.startswith(prefix) for prefix in IGNORE):
32+
domain = site.domain
33+
# Otherwise, try our old strategy of IP lookup through external services
34+
else:
35+
try:
36+
# first try jsonip.com
37+
domain = json.loads(urllib.urlopen(
38+
'http://jsonip.com',
39+
timeout=10).read())['ip']
40+
except urllib.URLError:
41+
# fall back to an AWS internal service
42+
domain = urllib.urlopen(
43+
'http://169.254.169.254/latest/meta-data/public-ipv4',
44+
timeout=10).read()
45+
46+
# Write a small JSON dict to stdout
47+
sys.stdout.write(json.dumps({'domain': domain}))
48+
sys.stdout.flush()
49+
sys.exit(0)

contrib/vagrant/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Provision a Deis Controller on Vagrant
2+
======================================
3+
4+
This document describes how to set up a Deis controller and two nodes with
5+
Vagrant for testing.
6+
7+
1. Install VirtualBox version 4.2.18. (Vagrant does not support version 4.3.)
8+
Then start VirtualBox and install the VirtualBox Extension Pack for 4.2.18.
9+
10+
2. Install Vagrant version 1.3.5 or later. Rather than fight Ruby dependencies,
11+
use a binary installer from vagrantup.com.
12+
13+
3. Run the provisioning script:
14+
```console
15+
$ ./contrib/vagrant/provision-vagrant-controller.sh
16+
```
17+
18+
This script will:
19+
- Create the data bags in your Chef account to support Deis
20+
- Run `vagrant up` to create a Deis controller and 2 static nodes
21+
- Register the controller with Chef and install Deis and supporting software
22+
23+
4. Register a user
24+
25+
5. Run the script to create a static formation:
26+
```console
27+
$ ./contrib/vagrant/create-static-formation.sh
28+
```
29+
30+
Notes
31+
-----
32+
33+
Mac OS X: if you see an error such as
34+
"failed to open /dev/vboxnetctl", try restarting VirtualBox:
35+
sudo /Library/StartupItems/VirtualBox/VirtualBox restart
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
function echo_color {
4+
echo -e "\033[1m$1\033[0m"
5+
}
6+
7+
# Require a command-line arg for the formation name
8+
if [ -z $1 ]; then
9+
echo usage: $0 [formation]
10+
exit 1
11+
fi
12+
formation=$1
13+
14+
# Create a "static" formation, where nodes must be added manually
15+
deis formations:create $formation --flavor=static
16+
17+
# Update the layer to SSH as "vagrant", and retrieve its SSH public key
18+
echo_color "Updating the runtime layer to SSH as \"vagrant\"..."
19+
ssh_key=$(deis layers:update $formation runtime --ssh_username=vagrant |
20+
grep -Eo '\"ssh_public_key\"\: \"(.*)\"' | cut -d\" -f4)
21+
authfile=.ssh/authorized_keys
22+
tmpfile=/tmp/authorized_keys.tmp
23+
24+
# SSH into deis-node-1 and authorize the SSH public key
25+
echo_color "Adding the layer's public key to deis-node-1..."
26+
vagrant ssh deis-node-1 -c "echo $ssh_key|cat - $authfile > $tmpfile && mv $tmpfile $authfile"
27+
28+
# Add deis-node-1 to the formation
29+
echo_color "Adding node deis-node-1 to formation and provisioning..."
30+
deis nodes:create $formation deis-node-1.local --layer=runtime
31+
32+
# SSH into deis-node-2 and authorize the SSH public key
33+
echo_color "Adding the layer's public key to deis-node-2..."
34+
vagrant ssh deis-node-2 -c "echo $ssh_key|cat - $authfile > $tmpfile && mv $tmpfile $authfile"
35+
36+
# Add deis-node-1 to the formation
37+
echo_color "Adding node deis-node-2 to formation and provisioning..."
38+
deis nodes:create $formation deis-node-2.local --layer=runtime
39+
40+
echo_color "Done. Now run \"deis create --formation=$formation\" in your app repository."
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash -ex
2+
3+
#
4+
# Prepare a Deis-optimized AMI from a vanilla Ubuntu 12.04
5+
# Prepare a Deis-optimized Vagrant box from vanilla Ubuntu 12.04
6+
#
7+
# Instructions:
8+
#
9+
# 1. Launch a vanilla Ubuntu 12.04 instance with `vagrant up`
10+
# 2. SSH in with `vagrant ssh`, do `sudo -i` and install the 3.8 kernel with:
11+
# apt-get update && apt-get install -yq linux-image-generic-lts-raring linux-headers-generic-lts-raring && reboot
12+
# 3. After reboot is complete, SSH in again and `uname -r` to confirm kernel is 3.8
13+
# 4. Run this script (as root!) to optimize the image for fast boot times
14+
# 5. Create a new box with `vagrant package && cp -f package.box contrib/vagrant/deis-base.box`
15+
#
16+
17+
# Remove any temporary work files, including the postinstall.sh script
18+
rm -f /home/${account}/{*.iso,postinstall*.sh}
19+
20+
# Install some essentials and mDNS daemon
21+
apt-get install python-software-properties curl apt-transport-https -y
22+
23+
# Add the Docker repository key to your local keychain
24+
# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9
25+
curl https://get.docker.io/gpg | apt-key add -
26+
27+
# Add the Docker repository to your apt sources list.
28+
echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list
29+
30+
# upgrade to latest packages
31+
apt-get update
32+
apt-get dist-upgrade -yq
33+
34+
# install required packages
35+
apt-get install lxc-docker git make python-setuptools python-pip -yq
36+
37+
# create buildstep docker image
38+
git clone https://github.com/opdemand/buildstep.git
39+
cd buildstep
40+
git checkout deis
41+
make
42+
cd ..
43+
rm -rf buildstep
44+
45+
# install chef 11.x deps
46+
apt-get install -yq ruby1.9.1 ruby1.9.1-dev make
47+
update-alternatives --set ruby /usr/bin/ruby1.9.1
48+
update-alternatives --set gem /usr/bin/gem1.9.1
49+
50+
# install mDNS support
51+
apt-get install avahi-daemon -yq
52+
53+
# clean and remove old packages
54+
apt-get clean
55+
apt-get autoremove -yq
56+
57+
# reset cloud-init
58+
rm -rf /var/lib/cloud
59+
60+
# purge SSH authorized keys
61+
# rm -f /home/ubuntu/.ssh/authorized_keys
62+
rm -f /root/.ssh/authorized_keys
63+
64+
# ssh host keys are automatically regenerated
65+
# on system boot by ubuntu cloud init
66+
67+
# purge /var/log
68+
find /var/log -type f | xargs rm
69+
70+
# Removing leftover leases and persistent rules
71+
rm -f /var/lib/dhcp3/*
72+
73+
# Make sure Udev doesn't block our network, see: http://6.ptmc.org/?p=164
74+
rm /etc/udev/rules.d/70-persistent-net.rules
75+
mkdir /etc/udev/rules.d/70-persistent-net.rules
76+
rm -rf /dev/.udev/
77+
rm /lib/udev/rules.d/75-persistent-net-generator.rules
78+
79+
# flush writes to block storage
80+
sync
81+
82+
# Zero out the free space to save space in the final image
83+
dd if=/dev/zero of=/EMPTY bs=1M
84+
rm -f /EMPTY

0 commit comments

Comments
 (0)