progress-cli 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- progress_cli/__init__.py +11 -0
- progress_cli/__main__.py +4 -0
- progress_cli/backup.py +63 -0
- progress_cli/clone.py +538 -0
- progress_cli/copy.py +264 -0
- progress_cli/dev.py +254 -0
- progress_cli/init.py +444 -0
- progress_cli/main.py +44 -0
- progress_cli/package.py +175 -0
- progress_cli/restore.py +169 -0
- progress_cli/runner.py +135 -0
- progress_cli/update.py +300 -0
- progress_cli-0.10.0.dist-info/METADATA +52 -0
- progress_cli-0.10.0.dist-info/RECORD +16 -0
- progress_cli-0.10.0.dist-info/WHEEL +4 -0
- progress_cli-0.10.0.dist-info/entry_points.txt +2 -0
progress_cli/init.py
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"""`progress init` — bootstrap a fresh Linux host into a single-node
|
|
2
|
+
Progress deployment.
|
|
3
|
+
|
|
4
|
+
Python port of deploy/single_node_setup.yaml (Docker Swarm + stack
|
|
5
|
+
deploy), per ADR-0006. Every step is idempotent: rerunning after a
|
|
6
|
+
partial failure resumes from the first incomplete step.
|
|
7
|
+
|
|
8
|
+
Deviations from ADR-0006, decided at implementation time:
|
|
9
|
+
- No bundled registry credentials. The registry is tried anonymously;
|
|
10
|
+
private registries take --registry-username/--registry-token.
|
|
11
|
+
- No --admin-email/--admin-password flags: the database init script
|
|
12
|
+
creates the initial admin account with a forced password reset on
|
|
13
|
+
first login, same as the Ansible playbook.
|
|
14
|
+
- Docker is installed via get.docker.com (distro-agnostic) instead of a
|
|
15
|
+
hardcoded Ubuntu-noble apt repository.
|
|
16
|
+
|
|
17
|
+
Everything that depends on the release (compose files, config, volumes,
|
|
18
|
+
networks, secrets) comes from the deploy:<release> package and its
|
|
19
|
+
manifest (ADR-0022), never from this code.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import ipaddress
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import platform
|
|
27
|
+
import secrets as pysecrets
|
|
28
|
+
import shutil
|
|
29
|
+
import socket
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
import time
|
|
33
|
+
from datetime import datetime, timezone
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
|
|
36
|
+
import httpx
|
|
37
|
+
import typer
|
|
38
|
+
|
|
39
|
+
from progress_cli.package import (
|
|
40
|
+
DEFAULT_CHANNEL, checkout_assets, extract_package, pull_package,
|
|
41
|
+
temp_admin_password,
|
|
42
|
+
)
|
|
43
|
+
from progress_cli.runner import (
|
|
44
|
+
PROD_ROOT, REGISTRY, StepError, console, docker, run, step,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
STACK_NAME = "progress"
|
|
48
|
+
MARKER = ".progress-installed"
|
|
49
|
+
DB_INIT_MARKER = ".db-initialized"
|
|
50
|
+
INIT_DB_SERVICE = "progress-init-db"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_ip(value: str) -> bool:
|
|
54
|
+
try:
|
|
55
|
+
ipaddress.ip_address(value)
|
|
56
|
+
return True
|
|
57
|
+
except ValueError:
|
|
58
|
+
return False
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _default_host_ip() -> str:
|
|
62
|
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
63
|
+
try:
|
|
64
|
+
s.connect(("8.8.8.8", 80))
|
|
65
|
+
return s.getsockname()[0]
|
|
66
|
+
except OSError:
|
|
67
|
+
return "127.0.0.1"
|
|
68
|
+
finally:
|
|
69
|
+
s.close()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _rerun_as_root() -> None:
|
|
73
|
+
"""Per-user installs (uv tool, pipx) live in ~/.local/bin, which
|
|
74
|
+
sudo's secure_path hides: re-exec this same interpreter under sudo."""
|
|
75
|
+
if platform.system() == "Linux" and os.geteuid() != 0 and shutil.which("sudo"):
|
|
76
|
+
os.execvp("sudo", ["sudo", sys.executable, "-m", "progress_cli", *sys.argv[1:]])
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def docker_minor(version: str) -> str:
|
|
80
|
+
"""`27.5.0` -> `27.5`: the granularity get.docker.com --version takes."""
|
|
81
|
+
return ".".join(version.split(".")[:2])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def install_docker(s, wanted: str | None = None) -> None:
|
|
85
|
+
"""Body of the "Installing Docker" step, shared with `progress clone`.
|
|
86
|
+
|
|
87
|
+
`wanted` pins the release line to install (clone passes the source's:
|
|
88
|
+
a clone is a copy, not a Docker upgrade, which changes image IDs
|
|
89
|
+
and runtime behaviour under old images). An existing Docker is
|
|
90
|
+
reused either way; a different line is flagged, not replaced.
|
|
91
|
+
"""
|
|
92
|
+
try:
|
|
93
|
+
existing = subprocess.run(
|
|
94
|
+
["docker", "--version"], capture_output=True, text=True
|
|
95
|
+
)
|
|
96
|
+
except FileNotFoundError:
|
|
97
|
+
existing = subprocess.CompletedProcess([], 1, "", "")
|
|
98
|
+
if existing.returncode == 0:
|
|
99
|
+
found = existing.stdout.split()[2].rstrip(",")
|
|
100
|
+
if int(found.split(".")[0]) < 24:
|
|
101
|
+
raise StepError(
|
|
102
|
+
f"Docker {found} is too old (need ≥ 24).",
|
|
103
|
+
hint="Upgrade Docker, then rerun.",
|
|
104
|
+
)
|
|
105
|
+
if wanted and docker_minor(found) != docker_minor(wanted):
|
|
106
|
+
s.done(f"already installed, {found} [yellow](source runs {wanted})[/]")
|
|
107
|
+
else:
|
|
108
|
+
s.done(f"already installed, {found}")
|
|
109
|
+
else:
|
|
110
|
+
script = httpx.get("https://get.docker.com", timeout=30,
|
|
111
|
+
follow_redirects=True).text
|
|
112
|
+
pin = ["--version", docker_minor(wanted)] if wanted else []
|
|
113
|
+
try:
|
|
114
|
+
run("sh", "-c", script, "get-docker", *pin, timeout=600)
|
|
115
|
+
except StepError as e:
|
|
116
|
+
if not wanted:
|
|
117
|
+
raise
|
|
118
|
+
raise StepError(
|
|
119
|
+
f"Could not install Docker {docker_minor(wanted)} (the source's) "
|
|
120
|
+
f"on this distro:\n{str(e)[-600:]}",
|
|
121
|
+
hint=f"Install Docker {docker_minor(wanted)} or the closest "
|
|
122
|
+
"available release yourself, then rerun: an existing Docker is reused.")
|
|
123
|
+
s.done(f"{docker_minor(wanted)} via get.docker.com" if wanted else "via get.docker.com")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _load_env_file(path: Path) -> dict[str, str]:
|
|
127
|
+
env: dict[str, str] = {}
|
|
128
|
+
for line in path.read_text().splitlines():
|
|
129
|
+
line = line.strip()
|
|
130
|
+
if line and not line.startswith("#") and "=" in line:
|
|
131
|
+
key, _, value = line.partition("=")
|
|
132
|
+
env[key] = value
|
|
133
|
+
return env
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def init(
|
|
137
|
+
release: str = typer.Option(None, "--release", help=f"Release to deploy: a registry tag such as 0.10.b57 (default: the release tagged {DEFAULT_CHANNEL})"),
|
|
138
|
+
host: str = typer.Option(None, "--host", help="Public hostname (or IP) for the Progress UI"),
|
|
139
|
+
enable_tls: bool = typer.Option(False, "--enable-tls/--no-tls", help="Provision a Let's Encrypt certificate via Traefik (requires --host with DNS pointing here)"),
|
|
140
|
+
tls_email: str = typer.Option(None, "--tls-email", help="Email for Let's Encrypt notifications (required with --enable-tls)"),
|
|
141
|
+
registry_username: str = typer.Option(None, "--registry-username", help="Container registry username (default: anonymous pull)"),
|
|
142
|
+
registry_token: str = typer.Option(None, "--registry-token", help="Container registry token"),
|
|
143
|
+
skip_pull: bool = typer.Option(False, "--skip-pull", help="Skip pre-pulling images (stack deploy still pulls missing ones)"),
|
|
144
|
+
non_interactive: bool = typer.Option(False, "--non-interactive", help="Never prompt; require flags for every answer"),
|
|
145
|
+
):
|
|
146
|
+
"""Initialize a single-node Progress deployment on this host.
|
|
147
|
+
|
|
148
|
+
Installs Docker if missing, creates /opt/progress, generates secrets,
|
|
149
|
+
initializes Docker Swarm, deploys the stack, and bootstraps the
|
|
150
|
+
database. Run as root on a fresh Linux host. Idempotent: rerun after
|
|
151
|
+
a failure to resume.
|
|
152
|
+
"""
|
|
153
|
+
_rerun_as_root()
|
|
154
|
+
marker = PROD_ROOT / "config" / MARKER
|
|
155
|
+
if marker.exists():
|
|
156
|
+
console.print(
|
|
157
|
+
f"[yellow]Already installed[/] — {marker} exists "
|
|
158
|
+
f"({marker.read_text().strip()}).\n"
|
|
159
|
+
f"Remove that file to force a re-install."
|
|
160
|
+
)
|
|
161
|
+
raise typer.Exit(1)
|
|
162
|
+
|
|
163
|
+
# ---- gather answers -------------------------------------------------
|
|
164
|
+
if non_interactive:
|
|
165
|
+
if not host:
|
|
166
|
+
raise typer.BadParameter("--non-interactive requires --host")
|
|
167
|
+
else:
|
|
168
|
+
console.print("\n[bold]Progress Platform installer.[/]\n")
|
|
169
|
+
if host is None:
|
|
170
|
+
console.print(
|
|
171
|
+
" Where will the UI be reached?\n"
|
|
172
|
+
" Enter a domain name (with DNS pointing here) or press Enter to\n"
|
|
173
|
+
" use this host's IP for HTTP-only mode."
|
|
174
|
+
)
|
|
175
|
+
host = typer.prompt(" Domain", default=_default_host_ip(), show_default=True).strip()
|
|
176
|
+
if not enable_tls and not _is_ip(host):
|
|
177
|
+
enable_tls = typer.confirm(
|
|
178
|
+
f" Enable TLS via Let's Encrypt? Requires {host} to resolve to this host.",
|
|
179
|
+
default=False,
|
|
180
|
+
)
|
|
181
|
+
if enable_tls and not tls_email:
|
|
182
|
+
tls_email = typer.prompt(" TLS notification email").strip()
|
|
183
|
+
if release is None:
|
|
184
|
+
release = typer.prompt(" Release tag to deploy", default=DEFAULT_CHANNEL).strip()
|
|
185
|
+
if bool(registry_username) != bool(registry_token):
|
|
186
|
+
raise typer.BadParameter(
|
|
187
|
+
"--registry-username and --registry-token go together")
|
|
188
|
+
if enable_tls and not tls_email:
|
|
189
|
+
raise typer.BadParameter("--enable-tls requires --tls-email")
|
|
190
|
+
if enable_tls and _is_ip(host):
|
|
191
|
+
raise typer.BadParameter("TLS needs a domain name, not an IP, in --host")
|
|
192
|
+
|
|
193
|
+
plan = [
|
|
194
|
+
f"create {PROD_ROOT} with the Progress directory layout",
|
|
195
|
+
"install Docker if not present",
|
|
196
|
+
f"fetch the {release or DEFAULT_CHANNEL} deploy package and check it against this CLI",
|
|
197
|
+
"create Docker volumes and overlay networks",
|
|
198
|
+
"initialize Docker Swarm",
|
|
199
|
+
"generate Docker secrets (DB and JWT credentials)",
|
|
200
|
+
"pull the release's image set",
|
|
201
|
+
"deploy the Progress stack" + (" with TLS" if enable_tls else " (HTTP)"),
|
|
202
|
+
"run the database init service to bootstrap databases and users",
|
|
203
|
+
]
|
|
204
|
+
if not non_interactive:
|
|
205
|
+
console.print("\n Ready to install. This will:\n")
|
|
206
|
+
for item in plan:
|
|
207
|
+
console.print(f" - {item}")
|
|
208
|
+
console.print()
|
|
209
|
+
if not typer.confirm(" Proceed?", default=True):
|
|
210
|
+
raise typer.Exit(0)
|
|
211
|
+
console.print()
|
|
212
|
+
|
|
213
|
+
# ---- steps ----------------------------------------------------------
|
|
214
|
+
with step("Checking prerequisites") as s:
|
|
215
|
+
if platform.system() != "Linux":
|
|
216
|
+
raise StepError(
|
|
217
|
+
"progress init provisions a Linux host.",
|
|
218
|
+
hint="For a local development stack use `progress dev`.",
|
|
219
|
+
)
|
|
220
|
+
if os.geteuid() != 0:
|
|
221
|
+
raise StepError("Must run as root.", hint="sudo progress init …")
|
|
222
|
+
free_gb = shutil.disk_usage("/").free / 1e9
|
|
223
|
+
if free_gb < 20:
|
|
224
|
+
raise StepError(f"Need 20+ GB free on /, found {free_gb:.0f} GB.")
|
|
225
|
+
ram_gb = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") / 1e9
|
|
226
|
+
if ram_gb < 3.5:
|
|
227
|
+
raise StepError(f"Need 4+ GB RAM, found {ram_gb:.1f} GB.")
|
|
228
|
+
for host_name in (REGISTRY.split("/")[0], "registry-1.docker.io"):
|
|
229
|
+
try:
|
|
230
|
+
httpx.head(f"https://{host_name}", timeout=10)
|
|
231
|
+
except httpx.HTTPError as e:
|
|
232
|
+
raise StepError(f"Cannot reach {host_name}: {e}")
|
|
233
|
+
s.done(f"{ram_gb:.0f} GB RAM, {free_gb:.0f} GB free")
|
|
234
|
+
|
|
235
|
+
with step("Installing Docker") as s:
|
|
236
|
+
install_docker(s)
|
|
237
|
+
|
|
238
|
+
with step("Logging in to registry") as s:
|
|
239
|
+
if not registry_username:
|
|
240
|
+
s.skip("anonymous pull")
|
|
241
|
+
docker("login", REGISTRY.split("/")[0], "-u", registry_username,
|
|
242
|
+
"--password-stdin", input=registry_token or "")
|
|
243
|
+
|
|
244
|
+
with step("Fetching deploy package") as s:
|
|
245
|
+
assets = checkout_assets()
|
|
246
|
+
if assets and release:
|
|
247
|
+
s.skip(f"{release}, files from repo checkout")
|
|
248
|
+
ref, release = pull_package(release, pull=not skip_pull)
|
|
249
|
+
if assets:
|
|
250
|
+
s.done(f"{release}, files from repo checkout")
|
|
251
|
+
else:
|
|
252
|
+
assets = extract_package(ref, PROD_ROOT / "package")
|
|
253
|
+
s.done(f"{release} into {PROD_ROOT / 'package'}")
|
|
254
|
+
manifest = assets.manifest
|
|
255
|
+
|
|
256
|
+
with step("Creating directory layout") as s:
|
|
257
|
+
for volume in manifest.volumes:
|
|
258
|
+
(PROD_ROOT / volume).mkdir(parents=True, exist_ok=True)
|
|
259
|
+
custom_certs = PROD_ROOT / "letsencrypt" / "custom"
|
|
260
|
+
custom_certs.mkdir(exist_ok=True)
|
|
261
|
+
custom_certs.chmod(0o700)
|
|
262
|
+
s.done(f"{len(manifest.volumes)} directories under {PROD_ROOT}")
|
|
263
|
+
|
|
264
|
+
with step("Copying deployment files") as s:
|
|
265
|
+
config_dir = PROD_ROOT / "config"
|
|
266
|
+
copied = 0
|
|
267
|
+
for src in sorted(assets.compose.glob("*.yaml")):
|
|
268
|
+
shutil.copy(src, config_dir / src.name)
|
|
269
|
+
copied += 1
|
|
270
|
+
for name in manifest.config_files:
|
|
271
|
+
shutil.copy(assets.config / name, config_dir / name)
|
|
272
|
+
copied += 1
|
|
273
|
+
shutil.copy(assets.db_init, PROD_ROOT / "db_init.py")
|
|
274
|
+
if assets.reports.exists():
|
|
275
|
+
shutil.copytree(assets.reports, PROD_ROOT / "reports", dirs_exist_ok=True)
|
|
276
|
+
s.done(f"{copied} files into {config_dir}")
|
|
277
|
+
|
|
278
|
+
with step("Rendering progress.env") as s:
|
|
279
|
+
env_lines = [
|
|
280
|
+
f"VERSION={release}",
|
|
281
|
+
f"HOST={host}",
|
|
282
|
+
f"ENABLE_TLS={'true' if enable_tls else 'false'}",
|
|
283
|
+
f"PROTOCOL={'https' if enable_tls else 'http'}",
|
|
284
|
+
]
|
|
285
|
+
if tls_email:
|
|
286
|
+
env_lines.append(f"TLS_EMAIL={tls_email}")
|
|
287
|
+
(PROD_ROOT / "config" / "progress.env").write_text("\n".join(env_lines) + "\n")
|
|
288
|
+
s.done(f"VERSION={release}, HOST={host}")
|
|
289
|
+
|
|
290
|
+
with step("Creating Docker volumes") as s:
|
|
291
|
+
existing_volumes = set(docker("volume", "ls", "-q").splitlines())
|
|
292
|
+
created = 0
|
|
293
|
+
for volume in manifest.volumes:
|
|
294
|
+
if volume in existing_volumes:
|
|
295
|
+
continue
|
|
296
|
+
docker("volume", "create", "--driver", "local",
|
|
297
|
+
"-o", "o=bind", "-o", "type=none",
|
|
298
|
+
"-o", f"device={PROD_ROOT / volume}", volume)
|
|
299
|
+
created += 1
|
|
300
|
+
s.done(f"{created} created, {len(manifest.volumes) - created} existing")
|
|
301
|
+
|
|
302
|
+
with step("Initializing Docker Swarm") as s:
|
|
303
|
+
state = docker("info", "--format", "{{.Swarm.LocalNodeState}}")
|
|
304
|
+
if state == "active":
|
|
305
|
+
s.skip("already active")
|
|
306
|
+
docker("swarm", "init")
|
|
307
|
+
|
|
308
|
+
with step("Creating overlay networks") as s:
|
|
309
|
+
existing_networks = set(
|
|
310
|
+
docker("network", "ls", "--format", "{{.Name}}").splitlines()
|
|
311
|
+
)
|
|
312
|
+
for network in manifest.networks:
|
|
313
|
+
if network not in existing_networks:
|
|
314
|
+
docker("network", "create", "--driver", "overlay",
|
|
315
|
+
"--attachable", network)
|
|
316
|
+
s.done(", ".join(manifest.networks))
|
|
317
|
+
|
|
318
|
+
with step("Generating Docker secrets") as s:
|
|
319
|
+
existing_secrets = set(
|
|
320
|
+
docker("secret", "ls", "--format", "{{.Name}}").splitlines()
|
|
321
|
+
)
|
|
322
|
+
created = 0
|
|
323
|
+
for name, length in manifest.secrets.items():
|
|
324
|
+
if name in existing_secrets:
|
|
325
|
+
continue
|
|
326
|
+
docker("secret", "create", name, "-",
|
|
327
|
+
input=pysecrets.token_hex(length))
|
|
328
|
+
created += 1
|
|
329
|
+
s.done(f"{created} created, {len(manifest.secrets) - created} existing")
|
|
330
|
+
|
|
331
|
+
config_dir = PROD_ROOT / "config"
|
|
332
|
+
deploy_env = {**os.environ, **_load_env_file(config_dir / "progress.env")}
|
|
333
|
+
stack_files = manifest.stack_files + ([manifest.tls_file] if enable_tls else [])
|
|
334
|
+
compose_args: list[str] = []
|
|
335
|
+
for f in stack_files:
|
|
336
|
+
compose_args += ["-c", f]
|
|
337
|
+
|
|
338
|
+
with step(f"Pulling images for {release}") as s:
|
|
339
|
+
if skip_pull:
|
|
340
|
+
s.skip("--skip-pull")
|
|
341
|
+
file_args: list[str] = []
|
|
342
|
+
for f in stack_files:
|
|
343
|
+
file_args += ["-f", str(config_dir / f)]
|
|
344
|
+
try:
|
|
345
|
+
images = run(
|
|
346
|
+
"docker", "compose", "--project-directory", str(config_dir),
|
|
347
|
+
*file_args, "config", "--images", env=deploy_env,
|
|
348
|
+
).splitlines()
|
|
349
|
+
except StepError as e:
|
|
350
|
+
if "not a docker command" in str(e):
|
|
351
|
+
raise StepError(
|
|
352
|
+
"The docker compose plugin is missing (pre-installed "
|
|
353
|
+
"Docker without docker-compose-plugin).",
|
|
354
|
+
hint="Install docker-compose-plugin, or rerun with "
|
|
355
|
+
"--skip-pull — stack deploy pulls images itself.",
|
|
356
|
+
)
|
|
357
|
+
raise
|
|
358
|
+
started = time.monotonic()
|
|
359
|
+
for image in sorted(set(filter(None, images))):
|
|
360
|
+
run("docker", "pull", image, timeout=1800)
|
|
361
|
+
s.done(f"{len(set(images))} images, {time.monotonic() - started:.0f}s")
|
|
362
|
+
|
|
363
|
+
with step("Deploying stack") as s:
|
|
364
|
+
run("sh", "-c",
|
|
365
|
+
f"cd {config_dir} && docker stack deploy --with-registry-auth "
|
|
366
|
+
+ " ".join(compose_args) + f" {STACK_NAME}",
|
|
367
|
+
env=deploy_env)
|
|
368
|
+
s.done(f"stack '{STACK_NAME}'")
|
|
369
|
+
|
|
370
|
+
with step("Running database init") as s:
|
|
371
|
+
if (config_dir / DB_INIT_MARKER).exists():
|
|
372
|
+
s.skip("already initialized")
|
|
373
|
+
subprocess.run(["docker", "service", "rm", INIT_DB_SERVICE],
|
|
374
|
+
capture_output=True)
|
|
375
|
+
secret_args: list[str] = []
|
|
376
|
+
for name in manifest.secrets:
|
|
377
|
+
secret_args += ["--secret", name]
|
|
378
|
+
started = time.monotonic()
|
|
379
|
+
docker(
|
|
380
|
+
"service", "create", "--detach", "--name", INIT_DB_SERVICE,
|
|
381
|
+
"--restart-condition", "none", "--network", "progress",
|
|
382
|
+
*secret_args,
|
|
383
|
+
"--mount", f"type=bind,source={PROD_ROOT / 'db_init.py'},target=/db_init.py",
|
|
384
|
+
"--mount", f"type=bind,source={config_dir},target=/output",
|
|
385
|
+
f"{REGISTRY}/api:{release}", "python3", "/db_init.py",
|
|
386
|
+
)
|
|
387
|
+
deadline = time.monotonic() + 300
|
|
388
|
+
while True:
|
|
389
|
+
tasks = docker("service", "ps", INIT_DB_SERVICE,
|
|
390
|
+
"--format", "{{json .}}").splitlines()
|
|
391
|
+
states = [json.loads(t)["CurrentState"] for t in tasks]
|
|
392
|
+
if any(state.startswith("Complete") for state in states):
|
|
393
|
+
break
|
|
394
|
+
if any(state.startswith(("Failed", "Rejected")) for state in states):
|
|
395
|
+
logs = subprocess.run(
|
|
396
|
+
["docker", "service", "logs", "--tail", "30", INIT_DB_SERVICE],
|
|
397
|
+
capture_output=True, text=True,
|
|
398
|
+
).stderr
|
|
399
|
+
raise StepError(
|
|
400
|
+
f"Database init failed:\n{logs[-1500:]}",
|
|
401
|
+
hint=f"docker service logs {INIT_DB_SERVICE}",
|
|
402
|
+
)
|
|
403
|
+
if time.monotonic() > deadline:
|
|
404
|
+
raise StepError("Database init did not finish within 5 minutes.",
|
|
405
|
+
hint=f"docker service logs {INIT_DB_SERVICE}")
|
|
406
|
+
time.sleep(3)
|
|
407
|
+
docker("service", "rm", INIT_DB_SERVICE)
|
|
408
|
+
(config_dir / DB_INIT_MARKER).write_text(
|
|
409
|
+
datetime.now(timezone.utc).isoformat() + "\n")
|
|
410
|
+
s.done(f"{time.monotonic() - started:.0f}s")
|
|
411
|
+
|
|
412
|
+
with step("Waiting for API to be ready") as s:
|
|
413
|
+
deadline = time.monotonic() + 300
|
|
414
|
+
last_error = "no response"
|
|
415
|
+
# verify=False: the probe hits localhost with a Host header; in TLS
|
|
416
|
+
# mode the ACME cert may not be issued yet when the API comes up.
|
|
417
|
+
while time.monotonic() < deadline:
|
|
418
|
+
try:
|
|
419
|
+
r = httpx.get("http://127.0.0.1/api/hello",
|
|
420
|
+
headers={"Host": host}, timeout=5,
|
|
421
|
+
follow_redirects=True, verify=False)
|
|
422
|
+
if r.status_code < 500:
|
|
423
|
+
s.done(f"HTTP {r.status_code}")
|
|
424
|
+
break
|
|
425
|
+
last_error = f"HTTP {r.status_code}"
|
|
426
|
+
except httpx.HTTPError as e:
|
|
427
|
+
last_error = str(e)
|
|
428
|
+
time.sleep(3)
|
|
429
|
+
else:
|
|
430
|
+
raise StepError(
|
|
431
|
+
f"API did not respond within 5 minutes ({last_error}).",
|
|
432
|
+
hint="docker service ls; docker service logs progress_api",
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
marker.write_text(f"{release} {datetime.now(timezone.utc).isoformat()}\n")
|
|
436
|
+
|
|
437
|
+
scheme = "https" if enable_tls else "http"
|
|
438
|
+
temp_password = temp_admin_password(assets.db_init)
|
|
439
|
+
console.print(
|
|
440
|
+
f"\n Progress is up at: [bold]{scheme}://{host}[/]\n\n"
|
|
441
|
+
f" Sign in as: [bold]cadmin[/]\n"
|
|
442
|
+
f" Temporary password: [bold]{temp_password}[/]\n\n"
|
|
443
|
+
f" You will be required to set a new password on first login.\n"
|
|
444
|
+
)
|
progress_cli/main.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Progress Platform operations CLI — Typer root app.
|
|
2
|
+
|
|
3
|
+
`progress` is the install/ops entrypoint for a Progress deployment:
|
|
4
|
+
bootstrap a host (init), snapshot and restore the database
|
|
5
|
+
(backup/restore), roll services to a new release (update), and run a
|
|
6
|
+
local development stack from a checkout (dev).
|
|
7
|
+
"""
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
from progress_cli import __version__
|
|
11
|
+
from progress_cli.backup import backup
|
|
12
|
+
from progress_cli.clone import clone
|
|
13
|
+
from progress_cli.copy import copy
|
|
14
|
+
from progress_cli.dev import dev
|
|
15
|
+
from progress_cli.init import init
|
|
16
|
+
from progress_cli.restore import restore
|
|
17
|
+
from progress_cli.update import update
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(
|
|
20
|
+
help="Progress Platform operations CLI.",
|
|
21
|
+
add_completion=False,
|
|
22
|
+
pretty_exceptions_show_locals=False,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
app.command()(init)
|
|
26
|
+
app.command()(backup)
|
|
27
|
+
app.command()(restore)
|
|
28
|
+
app.command()(update)
|
|
29
|
+
app.command()(clone)
|
|
30
|
+
app.command()(copy)
|
|
31
|
+
app.command()(dev)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@app.callback(invoke_without_command=True)
|
|
35
|
+
def _root(
|
|
36
|
+
ctx: typer.Context,
|
|
37
|
+
version: bool = typer.Option(False, "--version", help="Print the CLI version and exit", is_eager=True),
|
|
38
|
+
):
|
|
39
|
+
if version:
|
|
40
|
+
typer.echo(f"progress-cli {__version__}")
|
|
41
|
+
raise typer.Exit(0)
|
|
42
|
+
if ctx.invoked_subcommand is None:
|
|
43
|
+
typer.echo(ctx.get_help())
|
|
44
|
+
raise typer.Exit(0)
|
progress_cli/package.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""The deploy package (ADR-0022): everything that depends on the release.
|
|
2
|
+
|
|
3
|
+
Each platform release publishes registry…/deploy:<tag>, a files-only
|
|
4
|
+
image holding the compose files, config, db_init.py and a manifest that
|
|
5
|
+
names the stack files, volumes, networks and secrets. The CLI reads the
|
|
6
|
+
manifest instead of hardcoding them, so one CLI deploys any release whose
|
|
7
|
+
manifest it supports.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
import shutil
|
|
13
|
+
import subprocess
|
|
14
|
+
import tempfile
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import yaml
|
|
19
|
+
|
|
20
|
+
from progress_cli import __version__
|
|
21
|
+
from progress_cli.runner import REGISTRY, StepError, docker
|
|
22
|
+
|
|
23
|
+
SUPPORTED_SCHEMAS = {1}
|
|
24
|
+
PACKAGE_IMAGE = f"{REGISTRY}/deploy"
|
|
25
|
+
RELEASE_LABEL = "progress.release"
|
|
26
|
+
DEFAULT_CHANNEL = "stable"
|
|
27
|
+
UPGRADE_HINT = ("Upgrade the CLI: curl -fsSL https://progresslabit.github.io/"
|
|
28
|
+
"progress-platform/install.sh | sudo sh (or: uv tool upgrade progress-cli)")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class Manifest:
|
|
33
|
+
min_cli: str
|
|
34
|
+
stack_files: list[str]
|
|
35
|
+
tls_file: str
|
|
36
|
+
volumes: list[str]
|
|
37
|
+
networks: list[str]
|
|
38
|
+
secrets: dict[str, int]
|
|
39
|
+
config_files: list[str]
|
|
40
|
+
db_init: str
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _version(value: str) -> tuple[int, ...]:
|
|
44
|
+
parts = tuple(int(p) for p in value.split("."))
|
|
45
|
+
return parts + (0,) * (3 - len(parts))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_manifest(text: str, cli_version: str = __version__) -> Manifest:
|
|
49
|
+
"""Validate a manifest against this CLI; StepError says what to do."""
|
|
50
|
+
try:
|
|
51
|
+
data = yaml.safe_load(text)
|
|
52
|
+
except yaml.YAMLError as e:
|
|
53
|
+
raise StepError(f"manifest.yaml is not valid YAML: {e}")
|
|
54
|
+
if not isinstance(data, dict):
|
|
55
|
+
raise StepError("manifest.yaml is not a mapping.")
|
|
56
|
+
|
|
57
|
+
# min_cli first: a release with a newer schema also raises min_cli,
|
|
58
|
+
# and "upgrade to ≥ X" is the more useful message.
|
|
59
|
+
min_cli = str(data.get("min_cli", ""))
|
|
60
|
+
try:
|
|
61
|
+
too_old = _version(cli_version) < _version(min_cli)
|
|
62
|
+
except ValueError:
|
|
63
|
+
raise StepError(f"manifest.yaml: invalid min_cli {min_cli!r}.")
|
|
64
|
+
if too_old:
|
|
65
|
+
raise StepError(
|
|
66
|
+
f"This release requires progress-cli ≥ {min_cli} (installed: {cli_version}).",
|
|
67
|
+
hint=UPGRADE_HINT,
|
|
68
|
+
)
|
|
69
|
+
if data.get("schema") not in SUPPORTED_SCHEMAS:
|
|
70
|
+
raise StepError(
|
|
71
|
+
f"This release uses deploy package schema {data.get('schema')!r}; "
|
|
72
|
+
f"progress-cli {cli_version} supports {sorted(SUPPORTED_SCHEMAS)}.",
|
|
73
|
+
hint=UPGRADE_HINT,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def field(key: str, check) -> object:
|
|
77
|
+
value = data.get(key)
|
|
78
|
+
if not check(value):
|
|
79
|
+
raise StepError(f"manifest.yaml: missing or malformed `{key}`.")
|
|
80
|
+
return value
|
|
81
|
+
|
|
82
|
+
is_str = lambda v: isinstance(v, str) and bool(v) # noqa: E731
|
|
83
|
+
is_str_list = lambda v: isinstance(v, list) and all(map(is_str, v)) # noqa: E731
|
|
84
|
+
return Manifest(
|
|
85
|
+
min_cli=min_cli,
|
|
86
|
+
stack_files=field("stack_files", lambda v: is_str_list(v) and bool(v)),
|
|
87
|
+
tls_file=field("tls_file", is_str),
|
|
88
|
+
volumes=field("volumes", is_str_list),
|
|
89
|
+
networks=field("networks", is_str_list),
|
|
90
|
+
secrets=field("secrets", lambda v: isinstance(v, dict) and all(
|
|
91
|
+
is_str(k) and isinstance(n, int) and n > 0 for k, n in v.items())),
|
|
92
|
+
config_files=field("config_files", is_str_list),
|
|
93
|
+
db_init=field("db_init", is_str),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass
|
|
98
|
+
class Assets:
|
|
99
|
+
"""Deployment files of one release: an extracted deploy package, or the
|
|
100
|
+
repo tree when running from a checkout."""
|
|
101
|
+
|
|
102
|
+
manifest: Manifest
|
|
103
|
+
compose: Path
|
|
104
|
+
config: Path
|
|
105
|
+
db_init: Path
|
|
106
|
+
reports: Path
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def package_assets(root: Path, reports: Path | None = None) -> Assets:
|
|
110
|
+
manifest = parse_manifest((root / "manifest.yaml").read_text())
|
|
111
|
+
return Assets(manifest, root / "compose", root / "config",
|
|
112
|
+
root / manifest.db_init, reports or root / "reports")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def checkout_assets() -> Assets | None:
|
|
116
|
+
"""The live repo files when running from a checkout (editable install).
|
|
117
|
+
|
|
118
|
+
The only place outside `progress dev` that reads platform files
|
|
119
|
+
directly (tests/cli/test_package.py enforces it): the checkout's
|
|
120
|
+
deploy/ has the package layout, reports live in demos/.
|
|
121
|
+
"""
|
|
122
|
+
repo = Path(__file__).resolve().parents[2]
|
|
123
|
+
if not (repo / "deploy" / "manifest.yaml").exists():
|
|
124
|
+
return None
|
|
125
|
+
return package_assets(repo / "deploy", reports=repo / "demos" / "reports")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def pull_package(release: str | None, pull: bool = True) -> tuple[str, str]:
|
|
129
|
+
"""Pull deploy:<release> (default: stable). Returns (image ref, pinned
|
|
130
|
+
release): the image's progress.release label, so a channel tag such as
|
|
131
|
+
`stable` never ends up as the stack's VERSION."""
|
|
132
|
+
ref = f"{PACKAGE_IMAGE}:{release or DEFAULT_CHANNEL}"
|
|
133
|
+
local = subprocess.run(["docker", "image", "inspect", ref],
|
|
134
|
+
capture_output=True).returncode == 0
|
|
135
|
+
if pull or not local:
|
|
136
|
+
docker("pull", ref, timeout=600)
|
|
137
|
+
label = docker("image", "inspect", "--format",
|
|
138
|
+
f'{{{{index .Config.Labels "{RELEASE_LABEL}"}}}}', ref)
|
|
139
|
+
pinned = "" if label == "<no value>" else label
|
|
140
|
+
if not pinned and release in (None, DEFAULT_CHANNEL):
|
|
141
|
+
raise StepError(f"{ref} has no {RELEASE_LABEL} label.",
|
|
142
|
+
hint="Pass the release explicitly with --release.")
|
|
143
|
+
return ref, pinned or release
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def extract_package(ref: str, dest: Path) -> Assets:
|
|
147
|
+
"""Copy the package out of the image into dest. The manifest is checked
|
|
148
|
+
before dest is touched, so an incompatible release changes nothing."""
|
|
149
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
150
|
+
staging = Path(tempfile.mkdtemp(prefix=".package-", dir=dest.parent))
|
|
151
|
+
container = docker("create", ref, "none") # never started: scratch has no shell
|
|
152
|
+
try:
|
|
153
|
+
docker("cp", f"{container}:/package/.", str(staging))
|
|
154
|
+
package_assets(staging)
|
|
155
|
+
except StepError:
|
|
156
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
157
|
+
raise
|
|
158
|
+
finally:
|
|
159
|
+
subprocess.run(["docker", "rm", container], capture_output=True)
|
|
160
|
+
shutil.rmtree(dest, ignore_errors=True)
|
|
161
|
+
staging.rename(dest)
|
|
162
|
+
return package_assets(dest)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def temp_admin_password(db_init: Path) -> str:
|
|
166
|
+
"""The temporary password db_init.py seeds for the initial admin.
|
|
167
|
+
|
|
168
|
+
Derived from the release's db_init.py at runtime so the literal never
|
|
169
|
+
appears in CLI code or documentation.
|
|
170
|
+
"""
|
|
171
|
+
match = re.search(r"pwd_context\.hash\('([^']+)'\)", db_init.read_text())
|
|
172
|
+
if not match:
|
|
173
|
+
raise StepError("Could not derive the temporary admin password "
|
|
174
|
+
"from db_init.py.")
|
|
175
|
+
return match.group(1)
|