Adds new scripts for creating new work trees when developing locally.
`./create-worktree.sh <name>` creates a new `name` worktree and
checkouts to the new `name` branch.
Here's a rundown of how these scripts work for each infrastructure
component:
- Server: During development, we usually run FastAPI in the terminal, so
we try to find an available port, starting at `8002`, to account for the
main PingPong server and the PingPong Study server.
- Web: We run the web app outside Docker, so we need to find an
available port, starting at `5175` to account for the main PingPong web
app and the PingPong Study dashboard. We also control the port the
client app uses to communicate with the server.
- DB: We create a new DB based on the main `pingpong` database. Follows
the `pingpong_<branch_name>` pattern.
- OpenFGA: We also create a new store and authorization model for
OpenFGA. Technically, when we copy the database, we also copy the
`pingpong` store. However, `openfga-config.dev.yml` dictates the
datastore URI, so updating it would require a new deployment.
`./remove-worktree.sh <name>` removes a specific worktree, and
`cleanup-worktree-resources.sh` removes all DB and OpenFGA resources.
To take advantage of the port mapping in the script, you can add the
following tasks in your VS Code configuration:
```json
// .vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run server start on startup",
"type": "shell",
"command": "set -a && source .env.dev 2>/dev/null; set +a; CONFIG_PATH=${CONFIG_PATH:-config.local.toml} poetry run uvicorn pingpong:server --port ${BACKEND_PORT:-8000} --host 0.0.0.0 --reload",
"presentation": {
"reveal": "silent",
"panel": "dedicated"
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Run UI start on startup",
"type": "shell",
"command": "set -a && source .env.dev 2>/dev/null; set +a; cd web/pingpong && pnpm dev --port ${FRONTEND_PORT:-5173}",
"presentation": {
"reveal": "silent",
"panel": "dedicated"
},
"runOptions": { "runOn": "folderOpen" }
}
]
}
```