{"id":17599167,"url":"https://github.com/luizkowalski/devcontainer-rails","last_synced_at":"2025-11-11T18:48:07.037Z","repository":{"id":147327476,"uuid":"576409390","full_name":"luizkowalski/devcontainer-rails","owner":"luizkowalski","description":"💎 devcontainer configurations to run Ruby on Rails with PostgreSQL and Redis on GitHub Codespaces (or locally)","archived":false,"fork":false,"pushed_at":"2025-10-19T22:04:24.000Z","size":39,"stargazers_count":88,"open_issues_count":0,"forks_count":28,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-20T04:29:21.719Z","etag":null,"topics":["codespace","codespaces-friendly","postgresql","rails","redis","ruby","ruby-on-rails","valkey","vscode"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luizkowalski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-09T19:33:00.000Z","updated_at":"2025-10-19T22:04:27.000Z","dependencies_parsed_at":"2023-04-28T18:46:39.883Z","dependency_job_id":"3d6f4c7c-332d-47f8-a3ad-37ca83c7a056","html_url":"https://github.com/luizkowalski/devcontainer-rails","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"920fce61ae76d2f18d1d8f34b7d35f2addd4212b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luizkowalski/devcontainer-rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizkowalski%2Fdevcontainer-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizkowalski%2Fdevcontainer-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizkowalski%2Fdevcontainer-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizkowalski%2Fdevcontainer-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luizkowalski","download_url":"https://codeload.github.com/luizkowalski/devcontainer-rails/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luizkowalski%2Fdevcontainer-rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283910074,"owners_count":26915128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-11T02:00:06.610Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codespace","codespaces-friendly","postgresql","rails","redis","ruby","ruby-on-rails","valkey","vscode"],"created_at":"2024-10-22T10:09:23.656Z","updated_at":"2025-11-11T18:48:07.030Z","avatar_url":"https://github.com/luizkowalski.png","language":"Dockerfile","funding_links":[],"categories":["Dockerfile"],"sub_categories":[],"readme":"# Codespace on Rails\n\n## Why?\n\nI've been trying to get some Ruby on Rails projects I have set up on Codespaces. After many tries, I've finally got it working (at least the way I wanted it to), so now I'm creating this repository to keep these changes and copy them to other projects whenever needed.\n\nI mostly copied what was done [here](https://github.com/microsoft/vscode-dev-containers/tree/main/containers/ruby-rails-postgres) and fixed some things that were not working for me or that I didn't need.\n\n## How?\n\n1. Copy the `.devcontainer` folder to your project\n2. Copy `.env.example` to `.env` and customize environment variables\n3. Customize the files to your needs\n4. Open the project in Codespaces\n\n## What's in the box?\n\n- Ruby 3.4.6\n- PostgreSQL 18 (exposed locally on port 5433)\n- Valkey 8 (Redis-compatible, exposed locally on port 6379)\n- Node LTS\n- ZSH and Oh My Zsh\n- Mise version manager\n- Non root user\n\n## Security \u0026 Performance Features\n\nThis configuration includes several security and performance improvements:\n\n### Security\n- **Environment-based credentials**: Database and Redis passwords use environment variables\n- **Valkey authentication**: Password protection enabled by default\n- **Pinned versions**: All Docker images and features use specific versions\n- **Non-root user**: Runs as `vscode` user for better security\n\n### Performance \u0026 Reliability\n- **Service dependencies**: App waits for database and Redis to be healthy before starting\n- **Health checks**: Robust health monitoring with proper startup periods\n- **Resource limits**: Memory limits prevent resource exhaustion (PostgreSQL: 512M, Valkey: 128M)\n- **Optimized volumes**: Named volumes with explicit drivers for better persistence\n\n## Customizations\n\nThere are a couple of things you _can_ customize and a couple of things you _should_ customize.\n\n### Could\n\nYou can choose different Ruby and Node versions by updating the `devcontainer.json` file. Currently, it will install Ruby 3.4.x and Node LTS You can also change the PostgreSQL username and password, although I don't think it matters too much.\n\nYou can also change the project's name under `devcontainer.json` and `docker-compose.yml` if you want to. I've left it as `Your Project Name` for now.\n\nIf you change the `service` name (defaults to `app` right now), remember to update the app section in docker-compose.yml. They have to match.\n\n### Should\n\nYou should, however, update your `database.yml` file if you use one. Here is what mine looks like:\n\n```yaml\ndefault: \u0026default\n  adapter: postgresql\n  encoding: unicode\n  host: postgres     # This is the name of the container in the docker-compose.yml file\n  username: postgres # This is the default username for the postgres image\n  password: postgres # This is the default password for the postgres image\n  pool: \u003c%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %\u003e\n\ndevelopment:\n  \u003c\u003c: *default\n  database: app_development\n\ntest:\n  \u003c\u003c: *default\n  database: app_test\n\nproduction:\n  \u003c\u003c: *default\n  url: \u003c%= ENV[\"DATABASE_URL\"] %\u003e\n```\n\nNotice the `host: postgres`? That's the name of the container in the `docker-compose.yml` file. If you change it to `db`, you must update the `database.yml` file too.\n\n## Environment Variables\n\nThis devcontainer configuration supports customization through environment variables. Copy `.env.example` to `.env` and adjust the values as needed:\n\n### Database Configuration\n- `POSTGRES_USER`: PostgreSQL username (default: `postgres`)\n- `POSTGRES_DB`: PostgreSQL database name (default: `postgres`)\n- `POSTGRES_PASSWORD`: PostgreSQL password (default: `postgres`)\n\n### Valkey/Redis Configuration\n- `VALKEY_PASSWORD`: Valkey password (default: `devpassword`)\n- `VALKEY_PORT`: Host port for Valkey (default: `6379`)\n\n### Rails Configuration\n- `RAILS_ENV`: Rails environment (default: `development`)\n- `SECRET_KEY_BASE`: Rails secret key base\n- `RAILS_MASTER_KEY`: Rails master key for credentials\n\n## Service Connection Examples\n\n### Connecting to Valkey (Redis) from Rails\n\nConfigure in `config/application.rb` or an initializer:\n```ruby\n# config/initializers/redis.rb\nRedis.current = Redis.new(\n  host: 'valkey',  # Service name from docker-compose.yml\n  port: 6379,\n  password: ENV['VALKEY_PASSWORD'] || 'devpassword'\n)\n```\n\nUsing with Rails cache:\n```ruby\n# config/environments/development.rb\nconfig.cache_store = :redis_cache_store, {\n  url: \"redis://:#{ENV['VALKEY_PASSWORD'] || 'devpassword'}@valkey:6379/0\"\n}\n```\n\nUsing with Sidekiq:\n```ruby\n# config/initializers/sidekiq.rb\nSidekiq.configure_server do |config|\n  config.redis = {\n    url: \"redis://:#{ENV['VALKEY_PASSWORD'] || 'devpassword'}@valkey:6379/0\"\n  }\nend\n\nSidekiq.configure_client do |config|\n  config.redis = {\n    url: \"redis://:#{ENV['VALKEY_PASSWORD'] || 'devpassword'}@valkey:6379/0\"\n  }\nend\n```\n\n### Connecting to PostgreSQL from Rails\n\nYour `database.yml` should use the service name and environment variables:\n```yaml\ndefault: \u0026default\n  adapter: postgresql\n  encoding: unicode\n  host: postgres\n  username: \u003c%= ENV['POSTGRES_USER'] || 'postgres' %\u003e\n  password: \u003c%= ENV['POSTGRES_PASSWORD'] || 'postgres' %\u003e\n  pool: \u003c%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %\u003e\n```\n\n## How do I SSH into the Codespace instance?\n\nThis configuration includes an SSH server. To access your codespace instance, you should install the `gh` CLI and run `gh codespace ssh` and select your codespace.\n\n## How do I attach to my container if I'm not using Codespaces?\n\n```bash\ndocker exec -it --user vscode app /bin/zsh\n```\n\nor\n\n```bash\ndevcontainer exec --workspace-folder . zsh\n```\n\n(or use DevContainer VSCode extension)\n\n## Using devcontainer CLI\n\nInstall with `npm install -g @devcontainers/cli`\n\n### Setting it up\n```bash\ndevcontainer up --workspace-folder .\n```\n\n### Checking for outdated dependencies\n\n```bash\ndevcontainer --workspace-folder . outdated\n```\n\n### Upgrading your dependencies\n\n```bash\ndevcontainer upgrade --workspace-folder .\n```\n\n### Removing everything\n\n```bash\ndocker stop $(docker ps -q)\ndocker system prune -a --volumes --force\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizkowalski%2Fdevcontainer-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluizkowalski%2Fdevcontainer-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizkowalski%2Fdevcontainer-rails/lists"}