Add support for Rails 6.1.0

- Remove postmark TLS workaround that has since been fixed
- Prefer `bin/rails` over `bin/rake` in scripts
- Prefer the default `config/puma.rb` as provided by Rails
- Configure ActiveJob adapter in production (only), as recommended
- Use Rails-provided binstubs instead of what Spring generates
- Ensure all rubocop violations are fixed using `-A`, not `-a`
trunk
Matt Brictson 3 years ago
parent 2d7d61e1ea
commit 4e486d99db
No known key found for this signature in database
GPG Key ID: 2F279EAD1F2ACFAF

@ -35,7 +35,7 @@ jobs:
- run:
name: Install railties
command: |
gem install railties --version "~> 6.0.0" --no-document
gem install railties --version "~> 6.1.0" --no-document
- run:
name: Configure git
command: |

@ -8,16 +8,17 @@ This is the application template that I use for my Rails 6 projects. As a freela
For older versions of Rails, use these branches:
* [Rails 4.2.x](https://github.com/mattbrictson/rails-template/tree/rails-42)
* [Rails 5.0.x](https://github.com/mattbrictson/rails-template/tree/rails-50)
* [Rails 5.1.x](https://github.com/mattbrictson/rails-template/tree/rails-51)
* [Rails 6.0.x](https://github.com/mattbrictson/rails-template/tree/rails-60)
* [Rails 5.2.x](https://github.com/mattbrictson/rails-template/tree/rails-52)
* [Rails 5.1.x](https://github.com/mattbrictson/rails-template/tree/rails-51)
* [Rails 5.0.x](https://github.com/mattbrictson/rails-template/tree/rails-50)
* [Rails 4.2.x](https://github.com/mattbrictson/rails-template/tree/rails-42)
## Requirements
This template currently works with:
* Rails 6.0.x
* Rails 6.1.x
* Bundler 2.x
* PostgreSQL
* chromedriver

@ -9,10 +9,10 @@ def setup!
run "overcommit --install" if overcommit_present?
copy "example.env", ".env.development"
test_local_env_contains_required_keys
run "bin/rake tmp:create"
run "bin/rake db:prepare"
run "bin/rake db:test:prepare"
run "bin/rake db:seed"
run "bin/rails tmp:create"
run "bin/rails db:prepare"
run "bin/rails db:test:prepare"
run "bin/rails db:seed"
run "bin/webpack --display errors-only"
end
end

@ -1,11 +1,3 @@
gsub_file "config/application.rb",
"# config.time_zone = 'Central Time (US & Canada)'",
'config.time_zone = "Pacific Time (US & Canada)"'
insert_into_file "config/application.rb", before: /^ end/ do
<<-'RUBY'
# Use sidekiq to process Active Jobs (e.g. ActionMailer's deliver_later)
config.active_job.queue_adapter = :sidekiq
RUBY
end

@ -1,19 +1,21 @@
uncomment_lines "config/environments/production.rb", /config\.force_ssl = true/
uncomment_lines "config/environments/production.rb", /config\.active_job/
uncomment_lines "config/environments/production.rb", /raise_delivery_errors =/
gsub_file "config/environments/production.rb", ":resque", ":sidekiq"
gsub_file "config/environments/production.rb", /raise_delivery_errors = false/, "raise_delivery_errors = true"
gsub_file "config/environments/production.rb", /\bSTDOUT\b/, "$stdout"
gsub_file "config/environments/production.rb",
"config.force_ssl = true",
'config.force_ssl = ENV["RAILS_FORCE_SSL"].present?'
insert_into_file "config/environments/production.rb", after: /# config\.action_mailer\.raise_deliv.*\n/ do
insert_into_file "config/environments/production.rb", after: /config\.action_mailer\.raise_deliv.*\n/ do
<<-RUBY
# Production email config
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = {
api_token: ENV["POSTMARK_API_KEY"],
http_ssl_version: :TLSv1_2 # TODO: remove this workaround once Postmark supports TLS 1.3
api_token: ENV["POSTMARK_API_KEY"]
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = {
host: "#{production_hostname}",
protocol: "https"

@ -2,7 +2,6 @@ insert_into_file "config/environments/test.rb", after: /config\.action_mailer\.d
<<-RUBY
# Ensure mailer works in test
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: "localhost:3000" }
config.action_mailer.asset_host = "http://localhost:3000"
RUBY

@ -1,48 +0,0 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count)
threads min_threads_count, max_threads_count
port ENV.fetch("PORT", 3000)
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers_count = ENV.fetch("WEB_CONCURRENCY", 1).to_i
if workers_count > 1
workers workers_count
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
preload_app!
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
end
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
# Automatically open the browser when in development
require_relative "../lib/puma/plugin/open"
plugin :open

@ -1,9 +1,16 @@
apply "config/application.rb"
template "config/database.yml", force: true
copy_file "config/puma.rb", force: true
remove_file "config/secrets.yml"
copy_file "config/sidekiq.yml"
insert_into_file "config/puma.rb", <<~RUBY, after: /:tmp_restart$/
# Automatically open the browser when in development
require_relative "../lib/puma/plugin/open"
plugin :open
RUBY
gsub_file "config/routes.rb", / # root 'welcome#index'/ do
' root "home#index"'
end

@ -1,6 +1,6 @@
require "bundler"
require "json"
RAILS_REQUIREMENT = "~> 6.0.0".freeze
RAILS_REQUIREMENT = "~> 6.1.0".freeze
def apply_template!
assert_minimum_rails_version
@ -47,7 +47,6 @@ def apply_template!
install_dart_sass unless sprockets?
create_database_and_initial_migration
run_with_clean_bundler_env "bin/setup"
run_with_clean_bundler_env "bundle exec spring binstub --all"
binstubs = %w[brakeman bundler bundler-audit guard rubocop sidekiq terminal-notifier]
run_with_clean_bundler_env "bundle binstubs #{binstubs.join(' ')} --force"
@ -186,12 +185,12 @@ def run_with_clean_bundler_env(cmd)
end
def run_rubocop_autocorrections
run_with_clean_bundler_env "bin/rubocop -a --fail-level A > /dev/null || true"
run_with_clean_bundler_env "bin/rubocop -A --fail-level A > /dev/null || true"
end
def create_database_and_initial_migration
return if Dir["db/migrate/**/*.rb"].any?
run_with_clean_bundler_env "bin/rake db:create"
run_with_clean_bundler_env "bin/rails db:create"
run_with_clean_bundler_env "bin/rails generate migration initial_migration"
end

Loading…
Cancel
Save