bosh-gen 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,8 +19,17 @@ Or install it yourself as:
19
19
  ## Usage
20
20
 
21
21
  ```
22
- $ bosh-gen new my-new-project
22
+ $ bosh-gen new my-new-project --s3
23
+ $ bosh-gen new my-new-project --atmos
24
+ $ bosh-gen new my-new-project # local blobstore with a warning
25
+
23
26
  $ cd my-new-project
27
+ $ bosh create release
28
+ ```
29
+
30
+ TODO:
31
+
32
+ ```
24
33
  $ bosh-gen job somejob
25
34
  $ bosh-gen package somepackage -u somejob
26
35
  $ bosh-gen package anotherpackage
data/bin/bosh-gen CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.push File.dirname(__FILE__) + '/../lib'
3
3
 
4
- require 'rubygems'
5
- require 'bosh/gen/cli'
4
+ require "rubygems"
5
+ require "bosh/gen/cli"
6
6
 
7
7
  Bosh::Gen::Command.start
data/bosh-gen.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Bosh::Gen::VERSION
17
17
 
18
18
  gem.add_dependency "thor"
19
+ gem.add_dependency "bosh_cli"
19
20
 
20
21
  gem.add_development_dependency "rake"
21
22
  end
data/lib/bosh/gen/cli.rb CHANGED
@@ -1,18 +1,44 @@
1
- require 'thor'
1
+ require "thor"
2
+
3
+ # bosh_cli libraries
4
+ module Bosh; end
5
+ require "cli/config"
6
+ require "cli/core_ext"
7
+
2
8
 
3
9
  module Bosh
4
10
  module Gen
5
11
  class Command < Thor
6
12
  include Thor::Actions
7
13
 
8
- desc "new NAME", "Creates a new BOSH release"
14
+ desc "new PATH", "Creates a new BOSH release"
9
15
  method_option :s3, :alias => ["--aws"], :type => :boolean, :desc => "Use AWS S3 bucket for blobstore"
10
16
  method_option :atmos, :type => :boolean, :desc => "Use EMC ATMOS for blobstore"
11
- def new(name)
17
+ def new(path)
12
18
  flags = { :aws => options["s3"], :atmos => options["atmos"] }
13
19
 
14
20
  require 'bosh/gen/generators/new_release_generator'
15
- Bosh::Gen::Generators::NewReleaseGenerator.start([name, flags])
21
+ Bosh::Gen::Generators::NewReleaseGenerator.start([path, flags])
22
+ end
23
+
24
+ desc "package NAME", "Create a new package"
25
+ method_option :dependencies, :aliases => ['-d'], :type => :array, :desc => "List of package dependencies"
26
+ method_option :files, :aliases => ['-f', '--src'], :type => :array, :desc => "List of file paths to include"
27
+ def package(name)
28
+ dependencies = options[:dependencies] || []
29
+ files = options[:files] || []
30
+ require 'bosh/gen/generators/package_generator'
31
+ Bosh::Gen::Generators::PackageGenerator.start([name, dependencies, files])
32
+ end
33
+
34
+ desc "job NAME", "Create a new job"
35
+ method_option :dependencies, :aliases => ['-d'], :type => :array, :desc => "List of package dependencies"
36
+ method_option :templates, :aliases => ['-t'], :type => :array, :desc => "List of templates to use"
37
+ def job(name)
38
+ dependencies = options[:dependencies] || []
39
+ template_files = options[:template_files] || []
40
+ require 'bosh/gen/generators/job_generator'
41
+ Bosh::Gen::Generators::JobGenerator.start([name, dependencies, template_files])
16
42
  end
17
43
 
18
44
  no_tasks do
@@ -0,0 +1,77 @@
1
+ require 'yaml'
2
+ require 'thor/group'
3
+
4
+ module Bosh::Gen
5
+ module Generators
6
+ class JobGenerator < Thor::Group
7
+ include Thor::Actions
8
+
9
+ argument :name
10
+ argument :dependencies, :type => :array
11
+ argument :template_files, :type => :array
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), "job_generator", "templates")
15
+ end
16
+
17
+ def check_root_is_release
18
+ unless File.exist?("jobs") && File.exist?("packages")
19
+ raise Thor::Error.new("run inside a BOSH release project")
20
+ end
21
+ end
22
+
23
+ def check_name
24
+ raise Thor::Error.new("'#{name}' is not a vaild BOSH id") unless name.bosh_valid_id?
25
+ end
26
+
27
+ def warn_missing_dependencies
28
+ dependencies.each do |d|
29
+ raise Thor::Error.new("dependency '#{d}' is not a vaild BOSH id") unless d.bosh_valid_id?
30
+ unless File.exist?(File.join("packages", d))
31
+ say_status "warning", "missing dependency '#{d}'", :yellow
32
+ end
33
+ end
34
+ end
35
+
36
+ def templates
37
+ empty_directory job_dir("template")
38
+ end
39
+
40
+ def monit
41
+ create_file job_dir("monit"), ""
42
+ end
43
+
44
+ def job_specification
45
+ config = { "name" => name, "packages" => dependencies, "templates" => template_files }
46
+ create_file job_dir("spec"), YAML.dump(config)
47
+ end
48
+
49
+ private
50
+ def filenames
51
+ files.map {|f| File.basename(f) }
52
+ end
53
+
54
+ def job_dir(path)
55
+ File.join("jobs", name, path)
56
+ end
57
+
58
+ # Run a command in git.
59
+ #
60
+ # ==== Examples
61
+ #
62
+ # git :init
63
+ # git :add => "this.file that.rb"
64
+ # git :add => "onefile.rb", :rm => "badfile.cxx"
65
+ #
66
+ def git(commands={})
67
+ if commands.is_a?(Symbol)
68
+ run "git #{commands}"
69
+ else
70
+ commands.each do |cmd, options|
71
+ run "git #{cmd} #{options}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,94 @@
1
+ require 'yaml'
2
+ require 'thor/group'
3
+
4
+ module Bosh::Gen
5
+ module Generators
6
+ class PackageGenerator < Thor::Group
7
+ include Thor::Actions
8
+
9
+ argument :name
10
+ argument :dependencies, :type => :array
11
+ argument :files, :type => :array
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), "package_generator", "templates")
15
+ end
16
+
17
+ def check_root_is_release
18
+ unless File.exist?("jobs") && File.exist?("packages")
19
+ raise Thor::Error.new("run inside a BOSH release project")
20
+ end
21
+ end
22
+
23
+ def check_name
24
+ raise Thor::Error.new("'#{name}' is not a vaild BOSH id") unless name.bosh_valid_id?
25
+ end
26
+
27
+ def warn_missing_dependencies
28
+ dependencies.each do |d|
29
+ raise Thor::Error.new("dependency '#{d}' is not a vaild BOSH id") unless d.bosh_valid_id?
30
+ unless File.exist?(File.join("packages", d))
31
+ say_status "warning", "missing dependency '#{d}'", :yellow
32
+ end
33
+ end
34
+ end
35
+
36
+ def packaging
37
+ create_file package_dir("packaging") do
38
+ <<-SHELL.gsub(/^\s{10}/, '')
39
+ # abort script on any command that exit with a non zero value
40
+ set -e
41
+
42
+ SHELL
43
+ end
44
+
45
+ create_file package_dir("pre_packaging") do
46
+ <<-SHELL.gsub(/^\s{10}/, '')
47
+ # abort script on any command that exit with a non zero value
48
+ set -e
49
+
50
+ SHELL
51
+ end
52
+ end
53
+
54
+ def copy_src_files
55
+ files.each do |f|
56
+ copy_file File.expand_path(f), src_dir(File.basename(f))
57
+ end
58
+ end
59
+
60
+ def package_specification
61
+ src_files = files.map {|f| "src/#{name}/#{File.basename(f)}"}
62
+ config = { "name" => name, "dependencies" => dependencies, "files" => src_files }
63
+ create_file package_dir("spec"), YAML.dump(config)
64
+ end
65
+
66
+ private
67
+ def package_dir(path)
68
+ "packages/#{name}/#{path}"
69
+ end
70
+
71
+ def src_dir(path)
72
+ "src/#{name}/#{path}"
73
+ end
74
+
75
+ # Run a command in git.
76
+ #
77
+ # ==== Examples
78
+ #
79
+ # git :init
80
+ # git :add => "this.file that.rb"
81
+ # git :add => "onefile.rb", :rm => "badfile.cxx"
82
+ #
83
+ def git(commands={})
84
+ if commands.is_a?(Symbol)
85
+ run "git #{commands}"
86
+ else
87
+ commands.each do |cmd, options|
88
+ run "git #{cmd} #{options}"
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Gen
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70146989259840 !ruby/object:Gem::Requirement
16
+ requirement: &70178189586820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70146989259840
24
+ version_requirements: *70178189586820
25
+ - !ruby/object:Gem::Dependency
26
+ name: bosh_cli
27
+ requirement: &70178189585400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70178189585400
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rake
27
- requirement: &70146989259200 !ruby/object:Gem::Requirement
38
+ requirement: &70178189089040 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70146989259200
46
+ version_requirements: *70178189089040
36
47
  description: Generators for creating BOSH releases
37
48
  email:
38
49
  - drnicwilliams@gmail.com
@@ -50,11 +61,21 @@ files:
50
61
  - bosh-gen.gemspec
51
62
  - lib/bosh/gen.rb
52
63
  - lib/bosh/gen/cli.rb
64
+ - lib/bosh/gen/generators/job_generator.rb
65
+ - lib/bosh/gen/generators/job_generator/templates/blobs/.gitkeep
66
+ - lib/bosh/gen/generators/job_generator/templates/jobs/.gitkeep
67
+ - lib/bosh/gen/generators/job_generator/templates/packages/.gitkeep
68
+ - lib/bosh/gen/generators/job_generator/templates/src/.gitkeep
53
69
  - lib/bosh/gen/generators/new_release_generator.rb
54
70
  - lib/bosh/gen/generators/new_release_generator/templates/blobs/.gitkeep
55
71
  - lib/bosh/gen/generators/new_release_generator/templates/jobs/.gitkeep
56
72
  - lib/bosh/gen/generators/new_release_generator/templates/packages/.gitkeep
57
73
  - lib/bosh/gen/generators/new_release_generator/templates/src/.gitkeep
74
+ - lib/bosh/gen/generators/package_generator.rb
75
+ - lib/bosh/gen/generators/package_generator/templates/blobs/.gitkeep
76
+ - lib/bosh/gen/generators/package_generator/templates/jobs/.gitkeep
77
+ - lib/bosh/gen/generators/package_generator/templates/packages/.gitkeep
78
+ - lib/bosh/gen/generators/package_generator/templates/src/.gitkeep
58
79
  - lib/bosh/gen/version.rb
59
80
  homepage: https://github.com/drnic/bosh-gen
60
81
  licenses: []
@@ -70,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
91
  version: '0'
71
92
  segments:
72
93
  - 0
73
- hash: 487201214193427891
94
+ hash: 4165498384782219336
74
95
  required_rubygems_version: !ruby/object:Gem::Requirement
75
96
  none: false
76
97
  requirements:
@@ -79,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
100
  version: '0'
80
101
  segments:
81
102
  - 0
82
- hash: 487201214193427891
103
+ hash: 4165498384782219336
83
104
  requirements: []
84
105
  rubyforge_project:
85
106
  rubygems_version: 1.8.17