Sha256: ba2832249415b32ea713ba03d8e8feeb9d7238c14a309a04f94c3a3c62b4eb84

Contents?: true

Size: 1.83 KB

Versions: 34

Compression:

Stored size: 1.83 KB

Contents

require 'json'
require 'shellwords'

module DPL
  class Provider
    module Heroku
      class API < Generic
        def push_app
          pack_archive
          upload_archive
          trigger_build
        end

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

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

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

        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

        def get_url
          source_blob.fetch("get_url")
        end

        def put_url
          source_blob.fetch("put_url")
        end

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

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

        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
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
dpl-1.7.8.travis.646.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.8.travis.645.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.8.travis.643.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.7.travis.642.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.7.travis.633.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.7.travis.626.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.6 lib/dpl/provider/heroku/api.rb
dpl-1.7.6.travis.625.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.6.travis.623.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.5.travis.622.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.5 lib/dpl/provider/heroku/api.rb
dpl-1.7.5.travis.620.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.4 lib/dpl/provider/heroku/api.rb
dpl-1.7.4.travis.619.1 lib/dpl/provider/heroku/api.rb