Ruby on Rails devcontainer setup that includes Ruby, Ruby on Rails, PostgreSQL, Redis.
Softwares:
- Latest version of Git version control system
- Version
3.2.4of Ruby programming language - Version
20of 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:
- Docker
- GitLens
- Ruby LSP
- Code Spell Checker
- Git Graph
- git-autoconfig
- Path Intellisense
- Material Icon Theme
- Ruby Haml
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.
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
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: 5432This 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.
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.
- 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
.devcontainerdirectory - 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 :)