Skip to content

refactor: Composeファイル名の見直しと JWT_SECRET のバリデーション強化 - #234

Merged
cimura merged 3 commits into
developfrom
fix/makefile-and-jwtsecret
Aug 7, 2026
Merged

cimura merged 3 commits into
developfrom
fix/makefile-and-jwtsecret

Conversation

@taka2162

@taka2162 taka2162 commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

概要

本番用と開発用の docker-compose ファイルの命名を直感的なものに変更しました[cite: 4]。また、セキュリティ向上のため、JWT_SECRET に24文字以上の長さ制限を設けて起動時に検証するように改善しました[cite: 4]。

対応背景

本番用の起動をメインの要件とするため、デフォルトで参照されるファイル名を本番用に整理しました[cite: 4]。また、サンプルのシークレット値がそのまま本番で使用される事故を防ぐため、開発者が自身でセキュアな文字列を生成することを強制する仕組みが必要でした[cite: 4]。

詳細

  • 本番用のファイル名を docker-compose.prod.yml から docker-compose.yml に変更し、開発用を docker-compose.yml から docker-compose.dev.yml へリネームしました[cite: 4]。
  • .env.example に記載されていた JWT_SECRET のダミー値を削除し、openssl rand -base64 24 を使用して生成する案内を追記しました[cite: 4]。
  • バックエンドの環境変数バリデーション(env.validation.ts)を更新し、JWT_SECRET が24文字未満の場合や未設定の場合にバックエンドの起動をブロックするようにしました[cite: 4]。
  • Makefile に check-env ターゲットを追加し、.env が存在しない場合は自動コピーせず、開発者に手動での作成と設定を促すエラーメッセージを出力するように変更しました[cite: 4]。
  • Makefile の fclean および dev-fclean ターゲットの挙動を、システム全体をクリーンアップする docker system prune から、対象プロジェクトのみに安全に作用する docker compose down --rmi local -v --remove-orphans へ修正しました[cite: 4]。
  • これらに伴う README.md の起動手順や注意事項のドキュメント更新を行いました[cite: 4]。

動作確認

  • .env ファイルが存在しない状態で make を実行し、適切なエラーメッセージが表示されて処理が止まることを確認する[cite: 4]。
  • .env の JWT_SECRET が空、または24文字未満の場合、バックエンドコンテナがエラーを出力して起動しないことを確認する[cite: 4]。
  • openssl rand -base64 24 等で生成した24文字以上の値を設定した状態では、バックエンドが正常に起動することを確認する[cite: 4]。
  • make up が本番用環境(docker-compose.yml)、make dev-up が開発用環境(docker-compose.dev.yml)でそれぞれ正常に立ち上がることを確認する[cite: 4]。
  • make fclean が他のDockerリソースを巻き込まず、当該プロジェクトのイメージとボリュームのみをクリーンアップすることを確認する[cite: 4]。

テスト

  • バックエンドの環境変数バリデーションロジック(JWT_SECRET_MIN_LENGTH)が期待通りに機能することを確認する[cite: 4]。

その他

特になし

Summary by CodeRabbit

  • セキュリティ

    • JWT秘密鍵に24文字以上の要件を追加しました。
    • 秘密鍵が未設定または短すぎる場合、バックエンドが起動しません。
    • サンプル環境設定に秘密鍵の生成方法を追記しました。
  • 改善

    • 開発用と本番用の起動構成を分離しました。
    • 起動前に環境設定ファイルの存在を確認するようになりました。
    • 開発環境でフロントエンドを含む構成を利用できます。
  • ドキュメント

    • Docker Compose、環境変数、データベース設定、マイグレーション手順を更新しました。

@taka2162 taka2162 self-assigned this Aug 7, 2026
@taka2162
taka2162 requested review from cimura and rt6500 August 7, 2026 06:55
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

本番用と開発用のComposeファイルを分離しました。Makefileに.env確認を追加しました。JWT_SECRETの最小長検証を追加し、READMEと.env.exampleの設定手順を更新しました。

Changes

Compose環境管理

Layer / File(s) Summary
環境変数検証とMakefile連携
backend/src/env.validation.ts, .env.example, Makefile
JWT_SECRETに24文字以上の制約を追加しました。主要なMakeターゲットで.envの存在確認を必須にしました。完全クリーンアップ処理も更新しました。
本番・開発Compose構成
docker/docker-compose.yml, docker/docker-compose.dev.yml, Makefile
本番用と開発用のCompose構成を分離しました。開発用Composeにfrontendを追加し、本番用Composeからfrontendを削除しました。backendとnginxのDockerfile、ポート、依存関係、ヘルスチェックを更新しました。
セットアップ手順とデータベース文書
README.md
データベース情報、Docker Compose V2要件、.env作成手順、JWT_SECRET生成方法、起動時検証、マイグレーション確認コマンドを更新しました。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: rt6500, cimura, cimfs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルはComposeファイル名の変更とJWT_SECRETのバリデーション強化という主要な変更を明確に示しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/makefile-and-jwtsecret

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@taka2162

taka2162 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@taka2162

taka2162 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@taka2162

taka2162 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker/docker-compose.dev.yml`:
- Around line 40-47: 開発用 Compose の nginx 公開ポートを本番用の 8443
と競合しないホストポートへ変更し、docker-compose.dev.yml と docker-compose.yml の backend/nginx
にある固定 container_name を削除してください。サービス間の名前解決は Compose
のサービス名(backend、nginx)を使用するよう関連設定を更新し、同時起動不可の前提が残る場合は Makefile と README
に明記してください。
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 40b1bcad-dfd3-4bf1-88d0-d2045ee1a771

📥 Commits

Reviewing files that changed from the base of the PR and between dfcf0e3 and 4d68a44.

📒 Files selected for processing (6)
  • .env.example
  • Makefile
  • README.md
  • backend/src/env.validation.ts
  • docker/docker-compose.dev.yml
  • docker/docker-compose.yml

Comment thread docker/docker-compose.dev.yml
@cimura

cimura commented Aug 7, 2026

Copy link
Copy Markdown
Owner

good!!!!

@cimura
cimura merged commit 156fc72 into develop Aug 7, 2026
2 checks passed
@cimura
cimura deleted the fix/makefile-and-jwtsecret branch August 7, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants