devcontainer: use dynamic host ports so worktrees don't collide

Publish container ports without a fixed host side in the backend and
asset_list compose files, and switch forwardPorts to service-qualified
form. Lets a second worktree's devcontainer spin up without conflicting
on host 8000/5432 (backend) or 8081 (asset_list), matching the pattern
in assessment-model-sales-frontend.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-06-08 13:53:22 +00:00
parent 1b94da16d0
commit 18ad879f00
4 changed files with 15 additions and 6 deletions

View file

@ -9,7 +9,7 @@
// Optional, just makes getting from Downloads (local env) easier
"source=${localEnv:HOME},target=/home/vscode,type=bind"
],
"forwardPorts": [8081],
"forwardPorts": ["model-sal:8080"],
"customizations": {
"vscode": {
"extensions": [

View file

@ -12,7 +12,10 @@ services:
networks:
- model-net
ports:
- "8081:8080"
# Host port left unspecified so Docker assigns a free one — lets multiple
# worktrees of this repo run at once without colliding. VS Code's
# forwardPorts (in devcontainer.json) forwards container :8080 to your machine.
- "8080"
networks:
model-net:

View file

@ -42,9 +42,9 @@
"containerEnv": {
"PYTHONFLAGS": "-Xfrozen_modules=off"
},
"forwardPorts": [8000],
"forwardPorts": ["model-backend:8000"],
"portsAttributes": {
"8000": {
"model-backend:8000": {
"label": "FastAPI",
"onAutoForward": "notify"
}

View file

@ -10,7 +10,10 @@ services:
USER_GID: ${GID:-1000}
command: sleep infinity
ports:
- "8000:8000"
# Host port left unspecified so Docker assigns a free one — lets multiple
# worktrees of this repo run at once without colliding. VS Code's
# forwardPorts (in devcontainer.json) forwards container :8000 to your machine.
- "8000"
volumes:
- ../../:/workspaces/model
- ~/.gitconfig:/home/vscode/.gitconfig:ro
@ -30,7 +33,10 @@ services:
image: postgres:17.4
restart: unless-stopped
ports:
- 5432:5432
# Dynamic host port (see model-backend above) so a second worktree's db
# doesn't collide on 5432. Reach it from inside the container via host
# "db:5432"; from your machine, use the forwarded port VS Code reports.
- "5432"
environment:
- PGDATABASE=tech_team_local_db
- POSTGRES_USER=postgres