Module: WildlandDevTools::Heroku
- Defined in:
- lib/wildland_dev_tools/heroku.rb
Overview
:nodoc:
Constant Summary collapse
- VALID_REMOTES =
%w(production staging)
Class Method Summary collapse
- .backup_production_database(verbose = false) ⇒ Object
- .copy_production_data_to_staging(verbose = false) ⇒ Object
- .deploy_current_branch_to_staging(verbose = false, force = false) ⇒ Object
- .deploy_master_to_staging(verbose = false, force = false) ⇒ Object
- .deploy_to_staging(branch, verbose = false, force = false) ⇒ Object
- .heroku_toolbelt_available? ⇒ Boolean
- .import_production_database(verbose = false) ⇒ Object
- .import_staging_database(verbose = false) ⇒ Object
- .migrate_production_database(verbose = false) ⇒ Object
- .migrate_staging_database(verbose = false) ⇒ Object
- .production_remote_available? ⇒ Boolean
- .promote_staging_to_production(verbose = false) ⇒ Object
- .remote_available?(remote_name) ⇒ Boolean
- .rollback_production_database(verbose = false) ⇒ Object
- .rollback_production_deploy(verbose = false) ⇒ Object
- .rollback_staging_database(verbose = false) ⇒ Object
- .staging_remote_available? ⇒ Boolean
- .turn_off_heroku_maintenance_mode(verbose = false) ⇒ Object
- .turn_on_heroku_maintenance_mode(verbose = false) ⇒ Object
Class Method Details
.backup_production_database(verbose = false) ⇒ Object
97 98 99 100 101 |
# File 'lib/wildland_dev_tools/heroku.rb', line 97 def backup_production_database(verbose = false) remote = 'production' puts "Backing up the database for #{remote}" if verbose system("heroku pg:backups capture DATABASE -r #{remote}") end |
.copy_production_data_to_staging(verbose = false) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/wildland_dev_tools/heroku.rb', line 87 def copy_production_data_to_staging(verbose = false) puts 'Determining heroku app names.' if verbose staging_app_name = get_app_name('staging', verbose) production_app_name = get_app_name('production', verbose) puts "Copying #{production_app_name} database to #{staging_app_name}." if verbose system( "heroku pg:copy #{production_app_name}::DATABASE_URL DATABASE_URL -a #{staging_app_name} --confirm #{staging_app_name}" ) end |
.deploy_current_branch_to_staging(verbose = false, force = false) ⇒ Object
38 39 40 41 |
# File 'lib/wildland_dev_tools/heroku.rb', line 38 def deploy_current_branch_to_staging(verbose = false, force = false) puts 'Detecting current branch name.' if verbose deploy_to_staging(get_current_branch_name, verbose, force) end |
.deploy_master_to_staging(verbose = false, force = false) ⇒ Object
31 32 33 34 35 |
# File 'lib/wildland_dev_tools/heroku.rb', line 31 def deploy_master_to_staging(verbose = false, force = false) puts 'Detecting current branch name.' if verbose raise GitSyncException, 'Please checkout master branch' unless on_master_branch? deploy_to_staging(get_current_branch_name, verbose, force) end |
.deploy_to_staging(branch, verbose = false, force = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wildland_dev_tools/heroku.rb', line 43 def deploy_to_staging(branch, verbose = false, force = false) case status_of_current_branch when 'Up-to-date' if force puts "Force deploying #{branch} to staging." if verbose system("OVERCOMMIT_DISABLE=1 git push -f staging #{branch}:master") else puts "Deploying #{branch} to staging." if verbose system("OVERCOMMIT_DISABLE=1 git push staging #{branch}:master") end when 'Need to pull' raise GitSyncException, "Need to pull #{branch} from origin." when 'Need to push' raise GitSyncException, "Need to push #{branch} to origin." else raise GitSyncException, "Your local #{branch} has diverged from origin." end end |
.heroku_toolbelt_available? ⇒ Boolean
131 132 133 |
# File 'lib/wildland_dev_tools/heroku.rb', line 131 def heroku_toolbelt_available? system('which heroku > /dev/null 2>&1') end |
.import_production_database(verbose = false) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/wildland_dev_tools/heroku.rb', line 67 def import_production_database(verbose = false) puts 'Determining heroku app names.' if verbose production_app_name = get_app_name('production', verbose) scratch_file_name = 'latest.dump' database_name = Rails.configuration.database_configuration['development']['database'] download_database(production_app_name, scratch_file_name, verbose) import_database(database_name, scratch_file_name, verbose) File.delete(scratch_file_name) end |
.import_staging_database(verbose = false) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/wildland_dev_tools/heroku.rb', line 77 def import_staging_database(verbose = false) puts 'Determining heroku app names.' if verbose staging_app_name = get_app_name('staging', verbose) scratch_file_name = 'latest.dump' database_name = Rails.configuration.database_configuration['development']['database'] download_database(staging_app_name, scratch_file_name, verbose) import_database(database_name, scratch_file_name, verbose) File.delete(scratch_file_name) end |
.migrate_production_database(verbose = false) ⇒ Object
103 104 105 |
# File 'lib/wildland_dev_tools/heroku.rb', line 103 def migrate_production_database(verbose = false) migrate_database('production', verbose) end |
.migrate_staging_database(verbose = false) ⇒ Object
107 108 109 |
# File 'lib/wildland_dev_tools/heroku.rb', line 107 def migrate_staging_database(verbose = false) migrate_database('staging', verbose) end |
.production_remote_available? ⇒ Boolean
123 124 125 |
# File 'lib/wildland_dev_tools/heroku.rb', line 123 def production_remote_available? remote_available? 'production' end |
.promote_staging_to_production(verbose = false) ⇒ Object
62 63 64 65 |
# File 'lib/wildland_dev_tools/heroku.rb', line 62 def promote_staging_to_production(verbose = false) puts 'Promoting staging to production' if verbose system('heroku pipelines:promote -r staging') end |
.remote_available?(remote_name) ⇒ Boolean
127 128 129 |
# File 'lib/wildland_dev_tools/heroku.rb', line 127 def remote_available?(remote_name) Git.open('.').remotes.map(&:to_s).include?(remote_name) end |
.rollback_production_database(verbose = false) ⇒ Object
111 112 113 |
# File 'lib/wildland_dev_tools/heroku.rb', line 111 def rollback_production_database(verbose = false) rollback_codebase('production', verbose) end |
.rollback_production_deploy(verbose = false) ⇒ Object
8 9 10 11 |
# File 'lib/wildland_dev_tools/heroku.rb', line 8 def rollback_production_deploy(verbose = false) rollback_production_codebase(verbose) rollback_production_database(verbose) end |
.rollback_staging_database(verbose = false) ⇒ Object
115 116 117 |
# File 'lib/wildland_dev_tools/heroku.rb', line 115 def rollback_staging_database(verbose = false) rollback_database('staging', verbose) end |
.staging_remote_available? ⇒ Boolean
119 120 121 |
# File 'lib/wildland_dev_tools/heroku.rb', line 119 def staging_remote_available? remote_available? 'staging' end |
.turn_off_heroku_maintenance_mode(verbose = false) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/wildland_dev_tools/heroku.rb', line 22 def turn_off_heroku_maintenance_mode(verbose = false) %w(staging production).each do |remote| if remote_available? remote puts "Turning off maintenance mode for #{remote}" if verbose system("heroku maintenance:off -r #{remote}") end end end |
.turn_on_heroku_maintenance_mode(verbose = false) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/wildland_dev_tools/heroku.rb', line 13 def turn_on_heroku_maintenance_mode(verbose = false) %w(staging production).each do |remote| if remote_available? remote puts "Turning on maintenance mode for #{remote}" if verbose system("heroku maintenance:on -r #{remote}") end end end |