Add shared auth, deployment config, and dev tooling
This commit is contained in:
+15
-1
@@ -4,9 +4,23 @@
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# Shared DB: use SHARED_DB_PATH env var if set, else fall back to the
|
||||
# standard bincio_activity dev location created by its dev_test.py --fresh.
|
||||
if [[ -z "$SHARED_DB_PATH" ]]; then
|
||||
SHARED_DB_PATH="/tmp/bincio_dev_test/instance.db"
|
||||
if [[ ! -f "$SHARED_DB_PATH" ]]; then
|
||||
echo "⚠ Shared DB not found at $SHARED_DB_PATH"
|
||||
echo " Run bincio_activity's dev_test.py first:"
|
||||
echo " cd ../bincio_activity && uv run python scripts/dev_test.py --fresh"
|
||||
echo " Or set SHARED_DB_PATH to an existing instance.db."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
export SHARED_DB_PATH
|
||||
|
||||
# Start edit sidecar if requested
|
||||
if [[ "$*" == *"--edit"* ]]; then
|
||||
echo "Starting edit sidecar on :8001..."
|
||||
echo "Starting edit sidecar on :8001... (DB: $SHARED_DB_PATH)"
|
||||
uv sync -q
|
||||
uv run uvicorn edit.server:app --reload --port 8001 &
|
||||
SIDECAR_PID=$!
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Wiki dev test.
|
||||
|
||||
Starts the wiki edit sidecar + Astro dev server pointing at the
|
||||
bincio_activity dev database so both apps share the same users.
|
||||
|
||||
Prerequisites:
|
||||
Run bincio_activity's dev_test.py first to create the shared DB:
|
||||
cd ~/src/bincio_activity
|
||||
uv run python scripts/dev_test.py --fresh
|
||||
|
||||
Run from the bincio_wiki project root:
|
||||
uv run python scripts/dev_test.py [--wiki-only]
|
||||
|
||||
Options:
|
||||
--wiki-only Add a wiki-only user (no activity access) to test that path
|
||||
|
||||
Credentials (same as bincio_activity dev):
|
||||
dave / testpass (admin, wiki + activity)
|
||||
brut / testpass (wiki + activity)
|
||||
wiki_user / testpass (wiki only, if --wiki-only is used)
|
||||
|
||||
URL: http://localhost:4321
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import platform
|
||||
import resource
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_DIR = Path(__file__).resolve().parent.parent
|
||||
ACTIVITY_DIR = PROJECT_DIR.parent / "bincio_activity"
|
||||
SHARED_DB = Path("/tmp/bincio_dev_test/instance.db")
|
||||
PASSWORD = "testpass"
|
||||
|
||||
|
||||
def section(msg: str) -> None:
|
||||
print(f"\n\033[1;36m▸ {msg}\033[0m")
|
||||
|
||||
|
||||
def ok(msg: str) -> None:
|
||||
print(f" \033[32m✓\033[0m {msg}")
|
||||
|
||||
|
||||
def warn(msg: str) -> None:
|
||||
print(f" \033[33m·\033[0m {msg}")
|
||||
|
||||
|
||||
def err(msg: str) -> None:
|
||||
print(f" \033[31m✗\033[0m {msg}", file=sys.stderr)
|
||||
|
||||
|
||||
def check_shared_db() -> None:
|
||||
section("Checking shared DB")
|
||||
if not SHARED_DB.exists():
|
||||
err(f"Shared DB not found at {SHARED_DB}")
|
||||
err("Run bincio_activity's dev_test.py first:")
|
||||
err(f" cd {ACTIVITY_DIR}")
|
||||
err(" uv run python scripts/dev_test.py --fresh")
|
||||
sys.exit(1)
|
||||
ok(f"Found {SHARED_DB}")
|
||||
|
||||
|
||||
def add_wiki_only_user() -> None:
|
||||
section("Adding wiki-only test user")
|
||||
sys.path.insert(0, str(ACTIVITY_DIR))
|
||||
from bincio.serve.db import open_db, get_user, create_user
|
||||
|
||||
db = open_db(SHARED_DB.parent)
|
||||
if get_user(db, "wiki_user"):
|
||||
warn("user 'wiki_user' already exists — skipping")
|
||||
else:
|
||||
create_user(db, "wiki_user", "Wiki User", PASSWORD, is_admin=False,
|
||||
wiki_access=True, activity_access=False)
|
||||
ok("wiki-only user 'wiki_user' created")
|
||||
|
||||
|
||||
def start_dev() -> None:
|
||||
section("Starting wiki dev server")
|
||||
print()
|
||||
print(" \033[1mCredentials\033[0m")
|
||||
print(f" dave / {PASSWORD} (admin, wiki + activity)")
|
||||
print(f" brut / {PASSWORD} (wiki + activity)")
|
||||
print()
|
||||
print(" \033[1mURL\033[0m http://localhost:4321")
|
||||
print()
|
||||
print(" Press Ctrl+C to stop.\n")
|
||||
|
||||
env = os.environ.copy()
|
||||
env["SHARED_DB_PATH"] = str(SHARED_DB)
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
["bash", "scripts/dev.sh", "--edit"],
|
||||
cwd=PROJECT_DIR,
|
||||
env=env,
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
def raise_open_file_limit() -> None:
|
||||
if platform.system() != "Darwin":
|
||||
return
|
||||
target = 65536
|
||||
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||
if soft < target:
|
||||
resource.setrlimit(resource.RLIMIT_NOFILE, (min(target, hard), hard))
|
||||
ok(f"open-file limit raised to {min(target, hard)}")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument("--wiki-only", action="store_true",
|
||||
help="Add a wiki-only user (no activity access) for testing")
|
||||
args = parser.parse_args()
|
||||
|
||||
raise_open_file_limit()
|
||||
print(f"\033[1mbincio_wiki dev test\033[0m → shared DB: {SHARED_DB}")
|
||||
|
||||
check_shared_db()
|
||||
|
||||
if args.wiki_only:
|
||||
add_wiki_only_user()
|
||||
|
||||
start_dev()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user