I’m working on a application which is deployed to Engine Yard’s Cloud infrastructure and I wanted to automatically redeploy the application whenever our tests passed on our continuous integration server.
Engine Yard will eventually allow us to push a branch to our cloud environment from git (ie “git push engineyard master”) but until that is available the best option seems to be to trigger a github post receive hook directly.
To that end I rewrote an existing script to trigger post receive hooks as a rake task; http://gist.github.com/271433
require 'rubygems'
require 'json'
begin
require 'restclient'
rescue Exception
endnamespace :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'
enddesc 'Trigger a GitHub Post Receive Hook to deploy and migrate the app'
task :deploy_and_migrate do
post_receive_hook 'preview', true
enddef post_receive_hook(envname, migrate=false)
token = `git config --get cloud.token`.chompif token.empty?
token = ENV['cloud.token'] endif token.empty?
puts < [{"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
[/sourcecode]In setting this up I discovered a couple of potential stumbling points:
The folks at Engine Yard are working to correct some of those issues and now I've got a project which automatically pushes changes to the cloud every time our tests cycle.