Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bf4
Forked from anonymous/bootstrap.rb
Last active December 11, 2015 02:48
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 bf4/4532770 to your computer and use it in GitHub Desktop.
Save bf4/4532770 to your computer and use it in GitHub Desktop.

bootstrap script

  • a la zachholman http://zachholman.com/talk/ruby-patterns/

  • dependency checks

    • is mysql installed? (here's how to install it)
    • is redis running? (here's how to run it)
  • bundler

    • bundle install --binstubs --local --path=vendor/gems --without=production
  • db creation

    • rake db:create
  • db migration

    • rake db:migrate
  • db seeding

    • script/replicate-repo see rtomayko/replicate
    • e.g. script/replicate-repo holman/spark (clones issues, pull requests, users, git data, etc)
  • asset / static page compilation

    • 404, 500
  • language compilation

    • python, c, erlang...
  • cache bootstrap results

    • Check if we need to bundle install Gemfile and assets

script

 md5 << File.read('Gemfile')
 checksum = md5.hexdigest
 installed = File.read('.bundle/checksum').strip
  • We add script/cibuild to most projects. Lets us keep test config in the repository.

script

# set env vars
export RACK_ROOT=["..."]
export RACK_ENV="test"
# load gc ocnfig
# clean work dir
script/bootstrap
bin/rake

gh-setup

  • apps: dropbox + homebrew + chrome + 1password + etc.
  • dependencies: mysql + node + redis + riak + postgres + rbenv + etc.
  • config: disk encryption + vpn + screen locks + etc.
  • puppet

deploy locking (hubon + heaven)

  • you push a branch
  • ci starts a build
  • build passes
  • you deploy branch
  • 'heaven' prevents deploy conflicts
  • you merge branch
  • 'heaven' unlocks deploys
gem 'rake', '=0.8.7'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
#TODO don't shell out quite as much
namespace :bootstrap do
task :dev => ['bootstrap:copy_configs', 'bootstrap:bundle_gems', 'bootstrap:database'] do
run_cmd "bundle exec rake db:test:prepare"
end
task :ci => ['bootstrap:copy_configs','bootstrap:bundle_gems_ci', 'bootstrap:database']
#
# task :dependency checks
#
task :bundle_gems do
run_cmd "bundle"
end
task :bundle_gems_ci do
run_cmd "bundle --without production --path=gems"
# `bundle install --binstubs --local --path=vendor/gems --without=production`
end
task :copy_configs do
run_cmd "cp #{Rails.root}/config/app_config.yml.default #{Rails.root}/config/app_config.yml"
run_cmd "cp #{Rails.root}/config/database.yml.default #{Rails.root}/config/database.yml"
end
task :database => [:load_bundler, :environment] do
# task :db creation
# * `rake db:create`
# task :db migration
# * `rake db:migrate`
# task :db seeding
# * script/replicate-repo see [rtomayko/replicate](https://github.com/rtomayko/replicate)
# * e.g. script/replicate-repo holman/spark (clones issues, pull requests, users, git data, etc)
run_rake_task('db:setup')
end
task :load_bundler do
require "bundler/setup"
# Bundle.setup(:development,:test)
end
# * task: asset / static page compilation
# * 404, 500
# * task: language compilation
# * python, c, erlang...
# * task: cache bootstrap results
# * Check if we need to bundle install Gemfile and assets
#
# md5 << File.read('Gemfile')
# checksum = md5.hexdigest
# installed = File.read('.bundle/checksum').strip
end
desc 'run ci build'
task :ci => ['bootstrap:ci'] do
# these don't work right now
# run_rake_task('db:test:prepare')
# run_rake_task('spec')
# require 'rspec/core/rake_task'
# RSpec::Core::RakeTask.new(:spec)
# task :default => :spec
# * We add script/cibuild to most projects. Lets us keep test config in the repository.
#
# # set env vars
# export RACK_ROOT=["..."]
# export RACK_ENV="test"
# # load gc ocnfig
# # clean work dir
# script/bootstrap
# bin/rake
run_cmd "bundle exec rake db:test:prepare"
run_cmd "bundle exec rspec"
end
def run_rake_task(task,*args)
Rake::Task[task].invoke(*args)
end
def run_cmd(cmd)
puts "Running\t#{cmd}"
system cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment