This repo contains a setup for devcontainer using Ruby on Rails with Postgres.
For ease of use, we also included a generated Rails template using the container here.
- VSCode with
Remote - Containers
extension installed
There are two different ways to use this repo,
-
Download this repo
-
Copy the
.devcontainer
folder to your project folder -
Open project folder in VSCode, open
View -> Command Palette
and inputRemote-Containers: Rebuild and Reopen in Container
-
Done! Now your project is opened in a Ruby on rails environment!
-
Click "Use this template", and setup your desired repo name
-
Clone the project under your repo
-
Open project folder in VSCode, open
View -> Command Palette
and inputRemote-Containers: Rebuild and Reopen in Container
-
Done! Now your project is opened in a Ruby on rails environment!
Once the setup is completed, there is no need to rebuild the container everytime.
To reopen a project, open the project under the Welcome
page. A properly setup project's name is always suffixed with [Dev Container]
.
The devcontainer comes with heroku-cli
preinstalled, all you need to do before is heroku login
.
-
Ensure the database configs are setup correctly (
config/database.yml
file, see example) -
Run
bundle
to install all needed gems -
bundle exec rails db:migrate
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
username: postgres
password: postgres
host: localhost
port: 5432
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
Default settings are as follows,
- username:
postgres
- password:
postgres
- host:
localhost
Settings can be modified under .devcontainers/docker-compose.yaml
. Remember to rebuild the container after modifying the settings (Remote-Containers: Rebuild Container
under command palette).
- Ruby
2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
- Rails
6.1.3
- Bundler
2.1.4
- Heroku-cli
7.50.0