Skip to content

Instantly share code, notes, and snippets.

@stevemartin
Created September 10, 2013 22:39
Show Gist options
  • Save stevemartin/6516767 to your computer and use it in GitHub Desktop.
Save stevemartin/6516767 to your computer and use it in GitHub Desktop.
An example track deploy setup
require 'net/http'
require 'json'
before 'deploy:starting', 'track:start'
after 'deploy:finished', 'track:finish'
namespace :track do
task :start do
unless ENV['BYPASS_TRACKING']
user_name = `git config --get user.name`.chomp
user_email = `git config --get user.email`.chomp
params = "?branch=#{ENV['BRANCH']}&deployer=#{ENV['USER']}&last_commit=#{last_deployed_tag}"
uri = URI.parse("http://track-deploys.com/deploy/s0m3-d3pl0y-k5y/some-app/env/#{environment}#{params}")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
response = http.request(request)
json = JSON.parse(response.body)
raise "Another deploy is in progress, please check" if json['state'] == 'denied'
@deploy_key = json['uuid']
p "Deploy key: #{@deploy_key}"
end
end
task :finish do
unless ENV['BYPASS_TRACKING']
deploy_key = ENV['DEPLOY_KEY'] || @deploy_key
raise "No deploy key!" if deploy_key == nil
uri = URI.parse("http://track-deploys.com/deploy/s0m3-d3pl0y-k5y/some-app/env/#{environment}/completed/#{deploy_key}")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
response = http.request(request)
json = JSON.parse(response.body)
p "Deploy tracking: #{json['state']} for deploy key #{deploy_key}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment