/forge

Template for common Rails tools and configuration

Primary LanguageRuby

Overview

Forge is a Rails application template that installs common tools and performs common configurations to avoid repetition

Requirements

  • Rails (gem install rails)

Compatiblity

This has been tested with the newest Rails version at the time of writing, which is 7.1.3

Usage

New applications

Recommended previous step (RVM)

Use RVM or a similar Ruby version manager and isolate this app to its own gemset. With RVM, you can do this by adding .ruby-version and .ruby-gemset files in a new folder. If you do this, instead of calling rails new YOUR_APP_NAME, you can use rails new . in the command below.

# -d postgresql uses PostgreSQL instead of SQLite. It will be configured as expected.
# -T skips tests, since we will include RSpec.
rails new YOUR_APP_NAME -d postgresql -T -m https://raw.githubusercontent.com/higo-app/forge/main/lib/template.rb

Existing applications

# In your app's root folder
bin/rails app:template LOCATION=https://raw.githubusercontent.com/higo-app/forge/main/lib/template.rb

Applying only specific features

# In your app's root folder, for example if we only want to add Redis config
bin/rails app:template LOCATION=https://raw.githubusercontent.com/higo-app/forge/main/lib/settings/redis.rb

Features

App features (dependencies, configuration)

  • pg: Connects to a Postgres database. Configures a minimalistic config/database.yml and, optionally, configures UUID primary keys.
  • redis: Adds dependency and a single config/redis/shared.yml configuration, to be used by ActionCable, Kredis, Sidekiq, etc.
  • sidekiq: Background jobs
  • strong_migrations: Catches unsafe DB migrations
  • sentry-ruby: Error reporting. Adds and configures dependency. Also includes sentry-rails and sentry-sidekiq.
  • analytics-ruby: Segment analytics (customer data platform). Adds and configures dependency.
  • devise (Optional): Adds dependency, runs initializer, changes a couple of configurations, adds translations and optionally adds flashes to the application layout and a static page as a root path.
  • tailwindcss-rails (Optional): Adds dependency and runs initializer
  • Add Procfile (web, worker and release processes) and Procfile.dev (web and worker processes, although tailwind may also add a css process). Also includes bin/dev which runs Procfile.dev with foreman
  • Add staging environment (copy from production)
  • Compress (gzip) responses with Rack::Deflater in production and staging.
  • Changes default from (i.e. sender) in ApplicationMailer
  • Allows adding I18n available and default locales (from svenfuchs/rails-i18n)
  • Allows configuring hosts / default URL options for all environments
  • Populates README.md

Test, CI features

  • brakeman: Find security vulnerabilities in your app (added to GH workflow)
  • bundler-audit: Find vulnerable dependencies (added to GH workflow)
  • rubycritic: Enforce a good quality codebase (added to GH workflow)
  • factory_bot_rails: Simplifies record building/creating in tests
  • rspec-sidekiq: For Sidekiq testing.
  • shoulda-matchers: Simplifies common tests
  • rspec-rails: For tests. Includes, initializes the dependency (without AR fixtures, with transactional fixtures). Integrates with factory_bot_rails, rspec-sidekiq and shoulda-matchers
  • rubocop-rails: Adds and configures this dependency, along with extensions rubocop-performance, rubocop-rspec, rubocop-factory_bot
  • Github:
    • Add Dependabot configuration: .github/dependabot.yml configures weekly updates, groups development dependencies (i.e. the ones in development and test groups) and sentry gems
    • Add PR template
    • Workflows:
      • test: Runs test suite with rspec
      • code_analysis: Runs bundle-audit, rubocop, brakeman, rubycritic