Aplicativo Sinatra para implantar branch master com base na carga útil SemaphoreApp

Leia-me

Este aplicativo Sinatra é instalado em nosso servidor de teste da seguinte forma:

[wbrent @ dev-web1 deploy] $ pwd

/var/www/deploy

[wbrent @ dev-web1 implantar] $ tree

.
|-- Gemfile
|-- Gemfile.lock
|-- app.rb
|-- config.ru
|-- public
`-- tmp

Gemfile

source :rubygems

gem
'shotgun'
gem
'sinatra'
gem
'yajl-ruby'
gem
'tinder'

app.rb

post '/deploy' do

json
= request.body.read
data
= Yajl::Parser.parse(json)
token
= ENV['CAMPFIRE_TOKEN']
subdomain
= ENV['CAMPFIRE_SUBDOMAIN']
chatroom
= ENV['CAMPFIRE_CHATROOM']
campfire
= Tinder::Campfire.new subdomain, :token => token, :ssl_verify => false
room
= campfire.find_room_by_name(chatroom)
commit
= data['commit']

if data['branch_name'] == 'master' && data['result'] == 'passed'
room
.paste <<-END_OF_MESSAGE
Deploying to staging
Commit SHA1: #{commit['id']}
Author: #{commit['author_name']}
#{commit['message']}"
END_OF_MESSAGE


command
= "cd ~/path/to/deployment; git pull origin master; cap deploy staging"
pipe
= IO.popen(command)
response
= pipe.readlines
else
room
.paste <<-END_OF_MESSAGE
Skipping SemaphoreApp payload
Branch: #{data['branch_name']}
Build status: #{data['result']}
END_OF_MESSAGE

end
end

config.ru

require 'rubygems'
require 'sinatra'
require 'yajl'
require 'tinder'
require File.dirname(__FILE__) + "/app.rb"
run
Sinatra::Application

/etc/httpd/conf/httpd.conf

<VirtualHost *:80>
ServerName your.ip.address

DocumentRoot /var/www/deploy/public

<Directory /var/www/deploy/public>
AllowOverride all

Options -MultiViews

</Directory>
</VirtualHost>

Para obter mais dicas sobre UNIX, consulte
Learning the UNIX Command Line .

Aproveite,
Chip