Skip to content

Commit

Permalink
Merge pull request codeforjapan#628 from codeforjapan/redis-in-docker
Browse files Browse the repository at this point in the history
fix: Use Redis with docker compose
  • Loading branch information
ayuki-joto authored Aug 6, 2024
2 parents 47d3393 + 7bed543 commit 8fd59c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
x-custom:
app:
- &rails_env "development"
- &redis_cache_url "${REDIS_CACHE_URL:-redis://redis:6379/0}"
postgres:
- &postgres_user "${DATABASE_USERNAME:-postgres}"
- &postgres_password "${DATABASE_PASSWORD:-password}"
Expand Down Expand Up @@ -29,9 +30,9 @@ services:
volumes:
- .:/app
- node_modules:/app/node_modules
- rails-tmp:/app/tmp
# exclude volumes
- /app/vendor
- /app/tmp
- /app/log
- /app/.git
environment:
Expand All @@ -40,8 +41,11 @@ services:
DATABASE_USERNAME: *postgres_user
DATABASE_PASSWORD: *postgres_password
RAILS_ENV: *rails_env
REDIS_URL: *redis_cache_url
REDIS_CACHE_URL: *redis_cache_url
links:
- pg
- redis
pg:
image: "ghcr.io/codeforjapan/postgresql_bigm:12-latest"
volumes:
Expand All @@ -51,7 +55,15 @@ services:
POSTGRES_PASSWORD: *postgres_password
ports:
- 5433:5432
redis:
image: redis
ports:
- 6379:6379
volumes:
- redis-data:/data

volumes:
node_modules: {}
pg-data: {}
redis-data: {}
rails-tmp: {}
16 changes: 16 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ http://localhost:3000 にアクセス
* サービス画面 (http://localhost:3000/users/sign_in?locale=ja)
* [email protected] (組織管理者)
* [email protected] (通常ユーザ)

## 5. キャッシュとRedisについて

Railsのキャッシュはproduction環境ではRedis Cache Store(`ActiveSupport::Cache::RedisCacheStore`)を使うようになっています。

Redisの設定は環境変数 `REDIS_CACHE_URL` を使用しています。

development環境でのRailsの標準機能として、キャッシュのオン・オフをトグルで制御できます。オン・オフを切り替えたい場合、以下のコマンドを実行してください。

```console
# dockerを使っている場合
docker compose run app rails dev:cache

# localで動かしている場合
bin/rails dev:cache
```

0 comments on commit 8fd59c5

Please sign in to comment.