mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-28 08:49:42 +02:00
* feat(scripts): free trusted HTTPS via sslip.io for public-IP remote installs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: refactor setup scripts * chore: generate sdk * chore: fix messaging for setup_remote script * fix: fix ffmpeg download url * feat: centralise and simplify the url configuration * fix: force script run as sudo * fix: fix documentation --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8.3 KiB
8.3 KiB
scripts/
Bash ↔ PowerShell parity — keep them in sync
Most contributor-facing scripts ship as a .sh + .ps1 pair so macOS/Linux and Windows users get the same workflow. When you edit one, edit the other in the same change. Env-var names, defaults, flags, and behavior should match — if start_services_dev.sh reads HEALTH_MAX_ATTEMPTS, so should start_services_dev.ps1.
Current pairs:
setup_fork.{sh,ps1}— contributor bootstrap (git remotes, submodule, venv, env files)setup_requirements.{sh,ps1}— Python + pipecat dependency installstart_services_dev.{sh,ps1}— local backend launcher (auto-reload + health-check wait)stop_services.{sh,ps1}makemigrate.{sh,ps1}/migrate.{sh,ps1}— Alembic helperssetup_local.{sh,ps1}— OSS local Docker-compose setup (optional coturn/TURN)
Bash-only (deployment / CI / OSS-user setup — not intended for Windows contributors):
start_services.sh— VM productionstart_services_docker.sh— Docker image CMDrolling_update.sh— zero-downtime VM redeploysetup_remote.sh— OSS remote Docker-compose setupformat.sh/lint.sh/pre_commit.shgenerate_sdk.sh/release_sdks.sh/dump_docs_openapi.py
Deployment Memory — current OSS Docker state
This directory now has a shared deployment model for OSS Docker installs. If you touch any of the scripts below, assume they are coupled and review them together:
scripts/lib/setup_common.shis the shared deployment helper library. It is sourced bysetup_local.sh,setup_remote.sh,update_remote.sh,setup_custom_domain.sh,run_dograh_init.sh, and repo-rootremote_up.sh.setup_common.shmust stay safe to source. It should not set shell options likeset -ufor callers..envis the single operator-owned source of truth for remote deployment settings. Remote/runtime config should derive from it, not the other way around.- Canonical remote keys in
.env:ENVIRONMENT,SERVER_IP,PUBLIC_HOST,PUBLIC_BASE_URL,TURN_SECRET,FASTAPI_WORKERS,OSS_JWT_SECRET.PUBLIC_BASE_URL(+PUBLIC_HOST, andSERVER_IPfor coturn's literalexternal-ip) is the single endpoint source of truth. BACKEND_API_ENDPOINT,MINIO_PUBLIC_ENDPOINT,TURN_HOSTare derived in-app fromPUBLIC_BASE_URL/PUBLIC_HOST(api/constants.py) and are no longer written to a remote.env.dograh_sync_remote_env_fileneither writes nor deletes them — new installs omit them, and a value an operator sets by hand is left untouched as an explicit override for a split deployment (separate object store / TURN host).dograh_validate_remote_runtime_envtherefore no longer requires them or asserts they equalPUBLIC_BASE_URL.remote_up.shis the supported remote startup entrypoint. It runs preflight viadograh_prepare_remote_install, runsdocker compose config -q, then starts the stack.docker-compose.yamluses a one-shotdograh-initservice for profilesremoteandlocal-turn.cloudflaredis gated behind atunnelprofile (no longer always-on;apino longerdepends_onit).remote_up.shadds--profile tunnelwhenSERVER_IPis a private/reserved address (dograh_is_local_ipv4) — i.e. the host has no public IP; public-IP installs run--profile remoteonly and start no tunnel. Local installs opt in with--profile tunnel. The backend mirrors this exactly:api/utils/common.py:is_local_or_private_urldecides whenget_backend_endpoints()resolves the tunnel URL at runtime, so deploy-side and runtime stay in sync (keep the two IP classifiers aligned, incl. CGNAT 100.64.0.0/10).cloudflaredpicks a mode by token: withCLOUDFLARE_TUNNEL_TOKENit runs a named tunnel (stable hostname — setBACKEND_API_ENDPOINTto it and point its Cloudflare-dashboard ingress athttp://api:8000); without a token it runs a quick tunnel (ephemeral*.trycloudflare.com, discovered via the:2000metrics endpoint byapi/utils/tunnel.py).dograh-initexecutesscripts/run_dograh_init.sh, which renders nginx/coturn runtime config into named volumes consumed bynginxandcoturn.- Remote nginx/coturn config is runtime-generated. Host-managed
nginx.conf/turnserver.confare legacy only; update flow may back them up and delete them, but current installs should not depend on them. setup_remote.shwrites.env, downloads the deployment helper bundle, generates self-signed certs, validates the init-based config, and tells operators to start via./remote_up.shor./remote_up.sh --build. It hard-requires root (a guard near the top exits non-root with a "re-run with sudo" message) because it provisions Docker, binds :80/:443, and installs a Let's Encrypt cert + system renewal hook. Cloud-init/user-data callers (e.g.infrastructure/) already run as root, so they pass; interactive callers must usesudo. Docs that invoke it (docs/deployment/docker.mdx,docs/deployment/scaling.mdx) and the hint printed bysetup_custom_domain.shall usesudo.update_remote.shis the migration/upgrade path for prebuilt remote installs. It refreshesdocker-compose.yaml,remote_up.sh,scripts/run_dograh_init.sh,scripts/lib/setup_common.sh, anddeploy/templates/*, backs up touched files, removes legacy hostnginx.conf/turnserver.conf, and revalidates the init-based path.setup_custom_domain.shis certificate/domain glue only. It must not own nginx config. It updates canonical public URL keys in.env, copies Let's Encrypt certs intocerts/, installs renewal hook, and restarts through./remote_up.sh.setup_local.{sh,ps1}has an interactiveEnable coturn? [y/N]prompt unlessENABLE_COTURNis preset. If coturn is enabled, it downloads the minimal helper bundle needed forlocal-turn(setup_common.sh,run_dograh_init.sh, templates) and relies ondograh-initto render coturn config.setup_local.{sh,ps1}must remain safe under unset env vars; use${VAR:-}guards in Bash and null/empty checks in PowerShell for optional inputs likeENABLE_COTURN,TURN_HOST,TURN_SECRET,DOGRAH_SKIP_DOWNLOAD.run_dograh_init.shis an executable entrypoint, not a library. Compose runs it directly. If it ever gets refactored, keep the distinction between sourced helper logic (lib/) and executable entrypoints.dograh_prepare_remote_installinsetup_common.shcurrently does three things: sync canonical.envkeys, reject legacy compose layouts that do not usedograh-init, and preflight the init render in a temp directory.dograh_uses_init_compose_layout/dograh_require_init_compose_layoutare the guardrails for old installs. If a remote install still bind-mounts hostnginx.conf/turnserver.conf, the intended fix path is./update_remote.sh.- Templates live under
deploy/templates/.nginx.remote.conf.templatecontains the static shape anddograh_render_remote_nginx_confexpands the multi-worker upstream block dynamically.turnserver.remote.conf.templateis also rendered from env. - If you rename/move any of these deployment files, update all of: bootstrap curl URLs inside scripts, helper-bundle download paths in
setup_common.sh, backup lists inupdate_remote.sh, docs underdocs/deployment/, and any existence checks insetup_local.{sh,ps1}/setup_custom_domain.sh.
The three "start" scripts — pick the right one
| Script | Where it runs | Key behavior |
|---|---|---|
start_services_dev.sh |
Local dev shell | uvicorn --reload, exits after launching, restart by re-running, single arq worker, waits for /api/v1/health before exiting. |
start_services.sh |
VM production | Multi-port uvicorn behind nginx, sudo nginx -t && systemctl reload, writes run/active_band for rolling_update.sh. |
start_services_docker.sh |
Docker image CMD |
PID 1: traps SIGTERM, uvicorn --workers $FASTAPI_WORKERS, wait -n so a dying child tears the container down. |
If you find yourself adding nginx/sudo logic to the dev script, or --reload to the production/Docker scripts, stop — you probably want a different file.