ridoku 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4552e8d282baa6c182c87dcec67db693da9e05da
4
+ data.tar.gz: 6cc461fe71080bdd283f3562f27fcf98911e6852
5
+ SHA512:
6
+ metadata.gz: f5e25c2acec10b5de7f3e7b8676337a3f01774636e8d5427116e2b053a9a80b3f8acce7fbfad6aa378e23d22335b298ff73f9b4b0031fcd750decee7b04a9063
7
+ data.tar.gz: ca550fe9503c589089ec3c2315d50c15fdd971b0bb7efc47dae03d44cee21c420b02f7a1a4be7af73afa280c8b5bc44762fdc6614b0df2a1a97a99f7e811c6c8
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ *.sublime-*
21
+
22
+ ridoku/.cookbook*
23
+ .ridokurc
data/AUTHORS ADDED
@@ -0,0 +1,3 @@
1
+ AUTHORS
2
+
3
+ - Terry Meacham <zv1n.fire at gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.1.2'
3
+ #ruby-gemset=ridoku
4
+
5
+ # OpsWorks control SDK + some IAM stuff.
6
+ gem 'aws-sdk'
7
+
8
+ # For fetching logs from S3.
9
+ gem 'rest-client'
10
+ gem 'rake'
11
+
12
+ gem 'require_all'
13
+
14
+ gem 'awesome_print'
15
+
16
+ # JSON.load for the config file and for processing OpsWorks output.
17
+ gem 'json'
18
+
19
+ # Used for interacting with git
20
+ gem 'rugged'
21
+
22
+ # for deep merge
23
+ gem 'activesupport'
24
+ gem 'activesupport-inflector'
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.4)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ activesupport-inflector (0.1.0)
11
+ awesome_print (1.2.0)
12
+ aws-sdk (1.50.0)
13
+ json (~> 1.4)
14
+ nokogiri (>= 1.4.4)
15
+ i18n (0.6.11)
16
+ json (1.8.1)
17
+ mime-types (2.3)
18
+ mini_portile (0.6.0)
19
+ minitest (5.4.0)
20
+ netrc (0.7.7)
21
+ nokogiri (1.6.3.1)
22
+ mini_portile (= 0.6.0)
23
+ rake (10.3.2)
24
+ require_all (1.3.2)
25
+ rest-client (1.7.2)
26
+ mime-types (>= 1.16, < 3.0)
27
+ netrc (~> 0.7)
28
+ rugged (0.21.0)
29
+ thread_safe (0.3.4)
30
+ tzinfo (1.2.1)
31
+ thread_safe (~> 0.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ activesupport
38
+ activesupport-inflector
39
+ awesome_print
40
+ aws-sdk
41
+ json
42
+ rake
43
+ require_all
44
+ rest-client
45
+ rugged
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013, Terry Meacham
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ Redistributions in binary form must reproduce the above copyright notice, this
11
+ list of conditions and the following disclaimer in the documentation and/or
12
+ other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,271 @@
1
+ # *ridoku* v0.8
2
+
3
+ *ridoku* is intended to be a set of scripts for replacing a Heroku work flow
4
+ with AWS OpsWorks. It requires some manual configuration at the moment in
5
+ AWS OpsWorks and the IAM Control Panel.
6
+
7
+ ## User Configuration
8
+
9
+ You must add a user or add full permission to OpsWorks to your existing user.
10
+ The easiest way to do this is by following [this guide](http://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html). Once you have this
11
+ completed, you should be able to use `ridoku` to manage certain aspects of
12
+ your app deployment.
13
+
14
+ ## Stack Configuration
15
+
16
+ Currently, *ridoku* only works with the Rails Application Stack (rather, its
17
+ only been tested on the stack, and several layer-actions specify 'rails-app'
18
+ type, so your mileage may vary).
19
+
20
+ Also, when developing the scripts, I was using a Rails app with a custom
21
+ PostgreSQL, so the use of the OpsWorks MySQL layer has not been tested, but
22
+ probably won't be affected (it will probably only limit the use of the
23
+ [ridoku db](#db) command set for application management).
24
+
25
+ Once the Stack has been created and instances added using the OpsWorks GUI,
26
+ you should be able to start using *ridoku* to make edits to your database and
27
+ environment information, as well as running recipes and commands on the stack.
28
+
29
+ Sadly, at this point, the OpsWorks GUI is still required (stack config, layers,
30
+ etc are manual atm).
31
+
32
+ ## Custom Cookbooks
33
+
34
+ Currently, the Ridoku custom cookbooks are also required to ensure that the
35
+ environment is the same as is expected by a Heroku application.
36
+
37
+ ## Quickstart
38
+
39
+ If you have a Stack that is already configured to use *ridoku*, this section
40
+ gives you a quick run-down of commands necessary for Application management.
41
+
42
+ (`rid` can also be used as an alias for `ridoku`)
43
+
44
+ Each command below expects you to have run:
45
+
46
+ ```
47
+ $ ridoku --set-stack YourStack
48
+ $ ridoku --set-app YourApp
49
+ $ ridoku --set-backup-bucket YourBackupBucket
50
+ ```
51
+
52
+ The switches `--app app-name` and `--stack stack-name` can be used in any given
53
+ commandline to override defaults.
54
+
55
+ ### Deploy/Rollback
56
+
57
+ `$ ridoku deploy`
58
+
59
+ Deploys the application to all instances.
60
+ Note that **HEAD** is used for the repository branch associated with this app.
61
+ (This is currently only configurable in the OpsWorks console)
62
+
63
+ `$ ridoku deploy:rollback`
64
+
65
+ Rollback the application on all instances.
66
+
67
+ ### Database Backup
68
+
69
+ These commands only work if you are using *ridoku* to manage databases.
70
+
71
+ `$ ridoku backup:capture`
72
+
73
+ Captures the current applications database and stores it to S3.
74
+
75
+
76
+ ```
77
+ $ ridoku backup:list
78
+ $ ridoku backup:capture
79
+ $ ridoku backup:restore <backup name>
80
+ ```
81
+
82
+ Shows all existing database backups for the specified application,
83
+ captures a backup (safety first!), then restores the specified database backup.
84
+
85
+ ### Environment
86
+
87
+ *compare to `heroku config`*
88
+
89
+ All changes to the environment require an application `deploy` to take effect.
90
+ The Revision provider is used in the *ridoku* deployment cookbooks. As a result,
91
+ multiple deploy commands can be issued in a row without depleting the `rollback`
92
+ capability (which is limited to 5 total rollbacks).
93
+
94
+ `$ ridoku env`
95
+
96
+ Displays the current applications runtime environment configuration.
97
+
98
+ `$ ridoku env:set KEY:value KEY2:value2`
99
+
100
+ Sets or updates the specified key/value pairs.
101
+
102
+ `$ ridoku env:remove KEY`
103
+
104
+ Removes the specified key/value pair.
105
+
106
+ ## *ridoku* commands
107
+
108
+ Ridoku, 0.0.8
109
+
110
+ `usage: ridoku [OPTIONS] command [command options]`
111
+
112
+ ### backup
113
+
114
+ **TODO**
115
+
116
+ ### cook
117
+
118
+ **TODO**
119
+
120
+ ### create
121
+
122
+ **TODO**
123
+
124
+ ### db
125
+
126
+ **TODO**
127
+
128
+ ### deploy
129
+
130
+ **TODO**
131
+
132
+ ### domain
133
+
134
+ **TODO**
135
+
136
+ ### dump
137
+
138
+ **TODO**
139
+
140
+ ### env
141
+
142
+ **TODO**
143
+
144
+ ### list
145
+
146
+ **TODO**
147
+
148
+ ### packages
149
+
150
+ **TODO**
151
+
152
+ ### run
153
+
154
+ **TODO**
155
+
156
+ ### service
157
+
158
+ **TODO**
159
+
160
+ ### workers
161
+
162
+ **TODO**
163
+
164
+ ### Options:
165
+
166
+ |CL Switch|Description|
167
+ |---|---|
168
+ |--debug/-D|Turn on debugging outputs (for AWS and Exceptions).|
169
+ |--no-wait/-n|When issuing a command, do not wait for the command to return.|
170
+ |--key/-k &lt;key&gt;|Use the specified key as the AWS_ACCESS_KEY|
171
+ |--secret/-s &lt;secret&gt;|Use the specified secret as the AWS_SECRET_KEY|
172
+ |--set-app/-A &lt;app&gt;|Use the specified App as the default Application.|
173
+ |--set-backup-bucket/-B &lt;bucket name&gt;|Use the specified bucket name as the default Backup Bucket.|
174
+ |--backup-bucket/-b &lt;bucket name&gt;|Use the specified bucket name as the current Backup Bucket.|
175
+ |--set-stack/-S &lt;stack&gt;|Use the specified Stack as the default Stack.|
176
+ |--set-user/-U &lt;user&gt;|Use the specified user as the default login user in 'run:shell'.|
177
+ |--set-ssh-key/-K &lt;key file&gt;|Use the specified file as the default ssh key file.|
178
+ |--ssh-key/-f &lt;key file&gt;|Override the default ssh key file for this call.|
179
+ |--app/-a &lt;app&gt;|Override the default App name for this call.|
180
+ |--stack/-t &lt;stack&gt;|Override the default Stack name for this call.|
181
+ |--instances/-i &lt;instances&gt;|Run command on specified instances; valid delimiters: ',' or ':'|
182
+ |--user/-u &lt;user&gt;|Override the default user name for this call.|
183
+ |--comment/-m &lt;message&gt;|Optional for: deploy|
184
+ |--domains/-d &lt;domains&gt;|Optional for: create:app. Add the specified domains to the newly created application.|
185
+ |--layer/-l|**TODO**|
186
+ |--repo/-r|**TODO**|
187
+ |--service-arn/-V|**TODO**|
188
+ |--instance-arn/-N|**TODO**|
189
+ |--practice/-p|**TODO**|
190
+ |--wizard/-w|**TODO**|
191
+
192
+ ## Configuration Wizard:
193
+
194
+ In order to get ridoku configured with your OpsWorks account, Ridoku must
195
+ collect pertinent required info. The wizard can be run at any time after the
196
+ first with the command line option of `--wizard`.
197
+
198
+ ### Values to be configured:
199
+
200
+ #### ssh_key:
201
+
202
+ Path to the SSH key to be used for git repositories
203
+ (cook books, apps, etc). It is recommended that this be generated
204
+ separately from your personal SSH keys so that they can be revoked
205
+ effecting other logins.
206
+
207
+ #### service_role_arn:
208
+
209
+ If a valid service_role_arn cannot be found, Ridoku will attempt to
210
+ generate one for you. If you've already used OpsWorks, Ridoku should be
211
+ able to find the necessary Roles for you.
212
+
213
+ #### instance_role_arn:
214
+
215
+ If a valid instance_role_arn cannot be found, Ridoku will attempt to
216
+ generate one for you. If you've already used OpsWorks, Ridoku should be
217
+ able to find the necessary Roles for you.
218
+
219
+
220
+ ## Apps and Stacks:
221
+
222
+ Amazon OpsWorks similarly to Heroku, but, because you manage all the resources,
223
+ you'll have to provide a bit more information than you do to Heroku in order
224
+ for this commandline utility to assist.
225
+
226
+ ### Stacks:
227
+ The technology stack to use for a particular type of application.
228
+
229
+ Heroku probably has a similar structure internally, because they allow
230
+ you to use any number of program Stacks (Rails, PHP, Python, Go, etc).
231
+ The difference is that now in OpsWorks you control the stack environment,
232
+ where on Heroku you did not.
233
+
234
+ If you have a stack configured, you can view pertinent information using
235
+
236
+ `$ ridoku list:stacks`
237
+
238
+ This will display the stacks that are currently associated with your AWS
239
+ account. To
240
+
241
+ To set the specific stack to use:
242
+
243
+ `$ ridoku --set-stack <stackname>`
244
+
245
+ To set a single run stack or override the default:
246
+
247
+ `$ ridoku --stack <stackname> --app <appname> command…`
248
+
249
+ ### Apps:
250
+ The actual application which runs on the technology stack.
251
+
252
+ This is what you have control over on Heroku. You can customize the app
253
+ domains, database information, environment, etc, on a per-application
254
+ basis. The same goes for OpsWorks.
255
+
256
+ To set the default app to use:
257
+
258
+ `$ ridoku --set-app <stackname>`
259
+
260
+ To set a specific run app or override the default:
261
+
262
+ `$ ridoku --stack <stackname> --app <appname> command…`
263
+
264
+ ## Future
265
+
266
+ I would like to get this to the point of a fully functional Heroku replacement.
267
+ Adding a standard `Rails` stack using the standard `LB -> Web Server*N <-> DB` stack
268
+ layout should be fairly easily accomplished.
269
+
270
+ If you have any issues when attempting to use this toolchain, please feel free
271
+ to submit a pull request.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rid ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.join(File.dirname(__FILE__), 'ridoku')
@@ -0,0 +1,350 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ # Bundler.require(:default)
6
+
7
+ # add self to libpath
8
+ bin_file = Pathname.new(__FILE__).realpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require 'getoptlong'
12
+ require 'io-colorize'
13
+ require 'helpers'
14
+
15
+ require 'ridoku'
16
+ require 'options'
17
+
18
+ require 'require_all'
19
+ require_rel '../lib/ridoku'
20
+
21
+ RUNCOM = "#{ENV['HOME']}/.ridokurc"
22
+
23
+ config = {
24
+ access_key_id: ENV['AWS_ACCESS_KEY'],
25
+ secret_access_key: ENV['AWS_SECRET_KEY']
26
+ }
27
+
28
+ @validations = []
29
+
30
+ def validate(opt, arg, &block)
31
+ @validations << {
32
+ option: opt,
33
+ argument: arg,
34
+ block: block
35
+ }
36
+ end
37
+
38
+ def validate_arguments
39
+ @validations.each do |val|
40
+ val[:block].call(val[:option], val[:argument])
41
+ end
42
+ end
43
+
44
+ def print_options
45
+ $stderr.puts 'Options:'
46
+ Ridoku.options.each do |opt|
47
+ $stderr.puts " #{opt[0]}/#{opt[1]} #{opt[3]}"
48
+ $stderr.puts
49
+ end
50
+ end
51
+
52
+ def print_commands
53
+ $stderr.puts <<-EOF
54
+ Commands:
55
+ #{$stderr.colorize(Ridoku.commands.join("\n "), :bold)}
56
+
57
+ EOF
58
+ end
59
+
60
+ def print_help(full = false)
61
+ $stderr.puts <<-EOF
62
+ Ridoku, #{Ridoku::VERSION}
63
+ usage: ridoku [OPTIONS] command [command options]
64
+
65
+ EOF
66
+ print_commands
67
+
68
+ if full
69
+ print_options
70
+
71
+ $stderr.puts <<-EOF
72
+ #{Ridoku::ConfigWizard.help_text}
73
+
74
+ Apps and Stacks:
75
+
76
+ Amazon OpsWorks similarly to Heroku, but, because you own all the resources,
77
+ you'll have to provide a bit more information than you do to Heroku in order
78
+ for this commandline utility to assist.
79
+
80
+ Stacks: The technology stack to use for a particular type of application.
81
+
82
+ Heroku probably has a similar structure internally, because they allow
83
+ you to use any number of program Stacks (Rails, PHP, Python, Go, etc).
84
+ The difference is that now in OpsWorks you control the stack environment,
85
+ where on Heroku you did not.
86
+
87
+ If you have a stack configured, you can view pertinent information using
88
+
89
+ $ ridoku list:stacks
90
+
91
+ This will display the stacks that are currently associated with your AWS
92
+ account. To
93
+
94
+ To set the specific stack to use:
95
+
96
+ $ ridoku --set-stack <stackname>
97
+
98
+ To set a single run stack or override the default:
99
+
100
+ $ ridoku --stack <stackname> --app <appname> command...
101
+
102
+ Apps: The actual application which runs on the technology stack.
103
+
104
+ This is what you have control over on Heroku. You can customize the app
105
+ domains, database information, environment, etc, on a per-application
106
+ basis. The same goes for OpsWorks.
107
+
108
+ To set the default app to use:
109
+
110
+ $ ridoku --set-app <stackname>
111
+
112
+ To set a specific run app or override the default:
113
+
114
+ $ ridoku --stack <stackname> --app <appname> command...
115
+ EOF
116
+ end
117
+ end
118
+
119
+ opts = GetoptLong.new(
120
+ *Ridoku.options.map { |opt| opt[0..2] }
121
+ )
122
+
123
+ opts.quiet = true
124
+
125
+ Ridoku::Base.load_config(RUNCOM)
126
+
127
+ begin
128
+ opts.each do |opt, arg|
129
+ case opt
130
+ when '--debug'
131
+ Ridoku::Base.config[:debug] = true
132
+
133
+ when '--practice'
134
+ Ridoku::Base.config[:practice] = true
135
+
136
+ when '--key'
137
+ ENV['AWS_ACCESS_KEY'] = arg
138
+
139
+ when '--secret'
140
+ ENV['AWS_SECRET_KEY'] = arg
141
+
142
+ when '--set-app'
143
+ Ridoku::Base.config[:app] = arg
144
+ Ridoku::Base.save_config(RUNCOM)
145
+
146
+ puts "Default app set to: #{arg}"
147
+ exit 0 unless ARGV.length > 0
148
+ when '--set-stack'
149
+ Ridoku::Base.config[:stack] = arg
150
+ Ridoku::Base.save_config(RUNCOM)
151
+
152
+ puts "Default stack set to: #{arg}"
153
+ exit 0 unless ARGV.length > 0
154
+ when '--set-user'
155
+ Ridoku::Base.config[:shell_user] = arg
156
+ Ridoku::Base.save_config(RUNCOM)
157
+
158
+ puts "Default shell user set to: #{arg}"
159
+ exit 0 unless ARGV.length > 0
160
+ when '--set-backup-bucket'
161
+ Ridoku::Base.config[:backup_bucket] = arg
162
+ Ridoku::Base.save_config(RUNCOM)
163
+
164
+ puts "Default S3 backup bucket set to: #{arg}"
165
+ exit 0 unless ARGV.length > 0
166
+ when '--set-ssh-key'
167
+ Ridoku::Base.config[:ssh_key] = arg
168
+
169
+ validate(opt,arg) do |option, argument|
170
+ if File.exists?(argument)
171
+ Ridoku::Base.save_config(RUNCOM)
172
+ else
173
+ $stderr.puts 'Specified SSH Key file does not exist!'
174
+ print_help
175
+ exit 1
176
+ end
177
+ end
178
+
179
+ puts "Default shell user set to: #{arg}"
180
+ when '--ssh-key'
181
+ Ridoku::Base.config[:ssh_key] = arg
182
+
183
+ when '--repo'
184
+ Ridoku::Base.config[:repo] = arg
185
+
186
+ when '--backup-bucket'
187
+ Ridoku::Base.config[:backup_bucket] = arg
188
+
189
+ when '--domains'
190
+ Ridoku::Base.config[:domains] = arg.split(%r(\||;|:|,))
191
+
192
+ when '--service-arn'
193
+ Ridoku::Base.config[:service_arn] = arg
194
+
195
+ when '--rails-env'
196
+ Ridoku::Base.config[:rails_env] = arg
197
+
198
+ when '--instance-arn'
199
+ Ridoku::Base.config[:instance_arn] = arg
200
+
201
+ when '--wizard'
202
+ Ridoku::Base.config[:wizard] = true
203
+
204
+ when '--lines'
205
+ unless arg.match(/^[0-9]+$/)
206
+ $stderr.puts '--lines must be a number!'
207
+ exit 1
208
+ end
209
+ Ridoku::Base.config[:wizard] = arg
210
+
211
+ when '--stack'
212
+ Ridoku::Base.config[:stack] = arg
213
+
214
+ when '--force'
215
+ Ridoku::Base.config[:force] = true
216
+
217
+ when '--migrate'
218
+ Ridoku::Base.config[:migrate] = true
219
+
220
+ when '--user'
221
+ Ridoku::Base.config[:shell_user] = arg
222
+
223
+ when '--no-wait'
224
+ Ridoku::Base.config[:wait] = false
225
+
226
+ when '--layer'
227
+ Ridoku::Base.config[:layer] = arg
228
+
229
+ when '--app'
230
+ Ridoku::Base.config[:app] = arg
231
+
232
+ when '--comment'
233
+ Ridoku::Base.config[:comment] = arg
234
+
235
+ when '--instances'
236
+ Ridoku::Base.config[:instances] = arg.split(%r(,|\||;|:))
237
+
238
+ validate(opt, Ridoku::Base.config[:instances]) do |option, argument|
239
+ unless Ridoku::Base.valid_instances?(argument)
240
+ $stderr.puts 'Invalid instances provided.'
241
+
242
+ validinst = []
243
+ Ridoku::Base.instances.each do |inst|
244
+ next unless inst[:status] != 'stopped'
245
+ val = "#{inst[:hostname]} [#{inst[:status]}]"
246
+ validinst << $stderr.colorize(val, [:bold, :green])
247
+ end
248
+
249
+ invalidinst = []
250
+ Ridoku::Base.instances.each do |inst|
251
+ next unless inst[:status] != 'online'
252
+ val = "#{inst[:hostname]} [#{inst[:status]}]"
253
+ invalidinst << $stderr.colorize(val, [:bold, :red])
254
+ end
255
+
256
+ $stderr.puts 'Valid Instances:'
257
+ $stderr.puts validinst
258
+ $stderr.puts 'Invalid Instances:'
259
+ $stderr.puts invalidinst
260
+
261
+ puts 'Run the help command to see more.'
262
+ exit 1
263
+ end
264
+ end
265
+ else
266
+ print_help
267
+ exit 1
268
+ end
269
+ end
270
+ rescue => e
271
+ puts e.to_s
272
+ print_help
273
+ exit 1
274
+ end
275
+
276
+ if Ridoku::Base.config[:debug]
277
+ # log to standard out, strip all of the Ruby logger standard prefixes
278
+ logger = Logger.new($stdout)
279
+ logger.formatter = proc { |severity, datetime, progname, msg| msg }
280
+
281
+ config.merge!({
282
+ logger: logger,
283
+ log_formatter: AWS::Core::LogFormatter.colored,
284
+ http_wire_trace: true
285
+ })
286
+ end
287
+
288
+ begin
289
+ AWS.config(config)
290
+
291
+ unless ENV.key?('AWS_ACCESS_KEY') && ENV.key?('AWS_SECRET_KEY')
292
+ puts 'AWS_ACCESS_KEY and AWS_SECRET_KEY must be specified in your environment.'
293
+ exit 1
294
+ end
295
+
296
+ if !Ridoku::Base.config[:local_init] || Ridoku::Base.config[:wizard]
297
+ begin
298
+ wizard = Ridoku::ConfigWizard.new
299
+ wizard.run
300
+ rescue Ridoku::InvalidConfig => e
301
+ $stderr.puts "#{e.error.to_s.capitalize} #{e.type.to_s} specified."
302
+ $stderr.puts 'Use the `list` command to see relavent info.'
303
+ exit 1
304
+ end
305
+ end
306
+
307
+ validate_arguments
308
+
309
+ unless ARGV.length > 0
310
+ puts 'No arguments specified.'
311
+ print_help
312
+ exit 1
313
+ end
314
+
315
+ Ridoku::Base.config[:command] = ARGV.shift.split(':')
316
+
317
+ if Ridoku::Base.config[:command][0] == 'help'
318
+ print_help(true)
319
+ exit 0
320
+ end
321
+
322
+ begin
323
+ command = Ridoku.const_get(
324
+ Ridoku::Base.config[:command].first.capitalize
325
+ ).new
326
+ rescue => e
327
+ $stderr.puts "Invalid command specified: #{Ridoku::Base.config[:command][0]}"
328
+ puts e.to_s if Ridoku::Base.config[:debug]
329
+ print_help
330
+ exit 1
331
+ end
332
+
333
+ begin
334
+ command.run
335
+ rescue Ridoku::InvalidConfig => e
336
+ $stderr.puts "#{e.error.to_s.capitalize} #{e.type.to_s} specified."
337
+ $stderr.puts 'Use the `list` command to see relavent info.'
338
+ exit 1
339
+ rescue Ridoku::NoSshAccess
340
+ $stderr.puts 'Your user does not have access to ssh on the specified stack.'
341
+ exit 1
342
+ rescue ArgumentError => e
343
+ raise e if Ridoku::Base.config[:debug]
344
+ $stderr.puts e.to_s
345
+ end
346
+ rescue AWS::OpsWorks::Errors::UnrecognizedClientException => e
347
+ $stderr.puts e.to_s
348
+ $stderr.puts 'Check to ensure that AWS_ACCESS_KEY and AWS_SECRET_KEY are set properly.'
349
+ exit 1
350
+ end