Add workspace management and isolated worktree environments
This commit is contained in:
parent
e9555b8a22
commit
81e64e9fce
32 changed files with 1462 additions and 200 deletions
56
scripts/init-worktree-env.sh
Normal file
56
scripts/init-worktree-env.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ENV_FILE="${1:-.env.worktree}"
|
||||
|
||||
if [ -f "$ENV_FILE" ] && [ "${FORCE:-0}" != "1" ]; then
|
||||
echo "Refusing to overwrite existing $ENV_FILE. Re-run with FORCE=1 if you want to regenerate it."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
worktree_name="${WORKTREE_NAME:-$(basename "$PWD")}"
|
||||
slug="$(printf '%s' "$worktree_name" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/_/g; s/__*/_/g; s/^_//; s/_$//')"
|
||||
if [ -z "$slug" ]; then
|
||||
slug="multica"
|
||||
fi
|
||||
|
||||
hash_value="$(printf '%s' "$PWD" | cksum | awk '{print $1}')"
|
||||
offset=$((hash_value % 1000))
|
||||
|
||||
postgres_db="multica_${slug}"
|
||||
postgres_port=$((15432 + offset))
|
||||
backend_port=$((18080 + offset))
|
||||
frontend_port=$((13000 + offset))
|
||||
frontend_origin="http://localhost:${frontend_port}"
|
||||
compose_project_name="multica_${slug}_${offset}"
|
||||
|
||||
cat > "$ENV_FILE" <<EOF
|
||||
COMPOSE_PROJECT_NAME=${compose_project_name}
|
||||
POSTGRES_DB=${postgres_db}
|
||||
POSTGRES_USER=multica
|
||||
POSTGRES_PASSWORD=multica
|
||||
POSTGRES_PORT=${postgres_port}
|
||||
DATABASE_URL=postgres://multica:multica@localhost:${postgres_port}/${postgres_db}?sslmode=disable
|
||||
|
||||
PORT=${backend_port}
|
||||
JWT_SECRET=change-me-in-production
|
||||
MULTICA_SERVER_URL=ws://localhost:${backend_port}/ws
|
||||
|
||||
GOOGLE_CLIENT_ID=
|
||||
GOOGLE_CLIENT_SECRET=
|
||||
GOOGLE_REDIRECT_URI=${frontend_origin}/auth/callback
|
||||
|
||||
FRONTEND_PORT=${frontend_port}
|
||||
FRONTEND_ORIGIN=${frontend_origin}
|
||||
NEXT_PUBLIC_API_URL=http://localhost:${backend_port}
|
||||
NEXT_PUBLIC_WS_URL=ws://localhost:${backend_port}/ws
|
||||
EOF
|
||||
|
||||
echo "Generated $ENV_FILE for worktree '$worktree_name'"
|
||||
echo " Postgres: ${postgres_db} on localhost:${postgres_port}"
|
||||
echo " Backend: http://localhost:${backend_port}"
|
||||
echo " Frontend: ${frontend_origin}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " make setup"
|
||||
echo " make start"
|
||||
Loading…
Add table
Add a link
Reference in a new issue