Skip to content

Instantly share code, notes, and snippets.

@jonah-williams
Forked from ezmobius/gist:114954
Created January 7, 2010 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonah-williams/271433 to your computer and use it in GitHub Desktop.
Save jonah-williams/271433 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'json'
begin
require 'restclient'
rescue Exception
end
namespace :ey do
# Based on http://gist.github.com/114954
# Discussed at https://cloud-support.engineyard.com/discussions/questions/83-deploying-to-solo-instance-from-automated-build
desc 'Trigger a GitHub Post Receive Hook to deploy the app'
task :deploy do
post_receive_hook 'preview'
end
desc 'Trigger a GitHub Post Receive Hook to deploy and migrate the app'
task :deploy_and_migrate do
post_receive_hook 'preview', true
end
def post_receive_hook(envname, migrate=false)
token = `git config --get cloud.token`.chomp
if token.empty?
token = ENV['cloud.token']
end
if token.empty?
puts <<-EOT
The cloud token is not set.
To store the token, use:
$ git config --add cloud.token SOMETOKEN
or set the cloud.token environment variable.
EOT
exit 2
end
commit = `git rev-parse HEAD`.chomp
payload = {
"commits" => [{"id" => commit, "message"=>"[deploy #{envname}#{migrate ? ' migrate' : ''}]"}],
"ref" => "refs/heads/master",
}
puts "Triggering a deploy for #{commit} on #{envname}"
begin
response = RestClient.post("https://cloud.engineyard.com/github/#{token}",
:payload => payload.to_json)
puts "Successfully triggered the deploy"
rescue RestClient::RequestFailed => e
puts "Could not deploy your changes"
puts e.response.code
puts e.response.body
exit 1
end
end
end
@jonah-williams
Copy link
Author

@wojt-eu I would expect this to still work but I think there is now a better option. Take a look at EngineYard's CLI gem which you can use to trigger a deploy of a specific git revision: https://support.cloud.engineyard.com/entries/21009927-deploy-from-the-cli-engine-yard-cli-user-guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment