ors 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,12 +9,13 @@ Usage: ./ors <action> [environment=production] [options]
9
9
  === Actions
10
10
  changes View changes between what is deployed and committed
11
11
  check Prints out contents of restart.timestamp on the app servers
12
- console Bring up a console on the production servers
12
+ console Bring up a console on the console server
13
13
  deploy Update the code, run the migrations, and restart unicorn
14
14
  help You're looking at it
15
15
  logs Show the last few log entries from the production servers
16
16
  migrate Runs the migrations on the migration server
17
17
  restart Retarts unicorn on the app servers
18
+ runner Runs ruby code via Rails' runner on the console server
18
19
  setup Sets up the default environment on the servers
19
20
  start Starts up unicorn on the app servers
20
21
  stop Stops unicorn on the app servers
@@ -0,0 +1,35 @@
1
+ module ORS::Commands
2
+ class Runner < Base
3
+ def execute
4
+ begin
5
+ code = ORS::Config.options[ ORS::Config.options.index{|e| e =~ /^(-c|--code)$/} + 1 ]
6
+ raise if code.strip.empty?
7
+ rescue
8
+ fatal "ERROR: Missing option --code 'ruby code'."
9
+ end
10
+ results = execute_command console_server,
11
+ %(source ~/.rvm/scripts/rvm),
12
+ %({ cd #{deploy_directory} > /dev/null; }), # Silence RVM's "Using... gemset..."
13
+ %(if [ -f script/rails ]; then bundle exec rails runner -e #{environment} \\"#{code}\\"; else ./script/runner -e #{environment} \\"#{code}\\"; fi),
14
+ :capture => true, :quiet_ssh => true
15
+ results.sub!(/\AUsing BufferedLogger due to exception: .*?\n/, '') # The central_logger gem spits this out without any way of shutting it up
16
+ puts results
17
+ end
18
+
19
+ def help
20
+ puts <<-END
21
+ Usage: ./ors runner [environment=production] --code "ruby code here" [options]
22
+
23
+ === Description
24
+ Runs rails runner returning the result on STDOUT.
25
+ The ruby code will be transmitted within several nested quotes: '"\"ruby code here\""'
26
+ Keep that in mind if you need to use quotes.
27
+
28
+ === Options
29
+ --code (or -c) The code to run.
30
+ --pretend (or -p) Don't execute anything, just show me what you're going to do
31
+ --no-gateway (or -ng) Don't use a gateway (if you're inside the firewall)
32
+ END
33
+ end
34
+ end
35
+ end
data/lib/ors/helpers.rb CHANGED
@@ -79,9 +79,9 @@ module ORS
79
79
  end.map {|thread| thread.join }
80
80
  end
81
81
 
82
- # options = {:exec => ?, :capture => ?}
82
+ # options = {:exec => ?, :capture => ?, :quiet_ssh => ?}
83
83
  def execute_command server, *command_array
84
- options = {:exec => false, :capture => false}
84
+ options = {:exec => false, :capture => false, :quiet_ssh => false}
85
85
  options.merge!(command_array.pop) if command_array.last.is_a?(Hash)
86
86
  options[:local] = true if server.to_s == "localhost"
87
87
 
@@ -118,14 +118,15 @@ module ORS
118
118
 
119
119
  commands = command_array.join " && "
120
120
  psuedo_tty = options[:exec] ? '-t ' : ''
121
+ quiet_ssh = options[:quiet_ssh] ? '-q ' : ''
121
122
 
122
123
  if options[:local]
123
124
  commands
124
125
  else
125
126
  if use_gateway
126
- %(ssh #{psuedo_tty}#{gateway} 'ssh #{psuedo_tty}#{deploy_user}@#{server} "#{commands}"')
127
+ %(ssh #{quiet_ssh}#{psuedo_tty}#{gateway} 'ssh #{quiet_ssh}#{psuedo_tty}#{deploy_user}@#{server} "#{commands}"')
127
128
  else
128
- %(ssh #{psuedo_tty}#{deploy_user}@#{server} "#{commands}")
129
+ %(ssh #{quiet_ssh}#{psuedo_tty}#{deploy_user}@#{server} "#{commands}")
129
130
  end
130
131
  end
131
132
  end
data/lib/ors/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ORS
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe ORS::Commands::Runner do
4
+
5
+ context "#run" do
6
+ before do
7
+ stub(subject).name {'abc/growhealthy'}
8
+ stub(subject).environment {'production'}
9
+ end
10
+
11
+ it "should require --code 'ruby code'" do
12
+ lambda {subject.execute}.should raise_error
13
+ end
14
+
15
+ it "should require an argument to --code" do
16
+ ORS::Config.parse_options %w(--code)
17
+ lambda {subject.execute}.should raise_error
18
+ end
19
+
20
+ it "should require an argument to -c" do
21
+ ORS::Config.parse_options %w(--c)
22
+ lambda {subject.execute}.should raise_error
23
+ end
24
+
25
+ it "should require a non-empty argument to --code" do
26
+ ORS::Config.parse_options ['--code', ' ']
27
+ lambda {subject.execute}.should raise_error
28
+ end
29
+
30
+ it "should be successful with an argument to --code" do
31
+ ORS::Config.parse_options %w(--code true)
32
+ mock(subject).execute_command(is_a(String), is_a(String), is_a(String), is_a(String), is_a(Hash)).returns("results")
33
+ lambda {subject.execute}.should_not raise_error
34
+ end
35
+
36
+ it "should be successful with an argument to -c" do
37
+ ORS::Config.parse_options %w(-c true)
38
+ mock(subject).execute_command(is_a(String), is_a(String), is_a(String), is_a(String), is_a(Hash)).returns("results")
39
+ lambda {subject.execute}.should_not raise_error
40
+ end
41
+ end
42
+ end
@@ -52,6 +52,10 @@ describe ORS::Helpers do
52
52
  it "should build the command with psuedo tty" do
53
53
  subject.build_command("server", %(cd /tmp), :exec => true).should == %(ssh -t deploy-gateway 'ssh -t deployer@server "cd /tmp"')
54
54
  end
55
+
56
+ it "should build the command with quiet mode" do
57
+ subject.build_command("server", %(cd /tmp), :quiet_ssh => true).should == %(ssh -q deploy-gateway 'ssh -q deployer@server "cd /tmp"')
58
+ end
55
59
  end
56
60
 
57
61
  context "without gateway" do
@@ -64,6 +68,10 @@ describe ORS::Helpers do
64
68
  it "should build the command with psuedo tty" do
65
69
  subject.build_command("server", %(cd /tmp), :exec => true).should == %(ssh -t deployer@server "cd /tmp")
66
70
  end
71
+
72
+ it "should build the command with quiet mode" do
73
+ subject.build_command("server", %(cd /tmp), :quiet_ssh => true).should == %(ssh -q deployer@server "cd /tmp")
74
+ end
67
75
  end
68
76
  end
69
77
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ors
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 3
10
- version: 0.2.3
5
+ version: 0.2.4
11
6
  platform: ruby
12
7
  authors:
13
8
  - Jason Dew and John Long
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-04-25 00:00:00 -04:00
13
+ date: 2011-09-01 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,9 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
35
  version: "0"
47
36
  type: :development
48
37
  version_requirements: *id002
@@ -54,9 +43,6 @@ dependencies:
54
43
  requirements:
55
44
  - - ">="
56
45
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
46
  version: "0"
61
47
  type: :development
62
48
  version_requirements: *id003
@@ -90,6 +76,7 @@ files:
90
76
  - lib/ors/commands/logs.rb
91
77
  - lib/ors/commands/migrate.rb
92
78
  - lib/ors/commands/restart.rb
79
+ - lib/ors/commands/runner.rb
93
80
  - lib/ors/commands/setup.rb
94
81
  - lib/ors/commands/start.rb
95
82
  - lib/ors/commands/stop.rb
@@ -108,6 +95,7 @@ files:
108
95
  - spec/ors/commands/deploy_spec.rb
109
96
  - spec/ors/commands/help_spec.rb
110
97
  - spec/ors/commands/logs_spec.rb
98
+ - spec/ors/commands/runner_spec.rb
111
99
  - spec/ors/commands/update_spec.rb
112
100
  - spec/ors/config_spec.rb
113
101
  - spec/ors/helpers_spec.rb
@@ -127,23 +115,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
115
  requirements:
128
116
  - - ">="
129
117
  - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
118
  version: "0"
134
119
  required_rubygems_version: !ruby/object:Gem::Requirement
135
120
  none: false
136
121
  requirements:
137
122
  - - ">="
138
123
  - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
124
  version: "0"
143
125
  requirements: []
144
126
 
145
127
  rubyforge_project: ors
146
- rubygems_version: 1.4.2
128
+ rubygems_version: 1.6.2
147
129
  signing_key:
148
130
  specification_version: 3
149
131
  summary: Heroku-like deployment utilities for ORS
@@ -155,6 +137,7 @@ test_files:
155
137
  - spec/ors/commands/deploy_spec.rb
156
138
  - spec/ors/commands/help_spec.rb
157
139
  - spec/ors/commands/logs_spec.rb
140
+ - spec/ors/commands/runner_spec.rb
158
141
  - spec/ors/commands/update_spec.rb
159
142
  - spec/ors/config_spec.rb
160
143
  - spec/ors/helpers_spec.rb