Wire admin Docker service into deploy and compose generation

Add admin as a default-on deploy component with compose merge, image
packaging, sync-published-compose support, and caddy port stripping.

Co-authored-by: denis0001-dev <denis0001.dev@ya.ru>
This commit is contained in:
Cursor Agent
2026-11-11 16:31:23 +00:00
Unverified
parent f78f730255
commit 42e9fc5264
8 changed files with 119 additions and 33 deletions
+1
View File
@@ -11,6 +11,7 @@ import deploy.ui as ui
COMPONENT_OPTIONS: list[tuple[str, str, bool]] = [
("backend", "Backend (API, DB, LiveKit)", True),
("frontend", "Web frontend", True),
("admin", "Admin panel", True),
("caddy", "Caddy reverse proxy (TLS)", True),
# Updater is opt-in — Enter / default skips it.
("updater", "Auto-update service", False),
+4
View File
@@ -27,6 +27,7 @@ FROMCHAT_IMAGE_SERVICES = frozenset(
"file_storage",
"postgres",
"web",
"admin",
"caddy",
"updater",
"chat_filter",
@@ -302,6 +303,9 @@ def _generate_compose(
if "frontend" in components and paths.web_dir:
cmd.extend(["--frontend-compose", str(paths.web_dir / "compose.yml")])
cmd.extend(["--web-root", str(paths.web_dir)])
if "admin" in components and paths.admin_dir:
cmd.extend(["--admin-compose", str(paths.admin_dir / "compose.yml")])
cmd.extend(["--admin-root", str(paths.admin_dir)])
if include_updater:
cmd.append("--include-updater")
if paths.updater_dir:
+9 -3
View File
@@ -114,10 +114,10 @@ def load_settings(paths: ProjectPaths, argv: list[str]) -> DeploySettings:
if arg in ("-h", "--help"):
sys.stdout.write(
"Usage: deploy.sh [user@host] [deploy_path] [platform] "
"[--components backend,frontend,caddy,updater,chat_filter] [--tag TAG]\n"
"[--components backend,frontend,admin,caddy,updater,chat_filter] [--tag TAG]\n"
" Interactive component menu when --components is omitted.\n"
" Or set DEPLOYMENT_SERVER in .env\n"
" Paths: FROMCHAT_BACKEND_DIR, FROMCHAT_WEB_DIR, FROMCHAT_UPDATER_DIR\n"
" Paths: FROMCHAT_BACKEND_DIR, FROMCHAT_WEB_DIR, FROMCHAT_ADMIN_DIR, FROMCHAT_UPDATER_DIR\n"
" Saved choices: .deploy-cache/settings.json (--reset to clear)\n"
)
raise SystemExit(0)
@@ -177,7 +177,7 @@ def load_settings(paths: ProjectPaths, argv: list[str]) -> DeploySettings:
elif interactive and sys.stdin.isatty():
components = select_components_interactive()
else:
components = parse_components_csv("backend,frontend,caddy,chat_filter")
components = parse_components_csv("backend,frontend,admin,caddy,chat_filter")
except KeyboardInterrupt:
_persist_partial(
paths,
@@ -207,6 +207,12 @@ def load_settings(paths: ProjectPaths, argv: list[str]) -> DeploySettings:
"Set FROMCHAT_WEB_DIR or keep a sibling ../Web with compose.yml.\n"
)
raise SystemExit(1)
if "admin" in components and not paths.admin_dir:
sys.stderr.write(
"Admin component selected but admin repo not found.\n"
"Set FROMCHAT_ADMIN_DIR or keep a sibling ../admin with compose.yml.\n"
)
raise SystemExit(1)
if "caddy" in components and not paths.caddy_build_dir:
sys.stderr.write(
"Caddy component selected but backend/src/caddy not found.\n"
+12 -1
View File
@@ -1,4 +1,4 @@
"""Resolved paths for classic deploy against sibling backend/web repos."""
"""Resolved paths for classic deploy against sibling backend/web/admin repos."""
from __future__ import annotations
@@ -35,6 +35,7 @@ class ProjectPaths:
scripts_dir: Path
backend_dir: Path | None
web_dir: Path | None
admin_dir: Path | None
updater_dir: Path | None
caddy_build_dir: Path | None
env_file: Path
@@ -61,6 +62,11 @@ class ProjectPaths:
str(parent / "Web"),
str(parent / "web"),
)
admin = _find_repo_with_compose(
os.environ.get("FROMCHAT_ADMIN_DIR", ""),
str(parent / "Admin"),
str(parent / "admin"),
)
updater = _find_dir(
os.environ.get("FROMCHAT_UPDATER_DIR", ""),
str(parent / "updater"),
@@ -80,6 +86,7 @@ class ProjectPaths:
scripts_dir=scripts_dir,
backend_dir=backend,
web_dir=web,
admin_dir=admin,
updater_dir=updater,
caddy_build_dir=caddy_build,
env_file=env_file,
@@ -95,6 +102,8 @@ class ProjectPaths:
return self.backend_dir / "compose.yml"
if component == "frontend" and self.web_dir:
return self.web_dir / "compose.yml"
if component == "admin" and self.admin_dir:
return self.admin_dir / "compose.yml"
return None
def project_root_for(self, component: str) -> Path | None:
@@ -102,6 +111,8 @@ class ProjectPaths:
return self.backend_dir
if component == "frontend":
return self.web_dir
if component == "admin":
return self.admin_dir
return None
def deploy_env_source(self) -> Path | None:
+8 -3
View File
@@ -280,7 +280,7 @@ def _resolve_build_paths(compose_dir: Path, build: dict | str) -> tuple[Path, Pa
def discover_image_specs(paths: ProjectPaths) -> list[ImageSpec]:
"""Collect every compose service with a build: block across backend, web, updater."""
"""Collect every compose service with a build: block across backend, web, admin, updater."""
compose_files: list[tuple[Path, Path]] = []
if paths.backend_dir and (paths.backend_dir / "compose.yml").is_file():
compose_files.append((paths.backend_dir, paths.backend_dir / "compose.yml"))
@@ -289,11 +289,13 @@ def discover_image_specs(paths: ProjectPaths) -> list[ImageSpec]:
compose_files.append((paths.backend_dir, prod_compose))
if paths.web_dir and (paths.web_dir / "compose.yml").is_file():
compose_files.append((paths.web_dir, paths.web_dir / "compose.yml"))
if paths.admin_dir and (paths.admin_dir / "compose.yml").is_file():
compose_files.append((paths.admin_dir, paths.admin_dir / "compose.yml"))
if paths.updater_dir and (paths.updater_dir / "compose.yml").is_file():
compose_files.append((paths.updater_dir, paths.updater_dir / "compose.yml"))
if not compose_files:
ui.error("No compose.yml found in backend, web, or updater repos.")
ui.error("No compose.yml found in backend, web, admin, or updater repos.")
raise SystemExit(1)
specs: list[ImageSpec] = []
@@ -1334,7 +1336,10 @@ def _run(argv: list[str] | None = None) -> None:
ui.info("Mode: push local images only (--no-build)")
else:
ui.info("Platforms: " + PLATFORMS)
ui.info("Publishable services are read from compose build: blocks in backend, web, and updater.")
ui.info(
"Publishable services are read from compose build: blocks in "
"backend, web, admin, and updater."
)
ui.info("Tags come from each source repo's git tag on HEAD.")
ui.info("Default registries: GitHub Packages + Gitea.")
if saved:
+43 -16
View File
@@ -22,6 +22,7 @@ FROMCHAT_IMAGE_SERVICES = frozenset(
"file_storage",
"postgres",
"web",
"admin",
"caddy",
"updater",
"chat_filter",
@@ -34,6 +35,7 @@ BACKEND_SERVICES = frozenset(
{"backend", "messaging", "file_storage", "livekit", "postgres"}
)
FRONTEND_SERVICES = frozenset({"web"})
ADMIN_SERVICES = frozenset({"admin"})
UPDATER_SERVICES = frozenset({"updater"})
CHAT_FILTER_SERVICES = frozenset({"chat_filter"})
BACKEND_BUILD_SERVICES = frozenset(
@@ -157,6 +159,7 @@ def patch_build_roots(
*,
backend_root: Path | None,
web_root: Path | None,
admin_root: Path | None,
updater_root: Path | None,
) -> None:
for name, cfg in services.items():
@@ -167,6 +170,8 @@ def patch_build_roots(
_rewrite_build_context(build, backend_root)
elif name == "web" and web_root:
_rewrite_build_context(build, web_root)
elif name == "admin" and admin_root:
_rewrite_build_context(build, admin_root)
elif name == "updater" and updater_root:
build["context"] = str(updater_root)
build["dockerfile"] = "Dockerfile"
@@ -308,12 +313,14 @@ def generate(
backend_compose: Path | None,
backend_compose_prod: Path | None = None,
frontend_compose: Path | None,
admin_compose: Path | None = None,
tag: str,
components: set[str],
output: Path,
keep_build: bool = False,
backend_root: Path | None = None,
web_root: Path | None = None,
admin_root: Path | None = None,
updater_root: Path | None = None,
include_updater: bool = False,
include_chat_filter: bool = False,
@@ -328,6 +335,8 @@ def generate(
enabled |= CADDY_STACK_SERVICES
if "frontend" in components:
enabled |= FRONTEND_SERVICES
if "admin" in components:
enabled |= ADMIN_SERVICES
if include_updater:
enabled |= UPDATER_SERVICES
if include_chat_filter:
@@ -346,6 +355,8 @@ def generate(
sources.append(prod_compose)
if frontend_compose and frontend_compose.is_file():
sources.append(frontend_compose)
if admin_compose and admin_compose.is_file():
sources.append(admin_compose)
if not sources and not include_updater and not include_chat_filter:
raise SystemExit("No compose inputs found.")
@@ -381,12 +392,19 @@ def generate(
patch_caddy_additions_volume(
cfg, keep_build=keep_build, backend_root=backend_root
)
if "web" in services:
front_deps = [n for n in ("web", "admin") if n in services]
if front_deps:
deps = cfg.get("depends_on")
if isinstance(deps, list) and "web" not in deps:
deps.append("web")
if isinstance(deps, list):
for dep_name in front_deps:
if dep_name not in deps:
deps.append(dep_name)
elif deps is None:
cfg["depends_on"] = ["web"]
cfg["depends_on"] = front_deps
elif isinstance(deps, dict):
for dep_name in front_deps:
if dep_name not in deps:
deps[dep_name] = {"condition": "service_started"}
if name == "haproxy" and "caddy" in services:
cfg.setdefault("depends_on", ["caddy"])
@@ -395,21 +413,26 @@ def generate(
services,
backend_root=backend_root,
web_root=web_root,
admin_root=admin_root,
updater_root=updater_root,
)
if include_caddy and "web" in services:
web = services["web"]
# Caddy proxies to web:80 on the public network.
nets = web.get("networks")
if isinstance(nets, list):
if "public" not in nets:
nets.append("public")
else:
web["networks"] = ["public"]
ports = web.get("ports")
if isinstance(ports, list):
web["ports"] = [p for p in ports if not str(p).startswith("8301:")]
if include_caddy:
for pub_name, dev_port in (("web", "8301"), ("admin", "8304")):
if pub_name not in services:
continue
pub = services[pub_name]
# Caddy proxies to web:80 / admin:80 on the public network.
nets = pub.get("networks")
if isinstance(nets, list):
if "public" not in nets:
nets.append("public")
else:
pub["networks"] = ["public"]
ports = pub.get("ports")
if isinstance(ports, list):
prefix = f"{dev_port}:"
pub["ports"] = [p for p in ports if not str(p).startswith(prefix)]
if not keep_build:
for cfg in services.values():
@@ -442,6 +465,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--backend-compose", type=Path, default=None)
parser.add_argument("--backend-compose-prod", type=Path, default=None)
parser.add_argument("--frontend-compose", type=Path, default=None)
parser.add_argument("--admin-compose", type=Path, default=None)
parser.add_argument("--output", type=Path, default=Path("compose.yml"))
parser.add_argument(
"--keep-build",
@@ -450,6 +474,7 @@ def parse_args() -> argparse.Namespace:
)
parser.add_argument("--backend-root", type=Path, default=None)
parser.add_argument("--web-root", type=Path, default=None)
parser.add_argument("--admin-root", type=Path, default=None)
parser.add_argument("--updater-root", type=Path, default=None)
parser.add_argument("--include-updater", action="store_true")
parser.add_argument("--include-chat-filter", action="store_true")
@@ -463,12 +488,14 @@ def main() -> None:
backend_compose=args.backend_compose,
backend_compose_prod=args.backend_compose_prod,
frontend_compose=args.frontend_compose,
admin_compose=args.admin_compose,
tag=args.tag,
components=components,
output=args.output,
keep_build=args.keep_build,
backend_root=args.backend_root,
web_root=args.web_root,
admin_root=args.admin_root,
updater_root=args.updater_root,
include_updater=args.include_updater,
include_chat_filter=args.include_chat_filter,
+24 -5
View File
@@ -122,16 +122,17 @@ get_latest_semver_tag() {
}
select_components() {
local -a options=(backend frontend caddy updater chat_filter)
local -a options=(backend frontend admin caddy updater chat_filter)
local -a labels=(
"Backend (API, DB, LiveKit)"
"Web frontend"
"Admin panel"
"Caddy reverse proxy (TLS)"
"Auto-update service"
"Chat content filter service"
)
# Updater opt-in (N); chat filter on by default (Y).
local -a defaults=(Y Y Y N Y)
local -a defaults=(Y Y Y Y N Y)
SELECTED=()
local i choice hint
step "Select components"
@@ -192,8 +193,8 @@ print_success_banner() {
# Merge component compose files into ${install_dir}/compose.yml (image: fromchat/*:<tag>).
# Optional local compose paths (skip remote fetch when set):
# LOCAL_BACKEND_COMPOSE, LOCAL_BACKEND_COMPOSE_PROD, LOCAL_FRONTEND_COMPOSE
# Requires: DEPLOYMENT_ROOT, BACKEND_REPO, WEB_REPO (for remote fetch).
# LOCAL_BACKEND_COMPOSE, LOCAL_BACKEND_COMPOSE_PROD, LOCAL_FRONTEND_COMPOSE, LOCAL_ADMIN_COMPOSE
# Requires: DEPLOYMENT_ROOT, BACKEND_REPO, WEB_REPO, ADMIN_REPO (for remote fetch).
run_generate_compose() {
local install_dir="$1"
local components_csv="$2"
@@ -203,9 +204,11 @@ run_generate_compose() {
step "Generating compose.yml for tag ${tag} (components: ${components_csv})…"
local need_backend=false need_frontend=false need_caddy=false
local need_backend=false need_frontend=false need_admin=false need_caddy=false
ADMIN_REPO="${ADMIN_REPO:-${FROMCHAT_ADMIN_REPO:-https://github.com/fromchat-messenger/admin.git}}"
[[ ",${components_csv}," == *,backend,* ]] && need_backend=true
[[ ",${components_csv}," == *,frontend,* ]] && need_frontend=true
[[ ",${components_csv}," == *,admin,* ]] && need_admin=true
[[ ",${components_csv}," == *,caddy,* ]] && need_caddy=true
if ${need_backend}; then
@@ -238,6 +241,16 @@ run_generate_compose() {
success "Frontend compose.yml"
fi
fi
if ${need_admin}; then
if [[ -n "${LOCAL_ADMIN_COMPOSE:-}" && -f "${LOCAL_ADMIN_COMPOSE}" ]]; then
cp -f "${LOCAL_ADMIN_COMPOSE}" "${tmp}/admin.compose.yml"
success "Admin compose.yml (local)"
else
fetch_raw_file "${ADMIN_REPO}" "${tag}" "compose.yml" \
"${tmp}/admin.compose.yml"
success "Admin compose.yml"
fi
fi
local stack_csv
stack_csv="$(echo "${components_csv}" | tr ',' '\n' | grep -vE '^(updater|chat_filter)$' | paste -sd, - || true)"
@@ -258,6 +271,12 @@ run_generate_compose() {
if ${need_frontend}; then
gen_args+=(--frontend-compose "${tmp}/frontend.compose.yml")
fi
if ${need_admin}; then
gen_args+=(--admin-compose "${tmp}/admin.compose.yml")
if [[ -d "${DEPLOYMENT_ROOT}/../admin" ]]; then
gen_args+=(--admin-root "${DEPLOYMENT_ROOT}/../admin")
fi
fi
if [[ ",${components_csv}," == *,updater,* ]]; then
gen_args+=(--include-updater)
if [[ -d "${DEPLOYMENT_ROOT}/../updater" ]]; then
+18 -5
View File
@@ -38,7 +38,8 @@ dump_yaml_str = _generate_compose.dump_yaml_str
DEFAULT_BACKEND_REPO = "https://github.com/fromchat-messenger/backend.git"
DEFAULT_WEB_REPO = "https://github.com/fromchat-messenger/web.git"
DEFAULT_COMPONENTS = ("backend", "frontend", "caddy", "chat_filter")
DEFAULT_ADMIN_REPO = "https://github.com/fromchat-messenger/admin.git"
DEFAULT_COMPONENTS = ("backend", "frontend", "admin", "caddy", "chat_filter")
FULL_STACK_PACKAGES = (
"backend",
@@ -46,6 +47,7 @@ FULL_STACK_PACKAGES = (
"file_storage",
"postgres",
"web",
"admin",
"caddy",
"livekit",
"haproxy",
@@ -77,11 +79,13 @@ def packages_ready(tag: str) -> bool:
def resolve_latest_published_tag(
backend_repo: str,
web_repo: str,
admin_repo: str,
token: str | None,
) -> str | None:
backend_tags = fetch_semver_tags(backend_repo, token)
web_tags = fetch_semver_tags(web_repo, token)
common = backend_tags & web_tags
admin_tags = fetch_semver_tags(admin_repo, token)
common = backend_tags & web_tags & admin_tags
if not common:
return None
for tag in sorted(common, key=semver_key, reverse=True):
@@ -107,10 +111,11 @@ def sync_published_compose(
output: Path,
backend_repo: str,
web_repo: str,
admin_repo: str,
token: str | None,
components: tuple[str, ...] = DEFAULT_COMPONENTS,
) -> str | None:
tag = resolve_latest_published_tag(backend_repo, web_repo, token)
tag = resolve_latest_published_tag(backend_repo, web_repo, admin_repo, token)
if not tag:
print(
"No semver tag with all required fromchat/* images on Docker Hub.",
@@ -125,6 +130,7 @@ def sync_published_compose(
backend_compose = tmp / "backend.compose.yml"
backend_compose_prod = tmp / "backend.compose.prod.yml"
web_compose = tmp / "frontend.compose.yml"
admin_compose = tmp / "admin.compose.yml"
backend_compose.write_bytes(
fetch_raw_file(backend_repo, tag, "compose.yml", token)
)
@@ -134,11 +140,16 @@ def sync_published_compose(
web_compose.write_bytes(
fetch_raw_file(web_repo, tag, "compose.yml", token)
)
if "admin" in components:
admin_compose.write_bytes(
fetch_raw_file(admin_repo, tag, "compose.yml", token)
)
generate(
backend_compose=backend_compose,
backend_compose_prod=backend_compose_prod,
frontend_compose=web_compose,
frontend_compose=web_compose if "frontend" in components else None,
admin_compose=admin_compose if "admin" in components else None,
tag=tag,
components=set(components),
output=output,
@@ -176,10 +187,11 @@ def parse_args() -> argparse.Namespace:
)
parser.add_argument("--backend-repo", default=DEFAULT_BACKEND_REPO)
parser.add_argument("--web-repo", default=DEFAULT_WEB_REPO)
parser.add_argument("--admin-repo", default=DEFAULT_ADMIN_REPO)
parser.add_argument(
"--components",
default=",".join(DEFAULT_COMPONENTS),
help="Comma-separated components (default: backend,frontend,caddy,chat_filter)",
help="Comma-separated components (default: backend,frontend,admin,caddy,chat_filter)",
)
return parser.parse_args()
@@ -199,6 +211,7 @@ def main() -> None:
output=args.output.resolve(),
backend_repo=args.backend_repo,
web_repo=args.web_repo,
admin_repo=args.admin_repo,
token=token,
components=components,
)