Class: DPL::Provider::Heroku::API

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

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from Git

#api, #check_app, #check_auth, #deploy, #remove_key, #restart, #run, #setup_key

Methods inherited from DPL::Provider

apt_get, #check_app, #cleanup, #commit_msg, context, #create_key, #deploy, #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

#archive_fileObject



22
23
24
# File 'lib/dpl/provider/heroku/api.rb', line 22

def archive_file
  Shellwords.escape("#{ENV['HOME']}/.dpl.#{option(:app)}.tgz")
end

#get_urlObject



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

def get_url
  source_blob.fetch("get_url")
end

#needs_key?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/dpl/provider/heroku/api.rb', line 8

def needs_key?
  false
end

#pack_archiveObject



26
27
28
29
# File 'lib/dpl/provider/heroku/api.rb', line 26

def pack_archive
  log "creating application archive"
  context.shell "tar -zcf #{archive_file} ."
end

#post(subpath, body = nil, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dpl/provider/heroku/api.rb', line 59

def post(subpath, body = nil, options = {})
  options = {
    method: :post,
    path: "/apps/#{option(:app)}/#{subpath}",
    headers: { "Accept" => "application/vnd.heroku+json; version=edge" },
    expects: [200, 201]
  }.merge(options)

  if body
    options[:body]                    = JSON.dump(body)
    options[:headers]['Content-Type'] = 'application/json'
  end

  api.request(options).body
end

#push_appObject



16
17
18
19
20
# File 'lib/dpl/provider/heroku/api.rb', line 16

def push_app
  pack_archive
  upload_archive
  trigger_build
end

#put_urlObject



47
48
49
# File 'lib/dpl/provider/heroku/api.rb', line 47

def put_url
  source_blob.fetch("put_url")
end

#source_blobObject



51
52
53
# File 'lib/dpl/provider/heroku/api.rb', line 51

def source_blob
  @source_blog ||= post(:sources).fetch("source_blob")
end

#trigger_buildObject



36
37
38
39
40
41
# File 'lib/dpl/provider/heroku/api.rb', line 36

def trigger_build
  log "triggering new deployment"
  response   = post(:builds, source_blob: { url: get_url, version: version })
  stream_url = response.fetch('stream_url')
  context.shell "curl #{Shellwords.escape(stream_url)}"
end

#upload_archiveObject



31
32
33
34
# File 'lib/dpl/provider/heroku/api.rb', line 31

def upload_archive
  log "uploading application archive"
  context.shell "curl #{Shellwords.escape(put_url)} -X PUT -H 'Content-Type:' --data-binary @#{archive_file}"
end

#userObject



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

def user
  @user ||= api.get_user.body["email"]
end

#versionObject



55
56
57
# File 'lib/dpl/provider/heroku/api.rb', line 55

def version
  @version ||= options[:version] || ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
end