https://github.com/nullstone-io/rails6-api-quickstart
Rails API Quickstart for Nullstone
https://github.com/nullstone-io/rails6-api-quickstart
Last synced: 7 days ago
JSON representation
Rails API Quickstart for Nullstone
- Host: GitHub
- URL: https://github.com/nullstone-io/rails6-api-quickstart
- Owner: nullstone-io
- License: mit
- Created: 2022-05-04T20:12:52.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-17T15:24:15.000Z (almost 3 years ago)
- Last Synced: 2025-10-29T15:38:58.750Z (9 months ago)
- Language: Ruby
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rails API Quickstart
This is a Rails API Quickstart for [Nullstone](https://nullstone.io).
This is based off the official Rails [getting started](https://guides.rubyonrails.org/getting_started.html) guide.
This quickstart is set up with:
- Ruby 3.1
- Rails 6.1
- Postgresql Database
- Migrations are executed on start of docker image
- Error logs are emitted to stdout for docker builds
- Hot reload for local development
## How to launch via Nullstone
1. Create postgresql datastore.
2. Create a public web app. (Remember `app-name` for later)
3. Add the postgresql datastore (from step 1) to the app.
4. Add the `SECRET_KEY_BASE for Rails Cookies` capability to the app.
5. Provision
```shell
nullstone up --wait --block= --env=
```
6. Build, push, and deploy
```shell
docker build -t rails-quickstart .
nullstone launch --source=rails-quickstart --app= --env=
```
## Running locally
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:
- 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:
```shell
docker compose up
```
Then, visit [http://localhost:3000](http://localhost:3000).
### Hot reload
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.
### Update dependencies
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.
```shell
docker compose restart app
```
## Details on quickstart
This web app was generated following these steps.
1. `rails new . --database=postgresql --skip-test --api`
2. Add the following to `Gemfile`
```
group :test do
gem 'rspec-rails'
end
```
3. `bundle install`
4. `rails generate rspec:install`
5. 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
```
5. Swap out the default database config in `config/database.yml`
```yaml
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'] %>
```
6. Comment out production database settings in `config/database.yml`
```yaml
production:
<<: *default
# database: rails6_api_quickstart_production
# username: rails6_api_quickstart
# password: <%= ENV['RAILS6_API_QUICKSTART_DATABASE_PASSWORD'] %>
```