Sha256: b7dffed74a9141f0b2296b3a9110c47bdf18860292bbcdda1a570c59dd041c9e

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

module DPL
  class Provider
    module Heroku
      class Anvil < Git
        requires 'anvil-cli', :load => 'anvil/engine'
        requires 'excon' # comes with heroku
        requires 'json'

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

        def needs_key?
          false
        end

        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

        def slug_url
          @slug_url ||= begin
            ::Anvil.headers["X-Heroku-User"] = user
            ::Anvil.headers["X-Heroku-App"]  = option(:app)
            ::Anvil::Engine.build "."
          end
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dpl-1.3.1 lib/dpl/provider/heroku/anvil.rb
dpl-1.3.0 lib/dpl/provider/heroku/anvil.rb
dpl-1.2.0 lib/dpl/provider/heroku/anvil.rb
dpl-1.1.1 lib/dpl/provider/heroku/anvil.rb
dpl-1.1.0 lib/dpl/provider/heroku/anvil.rb
dpl-1.0.3 lib/dpl/provider/heroku/anvil.rb