This is a Rails Web App Quickstart for Nullstone. This is based off the official Rails getting started guide.
This quickstart is set up with:
- Ruby 3.1
- Rails 6.1
- Static Assets
- Configured to hot-reload assets for local development
- Precompiled and served through NGINX for docker builds
- Postgresql Database
- Migrations are executed on start of docker image
- Error logs
- Emitted to stdout for docker builds
- Pretty errors for local development
- Hot reload for local development
- Create postgresql datastore.
- Create a public web app. (Remember
app-name
for later) - Add the postgresql datastore (from step 1) to the app.
- Add the
SECRET_KEY_BASE for Rails Cookies
capability to the app. - Add the
Nginx Sidecar for Fargate Service
capability to the app. - Provision
nullstone up --wait --block=<app-name> --env=<env-name>
- Build, push, and deploy
docker build -t rails-quickstart .
nullstone launch --source=rails-quickstart --app=<app-name> --env=<env-name>
You can run this project locally inside Docker or using rails alone.
To use Docker, this project contains docker-compose.yml
that runs with RAILS_ENV=development
.
This ensures that using Docker doesn't prohibit handy development features:
- Assets are compiled on demand.
- Pretty error logs are displayed in the browser.
- Hot reload is configured so that changes to rails files doesn't require a docker rebuild or restart.
To run using Docker locally, use docker compose:
docker compose up
Then, visit http://localhost:3000.
The app
in docker-compose.yml
is configured to automatically reload changes to files.
You do not need to rebuild/restart the app when making changes to code.
To make changes to dependencies, make changes to Gemfile
and restart your docker container.
bundle install
happens automatically at the boot of the docker container to update dependencies.
docker compose restart app
This web app was generated following these steps.
rails . new --database=postgresql --skip-test --webpack
- Add the following to
Gemfile
group :test do
gem 'rspec-rails'
end
bundle install
rails generate rspec:install
- Set logs to stdout in development mode.
# config/environments/development.rb
...
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
- Swap out the default database config in
config/database.yml
default: &default
adapter: <%= ENV.fetch("DB_ADAPTER") { "postgresql" } %>
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: <%= ENV['DATABASE_URL'] %>
- Comment out production database settings in
config/database.yml
production:
<<: *default
# database: rails6_webapp_quickstart_production
# username: rails6_webapp_quickstart
# password: <%= ENV['RAILS6_WEBAPP_QUICKSTART_DATABASE_PASSWORD'] %>
rails g controller Articles index
- Add the following to
config/routes.rb
root 'articles#index'