From ac052edd3b241961e883aa15d22c473824234358 Mon Sep 17 00:00:00 2001 From: Ben Sheldon Date: Fri, 23 Jul 2021 15:25:49 -0700 Subject: [PATCH] Add Heroku demo application --- Procfile | 2 ++ Rakefile | 1 + app.json | 34 +++++++++++++++++++++++ bin/test_app_rake | 5 ++++ spec/test_app/Rakefile | 18 ++++++++++++ spec/test_app/config/database.yml | 5 ++++ spec/test_app/config/environments/demo.rb | 10 +++++++ spec/test_app/config/routes.rb | 2 +- 8 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Procfile create mode 100644 app.json create mode 100755 bin/test_app_rake create mode 100644 spec/test_app/config/environments/demo.rb diff --git a/Procfile b/Procfile new file mode 100644 index 000000000..165c96e68 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: bin/test_app_rake heroku:release +web: bin/test_app server diff --git a/Rakefile b/Rakefile index af94a8f61..9a86eb62e 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ end require 'dotenv/load' require_relative "lib/good_job/version" +Rake.load_rakefile 'spec/test_app/Rakefile' require 'rdoc/task' diff --git a/app.json b/app.json new file mode 100644 index 000000000..3e55ac752 --- /dev/null +++ b/app.json @@ -0,0 +1,34 @@ +{ + "name": "Day of the Shirt", + "description": "Daily pop-culture t-shirt sales", + "website": "https://dayoftheshirt.com/", + "repository": "https://github.com/bensheldon/dayoftheshirt-rails", + "env": { + "BUNDLE_WITHOUT": { + "description": "Install all Ruby gems, including dev dependencies", + "value": "_blank" + }, + "RACK_ENV": { + "value": "production" + }, + "RAILS_ENV": { + "value": "demo" + }, + "SECRET_KEY_BASE": { + "generator": "secret" + } + }, + "buildpacks": [ + { + "url": "heroku/ruby" + } + ], + "addons": [ + { + "plan": "heroku-postgresql" + } + ], + "scripts": { + "postdeploy": "bin/test_app_rake heroku:postdeploy" + } +} diff --git a/bin/test_app_rake b/bin/test_app_rake new file mode 100755 index 000000000..7faaf75d7 --- /dev/null +++ b/bin/test_app_rake @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../spec/test_app/config/application', __dir__) +ARGV << '-f' << File.expand_path('../spec/test_app/Rakefile', __dir__) +require_relative '../spec/test_app/config/boot' +require 'rails/commands' diff --git a/spec/test_app/Rakefile b/spec/test_app/Rakefile index e85f91391..ea6d8af2a 100644 --- a/spec/test_app/Rakefile +++ b/spec/test_app/Rakefile @@ -4,3 +4,21 @@ require_relative 'config/application' Rails.application.load_tasks + +namespace :heroku do + desc 'Heroku release tasks (runs on every code push, before postdeploy task on review app creation)' + task release: :environment do + unless ActiveRecord::SchemaMigration.table_exists? + Rails.logger.info "Database not initialized, skipping release tasks..." + next + end + + Rake::Task['db:migrate'].invoke + end + + desc 'Heroku postdeploy tasks (runs only on review app creation, after release task)' + task postdeploy: :environment do + Rake::Task['db:schema:load'].invoke + Rake::Task['db:seed'].invoke + end +end diff --git a/spec/test_app/config/database.yml b/spec/test_app/config/database.yml index f52918b13..2f4765519 100644 --- a/spec/test_app/config/database.yml +++ b/spec/test_app/config/database.yml @@ -82,3 +82,8 @@ test: production: <<: *default database: <%= ENV["CI"] ? "good_job_test" : "good_job_development" %> + +demo: + <<: *default + database: "good_job_demo" + url: <%= ENV['DATABASE_URL'] %> diff --git a/spec/test_app/config/environments/demo.rb b/spec/test_app/config/environments/demo.rb new file mode 100644 index 000000000..a45095d6b --- /dev/null +++ b/spec/test_app/config/environments/demo.rb @@ -0,0 +1,10 @@ +require_relative 'production' + +GoodJob.preserve_job_records = true +GoodJob.retry_on_unhandled_error = false + +Rails.application.configure do + config.active_job.queue_adapter = :good_job + config.good_job.execution_mode = :async_server + config.good_job.poll_interval = 30 +end diff --git a/spec/test_app/config/routes.rb b/spec/test_app/config/routes.rb index 15d7ff522..950e86e49 100644 --- a/spec/test_app/config/routes.rb +++ b/spec/test_app/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + root to: redirect('/good_job') mount GoodJob::Engine => "/good_job" get :create_job, to: 'application#create_job'