nise-bosh-vagrant 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +12 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/bin/nise-bosh-vagrant +7 -0
- data/lib/nise-bosh-vagrant/cli.rb +41 -0
- data/lib/nise-bosh-vagrant/runner.rb +88 -0
- data/lib/nise-bosh-vagrant/version.rb +3 -0
- data/lib/nise-bosh-vagrant.rb +5 -0
- data/nise-bosh-vagrant.gemspec +19 -0
- data/resources/Vagrantfile.erb +13 -0
- data/resources/install_release.sh.erb +1 -0
- data/scripts/prepare.sh +46 -0
- data/scripts/start.sh +3 -0
- data/scripts/stop.sh +3 -0
- metadata +81 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Nise BOSH Vagrant
|
2
|
+
=================
|
3
|
+
|
4
|
+
Nise BOSH Vagrant is a mashup of [nise_bosh](https://github.com/nttlabs/nise_bosh) and [Vagrant](http://www.vagrantup.com/)
|
5
|
+
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
------------
|
9
|
+
- Vagrant >= v1.2 (Not tested on anything older)
|
10
|
+
- A BOSH release to run
|
11
|
+
- A custom manifest file
|
12
|
+
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
`nise-bosh-vagrant <Path to Release> --manifest <Path to manifest>`
|
17
|
+
|
18
|
+
This will generate a Vagrantfile, spin up a VM, and use nise_bosh to deploy your BOSH release as defined in the manifest file
|
19
|
+
|
20
|
+
```
|
21
|
+
$ cd </path/to/release>
|
22
|
+
$ vagrant ssh
|
23
|
+
$ ./install_release.sh
|
24
|
+
$ ./start.sh
|
25
|
+
```
|
26
|
+
|
27
|
+
What does that command do?
|
28
|
+
--------------------------
|
29
|
+
|
30
|
+
1. Generate a Vagrantfile, install scripts, etc
|
31
|
+
2. Boot up a lucid64 image in Vagrant and install prerequisites
|
32
|
+
3. Create management scripts
|
33
|
+
|
34
|
+
Management Scripts
|
35
|
+
------------------
|
36
|
+
* `/home/vagrant/install_release.sh` -- Install your BOSH release using nise_bosh
|
37
|
+
* `/home/vagrant/start.sh` -- Start the BOSH release jobs after they've been installed
|
38
|
+
* `/home/vagrant/stop.sh` -- Stop the BOSH release jobs
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
|
3
|
+
require 'nise-bosh-vagrant/runner'
|
4
|
+
require 'nise-bosh-vagrant/version'
|
5
|
+
|
6
|
+
module NiseBOSHVagrant
|
7
|
+
class CLI
|
8
|
+
|
9
|
+
def self.start
|
10
|
+
opts = Trollop::options do
|
11
|
+
version NiseBOSHVagrant::VERSION
|
12
|
+
banner <<-EOS
|
13
|
+
Based on nise-bosh from NTT Labs and Vagrant from HashiCorp
|
14
|
+
|
15
|
+
Requires Vagrant >= 1.2
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
nise-bosh-vagrant [options] <BOSH Release>+
|
19
|
+
|
20
|
+
Options:
|
21
|
+
EOS
|
22
|
+
|
23
|
+
opt :manifest, "Path to manifest file", :type => :string
|
24
|
+
opt :nise, "Path to nise-bosh if you don't wish to pull HEAD of master from GitHub", :type => :string
|
25
|
+
end
|
26
|
+
|
27
|
+
Trollop::die :manifest, "must provilde a manifest file" if opts[:manifest].nil?
|
28
|
+
Trollop::die :manifest, "must exist" unless File.exist?(opts[:manifest])
|
29
|
+
|
30
|
+
opts[:release] = ARGV[0]
|
31
|
+
|
32
|
+
runner = NiseBOSHVagrant::Runner.new(opts)
|
33
|
+
runner.generate_vagrantfile
|
34
|
+
runner.copy_manifest
|
35
|
+
runner.generate_install_script
|
36
|
+
runner.start_vm
|
37
|
+
runner.prepare_vm
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'pty'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module NiseBOSHVagrant
|
6
|
+
class Runner
|
7
|
+
|
8
|
+
attr_reader :release_path, :nise_path, :scripts_path, :vagrantfile_path, :manifest_file, :manifest_copy_path, :install_script_path, :manifest_copy_name, :install_script_copy_name
|
9
|
+
|
10
|
+
def initialize(opts)
|
11
|
+
opts[:nise].nil? ? @nise_path = nil : @nise_path = opts[:nise]
|
12
|
+
@release_path = opts[:release]
|
13
|
+
@vagrantfile_path = File.join(@release_path, "Vagrantfile")
|
14
|
+
@scripts_path = File.join(File.dirname(File.expand_path(__FILE__)), "../../scripts")
|
15
|
+
@manifest_file = opts[:manifest]
|
16
|
+
|
17
|
+
@manifest_copy_name = '.nise-bosh-manifest.yml'
|
18
|
+
@install_script_copy_name = '.nise-bosh-install.sh'
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_vagrantfile(output_path=@vagrantfile_path)
|
23
|
+
vagrantfile_template = File.open(File.join(File.dirname(File.expand_path(__FILE__)), '../../resources/Vagrantfile.erb'), "rb") { |f| f.read }
|
24
|
+
template = ERB.new vagrantfile_template
|
25
|
+
vagrantfile = template.result(binding)
|
26
|
+
File.open(output_path, "wb") { |f| f.write(vagrantfile) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_manifest(output_dir=@release_path, manifest_file=@manifest_file)
|
30
|
+
@manifest_copy_path = File.join(output_dir, @manifest_copy_name)
|
31
|
+
FileUtils.cp(manifest_file, @manifest_copy_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_install_script(output_dir=@release_path, manifest_file=@manifest_copy_path)
|
35
|
+
manifest = YAML.load_file manifest_file
|
36
|
+
jobs = []
|
37
|
+
manifest['jobs'].each do |job|
|
38
|
+
jobs << job['name']
|
39
|
+
end
|
40
|
+
|
41
|
+
puts "Job list: #{jobs}"
|
42
|
+
|
43
|
+
install_script_template = File.open(File.join(File.dirname(File.expand_path(__FILE__)), '../../resources/install_release.sh.erb'), "rb") { |f| f.read }
|
44
|
+
install_script_erb = ERB.new install_script_template
|
45
|
+
|
46
|
+
install_script = "#!/bin/bash\n\n"
|
47
|
+
install_script += "(\n"
|
48
|
+
install_script += " cd /home/vagrant/nise_bosh\n"
|
49
|
+
|
50
|
+
|
51
|
+
jobs.each do |job|
|
52
|
+
manifest_path = "/home/vagrant/release/#{@manifest_copy_name}"
|
53
|
+
job_name = job
|
54
|
+
install_entry = install_script_erb.result(binding)
|
55
|
+
install_script += "#{install_entry}\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
install_script += ")"
|
59
|
+
|
60
|
+
@install_script_path = File.join(output_dir, @install_script_copy_name)
|
61
|
+
File.open(@install_script_path, "wb") { |f| f.write(install_script) }
|
62
|
+
FileUtils.chmod 0755, @install_script_path
|
63
|
+
end
|
64
|
+
|
65
|
+
def exec(cmd)
|
66
|
+
begin
|
67
|
+
PTY.spawn (cmd) do |stdout, stdin, pid|
|
68
|
+
begin
|
69
|
+
stdout.each { |line| print line }
|
70
|
+
rescue Errno::EIO
|
71
|
+
end
|
72
|
+
end
|
73
|
+
rescue PTY::ChildExited
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def start_vm(release_path=@release_path)
|
78
|
+
up_cmd = "cd #{release_path} ; vagrant up"
|
79
|
+
self.exec(up_cmd)
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def prepare_vm(release_path=@release_path)
|
84
|
+
prepare_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/scripts/prepare.sh\""
|
85
|
+
self.exec(prepare_cmd)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nise-bosh-vagrant/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian McClain"]
|
6
|
+
gem.email = ["brianmmcclain@gmail.com"]
|
7
|
+
gem.description = %q{Combining nise-bosh with Vagrant}
|
8
|
+
gem.summary = gem.summary
|
9
|
+
gem.homepage = "https://github.com/BrianMMcClain/nise-bosh-vagrant"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "nise-bosh-vagrant"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = NiseBOSHVagrant::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "trollop"
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure("2") do |config|
|
5
|
+
config.vm.box = "lucid64"
|
6
|
+
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
|
7
|
+
|
8
|
+
config.vm.network :private_network, ip: "192.168.10.10"
|
9
|
+
|
10
|
+
<% if not @nise_path.nil? %>config.vm.synced_folder "<%= @nise_path %>", "/home/vagrant/nise_bosh"<% end %>
|
11
|
+
config.vm.synced_folder "<%= @release_path %>", "/home/vagrant/release"
|
12
|
+
config.vm.synced_folder "<%= @scripts_path %>", "/home/vagrant/scripts"
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
sudo PATH=$PATH bundle exec ./bin/nise-bosh --keep-monit-files -y /home/vagrant/release <%= manifest_path %> <%= job_name %>
|
data/scripts/prepare.sh
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Install git
|
4
|
+
sudo apt-get update
|
5
|
+
sudo apt-get install -y git-core
|
6
|
+
|
7
|
+
# If not using local nise-bosh, pull it from github
|
8
|
+
if [ ! -d "/home/vagrant/nise_bosh" ]; then
|
9
|
+
git clone https://github.com/nttlabs/nise_bosh.git /home/vagrant/nise_bosh
|
10
|
+
fi
|
11
|
+
|
12
|
+
# Run nise_bosh init script
|
13
|
+
(
|
14
|
+
cd /home/vagrant/nise_bosh
|
15
|
+
sudo ./bin/init
|
16
|
+
)
|
17
|
+
|
18
|
+
# Install ruby 1.9.3-p392
|
19
|
+
curl -L https://get.rvm.io | bash -s stable
|
20
|
+
echo -e "\nsource /home/vagrant/.rvm/scripts/rvm" >> /home/vagrant/.profile
|
21
|
+
source /home/vagrant/.rvm/scripts/rvm
|
22
|
+
rvm install 1.9.3-p392
|
23
|
+
rvm use --default 1.9.3-p392
|
24
|
+
|
25
|
+
# Install BOSH CLI
|
26
|
+
gem install bundler --no-rdoc --no-ri
|
27
|
+
gem install bosh_cli --no-rdoc --no-ri
|
28
|
+
|
29
|
+
# Bundle nise-bosh gems
|
30
|
+
(
|
31
|
+
cd /home/vagrant/nise_bosh
|
32
|
+
sudo PATH=$PATH bundle install
|
33
|
+
)
|
34
|
+
|
35
|
+
# Copy install script
|
36
|
+
cp /home/vagrant/release/.nise-bosh-install.sh /home/vagrant/install_release.sh
|
37
|
+
chmod +x /home/vagrant/install_release.sh
|
38
|
+
|
39
|
+
# Copy start/stop scripts
|
40
|
+
cp /home/vagrant/scripts/start.sh /home/vagrant/start.sh
|
41
|
+
chmod +x /home/vagrant/start.sh
|
42
|
+
cp /home/vagrant/scripts/stop.sh /home/vagrant/stop.sh
|
43
|
+
chmod +x /home/vagrant/start.sh
|
44
|
+
|
45
|
+
# Copy manifest file
|
46
|
+
cp /home/vagrant/release/.nise-bosh-manifest.yml /home/vagrant/manifest.yml
|
data/scripts/start.sh
ADDED
data/scripts/stop.sh
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nise-bosh-vagrant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian McClain
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Combining nise-bosh with Vagrant
|
31
|
+
email:
|
32
|
+
- brianmmcclain@gmail.com
|
33
|
+
executables:
|
34
|
+
- nise-bosh-vagrant
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/nise-bosh-vagrant
|
44
|
+
- lib/nise-bosh-vagrant.rb
|
45
|
+
- lib/nise-bosh-vagrant/cli.rb
|
46
|
+
- lib/nise-bosh-vagrant/runner.rb
|
47
|
+
- lib/nise-bosh-vagrant/version.rb
|
48
|
+
- nise-bosh-vagrant.gemspec
|
49
|
+
- resources/Vagrantfile.erb
|
50
|
+
- resources/install_release.sh.erb
|
51
|
+
- scripts/prepare.sh
|
52
|
+
- scripts/start.sh
|
53
|
+
- scripts/stop.sh
|
54
|
+
homepage: https://github.com/BrianMMcClain/nise-bosh-vagrant
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
hash: 682713528875674633
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.25
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: ''
|
81
|
+
test_files: []
|