Skip to content

Instantly share code, notes, and snippets.

@gbissett
Created March 18, 2012 08:13

Revisions

  1. gbissett revised this gist Mar 18, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion minibuild.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    require 'sinatra'
    require 'haml'

    CODE_PATH = '/repo/lives/here'
    RVM_COMMAND = '[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm'
  2. gbissett created this gist Mar 18, 2012.
    30 changes: 30 additions & 0 deletions minibuild.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    require 'sinatra'
    require 'haml'

    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