Skip to content

Instantly share code, notes, and snippets.

@gbissett
Created March 18, 2012 08:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbissett/2069878 to your computer and use it in GitHub Desktop.
Save gbissett/2069878 to your computer and use it in GitHub Desktop.
a build server that is smaller and less capable than cijoe
require 'sinatra'
CODE_PATH = '/repo/lives/here'
RVM_COMMAND = '[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm'
UPDATE_COMMAND = 'git pull'
BUILD_COMMAND = 'bundle && rake db:migrate && rake'
def log(message='')
File.open('build.log', 'a') {|log| log.puts "#{Time.now.utc} #{message}" }
end
get '/*' do
`tail -n 1 build.log`
end
# POST from a github webhook triggers a build
post '/*' do
log 'building...'
build_process = fork { exec "/bin/bash -c '#{RVM_COMMAND} && cd #{CODE_PATH} && #{BUILD_COMMAND}'" }
Process.waitpid(build_process)
if $?.exitstatus.to_i == 0
log 'pass'
system "cd #{CODE_PATH} && .git/hooks/build-worked"
else
log 'fail'
system "cd #{CODE_PATH} && .git/hooks/build-failed"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment