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/copy.py
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"""`progress copy` — duplicate one Progress environment's data onto another.
|
|
2
|
+
|
|
3
|
+
scp style: `progress copy SRC DST`, where each side is `user@host` or `.`
|
|
4
|
+
(this machine). Both hosts must already be installed (`progress init` or
|
|
5
|
+
`progress clone`) and run the same release: this copies data, never
|
|
6
|
+
infrastructure, and never migrates it.
|
|
7
|
+
|
|
8
|
+
Parts (all by default, pick with --only/--skip):
|
|
9
|
+
- db: every database except _system, arangodump → arangorestore; _system
|
|
10
|
+
keeps the target's ArangoDB users so they match its Docker secrets;
|
|
11
|
+
- media, flows, reports, notebooks: the /opt/progress directories.
|
|
12
|
+
|
|
13
|
+
Each part is mirrored: the target's copy is replaced. Data streams
|
|
14
|
+
SRC → this machine → DST as tar over SSH, so the hosts never need SSH
|
|
15
|
+
access to each other and this machine needs no disk for it.
|
|
16
|
+
|
|
17
|
+
The target's wf-integration-worker (the service that runs client flows
|
|
18
|
+
against the customer's systems) is stopped and stays stopped unless
|
|
19
|
+
--live is given. Only a declared non-production environment is a valid
|
|
20
|
+
target (PROGRESS_ENV_NAME in progress.env, set by `clone --env`), or a
|
|
21
|
+
host whose progress.env says COPY_TARGET=allow; COPY_TARGET=deny always
|
|
22
|
+
refuses. See docs/cli/copy.md.
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
import shlex
|
|
28
|
+
import subprocess
|
|
29
|
+
|
|
30
|
+
import typer
|
|
31
|
+
|
|
32
|
+
from progress_cli.clone import PROD_NAMES, SSH_OPTS, WORKER_SUFFIX, release_tag
|
|
33
|
+
from progress_cli.init import MARKER
|
|
34
|
+
from progress_cli.runner import (
|
|
35
|
+
CONTAINER_BACKUP_DIR, PROD_ROOT, PS_FORMAT, StepError, console,
|
|
36
|
+
pick_arango_container, run, step,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
LOCAL = "."
|
|
40
|
+
PARTS = ["db", "media", "flows", "reports", "notebooks"]
|
|
41
|
+
DUMP_DIR = f"{CONTAINER_BACKUP_DIR}/.copy"
|
|
42
|
+
# Inside the db container: the root password never leaves the host.
|
|
43
|
+
ARANGO_AUTH = '--server.username root --server.password "$(cat /run/secrets/progress_db_root_pwd 2>/dev/null)"'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ---- pure helpers (tests/cli/test_copy.py) ------------------------------
|
|
47
|
+
|
|
48
|
+
def parse_endpoint(value: str) -> str:
|
|
49
|
+
"""`user@host`, `user@host:` (scp style) or `.` for this machine."""
|
|
50
|
+
value = value.rstrip(":")
|
|
51
|
+
if value in (".", "local", "localhost"):
|
|
52
|
+
return LOCAL
|
|
53
|
+
if not value or "/" in value:
|
|
54
|
+
raise typer.BadParameter(f"{value!r}: expected user@host or `.`")
|
|
55
|
+
return value
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def select_parts(only: list[str] | None, skip: list[str] | None) -> list[str]:
|
|
59
|
+
"""Parts to copy, in PARTS order. Values may be repeated or comma-separated."""
|
|
60
|
+
def split(values):
|
|
61
|
+
return {p.strip() for v in values or [] for p in v.split(",") if p.strip()}
|
|
62
|
+
chosen, skipped = split(only), split(skip)
|
|
63
|
+
if chosen and skipped:
|
|
64
|
+
raise typer.BadParameter("--only and --skip are mutually exclusive.")
|
|
65
|
+
unknown = (chosen | skipped) - set(PARTS)
|
|
66
|
+
if unknown:
|
|
67
|
+
raise typer.BadParameter(f"Unknown parts: {', '.join(sorted(unknown))}. Choose from {', '.join(PARTS)}.")
|
|
68
|
+
parts = [p for p in PARTS if (p in chosen if chosen else p not in skipped)]
|
|
69
|
+
if not parts:
|
|
70
|
+
raise typer.BadParameter("Nothing left to copy.")
|
|
71
|
+
return parts
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def env_value(text: str, key: str) -> str | None:
|
|
75
|
+
"""KEY's value in a dotenv text."""
|
|
76
|
+
for line in text.splitlines():
|
|
77
|
+
line = line.strip()
|
|
78
|
+
if line.startswith(f"{key}="):
|
|
79
|
+
return line.partition("=")[2].strip().strip("'\"")
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def copy_refusal(progress_env: str) -> str | None:
|
|
84
|
+
"""Why a host must not be overwritten, or None. Fails closed: a host
|
|
85
|
+
that declares no environment may be production."""
|
|
86
|
+
policy = (env_value(progress_env, "COPY_TARGET") or "").lower()
|
|
87
|
+
if policy == "deny":
|
|
88
|
+
return "has COPY_TARGET=deny in progress.env"
|
|
89
|
+
if policy == "allow":
|
|
90
|
+
return None
|
|
91
|
+
name = env_value(progress_env, "PROGRESS_ENV_NAME")
|
|
92
|
+
if not name:
|
|
93
|
+
return "declares no environment (PROGRESS_ENV_NAME in progress.env), so it may be production"
|
|
94
|
+
if name.lower() in PROD_NAMES:
|
|
95
|
+
return f"is {name}"
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def on(host: str, *argv: str) -> list[str]:
|
|
100
|
+
"""argv run on `host`: as is locally, through ssh otherwise."""
|
|
101
|
+
return list(argv) if host == LOCAL else ["ssh", *SSH_OPTS, host, shlex.join(argv)]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# ---- host plumbing ------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
def sh(host: str, *argv: str, timeout: int = 900) -> str:
|
|
107
|
+
return run(*on(host, *argv), timeout=timeout)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def succeeds(host: str, *argv: str) -> bool:
|
|
111
|
+
return subprocess.run(on(host, *argv), capture_output=True).returncode == 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def stream(src: str, src_argv: list[str], dst: str, dst_argv: list[str]) -> None:
|
|
115
|
+
"""Pipe a command's stdout on src into a command's stdin on dst."""
|
|
116
|
+
run("bash", "-c", "set -o pipefail; " + shlex.join(on(src, *src_argv))
|
|
117
|
+
+ " | " + shlex.join(on(dst, *dst_argv)), timeout=7200)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def label(host: str) -> str:
|
|
121
|
+
return "this machine" if host == LOCAL else host
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def copy(
|
|
125
|
+
src: str = typer.Argument(..., help="Source environment: user@host, or . for this machine"),
|
|
126
|
+
dst: str = typer.Argument(..., help="Target environment: user@host, or . for this machine. Its data is replaced"),
|
|
127
|
+
only: list[str] = typer.Option(None, "--only", help=f"Copy only these parts (repeat or comma-separate): {', '.join(PARTS)}"),
|
|
128
|
+
skip: list[str] = typer.Option(None, "--skip", help="Copy every part except these"),
|
|
129
|
+
live: bool = typer.Option(False, "--live", help="Start the target's wf-integration-worker afterwards. Default: leave it stopped, so the copy cannot act on the customer's systems"),
|
|
130
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip the confirmation before the target's data is replaced"),
|
|
131
|
+
):
|
|
132
|
+
"""Copy an environment's data (database, media, flows, reports,
|
|
133
|
+
notebooks) onto another installed host of the same release.
|
|
134
|
+
|
|
135
|
+
For development, testing and troubleshooting copies: no infrastructure
|
|
136
|
+
is touched. Run it anywhere that reaches both hosts as root over SSH.
|
|
137
|
+
"""
|
|
138
|
+
src, dst = parse_endpoint(src), parse_endpoint(dst)
|
|
139
|
+
if src == dst:
|
|
140
|
+
raise typer.BadParameter("Source and target are the same host.")
|
|
141
|
+
parts = select_parts(only, skip)
|
|
142
|
+
root = str(PROD_ROOT)
|
|
143
|
+
|
|
144
|
+
# ---- checks ---------------------------------------------------------
|
|
145
|
+
for host in (src, dst):
|
|
146
|
+
with step(f"Connecting to {label(host)}") as s:
|
|
147
|
+
if sh(host, "id", "-u") != "0":
|
|
148
|
+
raise StepError(f"{label(host)}: not root.",
|
|
149
|
+
hint="Use root@host, or sudo for `.`.")
|
|
150
|
+
s.done("root")
|
|
151
|
+
|
|
152
|
+
with step("Checking the target") as s:
|
|
153
|
+
if not succeeds(dst, "test", "-f", f"{root}/config/{MARKER}"):
|
|
154
|
+
raise StepError(f"{label(dst)} is not an installed Progress host.",
|
|
155
|
+
hint="Install it first with progress init (same release as the source).")
|
|
156
|
+
progress_env = subprocess.run(on(dst, "cat", f"{root}/config/progress.env"),
|
|
157
|
+
capture_output=True, text=True).stdout
|
|
158
|
+
refusal = copy_refusal(progress_env)
|
|
159
|
+
if refusal:
|
|
160
|
+
raise StepError(
|
|
161
|
+
f"{label(dst)} {refusal}: it refuses to be overwritten.",
|
|
162
|
+
hint="On a test host, add PROGRESS_ENV_NAME=TEST (or COPY_TARGET=allow) "
|
|
163
|
+
f"to {root}/config/progress.env.")
|
|
164
|
+
dst_env = env_value(progress_env, "PROGRESS_ENV_NAME")
|
|
165
|
+
s.done(f"installed, {dst_env or 'COPY_TARGET=allow'}")
|
|
166
|
+
|
|
167
|
+
with step("Comparing releases") as s:
|
|
168
|
+
releases = {}
|
|
169
|
+
for host in (src, dst):
|
|
170
|
+
ids = sh(host, "docker", "service", "ls", "-q").split()
|
|
171
|
+
if not ids:
|
|
172
|
+
raise StepError(f"No Swarm services on {label(host)}.", hint="Is the stack running?")
|
|
173
|
+
releases[host] = release_tag(json.loads(sh(host, "docker", "service", "inspect", *ids)))
|
|
174
|
+
if releases[src] != releases[dst]:
|
|
175
|
+
raise StepError(
|
|
176
|
+
f"Release mismatch: {label(src)} runs {releases[src]}, {label(dst)} runs {releases[dst]}.",
|
|
177
|
+
hint=f"Run progress update {releases[src]} on the target first. "
|
|
178
|
+
"Moving data across releases is an upgrade: use progress clone.",
|
|
179
|
+
)
|
|
180
|
+
s.done(releases[src])
|
|
181
|
+
|
|
182
|
+
with step("Checking source parts") as s:
|
|
183
|
+
missing = [p for p in parts if p != "db" and not succeeds(src, "test", "-d", f"{root}/{p}")]
|
|
184
|
+
parts = [p for p in parts if p not in missing]
|
|
185
|
+
s.done(", ".join(parts) + (f"; not on source: {', '.join(missing)}" if missing else ""))
|
|
186
|
+
|
|
187
|
+
if not yes:
|
|
188
|
+
console.print(
|
|
189
|
+
f"\n This replaces [bold]{', '.join(parts)}[/] on [bold]{label(dst)}[/]"
|
|
190
|
+
+ (f" ([bold]{dst_env}[/])" if dst_env else "") + " "
|
|
191
|
+
f"with the data of {label(src)}.\n The target's users and passwords become the source's."
|
|
192
|
+
)
|
|
193
|
+
if not typer.confirm(" Proceed?", default=False):
|
|
194
|
+
raise typer.Exit(0)
|
|
195
|
+
console.print()
|
|
196
|
+
|
|
197
|
+
# ---- copy -----------------------------------------------------------
|
|
198
|
+
workers = [n for n in sh(dst, "docker", "service", "ls", "--format", "{{.Name}}").split()
|
|
199
|
+
if n.endswith(WORKER_SUFFIX)]
|
|
200
|
+
with step("Stopping target flows") as s:
|
|
201
|
+
if not workers:
|
|
202
|
+
s.skip("no wf-integration-worker")
|
|
203
|
+
sh(dst, "docker", "service", "scale", "--detach", *(f"{w}=0" for w in workers))
|
|
204
|
+
s.done(", ".join(workers))
|
|
205
|
+
|
|
206
|
+
for part in [p for p in parts if p != "db"]:
|
|
207
|
+
with step(f"Copying {part}") as s:
|
|
208
|
+
path = f"{root}/{part}"
|
|
209
|
+
# Emptied in place, not replaced: the directory is a volume's bind source.
|
|
210
|
+
# ponytail: full stream every run; rsync between the hosts if repeat copies get slow.
|
|
211
|
+
stream(src, ["tar", "-C", path, "--numeric-owner", "-cf", "-", "."],
|
|
212
|
+
dst, ["sh", "-c", f"mkdir -p {path} && find {path} -mindepth 1 -delete"
|
|
213
|
+
f" && tar -C {path} --numeric-owner -xpf -"])
|
|
214
|
+
s.done(sh(dst, "du", "-sh", path).split()[0])
|
|
215
|
+
|
|
216
|
+
if "db" in parts:
|
|
217
|
+
with step("Dumping source databases") as s:
|
|
218
|
+
src_db = pick_arango_container(sh(src, "docker", "ps", "--format", PS_FORMAT))
|
|
219
|
+
sh(src, "docker", "exec", src_db, "sh", "-c",
|
|
220
|
+
f"rm -rf {DUMP_DIR} && arangodump {ARANGO_AUTH} --all-databases true"
|
|
221
|
+
f" --output-directory {DUMP_DIR}", timeout=7200)
|
|
222
|
+
s.done(sh(src, "docker", "exec", src_db, "du", "-sh", DUMP_DIR).split()[0])
|
|
223
|
+
|
|
224
|
+
with step("Transferring dump") as s:
|
|
225
|
+
dst_db = pick_arango_container(sh(dst, "docker", "ps", "--format", PS_FORMAT))
|
|
226
|
+
sh(dst, "docker", "exec", dst_db, "rm", "-rf", DUMP_DIR)
|
|
227
|
+
# docker cp speaks tar on stdin/stdout: no tar needed in the image.
|
|
228
|
+
stream(src, ["docker", "cp", f"{src_db}:{DUMP_DIR}", "-"],
|
|
229
|
+
dst, ["docker", "cp", "-", f"{dst_db}:{CONTAINER_BACKUP_DIR}"])
|
|
230
|
+
sh(src, "docker", "exec", src_db, "rm", "-rf", DUMP_DIR)
|
|
231
|
+
databases = sorted(
|
|
232
|
+
name for name in sh(dst, "docker", "exec", dst_db, "find", DUMP_DIR,
|
|
233
|
+
"-mindepth", "1", "-maxdepth", "1", "-type", "d",
|
|
234
|
+
"-exec", "basename", "{}", ";").split()
|
|
235
|
+
if name != "_system")
|
|
236
|
+
if not databases:
|
|
237
|
+
raise StepError("The source dump holds no databases besides _system.")
|
|
238
|
+
s.done(", ".join(databases))
|
|
239
|
+
|
|
240
|
+
try:
|
|
241
|
+
for name in databases:
|
|
242
|
+
with step(f"Restoring {name}") as s:
|
|
243
|
+
sh(dst, "docker", "exec", dst_db, "sh", "-c",
|
|
244
|
+
f"arangorestore {ARANGO_AUTH} --server.database {shlex.quote(name)}"
|
|
245
|
+
f" --create-database true --overwrite true"
|
|
246
|
+
f" --input-directory {DUMP_DIR}/{shlex.quote(name)}", timeout=7200)
|
|
247
|
+
s.done("collections replaced")
|
|
248
|
+
finally:
|
|
249
|
+
subprocess.run(on(dst, "docker", "exec", dst_db, "rm", "-rf", DUMP_DIR), capture_output=True)
|
|
250
|
+
|
|
251
|
+
if workers and live:
|
|
252
|
+
with step("Starting target flows") as s:
|
|
253
|
+
# --force reruns the entrypoint, which registers the copied flows.
|
|
254
|
+
for w in workers:
|
|
255
|
+
sh(dst, "docker", "service", "update", "--detach", "--force", "--replicas", "1", w)
|
|
256
|
+
s.done(", ".join(workers))
|
|
257
|
+
|
|
258
|
+
console.print(f"\n Copied [bold]{', '.join(parts)}[/] from {label(src)} to {label(dst)} ({releases[src]}).\n")
|
|
259
|
+
if workers and not live:
|
|
260
|
+
start = shlex.join(on(dst, "docker", "service", "update", "--force", "--replicas", "1", *workers[:1]))
|
|
261
|
+
console.print(
|
|
262
|
+
" Client flows are stopped on the target, so the copy cannot act on the customer's\n"
|
|
263
|
+
f" systems. Start them once their connections point elsewhere:\n {start}\n"
|
|
264
|
+
)
|
progress_cli/dev.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"""`progress dev` — run a local development stack from a repo checkout.
|
|
2
|
+
|
|
3
|
+
Brings up db + broker + api + router via docker compose (base.yaml +
|
|
4
|
+
dev.yaml + dev.cli.yaml), optionally seeds the database from an
|
|
5
|
+
arangodump snapshot, and starts the webapp dev servers (`yarn dev`)
|
|
6
|
+
with hot reload. The api container reloads on backend/api edits via the
|
|
7
|
+
bind mount + `uvicorn --reload` already defined in the dev overlays.
|
|
8
|
+
|
|
9
|
+
Requires a progress-platform checkout: the compose files build the api
|
|
10
|
+
image from backend/api and the webapps run from webapps/*.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import socket
|
|
15
|
+
import subprocess
|
|
16
|
+
import threading
|
|
17
|
+
import time
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
import httpx
|
|
21
|
+
import typer
|
|
22
|
+
|
|
23
|
+
from progress_cli.package import temp_admin_password
|
|
24
|
+
from progress_cli.runner import (
|
|
25
|
+
StepError, console, docker, find_arango_container, run, step,
|
|
26
|
+
)
|
|
27
|
+
from progress_cli.restore import (
|
|
28
|
+
check_snapshot, restore_databases, snapshot_databases, stage_in_container,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
PROJECT = "progress-dev"
|
|
32
|
+
DEV_VOLUMES = ["media", "db_backup", "db_data", "nats_data", "config"]
|
|
33
|
+
DEV_DB = "PROGRESS_PROD" # dev.yaml points the api at PROGRESS_PROD
|
|
34
|
+
WEBAPPS = ["main", "warehouse"]
|
|
35
|
+
ARANGO_URL = "http://localhost:8529"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def find_repo_root(start: Path | None = None) -> Path | None:
|
|
39
|
+
"""Walk upward looking for a progress-platform checkout."""
|
|
40
|
+
node = (start or Path.cwd()).resolve()
|
|
41
|
+
for candidate in (node, *node.parents):
|
|
42
|
+
if (candidate / "deploy" / "compose" / "dev.yaml").exists():
|
|
43
|
+
return candidate
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _compose(repo: Path, debug: bool) -> list[str]:
|
|
48
|
+
compose_dir = repo / "deploy" / "compose"
|
|
49
|
+
files = ["base.yaml", "dev.yaml"] + ([] if debug else ["dev.cli.yaml"])
|
|
50
|
+
cmd = ["docker", "compose", "-p", PROJECT,
|
|
51
|
+
"--project-directory", str(compose_dir)]
|
|
52
|
+
for f in files:
|
|
53
|
+
cmd += ["-f", str(compose_dir / f)]
|
|
54
|
+
return cmd
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _port_owner_is_ours(port: int) -> bool:
|
|
58
|
+
out = docker("ps", "--filter", f"publish={port}",
|
|
59
|
+
"--format", "{{.Names}}")
|
|
60
|
+
return bool(out) and all(name.startswith(PROJECT) for name in out.splitlines())
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _wait_for_arango(timeout: int = 120) -> None:
|
|
64
|
+
deadline = time.monotonic() + timeout
|
|
65
|
+
while time.monotonic() < deadline:
|
|
66
|
+
try:
|
|
67
|
+
if httpx.get(f"{ARANGO_URL}/_api/version", timeout=3).status_code == 200:
|
|
68
|
+
return
|
|
69
|
+
except httpx.HTTPError:
|
|
70
|
+
pass
|
|
71
|
+
time.sleep(2)
|
|
72
|
+
raise StepError("ArangoDB did not become ready within 2 minutes.",
|
|
73
|
+
hint=f"docker compose -p {PROJECT} logs db")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _db_has_data(db_name: str) -> bool:
|
|
77
|
+
try:
|
|
78
|
+
r = httpx.get(f"{ARANGO_URL}/_db/{db_name}/_api/collection", timeout=5)
|
|
79
|
+
except httpx.HTTPError:
|
|
80
|
+
return False
|
|
81
|
+
if r.status_code != 200:
|
|
82
|
+
return False
|
|
83
|
+
collections = [c for c in r.json().get("result", []) if not c["isSystem"]]
|
|
84
|
+
return len(collections) > 0
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _reset_dev_admin(db_container: str) -> None:
|
|
88
|
+
"""Point the seeded database's admin account back at the platform's
|
|
89
|
+
standard temporary password (the one db_init.py seeds on fresh
|
|
90
|
+
installs), with a forced reset on first login. A seeded snapshot
|
|
91
|
+
keeps its origin's credentials, which would leave the dev
|
|
92
|
+
environment without a known login."""
|
|
93
|
+
pwd_hash = docker(
|
|
94
|
+
"exec", f"{PROJECT}-api-1", "python", "-c",
|
|
95
|
+
"import sys; from passlib.context import CryptContext; "
|
|
96
|
+
"print(CryptContext(schemes=['bcrypt'], deprecated='auto').hash(sys.argv[1]))",
|
|
97
|
+
temp_admin_password(find_repo_root() / "deploy" / "scripts" / "db_init.py"),
|
|
98
|
+
)
|
|
99
|
+
docker(
|
|
100
|
+
"exec", db_container, "arangosh", "--server.authentication", "false",
|
|
101
|
+
"--javascript.execute-string",
|
|
102
|
+
'db._useDatabase("PROGRESS_PROD"); '
|
|
103
|
+
'var u = db.User.firstExample({username: "cadmin"}); '
|
|
104
|
+
f'if (u) {{ db.User.update(u, {{psw_hash: "{pwd_hash}", active: true, reset_password: true}}); }} '
|
|
105
|
+
'else { throw "no cadmin user in seeded data"; }',
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _echo_prefixed(name: str, proc: subprocess.Popen) -> threading.Thread:
|
|
110
|
+
def pump():
|
|
111
|
+
for line in proc.stdout:
|
|
112
|
+
console.print(f"[dim]\\[{name}][/] {line.rstrip()}")
|
|
113
|
+
t = threading.Thread(target=pump, daemon=True)
|
|
114
|
+
t.start()
|
|
115
|
+
return t
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def dev(
|
|
119
|
+
seed: Path = typer.Option(None, "--seed", help="arangodump snapshot directory to prepopulate the database from"),
|
|
120
|
+
reseed: bool = typer.Option(False, "--reseed", help="Restore the seed even if the database already has data (overwrites collections)"),
|
|
121
|
+
webapps: bool = typer.Option(True, "--webapps/--no-webapps", help="Start the webapp dev servers (yarn dev) in the foreground"),
|
|
122
|
+
debug: bool = typer.Option(False, "--debug", help="Keep dev.yaml's debugpy listener on :5678 — attach an IDE debugger any time (the api never waits for one)"),
|
|
123
|
+
down: bool = typer.Option(False, "--down", help="Stop and remove the dev stack containers (volumes are kept)"),
|
|
124
|
+
):
|
|
125
|
+
"""Run a prepopulated local dev stack: db, broker, api, webapps.
|
|
126
|
+
|
|
127
|
+
Hot reload everywhere: the api container watches backend/api via
|
|
128
|
+
uvicorn --reload; webapps run their own quasar dev servers. Must run
|
|
129
|
+
inside a progress-platform checkout.
|
|
130
|
+
"""
|
|
131
|
+
repo = find_repo_root()
|
|
132
|
+
if repo is None:
|
|
133
|
+
raise typer.BadParameter(
|
|
134
|
+
"Not inside a progress-platform checkout — `progress dev` needs "
|
|
135
|
+
"the repo (compose files, backend, webapps). cd into it first."
|
|
136
|
+
)
|
|
137
|
+
compose = _compose(repo, debug)
|
|
138
|
+
|
|
139
|
+
if down:
|
|
140
|
+
with step("Stopping dev stack") as s:
|
|
141
|
+
run(*compose, "down")
|
|
142
|
+
s.done("containers removed, volumes kept")
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
with step("Checking ports") as s:
|
|
146
|
+
busy = []
|
|
147
|
+
for port in (80, 443, 1883, 4222, 5678, 8000, 8080, 8222, 8529):
|
|
148
|
+
with socket.socket() as sock:
|
|
149
|
+
if sock.connect_ex(("127.0.0.1", port)) == 0 and not _port_owner_is_ours(port):
|
|
150
|
+
busy.append(port)
|
|
151
|
+
if busy:
|
|
152
|
+
raise StepError(
|
|
153
|
+
f"Ports in use by something else: {', '.join(map(str, busy))}.",
|
|
154
|
+
hint="Stop the other stack (e.g. `docker ps`) and rerun.",
|
|
155
|
+
)
|
|
156
|
+
s.done("80, 443, 1883, 4222, 5678, 8000, 8080, 8222, 8529")
|
|
157
|
+
|
|
158
|
+
with step("Ensuring Docker volumes") as s:
|
|
159
|
+
existing = set(docker("volume", "ls", "-q").splitlines())
|
|
160
|
+
for volume in DEV_VOLUMES:
|
|
161
|
+
if volume not in existing:
|
|
162
|
+
docker("volume", "create", volume)
|
|
163
|
+
s.done(", ".join(DEV_VOLUMES))
|
|
164
|
+
|
|
165
|
+
with step("Starting db, broker, api, router") as s:
|
|
166
|
+
run(*compose, "up", "-d", timeout=1800)
|
|
167
|
+
s.done(f"compose project '{PROJECT}'")
|
|
168
|
+
|
|
169
|
+
with step("Waiting for ArangoDB") as s:
|
|
170
|
+
_wait_for_arango()
|
|
171
|
+
s.done(ARANGO_URL)
|
|
172
|
+
|
|
173
|
+
has_data = _db_has_data(DEV_DB)
|
|
174
|
+
if seed and reseed and has_data:
|
|
175
|
+
console.print(
|
|
176
|
+
f"\n --reseed overwrites [bold]{DEV_DB}[/] in the shared "
|
|
177
|
+
f"db_data volume (any stack built on base.yaml uses it)."
|
|
178
|
+
)
|
|
179
|
+
if not typer.confirm(" Proceed?", default=False):
|
|
180
|
+
raise typer.Exit(0)
|
|
181
|
+
if seed and (not has_data or reseed):
|
|
182
|
+
with step("Checking seed snapshot") as s:
|
|
183
|
+
check_snapshot(seed)
|
|
184
|
+
available = snapshot_databases(seed)
|
|
185
|
+
if DEV_DB not in available:
|
|
186
|
+
raise StepError(
|
|
187
|
+
f"Seed snapshot has no {DEV_DB} dump "
|
|
188
|
+
f"(found: {', '.join(available) or 'flat layout'}).",
|
|
189
|
+
)
|
|
190
|
+
s.done(DEV_DB)
|
|
191
|
+
db_container = find_arango_container()
|
|
192
|
+
container_dir, staged = stage_in_container(db_container, seed)
|
|
193
|
+
try:
|
|
194
|
+
restore_databases(db_container, container_dir, [DEV_DB])
|
|
195
|
+
finally:
|
|
196
|
+
if staged:
|
|
197
|
+
subprocess.run(["docker", "exec", db_container, "rm", "-rf",
|
|
198
|
+
container_dir], capture_output=True)
|
|
199
|
+
with step("Resetting dev admin password") as s:
|
|
200
|
+
_reset_dev_admin(db_container)
|
|
201
|
+
s.done("cadmin → temporary password, reset forced on first login")
|
|
202
|
+
elif seed:
|
|
203
|
+
console.print(f" [dim]{DEV_DB} already has data — seed skipped (use --reseed to overwrite).[/]")
|
|
204
|
+
elif not has_data:
|
|
205
|
+
console.print(f" [yellow]{DEV_DB} is empty[/] — pass --seed <dump-dir> to prepopulate it.")
|
|
206
|
+
|
|
207
|
+
console.print(
|
|
208
|
+
f"\n API: [bold]http://localhost:8000[/] "
|
|
209
|
+
f"(via router: http://progress.localhost/api)\n"
|
|
210
|
+
f" ArangoDB: {ARANGO_URL}\n"
|
|
211
|
+
)
|
|
212
|
+
if debug:
|
|
213
|
+
console.print(" [yellow]--debug:[/] debugpy is listening on :5678 — attach whenever, the api serves regardless.\n")
|
|
214
|
+
|
|
215
|
+
if not webapps:
|
|
216
|
+
console.print(" Stack is up (running detached). Stop it with `progress dev --down`.\n")
|
|
217
|
+
return
|
|
218
|
+
|
|
219
|
+
procs: list[tuple[str, subprocess.Popen]] = []
|
|
220
|
+
try:
|
|
221
|
+
for name in WEBAPPS:
|
|
222
|
+
app_dir = repo / "webapps" / name
|
|
223
|
+
if not (app_dir / "package.json").exists():
|
|
224
|
+
continue
|
|
225
|
+
if not (app_dir / "node_modules").exists():
|
|
226
|
+
with step(f"Installing webapps/{name} dependencies") as s:
|
|
227
|
+
run("yarn", "--cwd", str(app_dir), "install", timeout=1800)
|
|
228
|
+
s.done("yarn install")
|
|
229
|
+
proc = subprocess.Popen(
|
|
230
|
+
["yarn", "dev"], cwd=app_dir, text=True,
|
|
231
|
+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
|
232
|
+
)
|
|
233
|
+
procs.append((name, proc))
|
|
234
|
+
_echo_prefixed(name, proc)
|
|
235
|
+
console.print(" [dim]Webapp dev servers starting — URLs appear in their output below. Ctrl-C stops everything.[/]\n")
|
|
236
|
+
while any(p.poll() is None for _, p in procs):
|
|
237
|
+
time.sleep(1)
|
|
238
|
+
for name, p in procs:
|
|
239
|
+
if p.returncode not in (0, None):
|
|
240
|
+
console.print(f"[red]webapps/{name} exited with {p.returncode}[/]")
|
|
241
|
+
except KeyboardInterrupt:
|
|
242
|
+
console.print("\n Stopping…")
|
|
243
|
+
finally:
|
|
244
|
+
for _, p in procs:
|
|
245
|
+
if p.poll() is None:
|
|
246
|
+
p.terminate()
|
|
247
|
+
deadline = time.monotonic() + 10
|
|
248
|
+
for _, p in procs:
|
|
249
|
+
while p.poll() is None and time.monotonic() < deadline:
|
|
250
|
+
time.sleep(0.2)
|
|
251
|
+
if p.poll() is None:
|
|
252
|
+
p.kill()
|
|
253
|
+
subprocess.run(compose + ["stop"], capture_output=True)
|
|
254
|
+
console.print(" Dev stack stopped (containers kept — next start is fast; `progress dev --down` removes them).\n")
|