Skip to content

Instantly share code, notes, and snippets.

@padwasabimasala
Created March 31, 2014 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save padwasabimasala/9903284 to your computer and use it in GitHub Desktop.
Save padwasabimasala/9903284 to your computer and use it in GitHub Desktop.
Post Receive Hook to Build Jruby Apps
require 'logger'
class Builder
attr :base_dir, :repo, :build_dir, :log
def initialize(dir)
@base_dir = File.expand_path dir
@repo = File.join base_dir, "#{base_dir.split(File::SEPARATOR).last}.git"
@build_dir = File.join base_dir, 'builds', latest_commit
@log = Logger.new STDERR #File.join @base_dir, 'build.log'
log.info "build initialized - base_dir=#{base_dir} repo=#{repo} build_dir=#{build_dir}"
end
def build
clone
bundle
warble
end
private
def latest_commit
unless @latest_commit
Dir.chdir repo
@latest_commit ||= %x{git log -n1 --pretty=oneline | cut -d' ' -f1}.strip
end
@latest_commit
end
def clone
log.info "cloning repo to #{build_dir}"
%x{git clone #{repo} #{build_dir}}
end
def bundle
log.info 'bundling'
Dir.chdir build_dir
%x{/home/deploy/bin/bundle install}
end
def warble
log.info 'warble'
Dir.chdir build_dir
%x{/home/deploy/bin/warble}
end
end
if __FILE__ == $0
%x{rm -Rf /home/deploy/passport/builds/*} # TODO remove
Builder.new(ARGV.first).build
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment