Class: DPL::Provider::EngineYard

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/engine_yard.rb

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #commit_msg, context, #create_key, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #user_agent, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#apiObject



16
17
18
# File 'lib/dpl/provider/engine_yard.rb', line 16

def api
  @api ||= EY::CloudClient.new(:token => token)
end

#check_appObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dpl/provider/engine_yard.rb', line 24

def check_app
  remotes = `git remote -v`.scan(/\t[^\s]+\s/).map { |c| c.strip }.uniq
  @current_sha = `git rev-parse HEAD`.chomp
  resolver = api.resolve_app_environments(
    :app_name => options[:app],
    :account_name => options[:account],
    :environment_name => options[:environment],
    :remotes => remotes)
  resolver.one_match { @app_env = resolver.matches.first }
  resolver.no_matches { error resolver.errors.join("\n").inspect }
  resolver.many_matches do |matches|
    message = "Multiple matches possible, please be more specific:\n\n"
    matches.each do |appenv|
      message << "environment: '#{appenv.environment.name}' account: '#{appenv.environment..name}'\n"
    end
    error message
  end
  @app_env
end

#check_authObject



20
21
22
# File 'lib/dpl/provider/engine_yard.rb', line 20

def check_auth
  log "authenticated as %s" % api.current_user.email
end

#cleanupObject



48
49
# File 'lib/dpl/provider/engine_yard.rb', line 48

def cleanup
end

#deployObject



82
83
84
85
86
# File 'lib/dpl/provider/engine_yard.rb', line 82

def deploy
  super
rescue EY::CloudClient::Error => e
  error(e.message)
end

#needs_key?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/dpl/provider/engine_yard.rb', line 44

def needs_key?
  false
end

#poll_for_result(deployment) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/dpl/provider/engine_yard.rb', line 71

def poll_for_result(deployment)
  until deployment.finished?
    sleep 5
    #TODO: configurable timeout?
    print "."
    deployment = EY::CloudClient::Deployment.get(api, deployment.app_environment, deployment.id)
  end
  puts "DONE: https://cloud.engineyard.com/apps/#{deployment.app.id}/environments/#{deployment.environment.id}/deployments/#{deployment.id}/pretty"
  deployment
end

#push_appObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dpl/provider/engine_yard.rb', line 54

def push_app
  deploy_opts = {:ref => @current_sha}
  if command = options[:migrate]
    if command === true || command === "true"
      error("\"true\" doesn't look like a migration command, try --migrate=\"rake db:migrate\"")
    end
    deploy_opts[:migrate] = true
    deploy_opts[:migration_command] = command
  end
  print "deploying "
  deployment = EY::CloudClient::Deployment.deploy(api, @app_env, deploy_opts)
  result = poll_for_result(deployment)
  unless result.successful
    error "Deployment failed (see logs on Engine Yard)"
  end
end

#tokenObject



8
9
10
11
12
13
14
# File 'lib/dpl/provider/engine_yard.rb', line 8

def token
  options[:api_key] ||= if options[:email] and options[:password]
    EY::CloudClient.authenticate(options[:email], options[:password])
  else
    option(:api_key) # will raise
  end
end

#uncleanupObject



51
52
# File 'lib/dpl/provider/engine_yard.rb', line 51

def uncleanup
end