engineyard-recipes 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/ChangeLog.md +7 -0
  2. data/bin/ey-recipes +2 -0
  3. data/engineyard-recipes.gemspec +1 -0
  4. data/features/clone-recipe.feature +5 -5
  5. data/features/generate-helper-definitions.feature +5 -4
  6. data/features/generate-recipe-gem.feature +41 -0
  7. data/features/init-new-cookbook.feature +31 -0
  8. data/features/install-package.feature +11 -10
  9. data/features/step_definitions/fixture_project_steps.rb +1 -0
  10. data/lib/engineyard-recipes/cli.rb +24 -14
  11. data/lib/engineyard-recipes/generators/base_generator.rb +4 -4
  12. data/lib/engineyard-recipes/generators/definition_generator.rb +2 -3
  13. data/lib/engineyard-recipes/generators/gem_generator.rb +41 -0
  14. data/lib/engineyard-recipes/generators/gem_generator/templates/gem/%repo_name%.gemspec.tt +22 -0
  15. data/lib/engineyard-recipes/generators/gem_generator/templates/gem/.gitignore +3 -0
  16. data/lib/engineyard-recipes/generators/{init_generator/templates/cookbooks/main/recipes/default.rb → gem_generator/templates/gem/ChangeLog.md} +0 -0
  17. data/lib/engineyard-recipes/generators/gem_generator/templates/gem/Gemfile +3 -0
  18. data/lib/engineyard-recipes/generators/gem_generator/templates/gem/README.md.tt +19 -0
  19. data/lib/engineyard-recipes/generators/gem_generator/templates/gem/Rakefile +2 -0
  20. data/lib/engineyard-recipes/generators/gem_generator/templates/metadata/metadata.json.tt +13 -0
  21. data/lib/engineyard-recipes/generators/gem_generator/templates/metadata/metadata.rb.tt +7 -0
  22. data/lib/engineyard-recipes/generators/gem_generator/templates/recipe/%recipe_name%/recipes/default.rb.tt +5 -0
  23. data/lib/engineyard-recipes/generators/init_bundled_chef_generator.rb +44 -0
  24. data/lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/cookbooks/main/recipes/default.rb +0 -0
  25. data/lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/deploy/before_migrate.rb +11 -0
  26. data/lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/deploy/solo.rb +25 -0
  27. data/lib/engineyard-recipes/generators/{init_generator.rb → init_resin_chef_generator.rb} +12 -4
  28. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/cookbooks/main/attributes/recipe.rb +0 -0
  29. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/cookbooks/main/definitions/ey_cloud_report.rb +0 -0
  30. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/cookbooks/main/libraries/ruby_block.rb +0 -0
  31. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/cookbooks/main/libraries/run_for_app.rb +0 -0
  32. data/lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/recipes/default.rb +0 -0
  33. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/deploy/before_migrate.rb +0 -0
  34. data/lib/engineyard-recipes/generators/{init_generator → init_resin_chef_generator}/templates/deploy/solo.rb +0 -0
  35. data/lib/engineyard-recipes/generators/local_recipe_clone_generator.rb +7 -6
  36. data/lib/engineyard-recipes/generators/package_generator.rb +11 -7
  37. data/lib/engineyard-recipes/generators/templates/cookbooks/main/attributes/recipe.rb +3 -0
  38. data/lib/engineyard-recipes/generators/templates/cookbooks/main/definitions/ey_cloud_report.rb +6 -0
  39. data/lib/engineyard-recipes/generators/templates/cookbooks/main/libraries/ruby_block.rb +40 -0
  40. data/lib/engineyard-recipes/generators/templates/cookbooks/main/libraries/run_for_app.rb +12 -0
  41. data/lib/engineyard-recipes/generators/templates/cookbooks/main/recipes/default.rb +0 -0
  42. data/lib/engineyard-recipes/generators/templates/deploy/before_migrate.rb +2 -0
  43. data/lib/engineyard-recipes/generators/templates/deploy/solo.rb +7 -0
  44. data/lib/engineyard-recipes/version.rb +1 -1
  45. metadata +58 -25
  46. data/lib/engineyard-recipes/generators/local_recipe_clone_generator/templates/cookbooks/%recipe_name%/definitions/%definition_name%.rb.tt +0 -3
@@ -1,5 +1,12 @@
1
1
  # ChangeLog
2
2
 
3
+ ## v0.5
4
+
5
+ * `init --on-deploy --chef` - gives you modern chef, and allows recipes-in-rubygems
6
+ * `gem` - create new recipes that are ready to be packaged as rubygems
7
+ * `gem --helper` - create project of libraries/definitions; no recipes
8
+ * Removed `--local` - recipe generators detect `.../cookbooks/` missing and assume it is a gem-recipe
9
+
3
10
  ## v0.4
4
11
 
5
12
  * `package` - renamed from `recipe`; bug fixes
@@ -6,6 +6,8 @@ require 'engineyard-recipes/cli'
6
6
 
7
7
  begin
8
8
  Engineyard::Recipes::CLI.start
