class Jumpup::Deis::Integrate
Attributes
app[R]
envs[R]
Public Class Methods
add_remote()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 26 def self.add_remote message = "Adding Deis git remotes for app #{integrate.app}" integrate.when_branch_send_to_deis(message) do integrate.add_remote end end
check()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 33 def self.check message = "Checking if there's already someone integrating to #{integrate.app}" integrate.when_branch_send_to_deis(message) do integrate.check end end
deploy()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 10 def self.deploy message = "Starting to deploy on Deis app #{integrate.app}" integrate.when_branch_send_to_deis(message) do integrate.deploy end end
deploy_to_production()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 17 def self.deploy_to_production app = Env.all[:production_app] integrate = new(app) message = "Starting to deploy to production on Deis app #{integrate.app}" integrate.when_branch_send_to_deis(message) do integrate.deploy_to_production end end
integrate()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 40 def self.integrate envs = Env.all app = envs[:app] || envs[:staging_app] new(app) end
new(app)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 46 def initialize(app) @app = app @envs = Env.all end
Public Instance Methods
add_remote()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 83 def add_remote remote = run_with_clean_env("git remote | grep deis").strip exec_with_clean_env("git remote add deis ssh://git@#{host}:2222/#{app}.git") if remote.blank? end
branches_that_send_to_deis()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 60 def branches_that_send_to_deis [Env.all[:deploy_branch], Env.all[:deploy_to_production_branch]] end
deploy()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 64 def deploy run_database_checks if run_database_tasks? push(Env.all[:deploy_branch]) migrate if run_database_tasks? seed if run_database_tasks? end
deploy_to_production()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 72 def deploy_to_production run_database_checks if run_database_tasks? confirm_deploy spec tag push(Env.all[:deploy_to_production_branch]) migrate if run_database_tasks? seed if run_database_tasks? end
when_branch_send_to_deis(message, &block)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 51 def when_branch_send_to_deis(message, &block) puts "--> #{message}" if branches_that_send_to_deis.include?(actual_branch) block.call else puts "----> Skipping since you are in a feature branch [#{actual_branch}]" end end
Private Instance Methods
actual_branch()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 173 def actual_branch run_with_clean_env("git rev-parse --abbrev-ref HEAD").strip end
check_if_migration_is_needed()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 91 def check_if_migration_is_needed files_changed = run_with_clean_env("git diff HEAD #{latest_remote_sha} --name-only -- db/migrate | wc -l").strip.to_i @migrations_changed = files_changed > 0 end
check_if_seed_is_needed()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 96 def check_if_seed_is_needed files_changed = run_with_clean_env("git diff HEAD #{latest_remote_sha} --name-only -- db/seeds* | wc -l").strip.to_i @seeds_changed = files_changed > 0 end
confirm(message)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 117 def confirm(message) print "\n#{message}\nAre you sure? [yN] " raise 'Ok. Bye...' unless STDIN.gets.chomp.downcase == 'y' end
confirm_deploy()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 149 def confirm_deploy confirm("[#{app}] Deploying to production using branch [#{Env.all[:deploy_to_production_branch]}]") end
exec_with_clean_env(command)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 109 def exec_with_clean_env(command) Bundler.with_clean_env do unless system(command) raise "Error while running #{command}" end end end
host()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 169 def host Env.all[:host] end
latest_remote_sha()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 101 def latest_remote_sha @latest_remote_sha ||= run_with_clean_env("git ls-remote ssh://git@#{host}:2222/#{app}.git HEAD 2>/dev/null | awk '{ print $1 }'").strip end
migrate()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 126 def migrate if @migrations_changed output "Migrating" exec_with_clean_env("deis run rake db:migrate --app #{app}") else output "Skipping migrations" end end
output(message)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 177 def output(message) puts "----> [#{app}] #{message}" end
push(branch)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 144 def push(branch) output "Pushing to #{host} from branch [#{branch}]" exec_with_clean_env("git push ssh://git@#{host}:2222/#{app}.git #{branch}:master") end
run_database_checks()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 181 def run_database_checks check_if_migration_is_needed check_if_seed_is_needed end
run_database_tasks?()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 122 def run_database_tasks? @envs[:run_database_tasks] end
run_with_clean_env(command)
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 105 def run_with_clean_env(command) Bundler.with_clean_env { `#{command}` } end
seed()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 135 def seed if @seeds_changed output "Seeding" exec_with_clean_env("deis run rake db:seed --app #{app}") else output "Skipping seeds" end end
spec()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 153 def spec puts "----> Running all specs" Rake::Task['spec'].invoke end
tag()
click to toggle source
# File lib/jumpup/deis/integrate.rb, line 158 def tag iso_date = Time.now.strftime('%Y-%m-%dT%H%M%S') tag_name = "production-#{iso_date}" puts "----> Tagging as #{tag_name}" exec_with_clean_env("git tag #{tag_name} master") puts "----> Pushing to origin" exec_with_clean_env("git push origin #{tag_name}") end