nise-bosh-vagrant 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,10 +25,15 @@ EOS
25
25
  opt :install, "Run install script after preparing the VM"
26
26
  opt :start, "Start all jobs after installing them (implies --install)"
27
27
  opt :memory, "Amount of memory to allocate to the VM in MB", :type => :integer, :default => 512
28
+ opt :preinstall, "Preinstall hook script", :type => :string
29
+ opt :postinstall, "Postinstall hook script", :type => :string
30
+ opt :address, "IP address for the VM", :type => :string, :default => "192.168.10.10"
28
31
  end
29
32
 
30
33
  Trollop::die :manifest, "must provide a manifest file" if opts[:manifest].nil?
31
34
  Trollop::die :manifest, "must exist" unless File.exist?(opts[:manifest])
35
+ Trollop::die :preinstall, "must exist" unless opts[:preinstall].nil? || File.exist?(opts[:preinstall])
36
+ Trollop::die :postinstall, "must exist" unless opts[:postinstall].nil? || File.exist?(opts[:postinstall])
32
37
 
33
38
  opts[:release] = ARGV[0]
34
39
 
@@ -40,6 +45,7 @@ EOS
40
45
  runner = NiseBOSHVagrant::Runner.new(opts)
41
46
  runner.generate_vagrantfile
42
47
  runner.copy_manifest
48
+ runner.copy_hook_scripts
43
49
  runner.generate_install_script
44
50
  puts "---> Starting Vagrant VM"
45
51
  runner.start_vm
@@ -48,8 +54,10 @@ EOS
48
54
 
49
55
  # If instructed, install the release
50
56
  if opts[:install]
57
+ runner.hook_preinstall_release
51
58
  puts "---> Installing release"
52
59
  runner.install_release
60
+ runner.hook_postinstall_release
53
61
  end
54
62
 
55
63
  # If instructed, start the release
@@ -60,4 +68,4 @@ EOS
60
68
  end
61
69
 
62
70
  end
63
- end
71
+ end
@@ -7,7 +7,7 @@ module NiseBOSHVagrant
7
7
  class Runner
8
8
 
9
9
  attr_reader :release_path, :nise_path, :scripts_path, :vagrantfile_path, :manifest_file, :manifest_copy_path, :install_script_path,
10
- :manifest_copy_name, :install_script_copy_name, :memory
10
+ :copy_name, :memory
11
11
 
12
12
  def initialize(opts)
13
13
  opts[:nise].nil? ? @nise_path = nil : @nise_path = opts[:nise]
@@ -15,10 +15,18 @@ module NiseBOSHVagrant
15
15
  @vagrantfile_path = File.join(@release_path, "Vagrantfile")
16
16
  @scripts_path = File.join(File.dirname(File.expand_path(__FILE__)), "../../scripts")
17
17
  @manifest_file = opts[:manifest]
18
+ @preinstall_file = opts[:preinstall]
19
+ @postinstall_file = opts[:postinstall]
18
20
  @memory = opts[:memory]
21
+ @ip_address = opts[:address]
19
22
 
20
- @manifest_copy_name = '.nise-bosh-manifest.yml'
21
- @install_script_copy_name = '.nise-bosh-install.sh'
23
+ copy_file_prefix = '.nise-bosh'
24
+ @copy_name = {
25
+ :manifest => "#{copy_file_prefix}-manifest.yml",
26
+ :preinstall => "#{copy_file_prefix}-preinstall",
27
+ :postinstall => "#{copy_file_prefix}-postinstall",
28
+ :install_script => "#{copy_file_prefix}-install.sh",
29
+ }
22
30
 
23
31
  end
24
32
 
@@ -30,10 +38,21 @@ module NiseBOSHVagrant
30
38
  end
31
39
 
32
40
  def copy_manifest(output_dir=@release_path, manifest_file=@manifest_file)
33
- @manifest_copy_path = File.join(output_dir, @manifest_copy_name)
41
+ @manifest_copy_path = File.join(output_dir, @copy_name[:manifest])
34
42
  FileUtils.cp(manifest_file, @manifest_copy_path)
35
43
  end
36
44
 
45
+ def copy_hook_scripts(output_dir=@release_path, preinstall_file=@preinstall_file, postinstall_file=@postinstall_file)
46
+ if preinstall_file
47
+ @preinstall_copy_path = File.join(output_dir, @copy_name[:preinstall])
48
+ FileUtils.cp(preinstall_file, @preinstall_copy_path)
49
+ end
50
+ if postinstall_file
51
+ @postinstall_copy_path = File.join(output_dir, @copy_name[:postinstall])
52
+ FileUtils.cp(postinstall_file, @postinstall_copy_path)
53
+ end
54
+ end
55
+
37
56
  def generate_install_script(output_dir=@release_path, manifest_file=@manifest_copy_path)
38
57
  manifest = YAML.load_file manifest_file
39
58
  jobs = []
@@ -52,7 +71,7 @@ module NiseBOSHVagrant
52
71
 
53
72
 
54
73
  jobs.each do |job|
55
- manifest_path = "/home/vagrant/release/#{@manifest_copy_name}"
74
+ manifest_path = "/home/vagrant/release/#{@copy_name[:manifest]}"
56
75
  job_name = job
57
76
  install_entry = install_script_erb.result(binding)
58
77
  install_script += "#{install_entry}\n"
@@ -60,7 +79,7 @@ module NiseBOSHVagrant
60
79
 
61
80
  install_script += ")"
62
81
 
63
- @install_script_path = File.join(output_dir, @install_script_copy_name)
82
+ @install_script_path = File.join(output_dir, @copy_name[:install_script])
64
83
  File.open(@install_script_path, "wb") { |f| f.write(install_script) }
65
84
  FileUtils.chmod 0755, @install_script_path
66
85
  end
@@ -93,9 +112,19 @@ module NiseBOSHVagrant
93
112
  self.exec(install_cmd)
94
113
  end
95
114
 
115
+ def hook_preinstall_release(release_path=@release_path)
116
+ hook_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/preinstall_release\""
117
+ self.exec(hook_cmd)
118
+ end
119
+
120
+ def hook_postinstall_release(release_path=@release_path)
121
+ hook_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/postinstall_release\""
122
+ self.exec(hook_cmd)
123
+ end
124
+
96
125
  def start_release(release_path=@release_path)
97
126
  start_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/start.sh\""
98
127
  self.exec(start_cmd)
99
128
  end
100
129
  end
101
- end
130
+ end
@@ -1,3 +1,3 @@
1
1
  module NiseBOSHVagrant
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
@@ -9,7 +9,7 @@ Vagrant.configure("2") do |config|
9
9
  v.customize ["modifyvm", :id, "--memory", "<%= @memory %>"]
10
10
  end
11
11
 
12
- config.vm.network :private_network, ip: "192.168.10.10"
12
+ config.vm.network :private_network, ip: "<%= @ip_address %>"
13
13
 
14
14
  <% if not @nise_path.nil? %>config.vm.synced_folder "<%= @nise_path %>", "/home/vagrant/nise_bosh"<% end %>
15
15
  config.vm.synced_folder "<%= @release_path %>", "/home/vagrant/release"
@@ -1 +1 @@
1
- sudo PATH=$PATH bundle exec ./bin/nise-bosh --keep-monit-files -y /home/vagrant/release <%= manifest_path %> <%= job_name %>
1
+ sudo PATH=$PATH bundle exec ./bin/nise-bosh --keep-monit-files -y -n <%= @ip_address %> /home/vagrant/release <%= manifest_path %> <%= job_name %>
data/scripts/prepare.sh CHANGED
@@ -42,5 +42,14 @@ chmod +x /home/vagrant/start.sh
42
42
  cp /home/vagrant/scripts/stop.sh /home/vagrant/stop.sh
43
43
  chmod +x /home/vagrant/start.sh
44
44
 
45
+ # Copy hook scripts
46
+ for hook in preinstall postinstall; do
47
+ echo ${hook}
48
+ if [ -f /home/vagrant/release/.nise-bosh-${hook} ]; then
49
+ cp /home/vagrant/release/.nise-bosh-${hook} /home/vagrant/${hook}_release
50
+ chmod +x /home/vagrant/${hook}_release
51
+ fi
52
+ done
53
+
45
54
  # Copy manifest file
46
- cp /home/vagrant/release/.nise-bosh-manifest.yml /home/vagrant/manifest.yml
55
+ cp /home/vagrant/release/.nise-bosh-manifest.yml /home/vagrant/manifest.yml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nise-bosh-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-23 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
@@ -65,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  segments:
67
67
  - 0
68
- hash: -1866514652364241547
68
+ hash: 3139040099582416769
69
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements: