fix: 別の worktree の開発コンテナと同時に起動できるようにする - #44
Merged
Merged
Conversation
docker-compose.yml pinned container_name to algorithm-visualizer-dev. Compose names each project after its directory, so every git worktree is a separate project, yet all of them tried to create a container with that one name. A stopped container left by another worktree was enough to make `docker compose up -d --build` fail. Nothing refers to the fixed name: the docs, the pre-commit hook and the devcontainer all address the `app` service. Drop it so Compose names the container `<project>-app-1`. With the names no longer clashing, the fixed host port is what still stops two worktrees from running at once. Let DEV_PORT change the published host port while Parcel keeps listening on 1234 inside the container. Parcel's HMR client connects to the page's own port when the HMR port matches the serve port, so HMR keeps working on a remapped port. Document DEV_PORT in the README and point to it from AGENTS.md. Also fix the "ifrst" typo in the compose header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docker-compose.ymlはコンテナ名をcontainer_name: algorithm-visualizer-devに固定していました。Compose はディレクトリ名からプロジェクト名を決めるので、git worktree はそれぞれ別のプロジェクトになります。それなのに、どのプロジェクトも同じ名前のコンテナを作ろうとするため、別の worktree に停止中のコンテナが残っているだけでdocker compose up -d --buildが失敗していました。変更
container_nameを削除しました。コンテナ名は<プロジェクト名>-app-1(例:compassionate-pike-ddb08f-app-1)になります。固定名を参照している箇所はありません。ドキュメント・.husky/pre-commit・devcontainer.jsonはいずれもサービス名appを使っており、docker compose exec appなどはそのまま動きます。Bind for 0.0.0.0:1234 failed: port is already allocated)。そこで、DEV_PORTでホスト側のポートだけを変えられるようにしました。既定値は 1234 のままです。コンテナ内の Parcel は 1234 で待ち受けたままです。DEV_PORTの使い方を追記し、AGENTS.md からその節を参照するようにしました。HMR は、Parcel のクライアントが「HMR ポート=配信ポート」のときにページ自身のポート(
location.port)へ接続する実装(@parcel/runtime-browser-hmr)なので、ホスト側のポートを付け替えても動きます。既存の
algorithm-visualizer-devコンテナは、同じプロジェクトで次にdocker compose upしたとき新しい名前で作り直される想定です(未確認)。検証
Docker Compose v2.6.1(Docker Desktop for Mac)で確認しました。
docker compose config:既定ではpublished: "1234"、DEV_PORT=1235では"1235"になることを確認しました。docker compose up -d --buildで作ったコンテナで、yarn typecheck・yarn lint・yarn format・yarn test(26 件)がすべて成功しました。DEV_PORT=1235)を同時に起動し、どちらも/ja/・/en/が 200 を返しました。DEV_PORTなしで 2 つ目を起動すると、上記のポート衝突エラーで止まることも確認しています。src/styles.cssを一時的に変更し、元に戻しました。どちらも、ページを再読み込みせずに反映されました(windowに置いた目印の値が残ったままでした)。fix: 開発コンテナの yarn build が開発版の React を同梱しないようにする #43 を取り込んだ後の構成でも、1235 で同じ結果になりました。🤖 Generated with Claude Code