mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
- Introduce cli.deploy.development build subcommand as single build SPOT - Remove legacy compose.build_infinito implementation - Make up use build-missing logic via build handler - Add --when-down flag to up (skip startup if stack already running) - Simplify restart/run to reuse up handler - Ensure tests use up --when-down to avoid stack interference - Make test targets depend on build-missing https://chatgpt.com/share/696fd3c9-99f0-800f-a0ab-33a91058419a
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
|
|
from .build import handler as build_handler
|
|
from .common import make_compose
|
|
|
|
|
|
def add_parser(sub: argparse._SubParsersAction) -> None:
|
|
p = sub.add_parser("up", help="Start compose stack (coredns + infinito).")
|
|
p.add_argument(
|
|
"--distro",
|
|
default=os.environ.get("INFINITO_DISTRO", "arch"),
|
|
choices=["arch", "debian", "ubuntu", "fedora", "centos"],
|
|
help="Target distro (compose env INFINITO_DISTRO).",
|
|
)
|
|
p.add_argument(
|
|
"--skip-entry-init",
|
|
action="store_true",
|
|
help="Do not run /opt/src/infinito/scripts/docker/entry.sh true after stack is up.",
|
|
)
|
|
p.add_argument(
|
|
"--when-down",
|
|
action="store_true",
|
|
help="Only start stack if it is not already running.",
|
|
)
|
|
p.set_defaults(_handler=handler)
|
|
|
|
|
|
def _maybe_build_missing(*, distro: str) -> int:
|
|
# CI: never build (image is pulled). Local: build if missing.
|
|
if os.environ.get("INFINITO_NO_BUILD", "0") == "1":
|
|
return 0
|
|
|
|
build_args = argparse.Namespace(
|
|
distro=distro,
|
|
missing=True,
|
|
no_cache=False,
|
|
target="",
|
|
tag="",
|
|
push=False,
|
|
publish=False,
|
|
registry="",
|
|
owner="",
|
|
repo_prefix="",
|
|
version="",
|
|
stable="",
|
|
)
|
|
|
|
return int(build_handler(build_args))
|
|
|
|
|
|
def _stack_is_running(*, distro: str) -> bool:
|
|
compose = make_compose(distro=distro)
|
|
r = compose.run(["ps", "-q", "infinito"], check=False, capture=True)
|
|
cid = (r.stdout or "").strip()
|
|
return bool(cid)
|
|
|
|
|
|
def handler(args: argparse.Namespace) -> int:
|
|
# when-down: skip if already running
|
|
if args.when_down:
|
|
if _stack_is_running(distro=args.distro):
|
|
print(">>> Stack already running — skipping up")
|
|
return 0
|
|
|
|
rc = _maybe_build_missing(distro=args.distro)
|
|
if rc != 0:
|
|
return rc
|
|
|
|
compose = make_compose(distro=args.distro)
|
|
compose.up(run_entry_init=not bool(args.skip_entry_init))
|
|
return 0
|