Class: EY::Action::Deploy

Inherits:
Object show all
Extended by:
Util
Defined in:
lib/engineyard/action/deploy.rb

Constant Summary collapse

EYSD_VERSION =
"~>0.2.7"

Class Method Summary collapse

Class Method Details

.call(env_name, branch, options) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/engineyard/action/deploy.rb', line 10

def self.call(env_name, branch, options)
  env_name ||= EY.config.default_environment

  app = fetch_app
  env = fetch_environment(env_name, app)
  branch = fetch_branch(env.name, branch, options[:force])

  running = env.app_master && env.app_master.status == "running"
  raise EnvironmentError, "No running instances for environment #{env.name}\nStart one at #{EY.config.endpoint}" unless running

  hostname = env.app_master.public_hostname
  username = env.username

  EY.ui.info "Connecting to the server..."
  ensure_eysd_present(hostname, username, options[:install_eysd])

  deploy_cmd = "#{eysd_path} deploy --app #{app.name} --branch #{branch}"
  if env.config
    escaped_config_option = env.config.to_json.gsub(/"/, "\\\"")
    deploy_cmd << " --config '#{escaped_config_option}'"
  end

  if options['migrate']
    deploy_cmd << " --migrate='#{options[:migrate]}'"
  end

  EY.ui.info "Running deploy on server..."
  deployed = ssh_to(hostname, deploy_cmd, username)

  if deployed
    EY.ui.info "Deploy complete"
  else
    raise EY::Error, "Deploy failed"
  end
end