ey-core 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.ruby-version +1 -1
  2. data/.travis.yml +1 -0
  3. data/Gemfile +0 -2
  4. data/examples/add_instance.rb +74 -0
  5. data/examples/boot_env.rb +60 -0
  6. data/examples/stop_env.rb +51 -0
  7. data/examples/terminate_instance.rb +58 -0
  8. data/lib/ey-core/cli/accounts.rb +14 -6
  9. data/lib/ey-core/cli/applications.rb +32 -12
  10. data/lib/ey-core/cli/console.rb +24 -10
  11. data/lib/ey-core/cli/current_user.rb +13 -5
  12. data/lib/ey-core/cli/deploy.rb +110 -52
  13. data/lib/ey-core/cli/environments.rb +34 -12
  14. data/lib/ey-core/cli/errors.rb +10 -6
  15. data/lib/ey-core/cli/help.rb +30 -0
  16. data/lib/ey-core/cli/helpers/archive.rb +70 -0
  17. data/lib/ey-core/cli/helpers/chef.rb +35 -0
  18. data/lib/ey-core/cli/helpers/core.rb +195 -0
  19. data/lib/ey-core/cli/helpers/deprecated.rb +39 -0
  20. data/lib/ey-core/cli/helpers/log_streaming.rb +41 -0
  21. data/lib/ey-core/cli/helpers/stream_printer.rb +42 -0
  22. data/lib/ey-core/cli/init.rb +11 -8
  23. data/lib/ey-core/cli/login.rb +33 -21
  24. data/lib/ey-core/cli/logout.rb +18 -10
  25. data/lib/ey-core/cli/logs.rb +57 -35
  26. data/lib/ey-core/cli/main.rb +52 -15
  27. data/lib/ey-core/cli/recipes.rb +5 -87
  28. data/lib/ey-core/cli/recipes/apply.rb +83 -43
  29. data/lib/ey-core/cli/recipes/download.rb +48 -22
  30. data/lib/ey-core/cli/recipes/main.rb +21 -0
  31. data/lib/ey-core/cli/recipes/upload.rb +56 -23
  32. data/lib/ey-core/cli/scp.rb +11 -8
  33. data/lib/ey-core/cli/servers.rb +37 -15
  34. data/lib/ey-core/cli/ssh.rb +127 -70
  35. data/lib/ey-core/cli/status.rb +54 -14
  36. data/lib/ey-core/cli/subcommand.rb +47 -108
  37. data/lib/ey-core/cli/timeout_deploy.rb +56 -26
  38. data/lib/ey-core/cli/version.rb +13 -5
  39. data/lib/ey-core/cli/web.rb +7 -7
  40. data/lib/ey-core/cli/web/disable.rb +46 -20
  41. data/lib/ey-core/cli/web/enable.rb +40 -17
  42. data/lib/ey-core/cli/web/main.rb +21 -0
  43. data/lib/ey-core/cli/web/restart.rb +34 -15
  44. data/lib/ey-core/cli/whoami.rb +11 -3
  45. data/lib/ey-core/mock/searching.rb +4 -0
  46. data/lib/ey-core/model.rb +5 -0
  47. data/lib/ey-core/models/deployment.rb +7 -0
  48. data/lib/ey-core/models/environment.rb +5 -0
  49. data/lib/ey-core/models/request.rb +2 -0
  50. data/lib/ey-core/models/user.rb +2 -0
  51. data/lib/ey-core/requests/get_servers.rb +1 -1
  52. data/lib/ey-core/response.rb +4 -0
  53. data/lib/ey-core/subscribable.rb +3 -3
  54. data/lib/ey-core/version.rb +1 -1
  55. data/spec/ey-core/cli/accounts_spec.rb +20 -0
  56. data/spec/ey-core/cli/recipes/apply_spec.rb +4 -17
  57. data/spec/ey-core/cli/recipes/download_spec.rb +93 -0
  58. data/spec/ey-core/cli/recipes/upload_spec.rb +80 -0
  59. data/spec/servers_spec.rb +15 -0
  60. data/spec/spec_helper.rb +7 -0
  61. data/spec/support/cli_helpers.rb +38 -2
  62. metadata +116 -53
  63. checksums.yaml +0 -7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 1.9.3
data/.travis.yml CHANGED
@@ -13,6 +13,7 @@ language: ruby
13
13
  cache: bundler
14
14
 
15
15
  rvm:
16
+ - 1.9.3
16
17
  - 2.3.1
17
18
 
18
19
  env:
data/Gemfile CHANGED
@@ -11,8 +11,6 @@ end
11
11
  group :test do
12
12
  gem 'codeclimate-test-reporter', '~> 0.3'
13
13
  gem 'faker'
14
- gem 'guard-bundler', require: false
15
- gem 'guard-rspec', '~> 4.2', require: false
16
14
  gem 'hashie'
17
15
  gem 'rack-test'
18
16
  gem 'rspec', '~> 3.1'
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Very basic example of how to add an instance to a given environment.
4
+ # As is attempts to add a t2.micro, see new_server_specs below.
5
+ # For more info visit http://developer.engineyard.com
6
+
7
+ require 'ey-core'
8
+ require 'optparse'
9
+ require 'yaml'
10
+
11
+ options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: add_instance.rb [options]"
14
+
15
+ opts.on('-a', '--account NAME', 'Account name') { |v| options[:account_name] = v }
16
+ opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment_name] = v }
17
+ opts.on('-n', '--iname NAME', 'Instance name') { |v| options[:instance_name] = v }
18
+ opts.on('-r', '--irole ROLE', 'Instance role (app, util)') { |v| options[:instance_role] = v }
19
+
20
+ end.parse!
21
+
22
+ # Token comes from '~/.eyrc'
23
+ eyrc = YAML.load_file(File.expand_path("~/.eyrc"))
24
+
25
+ client = Ey::Core::Client.new(token: eyrc['api_token'])
26
+
27
+ # Account name as shown in cloud.engineyard.com
28
+ account = client.accounts.first(name: options[:account_name])
29
+
30
+ # Environment's name
31
+ environment = account.environments.first(name: options[:environment_name])
32
+
33
+ # Instance's name
34
+ instance_name = options[:instance_name]
35
+
36
+ puts "Adding app instance #{instance_name} to environment #{environment.name}...."
37
+
38
+ # TO DO: read new_server_specs from a file provided as a parameter
39
+ new_server_specs = {
40
+ :environment => environment.id,
41
+ :flavor_id => "t2_micro",
42
+ :mnt_volume_size => "10",
43
+ :name => instance_name,
44
+ :role => options[:instance_role],
45
+ :volume_size => "10",
46
+ }
47
+
48
+ provision_request = client.servers.create!(new_server_specs)
49
+
50
+ # Provisioning the instance with a timeout of 1200sec.
51
+ # Adjust as necessary depending of the type/role of instance.
52
+ provision_request.ready!(1200)
53
+
54
+ ap provision_request.attributes
55
+
56
+ puts "Instance provisioned successfully"
57
+ puts "-------------------"
58
+
59
+ puts "Waiting for instance #{instance_name} to integrate into the environment #{environment.name}...."
60
+ new_server = provision_request.resource!
61
+
62
+ new_server.wait_for(1800) { |s| s.state == "running" || s.state == "error" }
63
+
64
+ if !new_server.enabled? then
65
+ puts "Adding of instance #{instance_name} into environment #{environment.name} FAILED!!!"
66
+ puts "Check cloud.engineyard.com for more details"
67
+ ap new_server.attributes
68
+ exit
69
+ end
70
+
71
+ puts "Adding of instance #{instance_name} into environment #{environment.name} SUCCEEDED!!!"
72
+
73
+
74
+
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Very basic example of how to boot a given environment from a blueprint
4
+ # For more info visit http://developer.engineyard.com
5
+
6
+ require 'ey-core'
7
+ require 'optparse'
8
+ require 'yaml'
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: boot_env.rb [options]"
13
+
14
+ opts.on('-a', '--account NAME', 'Account name') { |v| options[:account_name] = v }
15
+ opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment_name] = v }
16
+ opts.on('-b', '--blueprint NAME', 'Blueprint name') { |v| options[:blueprint_name] = v }
17
+
18
+ end.parse!
19
+
20
+ # Token comes from '~/.eyrc'
21
+ eyrc = YAML.load_file(File.expand_path("~/.eyrc"))
22
+
23
+ #client = Ey::Core::Client.new(token: "abcdefghijklmnrstuvwxyz123456789")
24
+ client = Ey::Core::Client.new(token: eyrc['api_token'])
25
+
26
+ # Account name as shown in cloud.engineyard.com
27
+ account = client.accounts.first(name: options[:account_name])
28
+
29
+ # Environment's name
30
+ environment = account.environments.first(name: options[:environment_name])
31
+
32
+ if environment.servers.count > 0 then
33
+ puts "Environment has instances running, are you sure you want to boot it?"
34
+ exit
35
+ end
36
+
37
+ # Get blueprint's name for cloud.engineyard.com
38
+ blueprint = environment.blueprints.first(name: options[:blueprint_name])
39
+ if !blueprint then
40
+ puts "Could not find the specified blueprint."
41
+ puts "Check cloud.engineyard.com for more details."
42
+ exit
43
+ end
44
+
45
+ env_options = {"blueprint_id": blueprint.id}
46
+ puts "Booting environment using an specific blueprint...."
47
+ provision_request = environment.boot(env_options)
48
+
49
+ # Booting the environment instance with a timeout of 1800sec (30mins).
50
+ # Adjust as necessary depending of the size of the environment.
51
+ provision_request.ready!(1800)
52
+
53
+ puts "-------------------"
54
+ if !provision_request.successful? then
55
+ puts "Boot environment FAILED!!!"
56
+ puts "Check cloud.engineyard.com for more details"
57
+ exit
58
+ end
59
+
60
+ puts "Boot environment SUCCEDED!!!"
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Very basic example of how to stop a given environment.
4
+ # For more info visit http://developer.engineyard.com
5
+
6
+ require 'ey-core'
7
+ require 'optparse'
8
+ require 'yaml'
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: stop_env.rb [options]"
13
+
14
+ opts.on('-a', '--account NAME', 'Account name') { |v| options[:account_name] = v }
15
+ opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment_name] = v }
16
+
17
+ end.parse!
18
+
19
+ # Token comes from '~/.eyrc'
20
+ eyrc = YAML.load_file(File.expand_path("~/.eyrc"))
21
+
22
+ client = Ey::Core::Client.new(token: eyrc['api_token'])
23
+
24
+ # Account name as shown in cloud.engineyard.com
25
+ account = client.accounts.first(name: options[:account_name])
26
+
27
+ # Environment's name
28
+ environment = account.environments.first(name: options[:environment_name])
29
+
30
+ if environment.servers.count == 0 then
31
+ puts "Environment doesn't have instances running, are you sure it isn't stopped already?"
32
+ exit
33
+ end
34
+
35
+ puts "Stopping environment #{environment.name}...."
36
+ deprovision_request = environment.deprovision
37
+
38
+ # Stoping the environment with a timeout of 1200sec.
39
+ # Adjust as necessary depending of the size of the environment.
40
+ deprovision_request.ready!(1200)
41
+
42
+ puts "-------------------"
43
+
44
+ if !deprovision_request.successful? then
45
+ puts "Stop environment FAILED!!!"
46
+ puts "Check cloud.engineyard.com for more details"
47
+ exit
48
+ end
49
+
50
+ puts "Stop environment SUCCEDED!!!"
51
+
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Very basic example of how to terminate a given instance in a given environment.
4
+ # For more info visit http://developer.engineyard.com
5
+
6
+ require 'ey-core'
7
+ require 'optparse'
8
+ require 'yaml'
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: terminate_instance.rb [options]"
13
+
14
+ opts.on('-a', '--account NAME', 'Account name') { |v| options[:account_name] = v }
15
+ opts.on('-e', '--environment NAME', 'Environment name') { |v| options[:environment_name] = v }
16
+ opts.on('-n', '--iname NAME', 'Instance name') { |v| options[:instance_name] = v }
17
+
18
+ end.parse!
19
+
20
+ # Token comes from '~/.eyrc'
21
+ eyrc = YAML.load_file(File.expand_path("~/.eyrc"))
22
+
23
+ client = Ey::Core::Client.new(token: eyrc['api_token'])
24
+
25
+ # Account name as shown in cloud.engineyard.com
26
+ account = client.accounts.first(name: options[:account_name])
27
+
28
+ # Environment's name
29
+ environment = account.environments.first(name: options[:environment_name])
30
+
31
+ # Instance's name
32
+ instance_name = options[:instance_name]
33
+
34
+ puts "Terminating instance #{instance_name} on environment #{environment.name}...."
35
+
36
+ servers = environment.servers.select{|s| s.name == instance_name}
37
+ if !servers then
38
+ puts "Couldn't find instance #{instance_name} on environment #{environment.name}!!!!"
39
+ puts "Check cloud.engineyard.com for more details"
40
+ exit
41
+ end
42
+
43
+ server = servers[0]
44
+ deprovision_request = server.destroy
45
+ if !deprovision_request then
46
+ puts "Termination of instance #{instance_name} FAILED!!!!"
47
+ puts "Check cloud.engineyard.com for more details"
48
+ exit
49
+ end
50
+
51
+ # Terminating the instance with a timeout of 1200sec (20min) as a ballpark figure.
52
+ # Adjust as necessary depending of the size/role of the instance.
53
+ deprovision_request.ready!(1200)
54
+
55
+ puts "*"
56
+ puts "Instance #{instance_name} terminated successfully"
57
+ puts "-------------------"
58
+
@@ -1,9 +1,17 @@
1
- class Ey::Core::Cli::Accounts < Ey::Core::Cli::Subcommand
2
- title "accounts"
3
- summary "Retrieve a list of Engine Yard accounts that you have access to."
1
+ require 'ey-core/cli/subcommand'
4
2
 
5
- def handle
6
- table_data = TablePrint::Printer.new(current_accounts, [{id: {width: 36}}, :name])
7
- puts table_data.table_print
3
+ module Ey
4
+ module Core
5
+ module Cli
6
+ class Accounts < Subcommand
7
+ title "accounts"
8
+ summary "Retrieve a list of Engine Yard accounts that you have access to."
9
+
10
+ def handle
11
+ table_data = TablePrint::Printer.new(core_accounts, [{id: {width: 36}}, :name])
12
+ puts table_data.table_print
13
+ end
14
+ end
15
+ end
8
16
  end
9
17
  end
@@ -1,16 +1,36 @@
1
- class Ey::Core::Cli::Applications < Ey::Core::Cli::Subcommand
2
- title "applications"
3
- summary "Retrieve a list of Engine Yard applications that you have access to."
4
- option :account, short: 'c', long: 'account', description: 'Filter by account name or id', argument: 'Account'
1
+ require 'ey-core/cli/subcommand'
5
2
 
6
- def handle
7
- applications = if option(:account)
8
- core_account_for(options).applications.all
9
- else
10
- current_accounts.map(&:applications).flatten.sort_by(&:id)
11
- end
3
+ module Ey
4
+ module Core
5
+ module Cli
6
+ class Applications < Subcommand
7
+ title "applications"
8
+ summary "Retrieve a list of Engine Yard applications that you have access to."
12
9
 
13
- table_data = TablePrint::Printer.new(applications, [{id: {width: 10}}, :name])
14
- puts table_data.table_print
10
+ option :account,
11
+ short: 'c',
12
+ long: 'account',
13
+ description: 'Filter by account name or id',
14
+ argument: 'Account'
15
+
16
+ def handle
17
+ table_data = TablePrint::Printer.new(
18
+ applications,
19
+ [{id: {width: 10}}, :name]
20
+ )
21
+
22
+ puts table_data.table_print
23
+ end
24
+
25
+ private
26
+ def applications
27
+ if option(:account)
28
+ core_account.applications.all
29
+ else
30
+ core_accounts.map(&:applications).flatten.sort_by(&:id)
31
+ end
32
+ end
33
+ end
34
+ end
15
35
  end
16
36
  end
@@ -1,14 +1,28 @@
1
- class Ey::Core::Cli::Console < Ey::Core::Cli::Subcommand
2
- title "console"
3
- summary "Start an interactive console"
4
- option :execute_command, short: "e", long: "command", description: "Command to execute", argument: "command"
1
+ require 'ey-core/cli/subcommand'
2
+ require 'pry'
5
3
 
6
- def handle
7
- if command = option(:execute_command)
8
- core_client.instance_eval(command)
9
- else
10
- Pry.config.prompt = proc { |obj, nest_level, _| "ey-core:> " }
11
- core_client.pry
4
+ module Ey
5
+ module Core
6
+ module Cli
7
+ class Console < Subcommand
8
+ title "console"
9
+ summary "Start an interactive console"
10
+
11
+ option :execute_command,
12
+ short: "e",
13
+ long: "command",
14
+ description: "Command to execute",
15
+ argument: "command"
16
+
17
+ def handle
18
+ if command = option(:execute_command)
19
+ core_client.instance_eval(command)
20
+ else
21
+ Pry.config.prompt = proc { |obj, nest_level, _| "ey-core:> " }
22
+ core_client.pry
23
+ end
24
+ end
25
+ end
12
26
  end
