Skip to content

Instantly share code, notes, and snippets.

@skierkowski
Created February 18, 2013 05:30
Show Gist options
  • Save skierkowski/4975286 to your computer and use it in GitHub Desktop.
Save skierkowski/4975286 to your computer and use it in GitHub Desktop.
Very basic example of deploying to Heroku without git
require 'json'
require 'rest-client'
require 'heroku'
require "heroku/command/base"
require "anvil"
require "anvil/engine"
require "uri"
class Cisaurus
CISAURUS_CLIENT_VERSION = "0.7-ALPHA"
CISAURUS_HOST = ENV['CISAURUS_HOST'] || "cisaurus.heroku.com"
def initialize(api_key, host = CISAURUS_HOST, api_version = "v1")
protocol = (host.start_with? "localhost") ? "http" : "https"
@base_url = "#{protocol}://:#{api_key}@#{host}"
@ver_url = "#{@base_url}/#{api_version}"
end
def downstreams(app, depth=nil)
JSON.parse RestClient.get pipeline_resource(app, "downstreams"), options(params :depth => depth)
end
def addDownstream(app, ds)
RestClient.post pipeline_resource(app, "downstreams", ds), "", options
end
def removeDownstream(app, ds)
RestClient.delete pipeline_resource(app, "downstreams", ds), options
end
def diff(app)
JSON.parse RestClient.get pipeline_resource(app, "diff"), options
end
def promote(app, interval = 2)
response = RestClient.post pipeline_resource(app, "promote"), "", options
while response.code == 202
response = RestClient.get @base_url + response.headers[:location], options
sleep(interval)
yield
end
JSON.parse response
end
def release(app, description, slug_url, interval = 2)
payload = {:description => description, :slug_url => slug_url}
extras = {:content_type => :json, :accept => :json}
response = RestClient.post app_resource(app, "release"), JSON.generate(payload), options(extras)
while response.code == 202
response = RestClient.get @base_url + response.headers[:location], options(extras)
sleep(interval)
yield
end
JSON.parse response
end
private
def app_resource(app, *extras)
"#{@ver_url}/" + extras.unshift("apps/#{app}").join("/")
end
def pipeline_resource(app, *extras)
app_resource(app, extras.unshift("pipeline").join("/"))
end
def params(tuples = {})
{ :params => tuples.reject { |k,v| k.nil? || v.nil? } }
end
def options(extras = {})
{
'User-Agent' => "heroku-push-cli/#{CISAURUS_CLIENT_VERSION}",
'X-Ruby-Version' => RUBY_VERSION,
'X-Ruby-Platform' => RUBY_PLATFORM
}.merge(extras)
end
end
app="hello-frank"
source=File.expand_path("~/Documents/git/hello/")
user="[email protected]"
# user = Heroku::Auth.api.post_login("", Heroku::Auth.password).body["email"]
puts "user: #{user}"
Anvil.append_agent "(heroku-push)"
Anvil.headers["X-Heroku-User"] = user
Anvil.headers["X-Heroku-App"] = app
slug_url = Anvil::Engine.build(source)
puts slug_url
h = Cisaurus.new(Heroku::Auth.password)
release = h.release(app, "Pushed by #{user}", slug_url) {
print "."
$stdout.flush
}
puts "release: #{release.inspect}"
# puts h.downstreams("hello-frank")
# puts h.promote('hello-frank')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment