Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created April 8, 2014 20:09
Show Gist options
  • Save squeedee/10183453 to your computer and use it in GitHub Desktop.
Save squeedee/10183453 to your computer and use it in GitHub Desktop.
zip up the buildpack and install it as an admin buildpack (and other stuff)
require "tmpdir"
require "zip"
EXCLUDE_FROM_BUILDPACK = [
/\.git/,
/repos/
]
def package
Dir.mktmpdir do |temp_dir|
copy_buildpack_contents(temp_dir)
compress_buildpack(temp_dir)
end
end
def copy_buildpack_contents(target_path)
run_cmd "cp -r * #{target_path}"
end
def in_pack?(file)
!EXCLUDE_FROM_BUILDPACK.any? { |re| file =~ re }
end
def compress_buildpack(target_path)
Zip::File.open('ruby_buildpack.zip', Zip::File::CREATE) do |zipfile|
Dir[File.join(target_path, '**', '**')].each do |file|
zipfile.add(file.sub(target_path + '/', ''), file) if (in_pack?(file))
end
end
end
def run_cmd(cmd)
puts "$ #{cmd}"
output = `#{cmd}`
puts output
output
end
run_cmd("rm ruby_buildpack.zip")
package
run_cmd("cf delete-buildpack heroku-buildpack -f")
run_cmd("cf create-buildpack heroku-buildpack ruby_buildpack.zip 1 --enable")
run_cmd("rm ruby_buildpack.zip")
Dir.chdir("/Users/pivotal/workspace/buildpacks/heroku-buildpack-ruby-integration/test_applications/rails_latest_web_app") do
run_cmd """
cf delete -f rails_latest_web_app &&
cf push rails_latest_web_app --no-start &&
cf bind-service rails_latest_web_app lilelephant &&
cf push rails_latest_web_app -c 'bundle exec rake db:migrate && bundle exec rails s -p $PORT' -b heroku-buildpack
"""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment