dooers-cli 0.11.4__tar.gz → 0.12.0__tar.gz
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.
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/PKG-INFO +2 -2
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/pyproject.toml +2 -2
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/agents.py +3 -1
- dooers_cli-0.12.0/src/dooers/cli/apps.py +156 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/cli.py +12 -3
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/config.py +13 -1
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/logs.py +2 -1
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/push.py +22 -52
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/push_client.py +2 -1
- dooers_cli-0.12.0/src/dooers/cli/push_env.py +39 -0
- dooers_cli-0.12.0/src/dooers/cli/push_poll.py +54 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/run.py +182 -28
- dooers_cli-0.12.0/src/dooers/cli/static_preview.py +34 -0
- dooers_cli-0.12.0/src/dooers/cli/versions.py +120 -0
- dooers_cli-0.12.0/tests/conftest.py +14 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_config.py +27 -0
- dooers_cli-0.12.0/tests/test_push_env.py +58 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_push_failure_display.py +1 -0
- dooers_cli-0.12.0/tests/test_run_heartbeat.py +32 -0
- dooers_cli-0.12.0/tests/test_versions.py +146 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/uv.lock +2 -2
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/.gitignore +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/README.md +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/__init__.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/agent_store.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/auth.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/core_client.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/env_prod.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/ignore.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/manifest_sync.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/org.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/runtime_client.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/settings.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/token_store.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/user_config.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/cli/validate.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/src/dooers/py.typed +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/__init__.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_agent_store.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_agents_delete.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_agents_update.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_core_client.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_encoding.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_env_prod.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_ignore.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_local_runtime_slot.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_logs.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_manifest_sync.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_org.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_push_client_async.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_push_hosting_guard.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_push_poll.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_push_teardown.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_smoke.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_token_store.py +0 -0
- {dooers_cli-0.11.4 → dooers_cli-0.12.0}/tests/test_validate.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: dooers-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Dooers CLI — run and deploy agents to Dooers, manage agent records, authenticate from the terminal
|
|
5
5
|
Project-URL: Repository, https://github.com/Dooers-ai/dooers-cli
|
|
6
6
|
Author-email: Dooers <dev@dooers.ai>
|
|
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Classifier: Typing :: Typed
|
|
17
17
|
Requires-Python: >=3.10
|
|
18
|
-
Requires-Dist: dooers-protocol>=0.
|
|
18
|
+
Requires-Dist: dooers-protocol>=0.11.0
|
|
19
19
|
Requires-Dist: httpx>=0.28.1
|
|
20
20
|
Requires-Dist: pydantic>=2.13.2
|
|
21
21
|
Requires-Dist: pyyaml>=6.0.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dooers-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.12.0"
|
|
4
4
|
description = "Dooers CLI — run and deploy agents to Dooers, manage agent records, authenticate from the terminal"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -27,7 +27,7 @@ dependencies = [
|
|
|
27
27
|
"pyyaml>=6.0.2",
|
|
28
28
|
"tqdm>=4.66.4",
|
|
29
29
|
"websockets>=15.0",
|
|
30
|
-
"dooers-protocol>=0.
|
|
30
|
+
"dooers-protocol>=0.11.0",
|
|
31
31
|
]
|
|
32
32
|
|
|
33
33
|
[tool.uv.sources]
|
|
@@ -13,7 +13,7 @@ from dooers.protocol.agents import (
|
|
|
13
13
|
)
|
|
14
14
|
from dooers.protocol.teardown import format_teardown_result
|
|
15
15
|
|
|
16
|
-
from dooers.cli import config
|
|
16
|
+
from dooers.cli import config, push_env
|
|
17
17
|
from dooers.cli.agent_store import AgentStoreError, HTTPCoreAgentStore
|
|
18
18
|
from dooers.cli.env_prod import upsert_agent_seed_secret
|
|
19
19
|
from dooers.cli.org import resolve_org_for_cli
|
|
@@ -243,6 +243,7 @@ def delete(
|
|
|
243
243
|
typer.echo(f"Archive failed: {e}", err=True)
|
|
244
244
|
raise typer.Exit(code=1) from e
|
|
245
245
|
|
|
246
|
+
push_env.require_push_environment(settings)
|
|
246
247
|
push = PushClient(base_url=settings.push_url, token=token)
|
|
247
248
|
try:
|
|
248
249
|
teardown = push.teardown(agent_id, env=settings.env)
|
|
@@ -291,6 +292,7 @@ def teardown(
|
|
|
291
292
|
abort=True,
|
|
292
293
|
)
|
|
293
294
|
|
|
295
|
+
push_env.require_push_environment(settings)
|
|
294
296
|
push = PushClient(base_url=settings.push_url, token=token)
|
|
295
297
|
try:
|
|
296
298
|
result = push.teardown(agent_id, env=settings.env)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Register, publish and inspect Dooers apps using the authenticated CLI session.
|
|
2
|
+
|
|
3
|
+
Apps publish to a single cloud environment (production). Test with `dooers run`
|
|
4
|
+
(private Local preview) before `dooers push`; undo with `dooers rollback`.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
import typer
|
|
12
|
+
|
|
13
|
+
from dooers.cli import ignore
|
|
14
|
+
from dooers.cli.push_client import PushTransientError
|
|
15
|
+
from dooers.cli.push_poll import PushTimeout, poll_until_terminal
|
|
16
|
+
from dooers.cli.settings import Settings
|
|
17
|
+
from dooers.cli.token_store import TokenStore, is_token_expired
|
|
18
|
+
from dooers.protocol.push import BuildStatus, BuildStatusResponse
|
|
19
|
+
|
|
20
|
+
app = typer.Typer(help="Register and publish Dooers apps.")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def headers() -> dict[str, str]:
|
|
24
|
+
store = TokenStore()
|
|
25
|
+
token = store.load()
|
|
26
|
+
if not token or is_token_expired(token, store=store):
|
|
27
|
+
raise typer.BadParameter("Run dooers login first")
|
|
28
|
+
return {"Authorization": f"Bearer {token}"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def data(response: httpx.Response):
|
|
32
|
+
if response.is_error:
|
|
33
|
+
raise typer.BadParameter(f"HTTP {response.status_code}: {response.text[:500]}")
|
|
34
|
+
body = response.json()
|
|
35
|
+
return body.get("data", body)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@app.command()
|
|
39
|
+
def register(ctx: typer.Context, organization_id: str, name: str, kind: str = "fullstack"):
|
|
40
|
+
settings: Settings = ctx.obj
|
|
41
|
+
if kind not in ("static", "fullstack"):
|
|
42
|
+
raise typer.BadParameter("kind must be static or fullstack")
|
|
43
|
+
result = data(
|
|
44
|
+
httpx.post(
|
|
45
|
+
settings.core_url.rstrip("/") + "/api/v2/apps",
|
|
46
|
+
headers=headers(),
|
|
47
|
+
json={"organizationId": organization_id, "name": name, "kind": kind},
|
|
48
|
+
timeout=30,
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
typer.echo(json.dumps(result, indent=2))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@app.command("list")
|
|
55
|
+
def list_apps(ctx: typer.Context):
|
|
56
|
+
settings: Settings = ctx.obj
|
|
57
|
+
typer.echo(
|
|
58
|
+
json.dumps(
|
|
59
|
+
data(
|
|
60
|
+
httpx.get(
|
|
61
|
+
settings.core_url.rstrip("/") + "/api/v2/apps", headers=headers(), timeout=30
|
|
62
|
+
)
|
|
63
|
+
),
|
|
64
|
+
indent=2,
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.command()
|
|
70
|
+
def push(ctx: typer.Context, app_id: str):
|
|
71
|
+
"""Upload the working directory, wait for its build, then publish it."""
|
|
72
|
+
settings: Settings = ctx.obj
|
|
73
|
+
if not Path("Dockerfile").is_file() and not Path("public/index.html").is_file():
|
|
74
|
+
raise typer.BadParameter("Provide Dockerfile or public/index.html. Start from dooers-apps-starter.")
|
|
75
|
+
archive_path = Path(ignore.make_archive("."))
|
|
76
|
+
endpoint = settings.push_url.rstrip("/") + f"/v1/apps/{app_id}/builds"
|
|
77
|
+
auth = headers()
|
|
78
|
+
try:
|
|
79
|
+
with archive_path.open("rb") as archive:
|
|
80
|
+
result = data(
|
|
81
|
+
httpx.post(
|
|
82
|
+
endpoint,
|
|
83
|
+
headers=auth,
|
|
84
|
+
files={"archive": (archive_path.name, archive, "application/gzip")},
|
|
85
|
+
timeout=180,
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
finally:
|
|
89
|
+
archive_path.unlink(missing_ok=True)
|
|
90
|
+
build_id = result["buildId"]
|
|
91
|
+
typer.echo(
|
|
92
|
+
f"Build {build_id}. If interrupted, resume with: dooers apps deploy {app_id} {build_id}"
|
|
93
|
+
)
|
|
94
|
+
try:
|
|
95
|
+
final = poll_until_terminal(
|
|
96
|
+
AppBuildStatusClient(endpoint, app_id, auth),
|
|
97
|
+
build_id,
|
|
98
|
+
timeout_s=1900,
|
|
99
|
+
interval_s=5,
|
|
100
|
+
on_phase=lambda phase: typer.echo(phase) if phase else None,
|
|
101
|
+
)
|
|
102
|
+
except PushTimeout as error:
|
|
103
|
+
raise typer.BadParameter("Build wait timed out. Inspect the build and resume deployment.") from error
|
|
104
|
+
except PushTransientError as error:
|
|
105
|
+
raise typer.BadParameter(str(error)) from error
|
|
106
|
+
if final.status == BuildStatus.failed:
|
|
107
|
+
raise typer.BadParameter(f"Build failed. {final.error or ''}")
|
|
108
|
+
deploy(ctx, app_id, build_id)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class AppBuildStatusClient:
|
|
112
|
+
def __init__(self, endpoint: str, app_id: str, auth: dict[str, str]):
|
|
113
|
+
self.endpoint = endpoint
|
|
114
|
+
self.app_id = app_id
|
|
115
|
+
self.auth = auth
|
|
116
|
+
|
|
117
|
+
def get_build_status(self, build_id: str) -> BuildStatusResponse:
|
|
118
|
+
try:
|
|
119
|
+
response = httpx.get(
|
|
120
|
+
f"{self.endpoint}/{build_id}",
|
|
121
|
+
headers=self.auth,
|
|
122
|
+
timeout=30,
|
|
123
|
+
)
|
|
124
|
+
except httpx.TransportError as error:
|
|
125
|
+
raise PushTransientError("Could not reach Push while checking the app build") from error
|
|
126
|
+
if response.status_code >= 500 or response.status_code == 429:
|
|
127
|
+
raise PushTransientError(f"App build status returned HTTP {response.status_code}")
|
|
128
|
+
payload = data(response)
|
|
129
|
+
phase = payload["status"]
|
|
130
|
+
status = BuildStatus.building
|
|
131
|
+
if phase == "SUCCESS":
|
|
132
|
+
status = BuildStatus.succeeded
|
|
133
|
+
elif phase in {"FAILURE", "INTERNAL_ERROR", "TIMEOUT", "CANCELLED", "EXPIRED"}:
|
|
134
|
+
status = BuildStatus.failed
|
|
135
|
+
return BuildStatusResponse(
|
|
136
|
+
build_id=build_id, agent_id=self.app_id, status=status, phase=phase,
|
|
137
|
+
error=payload.get("logUrl"),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@app.command()
|
|
142
|
+
def deploy(ctx: typer.Context, app_id: str, build_id: str):
|
|
143
|
+
"""Activate a finished build (resume an interrupted push or roll forward)."""
|
|
144
|
+
settings: Settings = ctx.obj
|
|
145
|
+
endpoint = settings.push_url.rstrip("/") + f"/v1/apps/{app_id}/builds/{build_id}/deploy"
|
|
146
|
+
result = data(httpx.post(endpoint, headers=headers(), timeout=360))
|
|
147
|
+
typer.echo(json.dumps(result, indent=2))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@app.command()
|
|
151
|
+
def status(ctx: typer.Context, app_id: str, build_id: str):
|
|
152
|
+
"""Show build state and the Cloud Build log URL."""
|
|
153
|
+
settings: Settings = ctx.obj
|
|
154
|
+
endpoint = settings.push_url.rstrip("/") + f"/v1/apps/{app_id}/builds/{build_id}"
|
|
155
|
+
result = data(httpx.get(endpoint, headers=headers(), timeout=30))
|
|
156
|
+
typer.echo(json.dumps(result, indent=2))
|
|
@@ -13,7 +13,7 @@ warnings.filterwarnings(
|
|
|
13
13
|
|
|
14
14
|
import typer # noqa: E402
|
|
15
15
|
|
|
16
|
-
from . import agents, auth, logs, org, push, run, validate # noqa: E402
|
|
16
|
+
from . import agents, apps, auth, logs, org, push, run, validate, versions # noqa: E402
|
|
17
17
|
from .settings import Settings # noqa: E402
|
|
18
18
|
|
|
19
19
|
app = typer.Typer(
|
|
@@ -51,6 +51,7 @@ app.add_typer(
|
|
|
51
51
|
name="agents",
|
|
52
52
|
help="Manage agents — subcommands: list | create | update | rotate-key | show | delete.",
|
|
53
53
|
)
|
|
54
|
+
app.add_typer(apps.app, name="apps")
|
|
54
55
|
app.add_typer(org.app, name="org", help="Manage organization — subcommands: list | use.")
|
|
55
56
|
app.command(
|
|
56
57
|
name="validate",
|
|
@@ -58,13 +59,21 @@ app.command(
|
|
|
58
59
|
)(validate.validate)
|
|
59
60
|
app.command(
|
|
60
61
|
name="run",
|
|
61
|
-
help="Run the
|
|
62
|
+
help="Run the app or agent in dooers.yaml through a temporary tunnel.",
|
|
62
63
|
)(run.run)
|
|
63
|
-
app.command(name="push", help="
|
|
64
|
+
app.command(name="push", help="Publish the agent or app declared in dooers.yaml.")(push.push)
|
|
64
65
|
app.command(
|
|
65
66
|
name="logs",
|
|
66
67
|
help="Show an agent's deployment logs; --follow to tail them.",
|
|
67
68
|
)(logs.logs)
|
|
69
|
+
app.command(
|
|
70
|
+
name="versions",
|
|
71
|
+
help="List retained versions of the agent or app in dooers.yaml.",
|
|
72
|
+
)(versions.versions)
|
|
73
|
+
app.command(
|
|
74
|
+
name="rollback",
|
|
75
|
+
help="Switch the agent or app back to a retained version (default: previous).",
|
|
76
|
+
)(versions.rollback)
|
|
68
77
|
|
|
69
78
|
|
|
70
79
|
if __name__ == "__main__":
|
|
@@ -4,6 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
|
|
5
5
|
import yaml
|
|
6
6
|
from dooers.protocol.agents import AgentManifest
|
|
7
|
+
from dooers.protocol.apps import AppManifest
|
|
7
8
|
|
|
8
9
|
MANIFEST_FILENAME = "dooers.yaml"
|
|
9
10
|
|
|
@@ -40,7 +41,18 @@ def read_manifest(directory: Path | None = None) -> AgentManifest | None:
|
|
|
40
41
|
return AgentManifest.model_validate(raw)
|
|
41
42
|
|
|
42
43
|
|
|
43
|
-
def
|
|
44
|
+
def read_deployment_manifest(directory: Path | None = None) -> AgentManifest | AppManifest | None:
|
|
45
|
+
"""Load the manifest variant used by the common push command."""
|
|
46
|
+
target = (directory or Path.cwd()) / MANIFEST_FILENAME
|
|
47
|
+
if not target.exists():
|
|
48
|
+
return None
|
|
49
|
+
raw = yaml.safe_load(target.read_text(encoding="utf-8"))
|
|
50
|
+
if isinstance(raw, dict) and raw.get("kind") == "app":
|
|
51
|
+
return AppManifest.model_validate(raw)
|
|
52
|
+
return AgentManifest.model_validate(raw)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def write_manifest(manifest: AgentManifest | AppManifest, directory: Path | None = None) -> Path:
|
|
44
56
|
"""Write `manifest` to `directory/dooers.yaml`. Returns the path written."""
|
|
45
57
|
target = (directory or Path.cwd()) / MANIFEST_FILENAME
|
|
46
58
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -20,7 +20,7 @@ import typer
|
|
|
20
20
|
from dooers.protocol.logs import LogEntry
|
|
21
21
|
from pydantic import ValidationError
|
|
22
22
|
|
|
23
|
-
from dooers.cli import config
|
|
23
|
+
from dooers.cli import config, push_env
|
|
24
24
|
from dooers.cli.push_client import (
|
|
25
25
|
PushClient,
|
|
26
26
|
PushClientError,
|
|
@@ -233,6 +233,7 @@ def logs(
|
|
|
233
233
|
typer.echo("Not authenticated. Run `dooers login`.", err=True)
|
|
234
234
|
raise typer.Exit(code=1)
|
|
235
235
|
|
|
236
|
+
push_env.require_push_environment(settings)
|
|
236
237
|
client = PushClient(base_url=settings.push_url, token=token)
|
|
237
238
|
cursor = _Cursor()
|
|
238
239
|
|
|
@@ -5,33 +5,27 @@ import sys
|
|
|
5
5
|
import threading
|
|
6
6
|
import time
|
|
7
7
|
from collections.abc import Callable
|
|
8
|
+
from dataclasses import replace
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
|
|
10
11
|
import typer
|
|
11
|
-
from dooers.protocol.push import (
|
|
12
|
-
BuildStatus,
|
|
13
|
-
BuildStatusResponse,
|
|
14
|
-
format_push_failure,
|
|
15
|
-
is_terminal,
|
|
16
|
-
)
|
|
17
12
|
|
|
18
|
-
from dooers.cli import config, ignore
|
|
13
|
+
from dooers.cli import apps, config, ignore, push_env
|
|
19
14
|
from dooers.cli.manifest_sync import build_agent_patch, build_runtime_patch
|
|
20
15
|
from dooers.cli.push_client import (
|
|
21
16
|
PushClient,
|
|
22
17
|
PushClientError,
|
|
23
|
-
PushTransientError,
|
|
24
18
|
friendly_push_error,
|
|
25
19
|
)
|
|
20
|
+
from dooers.cli.push_poll import PushTimeout, poll_until_terminal
|
|
26
21
|
from dooers.cli.runtime_client import RuntimeClient
|
|
27
22
|
from dooers.cli.settings import Settings
|
|
28
23
|
from dooers.cli.token_store import TokenStore, is_token_expired
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"""Raised when a build does not reach a terminal state within the timeout."""
|
|
24
|
+
from dooers.protocol.apps import AppManifest
|
|
25
|
+
from dooers.protocol.push import (
|
|
26
|
+
BuildStatus,
|
|
27
|
+
format_push_failure,
|
|
28
|
+
)
|
|
35
29
|
|
|
36
30
|
|
|
37
31
|
def _spinner(message: str) -> Callable[[], None]:
|
|
@@ -58,40 +52,6 @@ def _spinner(message: str) -> Callable[[], None]:
|
|
|
58
52
|
return cancel
|
|
59
53
|
|
|
60
54
|
|
|
61
|
-
def poll_until_terminal(
|
|
62
|
-
client: PushClient,
|
|
63
|
-
build_id: str,
|
|
64
|
-
*,
|
|
65
|
-
sleep: Callable[[float], object] = time.sleep,
|
|
66
|
-
now: Callable[[], float] = time.monotonic,
|
|
67
|
-
timeout_s: float = 1200.0,
|
|
68
|
-
interval_s: float = 4.0,
|
|
69
|
-
on_phase: Callable[[str | None], object] = lambda _p: None,
|
|
70
|
-
) -> BuildStatusResponse:
|
|
71
|
-
start = now()
|
|
72
|
-
consecutive_transient = 0
|
|
73
|
-
last_transient: PushTransientError | None = None
|
|
74
|
-
while True:
|
|
75
|
-
if now() - start >= timeout_s:
|
|
76
|
-
raise PushTimeout(f"build {build_id} did not finish within {timeout_s:.0f}s")
|
|
77
|
-
try:
|
|
78
|
-
status = client.get_build_status(build_id)
|
|
79
|
-
except PushTransientError as e:
|
|
80
|
-
consecutive_transient += 1
|
|
81
|
-
last_transient = e
|
|
82
|
-
if consecutive_transient > _MAX_CONSECUTIVE_TRANSIENT:
|
|
83
|
-
raise
|
|
84
|
-
sleep(interval_s)
|
|
85
|
-
continue
|
|
86
|
-
consecutive_transient = 0
|
|
87
|
-
last_transient = None
|
|
88
|
-
on_phase(status.phase)
|
|
89
|
-
if is_terminal(status.status):
|
|
90
|
-
return status
|
|
91
|
-
sleep(interval_s)
|
|
92
|
-
assert last_transient is None # pragma: no cover
|
|
93
|
-
|
|
94
|
-
|
|
95
55
|
def push(
|
|
96
56
|
ctx: typer.Context,
|
|
97
57
|
agent_id: str | None = typer.Argument(
|
|
@@ -100,14 +60,24 @@ def push(
|
|
|
100
60
|
),
|
|
101
61
|
tag: str = typer.Option("latest", help="Docker image tag."),
|
|
102
62
|
env: str | None = typer.Option(
|
|
103
|
-
None, help="Target environment
|
|
63
|
+
None, "--env", "--environment", help="Target deployment environment."
|
|
104
64
|
),
|
|
105
65
|
) -> None:
|
|
106
|
-
"""
|
|
66
|
+
"""Publish the agent or app declared in dooers.yaml."""
|
|
107
67
|
settings: Settings = ctx.obj
|
|
108
68
|
target_env = env or settings.env
|
|
109
|
-
|
|
110
|
-
|
|
69
|
+
push_env.require_push_environment(replace(settings, env=target_env))
|
|
70
|
+
|
|
71
|
+
manifest = config.read_deployment_manifest()
|
|
72
|
+
if isinstance(manifest, AppManifest):
|
|
73
|
+
if agent_id is not None:
|
|
74
|
+
raise typer.BadParameter("App ID is read from dooers.yaml.")
|
|
75
|
+
if env is not None and env != "prod":
|
|
76
|
+
raise typer.BadParameter(
|
|
77
|
+
"Apps publish to production only. Test with `dooers run` before pushing."
|
|
78
|
+
)
|
|
79
|
+
apps.push(ctx, str(manifest.app_id))
|
|
80
|
+
return
|
|
111
81
|
try:
|
|
112
82
|
agent_id = config.resolve_agent_id(agent_id, manifest)
|
|
113
83
|
except config.MissingAgentIdError as e:
|
|
@@ -29,7 +29,8 @@ def friendly_push_error(error_code: object, message: str) -> str:
|
|
|
29
29
|
if code == ErrorCode.forbidden.value:
|
|
30
30
|
return (
|
|
31
31
|
"You don't have access to this agent. "
|
|
32
|
-
"Run `dooers login` with the owner
|
|
32
|
+
"Run `dooers login` with the account of the agent's owner or of an agent admin, "
|
|
33
|
+
"or confirm the agent id "
|
|
33
34
|
"in dooers.yaml."
|
|
34
35
|
)
|
|
35
36
|
if code == ErrorCode.unauthenticated.value:
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Refuse to talk to a Push that serves another environment than the one requested.
|
|
2
|
+
|
|
3
|
+
A Push instance is bound to one Core, and everything it deploys trusts that Core.
|
|
4
|
+
`--env` alone does not change which Push or Core the CLI talks to, so
|
|
5
|
+
`dooers push --env dev` with the default URLs would reach the prod Push and
|
|
6
|
+
create a "dev" workload bound to the prod Core. The Push also rejects such a
|
|
7
|
+
request; checking here gives the creator an actionable message before uploading.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
import typer
|
|
12
|
+
|
|
13
|
+
from dooers.cli.settings import Settings
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def served_environment(push_url: str) -> str | None:
|
|
17
|
+
"""The environment the Push serves, or None when it cannot be determined."""
|
|
18
|
+
try:
|
|
19
|
+
response = httpx.get(push_url.rstrip("/") + "/health", timeout=10)
|
|
20
|
+
body = response.json() if response.is_success else None
|
|
21
|
+
except (httpx.HTTPError, ValueError):
|
|
22
|
+
return None
|
|
23
|
+
if not isinstance(body, dict):
|
|
24
|
+
return None
|
|
25
|
+
# A Push from before environments were declared serves production.
|
|
26
|
+
return str(body.get("environment") or "prod")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def require_push_environment(settings: Settings) -> None:
|
|
30
|
+
served = served_environment(settings.push_url)
|
|
31
|
+
if served is None or served == settings.env:
|
|
32
|
+
return # Unreachable here: the real request reports the failure.
|
|
33
|
+
typer.echo(
|
|
34
|
+
f"{settings.push_url} serves the '{served}' environment, not '{settings.env}'.\n"
|
|
35
|
+
f"Set DOOERS_PUSH_URL and DOOERS_CORE_URL to the {settings.env} services "
|
|
36
|
+
f"(or --push-url / --core-url), so the workload is bound to the {settings.env} Core.",
|
|
37
|
+
err=True,
|
|
38
|
+
)
|
|
39
|
+
raise typer.Exit(code=1)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Polling policy shared by agent builds and app releases."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from dooers.cli.push_client import PushTransientError
|
|
8
|
+
from dooers.protocol.push import BuildStatusResponse, is_terminal
|
|
9
|
+
|
|
10
|
+
_MAX_CONSECUTIVE_TRANSIENT = 10
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BuildStatusClient(Protocol):
|
|
14
|
+
def get_build_status(self, build_id: str) -> BuildStatusResponse: ...
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PushTimeout(RuntimeError):
|
|
18
|
+
"""Raised when a build does not reach a terminal state within the timeout."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def poll_until_terminal(
|
|
22
|
+
client: BuildStatusClient,
|
|
23
|
+
build_id: str,
|
|
24
|
+
*,
|
|
25
|
+
sleep: Callable[[float], object] = time.sleep,
|
|
26
|
+
now: Callable[[], float] = time.monotonic,
|
|
27
|
+
timeout_s: float = 1200.0,
|
|
28
|
+
interval_s: float = 4.0,
|
|
29
|
+
on_phase: Callable[[str | None], object] = lambda _p: None,
|
|
30
|
+
) -> BuildStatusResponse:
|
|
31
|
+
start = now()
|
|
32
|
+
consecutive_transient = 0
|
|
33
|
+
last_transient: PushTransientError | None = None
|
|
34
|
+
while True:
|
|
35
|
+
if now() - start >= timeout_s:
|
|
36
|
+
raise PushTimeout(f"build {build_id} did not finish within {timeout_s:.0f}s")
|
|
37
|
+
try:
|
|
38
|
+
status = client.get_build_status(build_id)
|
|
39
|
+
except PushTransientError as e:
|
|
40
|
+
consecutive_transient += 1
|
|
41
|
+
last_transient = e
|
|
42
|
+
if consecutive_transient > _MAX_CONSECUTIVE_TRANSIENT:
|
|
43
|
+
raise
|
|
44
|
+
sleep(interval_s)
|
|
45
|
+
continue
|
|
46
|
+
consecutive_transient = 0
|
|
47
|
+
last_transient = None
|
|
48
|
+
on_phase(status.phase)
|
|
49
|
+
if is_terminal(status.status):
|
|
50
|
+
return status
|
|
51
|
+
sleep(interval_s)
|
|
52
|
+
assert last_transient is None # pragma: no cover
|
|
53
|
+
|
|
54
|
+
|