- Bash
- Docker
-
Update Postgres and Redis connection configurations
# config/database.yml host: postgres port: 5432 username: postgres password: password
# config/initializers/sidekiq.rb Sidekiq.configure_server do |config| config.redis = {url: "redis://redis_queue:6379/1"} end Sidekiq.configure_client do |config| config.redis = {url: "redis://redis_queue:6379/1"} end
# config/environments/development.rb config.cache_store = :redis_cache_store, { url: "redis://redis_cache:6379/1" }
-
Create redis configuration files
Use the example files provided by Redis. https://raw.githubusercontent.com/redis/redis/6.0/redis.conf
-
config/redis-cache.conf
- setup for LRU cachemaxmemory 128mb maxmemory-policy allkeys-lru
-
config/redis-queue.conf
-
-
Run the app and all it's services
bin/docker/up
Note: It's possible that some services may not start on first boot. Simply run
bin/docker/restart
if anything fails to start. -
Develop on the host OS using your preferred editor and tools
This setup will create the following Docker containers for your Rails application.
- postgres - the primary database
- redis_cache - the application cache
- redis_queue - the background job queue
- web - the rails web server
- worker - the rails background job runner
- webpack - the dev server that serves webpack assets
- shell - a container dedicated to running scripts (bash commands, rails commands, etc...)
The docker containers mount the following volumes on the host. This ensures that data is preserved even when containers are destroyed.
.docker_volumes/postgres
.docker_volumes/redis_cache
.docker_volumes/redis_queue
-
bin/docker/up
- starts the entire containerized environment -
bin/docker/down
- stops all services and removes containers, networks, volumes, and images -
bin/docker/start
- starts stopped containersbin/docker/start bin/docker/start web bin/docker/start webpack bin/docker/start worker
-
bin/docker/stop
- stops containers without removing thembin/docker/stop bin/docker/stop web bin/docker/stop webpack bin/docker/stop worker
-
bin/docker/restart
- restarts containersbin/docker/restart bin/docker/restart web bin/docker/restart webpack bin/docker/restart worker
-
bin/docker/attach
- attach to container, useful for debugging with pry and byebugbin/docker/attach web bin/docker/attach webpack bin/docker/attach worker <CTRL-P><CTRL-Q>
-
bin/docker/exec
- executes a command inside a containerbin/docker/exec bash
-
bin/docker/tail
- tail logs in a containerbin/docker/tail web bin/docker/tail webpack bin/docker/tail worker
-
bin/docker/rails
- executes a rails command inside a containerbin/docker/rails c bin/docker/rails db:migrate bin/docker/rails credentials:edit
-
Add a breakpoint to the project
binding.pry
-
Attach to the appropriate container to debug
bin/docker/attach web
-
Detach from the container when finished
<CTRL-P><CTRL-Q>