9
+ rescue Engineyard::Recipes::Generators::CookbooksNotFound => e
10
+ error "Cannot discover cookbooks folder"
9
11
  rescue Interrupt => e
10
12
  puts
11
13
  puts "Quitting..."
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency("thor", ["~> 0.14.6"])
22
22
  s.add_dependency("engineyard", ["~> 1.4.6"])
23
+ s.add_dependency("activesupport", ["~> 3.0"])
23
24
 
24
25
  s.add_development_dependency("rake", ["~> 0.9.2"])
25
26
  s.add_development_dependency("cucumber", ["~> 1.1.2"])
@@ -35,15 +35,15 @@ Feature: Clone recipe from git repositories
35
35
  """
36
36
 
37
37
  Scenario: Clone a single recipe from a local folder into local folder instead of in cookbooks/
38
+ Given I am in the "rails" project folder
38
39
  Given I am have a local recipe "blank" at "/tmp/ey-recipes/blank"
39
- When I run local executable "ey-recipes" with arguments "clone /tmp/ey-recipes/blank --local"
40
- Then file "blank/README.rdoc" is created
41
- And file "blank/README.rdoc" contains "This is a local recipe"
40
+ When I run local executable "ey-recipes" with arguments "clone /tmp/ey-recipes/blank"
41
+ And file "README.rdoc" contains "This is a local recipe"
42
42
  And I should see exactly
43
43
  """
44
44
  exist
45
- create blank/README.rdoc
46
- create blank/recipes/default.rb
45
+ create README.rdoc
46
+ create recipes/default.rb
47
47
  """
48
48
 
49
49
  Scenario: Clone URI is an unknown local path
@@ -26,12 +26,13 @@ Feature: Generate helper definitions recipe
26
26
  """
27
27
 
28
28
  Scenario: Generate a new recipe into local folder instead of in cookbooks/
29
- When I run local executable "ey-recipes" with arguments "definition mylibrary helper1 --local"
30
- And file "mylibrary/definitions/helper1.rb" is created
31
- And file "mylibrary/definitions/helper1.rb" contains "define :helper1 do"
29
+ Given I am in the "rails" project folder
30
+ When I run local executable "ey-recipes" with arguments "definition mylibrary helper1"
31
+ And file "definitions/helper1.rb" is created
32
+ And file "definitions/helper1.rb" contains "define :helper1 do"
32
33
  And I should see exactly
33
34
  """
34
35
  exist
35
- create mylibrary/definitions/helper1.rb
36
+ create definitions/helper1.rb
36
37
  """
37
38
 
@@ -0,0 +1,41 @@
1
+ Feature: Generate recipe gem
2
+ I want to create a new recipe
3
+ And distribute it as a gem
4
+
5
+ Scenario: Generate a new recipe
6
+ When I run local executable "ey-recipes" with arguments "gem new_thing"
7
+ And I should see exactly
8
+ """
9
+ create eycloud-recipe-new_thing
10
+ create eycloud-recipe-new_thing/eycloud-recipe-new_thing.gemspec
11
+ create eycloud-recipe-new_thing/.gitignore
12
+ create eycloud-recipe-new_thing/ChangeLog.md
13
+ create eycloud-recipe-new_thing/Gemfile
14
+ create eycloud-recipe-new_thing/README.md
15
+ create eycloud-recipe-new_thing/Rakefile
16
+ exist eycloud-recipe-new_thing
17
+ create eycloud-recipe-new_thing/metadata.json
18
+ create eycloud-recipe-new_thing/metadata.rb
19
+ exist eycloud-recipe-new_thing
20
+ create eycloud-recipe-new_thing/new_thing/recipes/default.rb
21
+ """
22
+
23
+ Scenario: Generate a new helper gem (no recipes)
24
+ When I run local executable "ey-recipes" with arguments "gem new_thing --helper"
25
+ And I should see exactly
26
+ """
27
+ create eycloud-helper-new_thing
28
+ create eycloud-helper-new_thing/eycloud-helper-new_thing.gemspec
29
+ create eycloud-helper-new_thing/.gitignore
30
+ create eycloud-helper-new_thing/ChangeLog.md
31
+ create eycloud-helper-new_thing/Gemfile
32
+ create eycloud-helper-new_thing/README.md
33
+ create eycloud-helper-new_thing/Rakefile
34
+ exist eycloud-helper-new_thing
35
+ create eycloud-helper-new_thing/metadata.json
36
+ create eycloud-helper-new_thing/metadata.rb
37
+ """
38
+
39
+
40
+
41
+
@@ -32,3 +32,34 @@ Feature: Generate a new custom cookbook for your EY Cloud environments
32
32
  create deploy/cookbooks/main/libraries/run_for_app.rb
33
33
  create deploy/cookbooks/main/recipes/default.rb
