Skip to content

Ruby on Rails devcontainer setup that includes Ruby, Ruby on Rails, Selenium, PostgreSQL, Redis, MeiliSearch, and Memcached

Notifications You must be signed in to change notification settings

AliOsm/ruby-on-rails-devcontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Ruby on Rails DevContainer

Ruby on Rails DevContainer setup that includes Ruby, Ruby on Rails, Selenium, PostgreSQL, Redis, Memcached, and MeiliSearch.

Pre-requisits

What are we setting up in this DevContainer?

Softwares:

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

This DevContainer setup does the following for you while building the image:

  • Runs gem update --system
  • Runs bundle
  • Runs yarn
  • Runs rails db:create db:migrate db:seed

You can customize this behavior inside .devcontainer/setup.sh file.

Formatting

This DevContainer setup assumes that you are using erb-lint, erb-formatter, and i18n-tasks gems, as it sets up formatting commands using Run on Save VSCode extension to format erb, css, and yml files. See devcontainer.json lines 83-106 for more details.

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 db inside .devcontainer/docker-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 redis inside .devcontainer/docker-compose.yml, and you should access it by its name.

Memcached

Make sure to change config.cache_store = :memory_store to config.cache_store = :mem_cache_store inside config/environments/development.rb. Also, you will need to enable caching in development by running rails dev:cache command.

No need to specify the Memcached server as it is already defined inside .devcontainer/Dockerfile like this ENV MEMCACHE_SERVERS=memcached:11211.

MeiliSearch

Inside your config/initializers/meilisearch.rb initializer, make sure to set the meilisearch_url and meilisearch_api_key properties like this:

MeiliSearch::Rails.configuration = {
  meilisearch_url: ENV['MEILISEARCH_HOST'] || 'http://meilisearch:7700',
  meilisearch_api_key: ENV['MEILISEARCH_KEY'] || 'LOCAL_TEST_KEY'
}

You should define MEILISEARCH_HOST and MEILISEARCH_KEY in your production environment, while in development http://meilisearch:7700 and LOCAL_TEST_KEY will be used. This is required because the docker service for MeiliSearch is named meilisearch inside .devcontainer/docker-compose.yml, and you should access it by its name.

If you changed the meilisearch_api_key to something different than LOCAL_TEST_KEY, make sure to update .devcontainer/docker-compose.yml also.

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 :)

About

Ruby on Rails devcontainer setup that includes Ruby, Ruby on Rails, Selenium, PostgreSQL, Redis, MeiliSearch, and Memcached

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published