-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance base Rails template with better docs, etc
- Add improved bin/setup script - Specify 2-space indent and other general editor settings - Generate documentation - Create a Procfile - Set up default rake task - DRY up Gemfile and .ruby-version file - Improve title and meta information for HTML layout - Disable legacy javascript and stylesheet generators - Allow force_ssl to be controlled via env var - Create initial schema.rb - Set default time zone: America/Los_Angeles
- Loading branch information
Showing
13 changed files
with
200 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# https://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import("prettier").Config} */ | ||
|
||
module.exports = { | ||
tabWidth: 2, | ||
useTabs: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Deployment | ||
|
||
## Environment variables | ||
|
||
These environment variables affect how the app functions when deployed in production. | ||
|
||
- `RAILS_DISABLE_SSL` - Disable HSTS and secure cookies | ||
- `RAILS_ENV` **REQUIRED** - "production" | ||
- `RAILS_MAX_THREADS` - Number of threads per Puma process (default: 5) | ||
- `SECRET_KEY_BASE` **REQUIRED** - Unique, secret key used to encrypt and sign cookies and other sensitive data | ||
- `WEB_CONCURRENCY` - Number of Puma processes (default: number of CPUs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: bundle exec puma -C config/puma.rb | ||
release: bundle exec rake db:migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,48 @@ | ||
# README | ||
# shore | ||
|
||
This README would normally document whatever steps are necessary to get the | ||
application up and running. | ||
This is a Rails 7.1 app. | ||
|
||
Things you may want to cover: | ||
## Prerequisites | ||
|
||
* Ruby version | ||
This project requires: | ||
|
||
* System dependencies | ||
- Ruby (see [.ruby-version](./.ruby-version)), preferably managed using [rbenv](https://github.com/rbenv/rbenv) | ||
- PostgreSQL must be installed and accepting connections | ||
|
||
* Configuration | ||
On macOS, these [Homebrew](http://brew.sh) packages are recommended: | ||
|
||
* Database creation | ||
``` | ||
brew install rbenv | ||
brew install postgresql@16 | ||
``` | ||
|
||
* Database initialization | ||
## Getting started | ||
|
||
* How to run the test suite | ||
### bin/setup | ||
|
||
* Services (job queues, cache servers, search engines, etc.) | ||
Run this script to install necessary dependencies and prepare the Rails app to be started for the first time. | ||
|
||
* Deployment instructions | ||
``` | ||
bin/setup | ||
``` | ||
|
||
* ... | ||
> [!TIP] | ||
> The `bin/setup` script is idempotent and is designed to be run often. You should run it every time you pull code that introduces new dependencies or makes other significant changes to the project. | ||
### Run the app! | ||
|
||
Start the Rails server with this command: | ||
|
||
``` | ||
bin/rails s | ||
``` | ||
|
||
The app will be located at <http://localhost:3000/>. | ||
|
||
## Development | ||
|
||
Use this command to run the full suite of automated tests: | ||
|
||
``` | ||
bin/rake | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,107 @@ | ||
#!/usr/bin/env ruby | ||
require "fileutils" | ||
|
||
# path to your application root. | ||
APP_ROOT = File.expand_path("..", __dir__) | ||
# This script is a way to set up or update your development environment automatically. | ||
# This script is idempotent, so that you can run it at any time and get an expectable outcome. | ||
# Add necessary setup steps to this method. | ||
def setup! | ||
env ".env", from: ".env.sample" | ||
run "bundle install" if bundle_needed? | ||
run "overcommit --install" if overcommit_installable? | ||
run "bin/rails db:prepare" if database_present? | ||
run "yarn install" if yarn_needed? | ||
run "bin/rails tmp:create" if tmp_missing? | ||
run "bin/rails restart" | ||
|
||
def system!(*args) | ||
system(*args, exception: true) | ||
if git_safe_needed? | ||
say_status :notice, | ||
"Remember to run #{colorize("mkdir -p .git/safe", :yellow)} to trust the binstubs in this project", | ||
:magenta | ||
end | ||
|
||
say_status :Ready!, | ||
"Use #{colorize("bin/rails s", :yellow)} to start the app, " \ | ||
"or #{colorize("bin/rake", :yellow)} to run tests" | ||
end | ||
|
||
def run(command, echo: true, silent: false, exception: true) | ||
say_status(:run, command, :blue) if echo | ||
with_original_bundler_env do | ||
options = silent ? {out: File::NULL, err: File::NULL} : {} | ||
system(command, exception: exception, **options) | ||
end | ||
end | ||
|
||
def run?(command) | ||
run command, silent: true, echo: false, exception: false | ||
end | ||
|
||
def bundle_needed? | ||
!run("bundle check", silent: true, exception: false) | ||
end | ||
|
||
FileUtils.chdir APP_ROOT do | ||
# This script is a way to set up or update your development environment automatically. | ||
# This script is idempotent, so that you can run it at any time and get an expectable outcome. | ||
# Add necessary setup steps to this file. | ||
def overcommit_installable? | ||
File.exist?(".overcommit.yml") && !File.exist?(".git/hooks/overcommit-hook") && run?("overcommit -v") | ||
end | ||
|
||
puts "== Installing dependencies ==" | ||
system! "gem install bundler --conservative" | ||
system("bundle check") || system!("bundle install") | ||
def database_present? | ||
File.exist?("config/database.yml") | ||
end | ||
|
||
# Install JavaScript dependencies | ||
system("yarn check --check-files") || system!("yarn install") | ||
def yarn_needed? | ||
File.exist?("yarn.lock") && !run("yarn check --check-files", silent: true, exception: false) | ||
end | ||
|
||
# puts "\n== Copying sample files ==" | ||
# unless File.exist?("config/database.yml") | ||
# FileUtils.cp "config/database.yml.sample", "config/database.yml" | ||
# end | ||
def tmp_missing? | ||
!Dir.exist?("tmp/pids") | ||
end | ||
|
||
puts "\n== Preparing database ==" | ||
system! "bin/rails db:prepare" | ||
def git_safe_needed? | ||
ENV["PATH"].include?(".git/safe/../../bin") && !Dir.exist?(".git/safe") | ||
end | ||
|
||
def with_original_bundler_env(&block) | ||
return yield unless defined?(Bundler) | ||
|
||
puts "\n== Removing old logs and tempfiles ==" | ||
system! "bin/rails log:clear tmp:clear" | ||
Bundler.with_original_env(&block) | ||
end | ||
|
||
def env(env_file, from:) | ||
return unless File.exist?(from) | ||
|
||
unless File.exist?(env_file) | ||
say_status(:copy, "#{from} → #{env_file}", :magenta) | ||
require "fileutils" | ||
FileUtils.cp(from, env_file) | ||
end | ||
|
||
keys = ->(f) { File.readlines(f).filter_map { |l| l[/^([^#\s][^=\s]*)/, 1] } } | ||
|
||
missing = keys[from] - keys[env_file] | ||
return if missing.empty? | ||
|
||
say_status(:WARNING, "Your #{env_file} file is missing #{missing.join(", ")}. Refer to #{from} for details.", :red) | ||
end | ||
|
||
def say_status(label, message, color = :green) | ||
label = label.to_s.rjust(12) | ||
puts [colorize(label, color), message.gsub(/^/, " " * 13).strip].join(" ") | ||
end | ||
|
||
def colorize(str, color) | ||
return str unless color_supported? | ||
|
||
code = {red: 31, green: 32, yellow: 33, blue: 34, magenta: 35}.fetch(color) | ||
"\e[0;#{code};49m#{str}\e[0m" | ||
end | ||
|
||
def color_supported? | ||
if ENV["TERM"] == "dumb" || !ENV["NO_COLOR"].to_s.empty? | ||
false | ||
else | ||
[$stdout, $stderr].all? { |io| io.respond_to?(:tty?) && io.tty? } | ||
end | ||
end | ||
|
||
puts "\n== Restarting application server ==" | ||
system! "bin/rails restart" | ||
Dir.chdir(File.expand_path("..", __dir__)) do | ||
setup! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Rails.application.config.generators do |g| | ||
# Disable generators we don't need. | ||
g.javascripts false | ||
g.stylesheets false | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.