34
34
  """
35
+
36
+ # TODO - make --on-deploy the default
37
+ # TODO - include emerge definitions
38
+ Scenario: Cookbooks use modern chef
39
+ Given I am in the "rails" project folder
40
+ When I run local executable "ey-recipes" with arguments "init --chef -d"
41
+ Then file "deploy/before_migrate.rb" contains
42
+ """
43
+ # Set up a chef 0.10 dna.json file (for stack-v1 + stack-v2)
44
+ # TODO does this run on non-app-master/solo?
45
+ custom_json = node.dup
46
+ custom_json['run_list'] = 'recipe[main]'
47
+ File.open("/etc/chef-custom/dna.json", 'w') do |f|
48
+ f.puts JSON.pretty_generate(custom_json)
49
+ f.chmod(0600)
50
+ end
51
+
52
+ # Runs application cookbooks
53
+ run "cd #{latest_release}; sudo bundle exec chef-solo -c #{latest_release}/deploy/solo.rb -j /etc/chef-custom/dna.json"
54
+
55
+ """
56
+ And I should see exactly
57
+ """
58
+ create deploy
59
+ create deploy/before_migrate.rb
60
+ create deploy/solo.rb
61
+ create deploy/cookbooks
62
+ create deploy/cookbooks/main/recipes/default.rb
63
+ append Gemfile
64
+ """
65
+
@@ -85,18 +85,19 @@ Feature: Install a gentoo package
85
85
 
86
86
  """
87
87
 
88
- Scenario: Generate a new recipe into local folder instead of in cookbooks/
89
- When I run local executable "ey-recipes" with arguments "package component --local"
90
- And file "component/recipes/default.rb" is created
91
- And file "component/recipes/default.rb" contains "require_recipe 'component::install'"
92
- And file "component/recipes/install.rb" is created
93
- And file "component/attributes/recipe.rb" is created
94
- And file "component/attributes/recipe.rb" contains "# component_version('1.0.0')"
88
+ Scenario: Generate a new recipe into local folder if no deploy/cookbooks/ or cookbooks/ folder
89
+ Given I am in the "rails" project folder
90
+ When I run local executable "ey-recipes" with arguments "package component"
91
+ And file "recipes/default.rb" is created
92
+ And file "recipes/default.rb" contains "require_recipe 'component::install'"
93
+ And file "recipes/install.rb" is created
94
+ And file "attributes/recipe.rb" is created
95
+ And file "attributes/recipe.rb" contains "# component_version('1.0.0')"
95
96
  And I should see exactly
96
97
  """
97
98
  exist
98
- create component/attributes/recipe.rb
99
- create component/recipes/default.rb
100
- create component/recipes/install.rb
99
+ create attributes/recipe.rb
100
+ create recipes/default.rb
101
+ create recipes/install.rb
101
102
  """
102
103
 
@@ -1,6 +1,7 @@
1
1
  Given /^I am in the "([^\"]*)" project folder$/ do |project|
2
2
  project_folder = File.expand_path(File.join(@fixtures_path, "projects", project))
3
3
  in_tmp_folder do
4
+ FileUtils.rm_rf(project)
4
5
  FileUtils.cp_r(project_folder, project)
5
6
  setup_active_project_folder(project)
6
7
  end
@@ -9,12 +9,19 @@ module Engineyard
9
9
 
10
10
  desc "init", "Creates cookbooks scaffolding for your recipes"
11
11
  method_option :"on-deploy", :aliases => ['-d'], :type => :boolean, :desc => "Run recipes during deployment"
12
+ method_option :chef, :type => :boolean, :desc => "Use bundled chef instead of Engine Yard chef version"
12
13
  method_option :sm, :type => :boolean, :desc => "Also install SM framework support"
13
14
  def init
14
- on_deploy = options["on-deploy"] || false
15
+ on_deploy = options["on-deploy"] || false
16
+ bundled_chef = options["chef"] || false
15
17
 
16
- require 'engineyard-recipes/generators/init_generator'
17
- Engineyard::Recipes::Generators::InitGenerator.start([on_deploy])
18
+ if bundled_chef
19
+ require 'engineyard-recipes/generators/init_bundled_chef_generator'
20
+ Engineyard::Recipes::Generators::InitGenerator.start([{:on_deploy => on_deploy}])
21
+ else
22
+ require 'engineyard-recipes/generators/init_resin_chef_generator'
23
+ Engineyard::Recipes::Generators::InitGenerator.start([{:on_deploy => on_deploy}])
24
+ end
18
25
  init_sm if options[:sm]
19
26
  end
20
27
 
@@ -28,26 +35,32 @@ module Engineyard
28
35
  method_option :package, :aliases => ['-p'], :desc => "Gentoo package name, e.g. dev-util/gitosis-gentoo"
29
36
  method_option :version, :aliases => ['-v'], :desc => "Gentoo package version, e.g. 0.2_p20081028"
30
37
  method_options %w( unmasked -u ) => :boolean, :desc => "Unmask the required gentoo package"
31
- method_option :local, :aliases => ['-l'], :type => :boolean, :desc => "Generate into local folder, instead of cookbooks/RECIPE_NAME"
32
38
  def package(recipe_name)
33
39
  package = options["package"] || "UNKNOWN/#{recipe_name}"
