Created
December 4, 2012 20:05
-
-
Save chip/4208127 to your computer and use it in GitHub Desktop.
Deploy to staging server based on Payload JSON from SemaphoreApp
This file contains hidden or 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
| post '/deploy' do | |
| json = request.body.read | |
| data = Yajl::Parser.parse(json) | |
| token = ENV['CAMPFIRE_TOKEN'] | |
| account = ENV['CAMPFIRE_ACCOUNT'] | |
| campfire = Tinder::Campfire.new account, :token => token, :ssl_verify => false | |
| room = campfire.find_room_by_name("Rental Dev") | |
| commit = data['commit'] | |
| if data['branch_name'] == 'master' && data['result'] == 'passed' | |
| deploy_notification <<-END_OF_MESSAGE | |
| Deploying #{commit['id']} to staging | |
| #{commit['message']}" | |
| END_OF_MESSAGE | |
| room.paste deploy_notification | |
| workspace = 'rentwb_for_deployment' | |
| commands = ['git pull origin master', 'bundle install', 'bundle exec cap staging deploy:migrations'] | |
| begin | |
| commands.each do |command| | |
| command = "cd #{workspace} && #{command}" | |
| room.speak "Executing: #{command}" | |
| io = IO.popen(command) | |
| io.each do |line| | |
| write_log(line, :master) | |
| end | |
| end | |
| rescue => e | |
| write_log(e.inspect, :master) | |
| write_log("", :master) | |
| end | |
| end | |
| end | |
| def write_log(string, filename) | |
| file = File.new("log/deploy_#{filename.to_s}.log", "a") | |
| file << string.to_s | |
| file.close | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment