File: /var/www/vhosts/yiiwheels.2amigos.us/cgi-bin/deploy.rb
#!/usr/bin/ruby
require 'cgi'
class Servlet
CHECKOUT = 'git clone'
UPDATE = 'git pull'
URL = 'git@github.com:2amigos/yiiwheels-docs.git'
LOG = "/var/www/html/yiiwheels.2amigos.us/logs/deploy.log"
DEPLOG = "/var/www/html/yiiwheels.2amigos.us/logs/deplog.log"
DEPLOY_DIR = "/var/www/html/yiiwheels.2amigos.us/docroot"
#--------------------------------------------------
# Process CGI request
def cgi_process_request
@cgi = CGI.new('html4')
code = 'OK'
comment = ''
# Assembla may test if we are alive
if @cgi['project'].empty?
code = 'OK'
comment = 'Deploy agent is alive'
# Deploy the application
else
tmp = `echo -n ---Start: >> #{LOG}`
tmp = `date >> #{LOG}`
if ! File.directory?(DEPLOY_DIR)
Dir.chdir File.dirname(DEPLOY_DIR)
buildlog = `#{CHECKOUT} #{URL} 2>&1`
else
Dir.chdir DEPLOY_DIR
buildlog = `#{UPDATE} > #{DEPLOG}`
end
comment = "Deploy from URL #{URL} performed successfuly"
if $? != 0
code = 'NOT_FOUND'
comment = "Unable to deploy from URL #{URL}"
end
tmp = `echo Request created from IP: #{CGI.new.remote_addr} >> #{LOG}`
tmp = `echo Deploy requested from IP: #{CGI.new.remote_addr} >> #{DEPLOG}`
tmp = `echo #{comment} >> #{LOG}`
tmp = `echo -n ---End: >> #{LOG}`
tmp = `date >> #{LOG}`
end
@cgi.out("status" => code,
"type" => "text/html") {comment}
end
end
Servlet.new.cgi_process_request