13
27
  end
14
28
  end
@@ -1,8 +1,16 @@
1
- class Ey::Core::Cli::CurrentUser < Ey::Core::Cli::Subcommand
2
- title "current_user"
3
- summary "Print the current user information"
1
+ require 'ey-core/cli/subcommand'
4
2
 
5
- def handle
6
- ap core_client.users.current
3
+ module Ey
4
+ module Core
5
+ module Cli
6
+ class CurrentUser < Subcommand
7
+ title "current_user"
8
+ summary "Print the current user information"
9
+
10
+ def handle
11
+ ap core_client.users.current
12
+ end
13
+ end
14
+ end
7
15
  end
8
16
  end
@@ -1,65 +1,123 @@
1
- class Ey::Core::Cli::Deploy < Ey::Core::Cli::Subcommand
2
- title "deploy"
3
- summary "Deploy your application"
4
-
5
- option :environment, short: "e", long: "environment", description: "Name or id of the environment to deploy to.", argument: "Environment"
6
- option :account, short: 'c', long: 'account', description: 'Name or ID of the account that the environment resides in. If no account is specified, the app will deploy to the first environment that meets the criteria, in the accounts you have access to.', argument: 'Account name or id'
7
- option :ref, short: "r", long: "ref", description: "A git reference to deploy.", argument: "ref"
8
- option :migrate, short: "m", long: "migrate", description: "The migration command to run. This option has a 50 character limit.", argument: "migrate"
9
- option :app, short: "a", long: "app", description: "Application name or ID to deploy. If :account is not specified, this will be the first app that matches the criteria in the accounts you have access to.", argument: "app"
10
-
11
- switch :stream, long: "stream", description: "Stream deploy output to this console."
12
- switch :verbose, short: "v", long: "verbose", description: "Stream deploy output to this console. Alias to stream for backwards compatibility."
13
- switch :no_migrate, long: "no-migrate", description: "Skip migration."
14
-
15
- def handle
16
- %w(environment app).each { |option| raise "--#{option} is required" unless options[option.to_sym] }
17
- operator, environment = core_operator_and_environment_for(self.options)
18
- if operator.is_a?(Ey::Core::Client::Account)
19
- abort <<-EOF
1
+ require 'ey-core/cli/subcommand'
2
+ require 'ey-core/cli/helpers/log_streaming'
3
+
4
+ module Ey
5
+ module Core
6
+ module Cli
7
+ class Deploy < Subcommand
8
+ include Ey::Core::Cli::Helpers::LogStreaming
9
+ title "deploy"
10
+ summary "Deploy your application"
11
+
12
+ option :environment,
13
+ short: "e",
14
+ long: "environment",
15
+ description: "Name or id of the environment to deploy to.",
16
+ argument: "Environment"
17
+
18
+ option :account,
19
+ short: 'c',
20
+ long: 'account',
21
+ description: 'Name or ID of the account that the environment resides in. If no account is specified, the app will deploy to the first environment that meets the criteria, in the accounts you have access to.',
22
+ argument: 'Account name or id'
23
+
24
+ option :ref,
25
+ short: "r",
26
+ long: "ref",
27
+ description: "A git reference to deploy.",
28
+ argument: "ref"
29
+
30
+ option :migrate,
31
+ short: "m",
32
+ long: "migrate",
33
+ description: "The migration command to run. This option has a 50 character limit.",
34
+ argument: "migrate"
35
+
36
+ option :app,
37
+ short: "a",
38
+ long: "app",
39
+ description: "Application name or ID to deploy. If :account is not specified, this will be the first app that matches the criteria in the accounts you have access to.",
40
+ argument: "app"
41
+
42
+ switch :no_wait,
43
+ long: "no-wait",
44
+ description: "Don't wait for deploy to finish, exit after deploy is started"
45
+
46
+ switch :verbose,
47
+ short: "v",
48
+ long: "verbose",
49
+ description: "Deploy with verbose output"
50
+
51
+ switch :verbose,
52
+ short: "v",
53
+ long: "verbose",
54
+ description: "Stream deploy output to this console. Alias to stream for backwards compatibility."
55
+
56
+ switch :no_migrate,
57
+ long: "no-migrate",
58
+ description: "Skip migration."
59
+
60
+ def handle
61
+ operator, environment = core_operator_and_environment_for(self.options)
62
+ if operator.is_a?(Ey::Core::Client::Account)
63
+ abort <<-EOF
20
64
  Found account #{operator.name} but requested account #{option(:account)}.
21
65
  Use the ID of the account instead of the name.
22
66
  This can be retrieved by running "ey accounts".
23
- EOF
24
- .red unless operator.name == option(:account) || operator.id == option(:account)
25
- end
67
+ EOF
68
+ .red unless operator.name == option(:account) || operator.id == option(:account)
69
+ end
26
70
 
27
- unless environment
28
- abort "Unable to locate environment #{option[:environment]} in #{operator.name}".red
29
- end
71
+ unless environment
72
+ abort "Unable to locate environment #{option[:environment]} in #{operator.name}".red
73
+ end
30
74
 
31
- unless option(:account)
32
- self.options.merge!(environment: environment)
33
- end
75
+ unless option(:account)
76
+ self.options.merge!(environment: environment)
77
+ end
34
78
 
35
- app = core_application_for(self.options)
79
+ app = core_application_for(environment, self.options)
36
80
 
37
- deploy_options = {}
38
- deploy_options.merge!(ref: option(:ref)) if option(:ref)
39
- deploy_options.merge!(migrate_command: option(:migrate)) if option(:migrate)
40
- deploy_options.merge!(migrate_command: '') if switch_active?(:no_migrate)
41
- request = environment.deploy(app, deploy_options)
81
+ deploy_options = {verbose: options[:verbose], cli_args: ARGV}
82
+ latest_deploy = nil
83
+ if options[:ref]
84
+ deploy_options.merge!(ref: option(:ref))
85
+ else
86
+ puts "--ref not provided, checking latest deploy...".yellow
87
+ latest_deploy ||= environment.latest_deploy(app)
88
+ if latest_deploy && latest_deploy.ref
89
+ deploy_options[:ref] = latest_deploy.ref
90
+ else
91
+ raise "--ref is required (HEAD is the typical choice)"
92
+ end
93
+ end
94
+ if (options[:migrate] || options[:no_migrate])
95
+ deploy_options.merge!(migrate_command: option(:migrate)) if option(:migrate)
96
+ deploy_options.merge!(migrate_command: '') if switch_active?(:no_migrate)
97
+ else
98
+ puts "missing migrate option (--migrate or --no-migrate), checking latest deploy...".yellow
99
+ latest_deploy ||= environment.latest_deploy(app)
100
+ if latest_deploy
101
+ deploy_options.merge!(migrate_command: (latest_deploy.migrate && latest_deploy.migrate_command) || '')
102
+ else
103
+ raise "either --migrate or --no-migrate needs to be specified"
104
+ end
105
+ end
106
+ request = environment.deploy(app, deploy_options)
42
107
 
43
- puts <<-EOF
108
+ puts <<-EOF
44
109
  Deploy started to environment: #{environment.name} with application: #{app.name}
45
110
  Request ID: #{request.id}
46
- EOF
47
- if switch_active?(:stream) || switch_active?(:verbose)
48
- request.subscribe { |m| print m["message"] if m.is_a?(Hash) }
49
- puts "" # fix console output from stream
50
- else
51
- request.wait_for { |r| r.ready? } # dont raise from ready!
52
- end
53
-
54
- if request.successful
55
- puts "Deploy successful!".green
56
- else
57
- abort <<-EOF
58
- Deploy failed!
59
- Request output:
60
- #{request.message}
61
- EOF
62
- .red
111
+ EOF
112
+ ap request
113
+ ap request.resource
114
+ if switch_active?(:no_wait)
115
+ puts("Deploy started".green + " (use status command with --tail to view output)")
116
+ else
117
+ stream_deploy_log(request)
118
+ end
119
+ end
120
+ end
63
121
  end
64
122
  end
65
123
  end