Class: Ey::Core::Cli::Deploy

Inherits:
Subcommand
  • Object
show all
Includes:
Helpers::LogStreaming
Defined in:
lib/ey-core/cli/deploy.rb

Instance Method Summary collapse

Methods included from Helpers::LogStreaming

#finished_request, #stream_deploy_log

Methods inherited from Subcommand

#handle_core_error, #run_handle, #setup

Methods included from Helpers::Core

#core_account, #core_accounts, #core_application_for, #core_applications, #core_client, #core_environment_for, #core_environment_variables, #core_environments, #core_operator_and_environment_for, #core_server_for, #core_url, #core_yaml, #eyrc_yaml, included, #longest_length_by_name, #operator, #unauthenticated_core_client, #write_core_yaml

Instance Method Details

#handleObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ey-core/cli/deploy.rb', line 60

def handle
  operator, environment = core_operator_and_environment_for(self.options)
  if operator.is_a?(Ey::Core::Client::Account)
    abort <<-EOF
Found account #{operator.name} but requested account #{option(:)}.
Use the ID of the account instead of the name.
This can be retrieved by running "ey accounts".
EOF
    .red unless operator.name == option(:account) || operator.id == option(:account)
  end

  unless environment
    abort "Unable to locate environment #{option[:environment]} in #{operator.name}".red
  end

  unless option(:account)
    self.options.merge!(environment: environment)
  end

  app = core_application_for(environment, self.options)

  deploy_options = {verbose: options[:verbose], cli_args: ARGV}
  latest_deploy = nil
  if options[:ref]
    deploy_options.merge!(ref: option(:ref))
  else
    puts "--ref not provided, checking latest deploy...".yellow
    latest_deploy ||= environment.latest_deploy(app)
    if latest_deploy && latest_deploy.ref
      deploy_options[:ref] = latest_deploy.ref
    else
      raise "--ref is required (HEAD is the typical choice)"
    end
  end
  if (option(:migrate) || switch_active?(:no_migrate))
    deploy_options.merge!(migrate_command: option(:migrate)) if option(:migrate)
    deploy_options.merge!(migrate_command: nil) if switch_active?(:no_migrate)
  else
    puts "missing migrate option (--migrate or --no-migrate), checking latest deploy...".yellow
    latest_deploy ||= environment.latest_deploy(app)
    if latest_deploy
      deploy_options.merge!(migrate_command: (latest_deploy.migrate && latest_deploy.migrate_command) || nil)
    else
      raise "either --migrate or --no-migrate needs to be specified"
    end
  end
  request = environment.deploy(app, deploy_options)

  puts <<-EOF
Deploy started to environment: #{environment.name} with application: #{app.name}
Request ID: #{request.id}
EOF
  ap request
  ap request.resource
  if switch_active?(:no_wait)
    puts("Deploy started".green + " (use status command with --tail to view output)")
  else
    stream_deploy_log(request)
  end
end