34
40
  version = options["version"] || '1.0.0'
35
41
  unmasked = options["unmasked"] || false
36
- local = options["local"] || false
37
42
 
38
43
  require 'engineyard-recipes/generators/package_generator'
39
44
  Engineyard::Recipes::Generators::PackageGenerator.start([
40
- recipe_name, package, version, {:unmasked => unmasked, :local => local}
45
+ recipe_name, package, version, {:unmasked => unmasked}
41
46
  ])
42
47
  end
43
48
 
49
+ desc "gem NAME", "Name of the recipe"
50
+ method_option :repo, :aliases => ['-r'], :desc => "Name of the repository. Default: eycloud-recipes-NAME"
51
+ method_option :helper, :type => :boolean, :desc => "Only helpers/definitions, no recipes included."
52
+ def gem(recipe_name)
53
+ recipe_type ||= options["helper"] ? "helper" : "recipe"
54
+ repo_name ||= options["repo"] || "eycloud-#{recipe_type}-#{recipe_name}"
55
+
56
+ require 'engineyard-recipes/generators/gem_generator'
57
+ Engineyard::Recipes::Generators::GemGenerator.start([recipe_name, repo_name, recipe_type])
58
+ end
59
+
44
60
  desc "definition RECIPE DEFINITION", "Generate recipe for a package"
45
- method_option :local, :aliases => ['-l'], :type => :boolean, :desc => "Generate into local folder, instead of cookbooks/RECIPE_NAME"
46
61
  def definition(recipe_name, definition_name)
47
- local = options["local"] || false
48
-
49
62
  require 'engineyard-recipes/generators/definition_generator'
50
- Engineyard::Recipes::Generators::DefinitionGenerator.start([recipe_name, definition_name, {:local => local}])
63
+ Engineyard::Recipes::Generators::DefinitionGenerator.start([recipe_name, definition_name])
51
64
  end
52
65
 
53
66
  desc "timezone TIMEZONE", "Generate recipe to set the timezone"
@@ -60,14 +73,11 @@ module Engineyard
60
73
 
61
74
  desc "clone URI", "Clone a recipe into cookbook. URI can be git or local path."
62
75
  method_option :name, :aliases => ['-n'], :desc => "Specify name of recipe. Defaults to base name."
63
- method_option :local, :aliases => ['-l'], :type => :boolean, :desc => "Generate into local folder, instead of cookbooks/RECIPE_NAME"
64
76
  def clone(folder_path) # TODO support git URIs
65
- local = options["local"] || false
66
-
67
77
  require 'engineyard-recipes/generators/local_recipe_clone_generator'
68
78
  generator = Engineyard::Recipes::Generators::LocalRecipeCloneGenerator
69
79
  _, recipe_name = FetchUri.fetch_recipe(folder_path, generator.source_root, options["name"])
70
- generator.start([recipe_name, {:local => local}])
80
+ generator.start([recipe_name])
71
81
 
72
82
  rescue Engineyard::Recipes::FetchUri::UnknownPath => e
73
83
  error "No recipe found at #{e.message}"
@@ -2,20 +2,20 @@ require 'thor/group'
2
2
 
3
3
  module Engineyard::Recipes
4
4
  module Generators
5
+ class CookbooksNotFound < StandardError; end
6
+
5
7
  class BaseGenerator < Thor::Group
6
8
  include Thor::Actions
7
9
 
10
+
8
11
  protected
9
12
  def cookbooks_destination
10
13
  @cookbooks_destination ||= begin
11
- return "." if self.respond_to?(:flags) && flags[:local] # check for bonus --local flag in CLI
12
14
  possible_paths = ['deploy/cookbooks', 'cookbooks']
13
15
  destination = possible_paths.find do |cookbooks|
14
16
  File.directory?(File.join(destination_root, cookbooks))
15
17
  end
16
- unless destination
17
- error "Cannot discover cookbooks folder"
18
- end
18
+ raise CookbooksNotFound unless destination
19
19
  destination
20
20
  end
21
21
  end
@@ -7,7 +7,6 @@ module Engineyard::Recipes
7
7
 
8
8
  argument :recipe_name
9
9
  argument :definition_name
10
- argument :flags, :type => :hash
11
10
 
12
11
  def self.source_root
13
12
  File.join(File.dirname(__FILE__), "definition_generator", "templates")
@@ -15,9 +14,9 @@ module Engineyard::Recipes
15
14
 
16
15
  def install_cookbooks
17
16
  directory "cookbooks", cookbooks_destination
17
+ rescue CookbooksNotFound
18
+ directory "cookbooks/%recipe_name%", "."
18
19
  end
