Class: DPL::Provider::Heroku::Anvil

Inherits:
Git show all
Defined in:
lib/dpl/provider/heroku/anvil.rb

Constant Summary collapse

HEROKU_BUILDPACKS =
['ruby', 'nodejs', 'clojure', 'python', 'java', 'gradle', 'grails', 'scala', 'play']
HEROKU_BUILDPACK_PREFIX =
"https://github.com/heroku/heroku-buildpack-"

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from Git

#check_app, #check_auth, #remove_key, #restart, #run, #setup_key, #user

Methods inherited from DPL::Provider

apt_get, #check_app, #cleanup, #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, #uncleanup, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#apiObject

Raises:



11
12
13
14
# File 'lib/dpl/provider/heroku/anvil.rb', line 11

def api
  raise Error, 'anvil deploy strategy only works with api_key' unless options[:api_key]
  super
end

#deployObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dpl/provider/heroku/anvil.rb', line 20

def deploy
  warn ''
  if options[:strategy]
    warn 'You have explicitly set your deploy strategy to %p.' % options[:strategy]
    warn 'Anvil support will be dropped in the near future.'
    warn 'Please consider changing it to "api" or "git".'
  else
    warn 'The default strategy for Heroku deployments is currently "anvil".'
    warn 'This will be changed to "api" in the near future.'
    warn 'Consider setting it explicitly to "api" or "git".'
  end
  warn ''

  super
end

#needs_key?Boolean

Returns:

  • (Boolean)


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

def needs_key?
  false
end

#push_appObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dpl/provider/heroku/anvil.rb', line 36

def push_app
  sha = ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
  response = Excon.post release_url,
    :body    => { "slug_url" => slug_url, "description" => "Deploy #{sha} via Travis CI" }.to_json,
    :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }

  print "\nDeploying slug "
  while response.status == 202
    location = response.headers['Location']
    response = Excon.get("https://:#{option(:api_key)}@cisaurus.heroku.com#{location}")
    sleep(1)
    print '.'
  end

  if response.status.between? 200, 299
    puts " success!"
  else
    raise Error, "deploy failed, anvil response: #{response.body}"
  end
end

#release_urlObject



70
71
72
# File 'lib/dpl/provider/heroku/anvil.rb', line 70

def release_url
  "https://:#{option(:api_key)}@cisaurus.heroku.com/v1/apps/#{option(:app)}/release"
end

#slug_urlObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dpl/provider/heroku/anvil.rb', line 57

def slug_url
  @slug_url ||= begin
    ::Anvil.headers["X-Heroku-User"] = user
    ::Anvil.headers["X-Heroku-App"]  = option(:app)
    if HEROKU_BUILDPACKS.include? options[:buildpack]
      options[:buildpack] = HEROKU_BUILDPACK_PREFIX + options[:buildpack] + ".git"
    end
    ::Anvil::Engine.build ".", :buildpack => options[:buildpack]
  rescue ::Anvil::Builder::BuildError => e
    raise Error, "deploy failed, anvil build error: #{e.message}"
  end
end