Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Latest commit

 

History

History
86 lines (61 loc) · 3.85 KB

File metadata and controls

86 lines (61 loc) · 3.85 KB

Ruby on Rails Devcontainer

Ruby on Rails devcontainer setup that includes Ruby, Ruby on Rails, PostgreSQL, Redis.

Pre-requisits

What are we setting up in this devcontainer?

Softwares:

  • Latest version of Git version control system
  • Version 3.2.4 of Ruby programming language
  • Version 20 of NodeJS JavaScript runtime environment
  • PostgreSQL database based on the latest official docker image
  • Redis in-memory key-value store based on the latest official docker image
  • postgresql-client

Extensions:

How to use?

Copy the .devcontainer directory into your Ruby on Rails project root directory and open it inside VSCode, then you will be able to use devcontainers as documented here.

Things to be aware of

Automatic setup

At the end of creating containers required for dev setup, it try to runs bin/setup ruby script which comes with Rail project since Rails version 7. If you don't have that script you can skip that command by commenting out "postCreateCommand": "./bin/setup" in .devcontainer/devcontainer.json

PostgreSQL

You need to set the host and port properties for your development and testing databases in config/database.yml like this:

development:
  <<: *default
  database: ror_project_development

  username: postgres
  password: postgres
  host: db
  port: 5432

test:
  <<: *default
  database: ror_project_test

  username: postgres
  password: postgres
  host: db
  port: 5432

This is required because the docker service for PostgreSQL is named as db inside .devcontainer/docket-compose.yml, and you should access it by its name.

If you changed the username and/or password inside config/database.yml, then you will need to change them inside .devcontainer/devcontainer.json file to get sqltools extensions works properly.

Redis

To connect to Redis in the development environment, you need to instantiate the connection like this:

redis = Redis.new(url: ENV['REDIS_URL'] || 'http://redis:6379')

You should define REDIS_URL in your production environment, while in development redis://redis:6379 will be used. This is required because the docker service for Redis is named as redis inside .devcontainer/docket-compose.yml, and you should access it by its name.

Notes

  • This is just a development setup, make sure to setup these services in your production environment also if you are using them
  • Rebuild your devcontainer image when you change any file inside .devcontainer directory
  • Take a look at the installed extensions and modify the list as required
  • This could be used in GitHub Codespaces easily with a single click
  • Feel free to submit any change you feel it is benefitial to this repo :)