19
-
20
- private
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,41 @@
1
+ require 'thor/group'
2
+ require 'active_support/core_ext/string'
3
+
4
+ module Engineyard::Recipes
5
+ module Generators
6
+ class GemGenerator < BaseGenerator
7
+ include Thor::Actions
8
+
9
+ argument :recipe_name
10
+ argument :repo_name
11
+ argument :recipe_type
12
+
13
+ def self.source_root
14
+ File.join(File.dirname(__FILE__), "gem_generator", "templates")
15
+ end
16
+
17
+ def install_gem
18
+ directory "gem", repo_name
19
+ end
20
+
21
+ def install_metadata
22
+ directory "metadata", repo_name
23
+ end
24
+
25
+ def install_recipe
26
+ if recipe_type == "recipe"
27
+ directory "recipe", repo_name
28
+ end
29
+ end
30
+
31
+ protected
32
+ def git_user_name
33
+ `git config --global user.name`.strip
34
+ end
35
+
36
+ def git_user_email
37
+ `git config --global user.email`.strip
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ version = "0.1.0" # TODO get from metadata.json or .rb
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "<%= repo_name %>"
8
+ s.version = version
9
+ s.authors = ["<%= git_user_name %>"]
10
+ s.email = ["<%= git_user_email %>"]
11
+ s.homepage = ""
12
+ s.summary = %q{<%= recipe_name.humanize.titleize %> recipe for EY Cloud} # TODO from metadata
13
+ s.description = %q{<%= recipe_name.humanize.titleize %> recipe for EY Cloud} # TODO from metadata long_description
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # s.add_dependency("eycloud-helper-cronjobs")
21
+ s.add_development_dependency("rake")
22
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,19 @@
1
+ # <%= recipe_name.humanize.titleize %> recipe for EY Cloud
2
+
3
+ DESCRIPTION HERE
4
+
5
+ ## Installation
6
+
7
+ INSTALLATION HERE
8
+
9
+ ## Contributing
10
+
11
+ 1. Fork it
12
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
13
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
14
+ 4. Push to the branch (`git push origin my-new-feature`)
15
+ 5. Create new Pull Request
16
+
17
+ ## License
18
+
19
+ MIT LICENSE
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "<%= recipe_name %>",
3
+ "description": "<%= recipe_name.humanize.titleize %> recipe for EY Cloud",
4
+ "long_description": "",
5
+ "license": "MIT",
6
+ "maintainer": "<%= git_user_name %>",
7
+ "maintainer_email": "<%= git_user_email %>",
8
+ "version": "0.1.0",
9
+ "attributes": {
10
+ },
11
+ "dependencies": {
12
+ }
13
+ }
@@ -0,0 +1,7 @@
1
+ name "<%= recipe_name %>"
2
+ description "<%= recipe_name.humanize.titleize %> recipe for EY Cloud"
3
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
4
+ maintainer "<%= git_user_name %>"
5
+ maintainer_email "<%= git_user_email %>"
6
+ version "0.1.0"
7
+ # depends "cronjobs"
@@ -0,0 +1,5 @@
1
+ #
2
+ # Cookbook Name:: <%= recipe_name %>
3
+ # Recipe:: default
4
+ #
5
+
@@ -0,0 +1,44 @@
1
+ require 'thor/group'
2
+
3
+ module Engineyard::Recipes
4
+ module Generators
5
+ class InitGenerator < BaseGenerator
6
+ include Thor::Actions
7
+
8
+ argument :flags, :type => :hash
9
+
10
+ def self.source_root
11
+ File.join(File.dirname(__FILE__), "init_bundled_chef_generator", "templates")
12
+ end
13
+
14
+ def gemfile
15
+ append_file "Gemfile", <<-GEMS
16
+
17
+ gem "eycloud-helper-common", :group => :eycloud
18
+ GEMS
19
+ end
20
+
21
+ def install_cookbooks
22
+ if on_deploy?
23
+ directory "deploy"
24
+ end
25
+ unless File.exists?(File.join(destination_root, "#{cookbooks_destination}/main/recipes/default.rb"))
26
+ directory "cookbooks", cookbooks_destination
27
+ end
28
+ end
29
+
30
+ protected
31
+ def cookbooks_destination
32
+ if on_deploy?
33
+ "deploy/cookbooks"
34
+ else
35
+ "cookbooks"
36
+ end
37
+ end
38
+
39
+ def on_deploy?
40
+ flags[:on_deploy]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ # Set up a chef 0.10 dna.json file (for stack-v1 + stack-v2)
2
+ # TODO does this run on non-app-master/solo?
3
+ custom_json = node.dup
4
+ custom_json['run_list'] = 'recipe[main]'
5
+ File.open("/etc/chef-custom/dna.json", 'w') do |f|
6
+ f.puts JSON.pretty_generate(custom_json)
7
+ f.chmod(0600)
8
+ end
9
+
10
+ # Runs application cookbooks
11
+ run "cd #{latest_release}; sudo bundle exec chef-solo -c #{latest_release}/deploy/solo.rb -j /etc/chef-custom/dna.json"
@@ -0,0 +1,25 @@
1
+ base_dir = File.dirname(__FILE__)
2
+ node = Yajl::Parser.new.parse(File.new("/etc/chef-custom/dna.json", "r"))
3
+
4
+ cookbooks_path = "#{base_dir}/cookbooks"
5
+
6
+ file_store_path base_dir
7
+ file_cache_path base_dir
8
+ cookbook_path cookbooks_path
9
+ role_path "#{base_dir}/roles"
10
+ node_name node["engineyard"]["this"]
11
+
12
+ require "fileutils"
13
+ $LOAD_PATH.each do |path|
14
+ recipe_path = path.gsub(%r{/lib$},'')
15
+ if File.exist?(metadata_path = File.join(recipe_path, 'metadata.json'))
16
+ metadata = Yajl::Parser.new.parse(File.new(metadata_path, "r"))
17
+ if metadata["name"]
18
+ puts "Unpacking #{metadata["name"]} recipe into cookbooks from #{cookbooks_path}"
19
+ FileUtils.cp_r(recipe_path, File.join(cookbooks_path, metadata["name"]))
20
+ else
21
+ puts "ERROR: Recipe has no 'name' in metadata.json (#{cookbooks_path})"
22
+ end
23
+ end
24
+ end
25
+
@@ -5,14 +5,14 @@ module Engineyard::Recipes
5
5
  class InitGenerator < BaseGenerator
6
6
  include Thor::Actions
7
7
 
8
- argument :on_deploy, :optional => true
8
+ argument :flags, :type => :hash
9
9
 
10
10
  def self.source_root
11
- File.join(File.dirname(__FILE__), "init_generator", "templates")
11
+ File.join(File.dirname(__FILE__), "init_resin_chef_generator", "templates")
12
12
  end
13
13
 
14
14
  def install_cookbooks
15
- if on_deploy
15
+ if on_deploy?
16
16
  directory "deploy"
17
17
  end
18
18
  unless File.exists?(File.join(destination_root, "#{cookbooks_destination}/main/recipes/default.rb"))
@@ -22,12 +22,20 @@ module Engineyard::Recipes
22
22
 
23
23
  protected
24
24
  def cookbooks_destination
25
- if on_deploy
25
+ if on_deploy?
26
26
  "deploy/cookbooks"
27
27
  else
28
28
  "cookbooks"
29
29
  end
30
30
  end
31
+
32
+ def on_deploy?
33
+ flags[:on_deploy]
34
+ end
35
+
36
+ def bundled_chef?
37
+ flags[:bundled_chef]
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -6,7 +6,6 @@ module Engineyard::Recipes
6
6
  include Thor::Actions
7
7
 
8
8
  argument :recipe_name
9
- argument :flags, :type => :hash
10
9
 
11
10
  def self.source_root
12
11
  @tmpdir ||= Dir.mktmpdir
@@ -14,14 +13,16 @@ module Engineyard::Recipes
14
13
 
15
14
  def install_cookbooks
16
15
  directory "cookbooks", cookbooks_destination
16
+ rescue CookbooksNotFound
17
+ directory "cookbooks/#{recipe_name}", "."
17
18
  end
18
19
 
19
20
  def auto_require_package
20
- unless local?
21
- file = cookbooks_dir "main/recipes/default.rb"
22
- require_recipe = "\nrequire_recipe '#{recipe_name}'\n"
23
- append_to_file file, require_recipe
24
- end
21
+ file = cookbooks_dir "main/recipes/default.rb"
22
+ require_recipe = "\nrequire_recipe '#{recipe_name}'\n"
23
+ append_to_file file, require_recipe
24
+ rescue CookbooksNotFound
25
+ # step not required if no cookbooks/ found
25
26
  end
26
27
 
27
28
  private
@@ -8,22 +8,26 @@ module Engineyard::Recipes
8
8
  argument :recipe_name
9
9
  argument :package
10
10
  argument :version
11
- argument :flags, :type => :hash # :unmasked & :local
11
+ argument :flags, :type => :hash # :unmasked
12
12
 
13
13
  def self.source_root
14
14
  File.join(File.dirname(__FILE__), "package_generator", "templates")
15
15
  end
16
16
 
17
17
  def install_cookbooks
18
- directory "cookbooks", cookbooks_destination
18
+ begin
19
+ directory "cookbooks", cookbooks_destination
20
+ rescue CookbooksNotFound
21
+ directory "cookbooks/%recipe_name%", "."
22
+ end
19
23
  end
20
24
 
21
25
  def auto_require_package
22
- unless local?
23
- file = cookbooks_dir "main/recipes/default.rb"
24
- require_recipe = "\nrequire_recipe '#{recipe_name}'\n"
25
- append_to_file file, require_recipe
26
- end
26
+ file = cookbooks_dir "main/recipes/default.rb"
27
+ require_recipe = "\nrequire_recipe '#{recipe_name}'\n"
28
+ append_to_file file, require_recipe
29
+ rescue CookbooksNotFound
30
+ # step not required if no cookbooks/ found
27
31
  end
28
32
 
29
33
  protected
@@ -0,0 +1,3 @@
1
+ recipes('main')
2
+ owner_name(@attribute[:users].first[:username])
3
+ owner_pass(@attribute[:users].first[:password])
@@ -0,0 +1,6 @@
1
+ define :ey_cloud_report do
2
+ execute "reporting for #{params[:name]}" do
3
+ command "ey-enzyme --report '#{params[:message]}'"
4
+ epic_fail true
5
+ end
6
+ end
@@ -0,0 +1,40 @@
1
+
2
+ class Chef
3
+ class Resource
4
+ class RubyBlock < Chef::Resource
5
+ def initialize(name, collection=nil, node=nil)
6
+ super(name, collection, node)
7
+ @resource_name = :ruby_block
8
+ @action = :create
9
+ @allowed_actions.push(:create)
10
+ end
11
+
12
+ def block(&block)
13
+ if block
14
+ @block = block
15
+ else
16
+ @block
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ class Chef
25
+ class Provider
26
+ class RubyBlock < Chef::Provider
27
+ def load_current_resource
28
+ Chef::Log.debug(@new_resource.inspect)
29
+ true
30
+ end
31
+
32
+ def action_create
33
+ @new_resource.block.call
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ Chef::Platform.platforms[:default].merge! :ruby_block => Chef::Provider::RubyBlock
40
+
@@ -0,0 +1,12 @@
1
+ class Chef
2
+ class Recipe
3
+ def run_for_app(*apps, &block)
4
+ apps.map! {|a| a.to_s }
5
+ node[:applications].map{|k,v| [k,v] }.sort_by {|a,b| a }.each do |name, app_data|
6
+ if apps.include?(name)
7
+ block.call(name, app_data)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ # Runs application cookbooks
2
+ sudo "/usr/local/ey_resin/ruby/bin/chef-solo -c #{latest_release}/deploy/solo.rb -j /etc/chef/dna.json"
@@ -0,0 +1,7 @@
1
+ require 'dnapi'
2
+ base_dir = File.dirname(__FILE__)
3
+
4
+ file_store_path base_dir
5
+ file_cache_path base_dir
6
+ cookbook_path "#{base_dir}/cookbooks"
7
+ node_name DNApi.from(File.read("/etc/chef/dna.json")).id
@@ -1,5 +1,5 @@
1
1
  module Engineyard
2
2
  module Recipes
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-17 00:00:00.000000000 Z
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70236150882240 !ruby/object:Gem::Requirement
16
+ requirement: &70261653662340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.14.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70236150882240
24
+ version_requirements: *70261653662340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: engineyard
27
- requirement: &70236150881400 !ruby/object:Gem::Requirement
27
+ requirement: &70261653660900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: 1.4.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70236150881400
35
+ version_requirements: *70261653660900
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ requirement: &70261653658540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70261653658540
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rake
38
- requirement: &70236150880580 !ruby/object:Gem::Requirement
49
+ requirement: &70261653657600 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 0.9.2
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70236150880580
57
+ version_requirements: *70261653657600
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: cucumber
49
- requirement: &70236150879640 !ruby/object:Gem::Requirement
60
+ requirement: &70261653656920 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: 1.1.2
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70236150879640
68
+ version_requirements: *70261653656920
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rspec
60
- requirement: &70236150878820 !ruby/object:Gem::Requirement
71
+ requirement: &70261653656300 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 2.7.0
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70236150878820
79
+ version_requirements: *70261653656300
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: launchy
71
- requirement: &70236150877960 !ruby/object:Gem::Requirement
82
+ requirement: &70261653655460 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70236150877960
90
+ version_requirements: *70261653655460
80
91
  description: Tools to generate, upload, test and apply chef recipes for Engine Yard
81
92
  Cloud.
82
93
  email:
@@ -97,6 +108,7 @@ files:
97
108
  - engineyard-recipes.gemspec
98
109
  - features/clone-recipe.feature
99
110
  - features/generate-helper-definitions.feature
111
+ - features/generate-recipe-gem.feature
100
112
  - features/init-new-cookbook.feature
101
113
  - features/init-sm-framework.feature
102
114
  - features/install-package.feature
@@ -120,20 +132,33 @@ files:
120
132
  - lib/engineyard-recipes/generators/base_generator.rb
121
133
  - lib/engineyard-recipes/generators/definition_generator.rb
122
134
  - lib/engineyard-recipes/generators/definition_generator/templates/cookbooks/%recipe_name%/definitions/%definition_name%.rb.tt
123
- - lib/engineyard-recipes/generators/init_generator.rb
124
- - lib/engineyard-recipes/generators/init_generator/templates/cookbooks/main/attributes/recipe.rb
125
- - lib/engineyard-recipes/generators/init_generator/templates/cookbooks/main/definitions/ey_cloud_report.rb
126
- - lib/engineyard-recipes/generators/init_generator/templates/cookbooks/main/libraries/ruby_block.rb
127
- - lib/engineyard-recipes/generators/init_generator/templates/cookbooks/main/libraries/run_for_app.rb
128
- - lib/engineyard-recipes/generators/init_generator/templates/cookbooks/main/recipes/default.rb
129
- - lib/engineyard-recipes/generators/init_generator/templates/deploy/before_migrate.rb
130
- - lib/engineyard-recipes/generators/init_generator/templates/deploy/solo.rb
135
+ - lib/engineyard-recipes/generators/gem_generator.rb
136
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/%repo_name%.gemspec.tt
137
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/.gitignore
138
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/ChangeLog.md
139
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/Gemfile
140
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/README.md.tt
141
+ - lib/engineyard-recipes/generators/gem_generator/templates/gem/Rakefile
142
+ - lib/engineyard-recipes/generators/gem_generator/templates/metadata/metadata.json.tt
143
+ - lib/engineyard-recipes/generators/gem_generator/templates/metadata/metadata.rb.tt
144
+ - lib/engineyard-recipes/generators/gem_generator/templates/recipe/%recipe_name%/recipes/default.rb.tt
145
+ - lib/engineyard-recipes/generators/init_bundled_chef_generator.rb
146
+ - lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/cookbooks/main/recipes/default.rb
147
+ - lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/deploy/before_migrate.rb
148
+ - lib/engineyard-recipes/generators/init_bundled_chef_generator/templates/deploy/solo.rb
149
+ - lib/engineyard-recipes/generators/init_resin_chef_generator.rb
150
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/attributes/recipe.rb
151
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/definitions/ey_cloud_report.rb
152
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/libraries/ruby_block.rb
153
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/libraries/run_for_app.rb
154
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/cookbooks/main/recipes/default.rb
155
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/deploy/before_migrate.rb
156
+ - lib/engineyard-recipes/generators/init_resin_chef_generator/templates/deploy/solo.rb
131
157
  - lib/engineyard-recipes/generators/init_sm_generator.rb
132
158
  - lib/engineyard-recipes/generators/init_sm_generator/templates/cookbooks/sm/attributes/recipe.rb
133
159
  - lib/engineyard-recipes/generators/init_sm_generator/templates/cookbooks/sm/recipes/default.rb
134
160
  - lib/engineyard-recipes/generators/init_sm_generator/templates/cookbooks/sm/recipes/install.rb
135
161
  - lib/engineyard-recipes/generators/local_recipe_clone_generator.rb
136
- - lib/engineyard-recipes/generators/local_recipe_clone_generator/templates/cookbooks/%recipe_name%/definitions/%definition_name%.rb.tt
137
162
  - lib/engineyard-recipes/generators/package_generator.rb
138
163
  - lib/engineyard-recipes/generators/package_generator/templates/cookbooks/%recipe_name%/attributes/recipe.rb.tt
139
164
  - lib/engineyard-recipes/generators/package_generator/templates/cookbooks/%recipe_name%/recipes/default.rb.tt
@@ -143,6 +168,13 @@ files:
143
168
  - lib/engineyard-recipes/generators/sm_generator/templates/cookbooks/%recipe_name%/attributes/recipe.rb.tt
144
169
  - lib/engineyard-recipes/generators/sm_generator/templates/cookbooks/%recipe_name%/recipes/default.rb.tt
145
170
  - lib/engineyard-recipes/generators/sm_generator/templates/cookbooks/%recipe_name%/recipes/install_sm_ext.rb.tt
171
+ - lib/engineyard-recipes/generators/templates/cookbooks/main/attributes/recipe.rb
172
+ - lib/engineyard-recipes/generators/templates/cookbooks/main/definitions/ey_cloud_report.rb
173
+ - lib/engineyard-recipes/generators/templates/cookbooks/main/libraries/ruby_block.rb
174
+ - lib/engineyard-recipes/generators/templates/cookbooks/main/libraries/run_for_app.rb
175
+ - lib/engineyard-recipes/generators/templates/cookbooks/main/recipes/default.rb
176
+ - lib/engineyard-recipes/generators/templates/deploy/before_migrate.rb
177
+ - lib/engineyard-recipes/generators/templates/deploy/solo.rb
146
178
  - lib/engineyard-recipes/generators/timezone_generator.rb
147
179
  - lib/engineyard-recipes/generators/timezone_generator/templates/cookbooks/%recipe_name%/recipes/default.rb.tt
148
180
  - lib/engineyard-recipes/git_cmd.rb
@@ -165,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
197
  version: '0'
166
198
  segments:
167
199
  - 0
168
- hash: 979474682271499265
200
+ hash: 1880085431583266661
169
201
  required_rubygems_version: !ruby/object:Gem::Requirement
170
202
  none: false
171
203
  requirements:
@@ -174,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
206
  version: '0'
175
207
  segments:
176
208
  - 0
177
- hash: 979474682271499265
209
+ hash: 1880085431583266661
178
210
  requirements: []
179
211
  rubyforge_project: engineyard-recipes
180
212
  rubygems_version: 1.8.17
@@ -184,6 +216,7 @@ summary: Tools to generate, upload, test and apply chef recipes for Engine Yard
184
216
  test_files:
185
217
  - features/clone-recipe.feature
186
218
  - features/generate-helper-definitions.feature
219
+ - features/generate-recipe-gem.feature
187
220
  - features/init-new-cookbook.feature
188
221
  - features/init-sm-framework.feature
189
222
  - features/install-package.feature