Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule Heroku Backups and Capture backup of existing staging database for Review Apps #826

Merged
merged 11 commits into from
Mar 24, 2017
9 changes: 9 additions & 0 deletions lib/suspenders/adapters/heroku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def set_heroku_rails_secrets
end
end

def set_heroku_backup_schedule
%w(staging production).each do |environment|
run_toolbelt_command(
"pg:backups:schedule DATABASE_URL --at '10:00 UTC'",
environment,
)
end
end

def create_review_apps_setup_script
app_builder.template(
"bin_setup_review_app.erb",
Expand Down
1 change: 1 addition & 0 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AppBuilder < Rails::AppBuilder
:create_staging_heroku_app,
:create_review_apps_setup_script,
:set_heroku_rails_secrets,
:set_heroku_backup_schedule,
:set_heroku_remotes,
:set_heroku_application_host

Expand Down
1 change: 1 addition & 0 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def create_heroku_apps
build :set_heroku_remotes
build :set_heroku_rails_secrets
build :set_heroku_application_host
build :set_heroku_backup_schedule
build :create_heroku_pipeline
build :configure_automatic_deployment
end
Expand Down
15 changes: 15 additions & 0 deletions spec/adapters/heroku_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ module Adapters
)
end

it "sets the heroku backup schedule" do
app_builder = double(app_name: app_name)
allow(app_builder).to receive(:run)

Heroku.new(app_builder).set_heroku_backup_schedule

expect(app_builder).to have_backup_schedule("staging")
expect(app_builder).to have_backup_schedule("production")
end

it "sets the application host" do
app_builder = double(app_name: app_name)
allow(app_builder).to receive(:run)
Expand All @@ -49,6 +59,11 @@ def app_name
SuspendersTestHelpers::APP_NAME
end

def have_backup_schedule(remote_name)
have_received(:run).
with(/pg:backups:schedule DATABASE_URL --at '02:00 America\/Los_Angeles' --remote #{remote_name}/)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [108/80]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [108/80]

end

def have_configured_var(remote_name, var)
have_received(:run).with(/config:add #{var}=.+ --remote #{remote_name}/)
end
Expand Down
3 changes: 3 additions & 0 deletions templates/bin_setup_review_app.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ fi

PARENT_APP_NAME=<%= app_name.dasherize %>-staging
APP_NAME=<%= app_name.dasherize %>-staging-pr-$1

heroku pg:backups:capture --app $PARENT_APP_NAME

URL=`heroku pg:backups public-url --app $PARENT_APP_NAME`

heroku pg:backups restore $URL DATABASE_URL --confirm $APP_NAME --app $APP_NAME
Expand Down