Class: DPL::Provider::EngineYard

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

Instance Method Summary collapse

Instance Method Details

#apiObject



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

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

#check_appObject



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

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[:env] || 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



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

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

#cleanupObject



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

def cleanup
end

#deployObject



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

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

#needs_key?Boolean

Returns:

  • (Boolean)


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

def needs_key?
  false
end

#poll_for_result(deployment) ⇒ Object



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

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



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

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



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

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



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

def uncleanup
end