From 36046304da08d885e3c538a51c1db2d24520ea3b Mon Sep 17 00:00:00 2001 From: Ben Stull Date: Wed, 10 Jun 2026 08:39:37 -0700 Subject: [PATCH] =?UTF-8?q?feat(slice-1):=20scripts/dev.sh=20=E2=80=94=20o?= =?UTF-8?q?wns=20dev=20Postgres=20lifecycle=20+=20backend=20+=20Vite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/dev.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/dev.sh diff --git a/scripts/dev.sh b/scripts/dev.sh new file mode 100755 index 0000000..5b76cab --- /dev/null +++ b/scripts/dev.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Local bring-up for ecomm (SD-0001 PUC-10). From a clean checkout this: +# 1. starts the dev Postgres container and waits for it to be healthy (owns its +# lifecycle — Docker is the one prerequisite, docs/BOOTSTRAP.md); +# 2. ensures the backend venv + deps and the frontend node_modules; +# 3. runs the FastAPI backend (:8000, self-migrating an empty DB) and the Vite dev +# server (:5173, proxying /api -> :8000) together. +# Ctrl-C stops both processes; the container keeps running (stop it with +# `docker compose down`, or `docker compose down -v` to reset to empty). +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$repo_root" + +export ECOMM_DATABASE_URL="${ECOMM_DATABASE_URL:-postgresql://ecomm:ecomm@localhost:5432/ecomm}" + +echo "==> dev Postgres (docker compose up --wait)" +docker compose up -d --wait db + +if [ ! -x "$repo_root/.venv/bin/python" ]; then + echo "==> creating backend venv" + python3 -m venv "$repo_root/.venv" + "$repo_root/.venv/bin/python" -m pip install --upgrade pip + "$repo_root/.venv/bin/python" -m pip install -r "$repo_root/backend/requirements.txt" +fi + +if [ ! -d "$repo_root/frontend/node_modules" ]; then + echo "==> installing frontend deps" + ( cd "$repo_root/frontend" && npm install ) +fi + +echo "==> starting backend (:8000) and Vite (:5173) — Ctrl-C to stop" +"$repo_root/.venv/bin/python" -m uvicorn app.main:app --app-dir "$repo_root/backend" --port 8000 --reload & +backend_pid=$! +( cd "$repo_root/frontend" && npm run dev ) & +frontend_pid=$! + +cleanup() { + echo + echo "==> stopping backend and Vite" + kill "$backend_pid" "$frontend_pid" 2>/dev/null || true + wait "$backend_pid" "$frontend_pid" 2>/dev/null || true +} +trap cleanup INT TERM + +wait -n "$backend_pid" "$frontend_pid" +cleanup