momentum 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f0149ba8b46a7d55c702254909243a62474c664
4
- data.tar.gz: 651a98e07b3a42aff25fa4a413cd8f153525b82a
3
+ metadata.gz: 07fa3ea25f97bde202d9f8acec655b0368f1b506
4
+ data.tar.gz: d9ceff35e20913d65d69dc60580184fea8c2828b
5
5
  SHA512:
6
- metadata.gz: 6957fdd5f8894a80f6fb65c3ca003446d485d5daff7f1a74c7e4b8b17c3ff2540e9b1bf0571ebf8d48599444da8e60d522ce7138cf1d72f016a8d5fe117ccc54
7
- data.tar.gz: 90936ccf9409422c09fcf85c43a268ddcf65a907423a935febbb8d7287d1f123ed2c5f544e82a96f3a1cd034f138eb3eba7d2470410ec18338f1c5772339e822
6
+ metadata.gz: 75f121953e6b4ea15a3dcd6113d5639598a13c0807c31d14551e0f19e8328bd83cc6a0e01892f58b00580f5612ea670ce09d84acf5baa135d518151ecc4e694b
7
+ data.tar.gz: 24f71286c888b889cb5fbb79f8fce6fb4814073dc0fc7a3d30077054f3bd3fc336916fcaef1c5786dbeac89f971d4338307400f85f4b835b184dc014222c3b12
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.0.6 (2014-01-31)
2
+ -----
3
+
4
+ * Add `ow:logs[to,instance,log_path]` task - [@ibussieres](https://github.com/ibussieres)
data/README.md CHANGED
@@ -73,6 +73,14 @@ Trigger an OpsWorks deploy to the given stack. By default, deploys app to all ru
73
73
  # or just:
74
74
  bundle exec rake ow:deploy:staging
75
75
 
76
+ ### ow:logs[to,instance,log_path,aws_id,aws_secret]
77
+
78
+ Execute a tail -f (follow) command against an error or access log file on the given remote OpsWorks stack. Default log is 'ssl-error'. Chooses an instance of the _rails-app_ layer. E.g.:
79
+
80
+ bundle exec rake ow:logs[staging,rails-app1,/srv/www/myapp/shared/log/staging.log]
81
+
82
+ The log path may include wildcards.
83
+
76
84
  ## Configuration:
77
85
 
78
86
  * **app_base_name** - Your app's name. Stacks are assumed to be named like _appbasename-env_ (e.g., _gravity-staging_ or _reflection-joey_).
@@ -86,6 +94,7 @@ Trigger an OpsWorks deploy to the given stack. By default, deploys app to all ru
86
94
 
87
95
  * git/branch helpers
88
96
  * Integrate librarian-chef as legit dependency once rails/chef conflicts resolved
97
+ * Tests
89
98
 
90
99
 
91
100
  © 2014 [Artsy](http://artsy.net). See [LICENSE](LICENSE.txt) for details.
@@ -16,6 +16,11 @@ module Momentum::OpsWorks
16
16
  client.describe_apps(stack_id: stack[:stack_id])[:apps].detect { |a| a[:name] == app_name }
17
17
  end
18
18
 
19
+ # apparently, public_dns is not always set, fallback to elastic_ip (if available!)
20
+ def self.get_instance_endpoint(instance)
21
+ instance[:public_dns] || instance[:elastic_ip]
22
+ end
23
+
19
24
  def self.get_layers(client, stack, layer_names)
20
25
  client.describe_layers(stack_id: stack[:stack_id])[:layers].select { |l| layer_names.include?(l[:shortname]) }
21
26
  end
@@ -28,6 +33,14 @@ module Momentum::OpsWorks
28
33
  client.describe_instances(query)[:instances].select { |i| i[:status] == 'online' }
29
34
  end
30
35
 
36
+ def self.ssh_command_to(endpoint, command)
37
+ [ 'ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
38
+ (['-i', ENV['AWS_PUBLICKEY']] if ENV['AWS_PUBLICKEY']),
39
+ (['-l', ENV['AWS_USER']] if ENV['AWS_USER']),
40
+ endpoint,
41
+ command ].compact.flatten.join(' ')
42
+ end
43
+
31
44
  class Config
32
45
 
33
46
  def self.from_stack(client, stack_name, app_name = Momentum.config[:app_base_name])
@@ -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-logs.rake'
12
13
  end
13
14
 
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module Momentum
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/momentum.rb CHANGED
@@ -8,7 +8,8 @@ module Momentum
8
8
  cookbooks_install_path: 'tmp/cookbooks',
9
9
  custom_cookbooks_bucket: 'artsy-cookbooks',
10
10
  rails_console_layer: 'rails-app',
11
- app_layers: ['rails-app']
11
+ app_layers: ['rails-app'],
12
+ logs_root: '/var/log/apache2/'
12
13
  }
13
14
 
14
15
  def self.config
@@ -11,16 +11,12 @@ namespace :ow do
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
13
  instance = Momentum::OpsWorks.get_online_instances(ow, layer_id: layer[:layer_id]).sample
14
- raise "No online #{Momentum.config[:rails_console_layer]} instances found for #{name} stack!" unless instance
14
+ endpoint = Momentum::OpsWorks.get_instance_endpoint(instance)
15
+ raise "No online #{Momentum.config[:rails_console_layer]} instances found for #{name} stack!" unless endpoint
15
16
 
16
17
  $stderr.puts "Starting remote console... (use Ctrl-D to exit cleanly)"
17
- sh [
18
- 'ssh -t',
19
- (['-i', ENV['AWS_PUBLICKEY']] if ENV['AWS_PUBLICKEY']),
20
- (['-l', ENV['AWS_USER']] if ENV['AWS_USER']),
21
- instance[:public_dns],
22
- "'sudo su deploy --session-command=\"cd /srv/www/#{Momentum.config[:app_base_name]}/current && RAILS_ENV=#{args[:env] || args[:to]} bundle exec rails console\"'"
23
- ].compact.flatten.join(' ')
18
+ command = "'sudo su deploy -c \"cd /srv/www/#{Momentum.config[:app_base_name]}/current && RAILS_ENV=#{args[:env] || args[:to]} bundle exec rails console\"'"
19
+ sh Momentum::OpsWorks.ssh_command_to(endpoint,command)
24
20
  end
25
21
 
26
22
  end
@@ -0,0 +1,21 @@
1
+ namespace :ow do
2
+
3
+ require 'momentum/opsworks'
4
+ require 'momentum/tasks'
5
+
6
+ desc "Open a web server log tail on the given remote OpsWorks stack (uses AWS_USER as SSH username)."
7
+ task :logs, [:to, :instance, :log_path, :aws_id, :aws_secret] do |t, args|
8
+ require_credentials!(args)
9
+ ow = Momentum::OpsWorks.client(args[:aws_id], args[:aws_secret])
10
+ name = stack_name(args[:to])
11
+ stack = Momentum::OpsWorks.get_stack(ow, name)
12
+ instance = Momentum::OpsWorks.get_online_instances(ow, stack_id: stack[:stack_id]).detect{|i| i[:hostname] == args[:instance] }
13
+ endpoint = Momentum::OpsWorks.get_instance_endpoint(instance)
14
+ raise "Online instance #{args[:instance]} not found for #{name} stack!" unless endpoint
15
+
16
+ $stderr.puts "Starting tail -f remotely... (use Ctrl-D to exit cleanly)"
17
+ command = "'sudo su deploy -c \"tail -f #{args[:log_path]}\"'"
18
+ sh Momentum::OpsWorks.ssh_command_to(endpoint,command)
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: momentum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joey Aghion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - .gitignore
63
+ - CHANGELOG.md
63
64
  - Gemfile
64
65
  - LICENSE.txt
65
66
  - README.md
@@ -75,6 +76,7 @@ files:
75
76
  - lib/tasks/ow-console.rake
76
77
  - lib/tasks/ow-cookbooks.rake
77
78
  - lib/tasks/ow-deploy.rake
79
+ - lib/tasks/ow-logs.rake
78
80
  - momentum.gemspec
79
81
  homepage: https://github.com/artsy/momentum
80
82
  licenses: