momentum 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.10 (2014-04-14)
2
+
3
+ * Add `ow:execute_recipe` task - [@mzikherman](https://github.com/mzikherman)
4
+
1
5
  0.0.9 (2014-03-13)
2
6
  -----
3
7
 
data/README.md CHANGED
@@ -93,6 +93,13 @@ SSH to an OpsWorks instance. If the `layer_or_instance` argument is a layer, an
93
93
  # or...
94
94
  bundle exec rake ow:ssh[staging,rails-app1]
95
95
 
96
+ ### ow:execute_recipe[to,layer,recipe,aws_id,aws_secret]
97
+
98
+ Execute a Chec recipe on the given layer in the given stack. By default, will execute recipes on all running instances of the _rails-app_ layer, or the list configured in `app_layers`. E.g.:
99
+
100
+ bundle exec rake ow:execute_recipe[staging,rails-app,restart_unicorns]
101
+ # Assuming 'restart_unicorns' is a valid Chef recipe.
102
+
96
103
 
97
104
  ## Configuration:
98
105
 
@@ -77,6 +77,27 @@ module Momentum::OpsWorks
77
77
  @ow = Momentum::OpsWorks.client(aws_id, aws_secret)
78
78
  end
79
79
 
80
+ def execute_recipe!(stack_name, layer, recipe, app_name = Momentum.config[:app_base_name])
81
+ raise "No recipe provided" unless recipe
82
+ stack = Momentum::OpsWorks.get_stack(@ow, stack_name)
83
+ app = Momentum::OpsWorks.get_app(@ow, stack, app_name)
84
+ layer_names = layer ? [layer] : Momentum.config[:app_layers]
85
+ layers = Momentum::OpsWorks.get_layers(@ow, stack, layer_names)
86
+ instance_ids = layers.inject([]) { |ids, l| ids + Momentum::OpsWorks.get_online_instance_ids(@ow, layer_id: l[:layer_id]) }
87
+ raise 'No online instances found!' if instance_ids.empty?
88
+ @ow.create_deployment(
89
+ stack_id: stack[:stack_id],
90
+ app_id: app[:app_id],
91
+ command: {
92
+ name: 'execute_recipes',
93
+ args: {
94
+ 'recipes' => [recipe.to_s]
95
+ }
96
+ },
97
+ instance_ids: instance_ids
98
+ )
99
+ end
100
+
80
101
  def deploy!(stack_name, migrate_db = false, app_name = Momentum.config[:app_base_name])
81
102
  stack = Momentum::OpsWorks.get_stack(@ow, stack_name)
82
103
  app = Momentum::OpsWorks.get_app(@ow, stack, app_name)
@@ -86,11 +107,11 @@ module Momentum::OpsWorks
86
107
  @ow.create_deployment(
87
108
  stack_id: stack[:stack_id],
88
109
  app_id: app[:app_id],
89
- command: {
110
+ command: {
90
111
  name: 'deploy',
91
112
  args: {
92
113
  'migrate' => [migrate_db.to_s]
93
- }
114
+ }
94
115
  },
95
116
  instance_ids: instance_ids
96
117
  )
@@ -9,6 +9,7 @@ class Momentum::Railtie < ::Rails::Railtie
9
9
  load 'tasks/ow-console.rake'
10
10
  load 'tasks/ow-cookbooks.rake'
11
11
  load 'tasks/ow-deploy.rake'
12
+ load 'tasks/ow-execute_recipe.rake'
12
13
  load 'tasks/ow-logs.rake'
13
14
  load 'tasks/ow-ssh.rake'
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module Momentum
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -10,9 +10,11 @@ namespace :ow do
10
10
  name = stack_name(args[:to])
11
11
  stack = Momentum::OpsWorks.get_stack(ow, name)
12
12
  layer = ow.describe_layers(stack_id: stack[:stack_id])[:layers].detect { |l| l[:shortname] == Momentum.config[:rails_console_layer] }
13
+ raise "No '#{Momentum.config[:rails_console_layer]}' layer found for #{name} stack!" unless layer
13
14
  instance = Momentum::OpsWorks.get_online_instances(ow, layer_id: layer[:layer_id]).sample
15
+ raise "No '#{Momentum.config[:rails_console_layer]}' instances found for #{name} stack!" unless instance
14
16
  endpoint = Momentum::OpsWorks.get_instance_endpoint(instance)
15
- raise "No online #{Momentum.config[:rails_console_layer]} instances found for #{name} stack!" unless endpoint
17
+ raise "No online '#{Momentum.config[:rails_console_layer]}' instances found for #{name} stack!" unless endpoint
16
18
 
17
19
  $stderr.puts "Starting remote console... (use Ctrl-D to exit cleanly)"
18
20
  command = "'sudo su deploy -c \"cd /srv/www/#{Momentum.config[:app_base_name]}/current && RAILS_ENV=#{args[:env] || args[:to]} bundle exec rails console\"'"
@@ -0,0 +1,21 @@
1
+ namespace :ow do
2
+
3
+ require 'momentum/tasks'
4
+
5
+ namespace :execute_recipe do
6
+ %w{staging production}.each do |env|
7
+ desc "Execute recipe on #{Momentum.config[:app_base_name]} in the #{stack_name(env)} OpsWorks stack."
8
+ task(env.to_sym) { Rake::Task['ow:execute_recipe'].invoke(env) }
9
+ end
10
+ end
11
+
12
+ desc "Execute a recipe on the given OpsWorks stack."
13
+ task :execute_recipe, [:to, :layer, :recipe, :aws_id, :aws_secret] do |t, args|
14
+ require_credentials!(args)
15
+ deployer = Momentum::OpsWorks::Deployer.new(args[:aws_id], args[:aws_secret])
16
+ name = stack_name(args[:to])
17
+ recipe_runner = deployer.execute_recipe!(name, args[:layer], args[:recipe])
18
+ $stderr.puts "Running #{recipe} #{deployment[:deployment_id]} to #{name}..."
19
+ deployer.wait_for_success!(recipe_runner)
20
+ end
21
+ end
metadata CHANGED
@@ -1,64 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: momentum
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.9
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 10
9
+ version: 0.0.10
5
10
  platform: ruby
6
- authors:
11
+ authors:
7
12
  - Joey Aghion
8
13
  autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2015-04-14 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
14
21
  name: aws-sdk
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.30'
20
- type: :runtime
21
22
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
24
25
  - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '1.30'
27
- - !ruby/object:Gem::Dependency
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 30
30
+ version: "1.30"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
28
34
  name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.3'
34
- type: :development
35
35
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
38
  - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.3'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 3
43
+ version: "1.3"
48
44
  type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
49
48
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
55
58
  description: Utilities for working with OpsWorks apps in the style of Artsy Engineering.
56
- email:
59
+ email:
57
60
  - joey@aghion.com
58
61
  executables: []
62
+
59
63
  extensions: []
64
+
60
65
  extra_rdoc_files: []
61
- files:
66
+
67
+ files:
62
68
  - .gitignore
63
69
  - CHANGELOG.md
64
70
  - Gemfile
@@ -76,31 +82,39 @@ files:
76
82
  - lib/tasks/ow-console.rake
77
83
  - lib/tasks/ow-cookbooks.rake
78
84
  - lib/tasks/ow-deploy.rake
85
+ - lib/tasks/ow-execute_recipe.rake
79
86
  - lib/tasks/ow-logs.rake
80
87
  - lib/tasks/ow-ssh.rake
81
88
  - momentum.gemspec
89
+ has_rdoc: true
82
90
  homepage: https://github.com/artsy/momentum
83
- licenses:
91
+ licenses:
84
92
  - MIT
85
- metadata: {}
86
93
  post_install_message:
87
94
  rdoc_options: []
88
- require_paths:
95
+
96
+ require_paths:
89
97
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
100
112
  requirements: []
113
+
101
114
  rubyforge_project:
102
- rubygems_version: 2.1.11
115
+ rubygems_version: 1.3.6
103
116
  signing_key:
104
- specification_version: 4
117
+ specification_version: 3
105
118
  summary: Utilities for working with OpsWorks apps in the style of Artsy Engineering.
106
119
  test_files: []
120
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: e551ddc456b077ea202e4929c18fd1d4364625f8
4
- data.tar.gz: 8f501e1026833960b12c1592c0a8556dd6b0a6d9
5
- SHA512:
6
- metadata.gz: 3e1881e2817372c888ce9ada604a341c2bd4ce78cf93e1de51a3c2758b1babee73da7116af6a59d89d504aa872e4eda0c5f00bc475c06370eb30b98ce955a8c4
7
- data.tar.gz: f3c8d38f2fcf10f6c673211886f1e1768690189bbb6a838d8b97ec98b433d8ec52768f15728d4e211e3d08462ed456523b8f1d009027d81c4b98503456147b7a