-
-
Save jonah-williams/271433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
@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
Will this thing still work?