bosh-gen 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## v0.4
4
+
5
+ * `job` - added --ruby flag to include a ruby/rack-specifc ctl script
6
+ * releases include a rake task to document what properties are required
7
+ * `manifest` - has a --disk/-d flag to assign a persistent disk to all VMs (common pool)
8
+ * `job` - export some variables in ctl scripts so they are available to application
9
+ * `job` - ctl script has logs/tail/clearlogs commands
10
+
3
11
  ## v0.3
4
12
 
5
13
  Added:
@@ -48,10 +48,12 @@ module Bosh
48
48
 
49
49
  desc "job NAME", "Create a new job"
50
50
  method_option :dependencies, :aliases => ['-d'], :type => :array, :desc => "List of package dependencies"
51
+ method_option :ruby, :type => :boolean, :desc => "Use templates for running Ruby/Rack process"
51
52
  def job(name)
53
+ flags = { :ruby => options["ruby"] || false }
52
54
  dependencies = options[:dependencies] || []
53
55
  require 'bosh/gen/generators/job_generator'
54
- Bosh::Gen::Generators::JobGenerator.start([name, dependencies])
56
+ Bosh::Gen::Generators::JobGenerator.start([name, dependencies, flags])
55
57
  end
56
58
 
57
59
  desc "template JOB FILE_PATH", "Add a Job template (example FILE_PATH: config/httpd.conf)"
@@ -63,10 +65,11 @@ module Bosh
63
65
  desc "manifest NAME PATH UUID", "Creates a deployment manifest based on the release located at PATH"
64
66
  method_option :force, :type => :boolean, :desc => "Force override existing target manifest file"
65
67
  method_option :addresses, :aliases => ['-a'], :type => :array, :desc => "List of IP addresses available for jobs"
68
+ method_option :disk, :aliases => ['-d'], :type => :string, :desc => "Attach persistent disks to VMs of specific size, e.g. 8196"
66
69
  def manifest(name, release_path, uuid)
67
70
  release_path = File.expand_path(release_path)
68
71
  ip_addresses = options["addresses"] || []
69
- flags = { :force => options["force"] || false }
72
+ flags = { :force => options["force"] || false, :disk => options[:disk] }
70
73
  require 'bosh/gen/generators/deployment_manifest_generator'
71
74
  Bosh::Gen::Generators::DeploymentManifestGenerator.start([name, release_path, uuid, ip_addresses, flags])
72
75
  end
@@ -26,6 +26,7 @@ module Bosh::Gen
26
26
  # Create a deployment manifest (initially for AWS only)
27
27
  def create_deployment_manifest
28
28
  cloud_properties = { "instance_type" => "m1.small", "availability_zone" => "us-east-1e" }
29
+ cloud_properties[:persistent_disk] = flags[:disk] if flags[:disk]
29
30
  manifest = Bosh::Gen::Models::DeploymentManifest.new(name, director_uuid, release_properties, cloud_properties)
30
31
  manifest.jobs = job_manifests(ip_addresses)
31
32
  create_file manifest_file_name, manifest.to_yaml, :force => flags[:force]
@@ -8,6 +8,7 @@ module Bosh::Gen
8
8
 
9
9
  argument :job_name
10
10
  argument :dependencies, :type => :array
11
+ argument :flags, :type => :hash
11
12
 
12
13
  def self.source_root
13
14
  File.join(File.dirname(__FILE__), "job_generator", "templates")
@@ -33,7 +34,11 @@ module Bosh::Gen
33
34
  end
34
35
 
35
36
  def template_files
36
- directory "jobs/%job_name%"
37
+ if ruby?
38
+ directory "jobs/%job_name%_rubyrack", "jobs/#{job_name}"
39
+ else
40
+ directory "jobs/%job_name%"
41
+ end
37
42
  @template_files = { "#{job_name}_ctl" => "bin/#{job_name}_ctl" }
38
43
  end
39
44
 
@@ -59,6 +64,10 @@ module Bosh::Gen
59
64
  File.join("jobs", job_name, path)
60
65
  end
61
66
 
67
+ def ruby?
68
+ flags[:ruby]
69
+ end
70
+
62
71
  # Run a command in git.
63
72
  #
64
73
  # ==== Examples
@@ -1,15 +1,30 @@
1
1
  #!/bin/bash
2
2
 
3
- # Control script to start/stop <%= job_name %> job on a BOSH controlled VM
3
+ # Control script to start/stop ruby/rack <%= job_name %> job on a BOSH controlled VM
4
4
  #
5
+ # In local development, this script can be run manually. Examples below assume you are in the root of this release project.
6
+ #
7
+ # Start process example:
8
+ # APP_DIR=/path/to/<%= job_name %> RACK_ENV=development COMMAND=shotgun PORT=9393 jobs/<%= job_name %>/templates/<%= job_name %>_ctl start
9
+ #
10
+ # View STDOUT/STDERR logs:
11
+ # jobs/<%= job_name %>/templates/<%= job_name %>_ctl logs
12
+ #
13
+ # Clear logs:
14
+ # jobs/<%= job_name %>/templates/<%= job_name %>_ctl clearlogs
15
+
5
16
  # TODO - change "EXECUTABLE_SERVER" to the command to run
6
- # TODO - ensure executable stores PID in $PIDFILE
7
17
 
8
18
  RUN_DIR=/var/vcap/sys/run/<%= job_name %>
9
19
  LOG_DIR=/var/vcap/sys/log/<%= job_name %>
10
20
  STORE=/var/vcap/store/<%= job_name %>
11
21
  PIDFILE=$RUN_DIR/<%= job_name %>.pid
12
22
 
23
+ export PATH=/var/vcap/packages/ruby/bin:$PATH
24
+
25
+ COMMAND=${COMMAND:-/var/vcap/packages/<%= job_name %>/bin/EXECUTABLE_SERVER}
26
+ HOME=${HOME:-/home/vcap}
27
+
13
28
  case $1 in
14
29
 
15
30
  start)
@@ -19,7 +34,7 @@ case $1 in
19
34
 
20
35
  echo $$ > $PIDFILE
21
36
 
22
- exec /var/vcap/packages/<%= job_name %>/bin/EXECUTABLE_SERVER >>$LOG_DIR/<%= job_name %>.stdout.log 2>>$LOG_DIR/<%= job_name %>.stderr.log
37
+ exec $COMMAND >>$LOG_DIR/<%= job_name %>.stdout.log 2>>$LOG_DIR/<%= job_name %>.stderr.log
23
38
  ;;
24
39
 
25
40
  stop)
@@ -29,7 +44,19 @@ case $1 in
29
44
  rm -f $PIDFILE
30
45
  ;;
31
46
 
47
+ logs)
48
+ cat $LOG_DIR/*
49
+ ;;
50
+
51
+ tail)
52
+ tail -f $LOG_DIR/*
53
+ ;;
54
+
55
+ clearlogs)
56
+ rm $LOG_DIR/*
57
+ ;;
58
+
32
59
  *)
33
- echo "Usage: <%= job_name %>_ctl {start|stop}" ;;
60
+ echo "Usage: <%= job_name %>_ctl {start|stop|logs|tail|clearlogs}" ;;
34
61
  esac
35
62
  exit 0
@@ -0,0 +1,5 @@
1
+ check process <%= job_name %>
2
+ with pidfile /var/vcap/sys/run/<%= job_name %>/<%= job_name %>.pid
3
+ start program "/var/vcap/jobs/<%= job_name %>/bin/<%= job_name %>_ctl start"
4
+ stop program "/var/vcap/jobs/<%= job_name %>/bin/<%= job_name %>_ctl stop"
5
+ group vcap
@@ -0,0 +1,64 @@
1
+ #!/bin/bash
2
+
3
+ # Control script to start/stop ruby/rack <%= job_name %> job on a BOSH controlled VM
4
+ #
5
+ # In local development, this script can be run manually. Examples below assume you are in the root of this release project.
6
+ #
7
+ # Start process example:
8
+ # APP_DIR=/path/to/<%= job_name %> RACK_ENV=development COMMAND=shotgun PORT=9393 jobs/<%= job_name %>/templates/<%= job_name %>_ctl start
9
+ #
10
+ # View STDOUT/STDERR logs:
11
+ # jobs/<%= job_name %>/templates/<%= job_name %>_ctl logs
12
+ #
13
+ # Clear logs:
14
+ # jobs/<%= job_name %>/templates/<%= job_name %>_ctl clearlogs
15
+
16
+ RUN_DIR=/var/vcap/sys/run/<%= job_name %>
17
+ LOG_DIR=/var/vcap/sys/log/<%= job_name %>
18
+ STORE=/var/vcap/store/<%= job_name %>
19
+ PIDFILE=$RUN_DIR/<%= job_name %>.pid
20
+
21
+ export PATH=/var/vcap/packages/ruby/bin:$PATH
22
+
23
+ COMMAND=${COMMAND:-/var/vcap/packages/ruby/bin/bundle exec rackup}
24
+ APP_DIR=${APP_DIR:-/var/vcap/packages/<%= job_name %>/}
25
+ PORT=${PORT:-5000}
26
+ RACK_ENV=${RACK_ENV:-production}
27
+ HOME=${HOME:-/home/vcap}
28
+
29
+ case $1 in
30
+
31
+ start)
32
+ mkdir -p $RUN_DIR
33
+ mkdir -p $LOG_DIR
34
+ mkdir -p $STORE
35
+
36
+ echo $$ > $PIDFILE
37
+
38
+ cd $APP_DIR
39
+ exec ${COMMAND} -p $PORT -E $RACK_ENV >>$LOG_DIR/<%= job_name %>.stdout.log 2>>$LOG_DIR/<%= job_name %>.stderr.log
40
+ ;;
41
+
42
+ stop)
43
+ PID=$(head -1 $PIDFILE)
44
+ kill $PID
45
+ while [ -e /proc/$PID ]; do sleep 0.1; done
46
+ rm -f $PIDFILE
47
+ ;;
48
+
49
+ logs)
50
+ cat $LOG_DIR/*
51
+ ;;
52
+
53
+ tail)
54
+ tail -f $LOG_DIR/*
55
+ ;;
56
+
57
+ clearlogs)
58
+ rm $LOG_DIR/*
59
+ ;;
60
+
61
+ *)
62
+ echo "Usage: <%= job_name %>_ctl {start|stop|logs|tail|clearlogs}" ;;
63
+ esac
64
+ exit 0
@@ -23,6 +23,10 @@ module Bosh::Gen
23
23
  template "README.md.tt", "README.md"
24
24
  end
25
25
 
26
+ def rakefile
27
+ copy_file "Rakefile"
28
+ end
29
+
26
30
  def directories
27
31
  %w[jobs packages src blobs].each do |dir|
28
32
  directory dir
@@ -0,0 +1,15 @@
1
+ desc "Generates a properties file for each job based on properties.X.Y used in templates"
2
+ task :job_properties do
3
+ require "fileutils"
4
+ Dir["jobs/*"].each do |path|
5
+ puts "Searching job #{File.basename(path)}..."
6
+ FileUtils.chdir(path) do
7
+ properties = []
8
+ Dir["templates/*.erb"].each do |template_path|
9
+ properties |= File.read(template_path).scan(/\bproperties\.[\w\.]*\b/)
10
+ puts properties.join("\n")
11
+ File.open("properties", "w") { |file| file << properties.join("\n") }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -10,6 +10,8 @@ module Bosh::Gen::Models
10
10
  @security_groups = ["default"]
11
11
  @stemcell_version = "0.5.1"
12
12
  @stemcell = { "name" => "bosh-stemcell", "version" => @stemcell_version }
13
+ @persistent_disk = cloud_properties.delete(:persistent_disk)
14
+
13
15
  manifest["name"] = name
14
16
  manifest["director_uuid"] = director_uuid
15
17
  manifest["release"] = release_properties.dup
@@ -46,6 +48,7 @@ module Bosh::Gen::Models
46
48
  "cloud_properties" => cloud_properties.dup
47
49
  }
48
50
  ]
51
+ manifest["resource_pools"].first["persistent_disk"] = @persistent_disk if @persistent_disk
49
52
  manifest["jobs"] = []
50
53
  manifest["properties"] = {}
51
54
  end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Gen
3
- VERSION = "0.3.4"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
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: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -132,9 +132,13 @@ files:
132
132
  - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%/TODO.md.tt
133
133
  - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%/monit.tt
134
134
  - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%/templates/%job_name%_ctl.tt
135
+ - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_rubyrack/TODO.md.tt
136
+ - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_rubyrack/monit.tt
137
+ - lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_rubyrack/templates/%job_name%_ctl.tt
135
138
  - lib/bosh/gen/generators/job_template_generator.rb
136
139
  - lib/bosh/gen/generators/new_release_generator.rb
137
140
  - lib/bosh/gen/generators/new_release_generator/templates/README.md.tt
141
+ - lib/bosh/gen/generators/new_release_generator/templates/Rakefile
138
142
  - lib/bosh/gen/generators/new_release_generator/templates/blobs/.gitkeep
139
143
  - lib/bosh/gen/generators/new_release_generator/templates/jobs/.gitkeep
140
144
  - lib/bosh/gen/generators/new_release_generator/templates/packages/.gitkeep
@@ -168,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
172
  version: '0'
169
173
  segments:
170
174
  - 0
171
- hash: 983046583635840744
175
+ hash: -3504528361068900288
172
176
  required_rubygems_version: !ruby/object:Gem::Requirement
173
177
  none: false
174
178
  requirements:
@@ -177,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
181
  version: '0'
178
182
  segments:
179
183
  - 0
180
- hash: 983046583635840744
184
+ hash: -3504528361068900288
181
185
  requirements: []
182
186
  rubyforge_project:
183
187
  rubygems_version: 1.8.23