verulla-cli 0.0.3__tar.gz → 0.0.5__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.
- verulla_cli-0.0.5/CHANGELOG.md +5 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/PKG-INFO +1 -1
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/pyproject.toml +1 -1
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_buildkit.py +23 -16
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_buildkit_real.py +1 -0
- verulla_cli-0.0.5/tests/test_cli_import.py +4 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_dev_check.py +121 -4
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_main.py +64 -11
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/__init__.py +1 -1
- verulla_cli-0.0.5/verulla_cli/buildkit.py +208 -0
- verulla_cli-0.0.5/verulla_cli/config.py +3 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/main.py +79 -49
- verulla_cli-0.0.3/tests/test_cli_import.py +0 -4
- verulla_cli-0.0.3/verulla_cli/buildkit.py +0 -107
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/.gitignore +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_admin_cmd.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_apps_client.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_auth.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_deploy_client.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_emulate.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_owner_commands.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_packaging.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_secrets_client.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/tests/test_sketch_status.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/apps_client.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/auth.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/deploy_client.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/emulate.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/packaging.py +0 -0
- {verulla_cli-0.0.3 → verulla_cli-0.0.5}/verulla_cli/secrets_client.py +0 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# verulla-cli changelog
|
|
2
|
+
|
|
3
|
+
## 0.0.5
|
|
4
|
+
|
|
5
|
+
- Make `verulla deploy --wait` wait for the deployed app's runtime health to become ready, not just build/apply completion. It exits nonzero on a crash and reports the available crash cause plus a hint to check the configured (or default 8080) listening port; the wait timeout remains bounded.
|
|
@@ -25,12 +25,15 @@ def test_auto_error_names_both_backends(monkeypatch):
|
|
|
25
25
|
select_builder("auto", docker_available=False)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def
|
|
28
|
+
def test_buildkit_timeout_reports_safe_progress_without_leaking_output(tmp_path, monkeypatch):
|
|
29
29
|
import subprocess
|
|
30
|
+
import traceback
|
|
30
31
|
|
|
31
32
|
import verulla_cli.buildkit as buildkit
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
secret_marker = "SYNTHETIC_SECRET_MARKER_42"
|
|
35
|
+
builder_address = "tcp://private-builder:1234"
|
|
36
|
+
monkeypatch.setenv("BUILDKIT_HOST", builder_address)
|
|
34
37
|
monkeypatch.setattr(buildkit.shutil, "which", lambda _: "/usr/bin/buildctl")
|
|
35
38
|
|
|
36
39
|
def hang(*args, **kwargs):
|
|
@@ -38,28 +41,32 @@ def test_buildkit_timeout_is_bounded_and_does_not_leak_process_details(tmp_path,
|
|
|
38
41
|
raise subprocess.TimeoutExpired(
|
|
39
42
|
cmd=args[0],
|
|
40
43
|
timeout=kwargs["timeout"],
|
|
41
|
-
output=
|
|
42
|
-
|
|
44
|
+
output=(
|
|
45
|
+
f"#3 [stage-0 2/3] RUN echo {secret_marker}\n"
|
|
46
|
+
"#3 RUN echo private build output\n"
|
|
47
|
+
"#4 [stage-0 3/3] RUN npm ci\n"
|
|
48
|
+
),
|
|
49
|
+
stderr=f"secret environment value {secret_marker}",
|
|
43
50
|
)
|
|
44
51
|
|
|
45
52
|
monkeypatch.setattr(buildkit.subprocess, "run", hang)
|
|
46
53
|
|
|
47
54
|
with pytest.raises(EmulationError) as error:
|
|
48
|
-
BuildKitRunner().build(tmp_path, "Dockerfile")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
assert "
|
|
52
|
-
assert "
|
|
53
|
-
assert
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
BuildKitRunner().build(tmp_path, "Dockerfile", check=True)
|
|
56
|
+
|
|
57
|
+
message = str(error.value)
|
|
58
|
+
assert "BuildKit build timed out after 600 seconds" in message
|
|
59
|
+
assert "vertex #4 RUN instruction [running]" in message
|
|
60
|
+
assert secret_marker not in message
|
|
61
|
+
assert "private build output" not in message
|
|
62
|
+
assert "secret environment value" not in message
|
|
63
|
+
assert builder_address not in message
|
|
57
64
|
formatted_traceback = "".join(traceback.format_exception(error.value))
|
|
58
|
-
assert
|
|
65
|
+
assert secret_marker not in formatted_traceback
|
|
59
66
|
assert "private build output" not in formatted_traceback
|
|
60
67
|
assert "secret environment value" not in formatted_traceback
|
|
61
|
-
assert
|
|
62
|
-
assert
|
|
68
|
+
assert builder_address not in formatted_traceback
|
|
69
|
+
assert error.value.__suppress_context__
|
|
63
70
|
|
|
64
71
|
|
|
65
72
|
def test_buildkit_uses_shared_dockerfile_and_fake_buildctl(tmp_path, monkeypatch):
|
|
@@ -91,5 +91,6 @@ def _build_and_assert_route(build: FunctionBuild, routes: list[RouteSpec], root:
|
|
|
91
91
|
check_name = check_dockerfile(build, routes)
|
|
92
92
|
print(f"BuildKit real smoke: {build.adapter_name} build and route probes starting", flush=True)
|
|
93
93
|
output = BuildKitRunner().build(root, check_name, check=True)
|
|
94
|
+
print(output, flush=True)
|
|
94
95
|
print(f"BuildKit real smoke: {build.adapter_name} build completed", flush=True)
|
|
95
96
|
assert expected in output, output
|
|
@@ -113,7 +113,121 @@ def test_buildkit_check_probe_isolated_from_host_listener(tmp_path):
|
|
|
113
113
|
assert "127.0.0.1:8080" in content
|
|
114
114
|
|
|
115
115
|
|
|
116
|
-
def
|
|
116
|
+
def test_buildkit_check_stops_app_process_group_on_exit(tmp_path):
|
|
117
|
+
import os
|
|
118
|
+
import shutil
|
|
119
|
+
import subprocess
|
|
120
|
+
from types import SimpleNamespace
|
|
121
|
+
|
|
122
|
+
from verulla_cli.buildkit import check_dockerfile
|
|
123
|
+
|
|
124
|
+
(tmp_path / "Dockerfile").write_text("FROM custom:latest\n")
|
|
125
|
+
child_file = tmp_path / "child.pid"
|
|
126
|
+
function = SimpleNamespace(
|
|
127
|
+
build_plan=SimpleNamespace(
|
|
128
|
+
dockerfile_path="Dockerfile",
|
|
129
|
+
run_cmd=["sh", "-c", f"sleep 300 & echo $! > {child_file}; wait"],
|
|
130
|
+
port=8080,
|
|
131
|
+
base_image="custom:latest",
|
|
132
|
+
),
|
|
133
|
+
src_root=tmp_path,
|
|
134
|
+
name="web",
|
|
135
|
+
)
|
|
136
|
+
generated = tmp_path / check_dockerfile(
|
|
137
|
+
function, [SimpleNamespace(path="/", function="web")]
|
|
138
|
+
)
|
|
139
|
+
run_line = next(
|
|
140
|
+
line for line in generated.read_text().splitlines() if line.startswith("RUN --network=none ")
|
|
141
|
+
)
|
|
142
|
+
script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
|
|
143
|
+
|
|
144
|
+
setsid = shutil.which("setsid")
|
|
145
|
+
assert setsid, "setsid is required for the process-group regression test"
|
|
146
|
+
shells = [shutil.which("dash")]
|
|
147
|
+
busybox = shutil.which("busybox")
|
|
148
|
+
if busybox:
|
|
149
|
+
shells.append(f"{busybox} sh")
|
|
150
|
+
bin_dir = tmp_path / "bin"
|
|
151
|
+
bin_dir.mkdir()
|
|
152
|
+
wget = bin_dir / "wget"
|
|
153
|
+
wget.write_text("#!/bin/sh\nif [ \"$1\" = -q ]; then exit 0; fi\necho 'HTTP/1.1 500 Failed' >&2\nexit 0\n")
|
|
154
|
+
wget.chmod(0o755)
|
|
155
|
+
|
|
156
|
+
for shell in filter(None, shells):
|
|
157
|
+
shell_cmd = shell.split()
|
|
158
|
+
child_file.unlink(missing_ok=True)
|
|
159
|
+
result = subprocess.run(
|
|
160
|
+
[setsid, *shell_cmd, "-c", script], cwd=tmp_path,
|
|
161
|
+
env={**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}"},
|
|
162
|
+
text=True, capture_output=True, timeout=10
|
|
163
|
+
)
|
|
164
|
+
assert child_file.exists(), result.stderr
|
|
165
|
+
child_pid = int(child_file.read_text())
|
|
166
|
+
assert result.returncode == 1, result.stderr
|
|
167
|
+
try:
|
|
168
|
+
os.kill(child_pid, 0)
|
|
169
|
+
except ProcessLookupError:
|
|
170
|
+
pass
|
|
171
|
+
else:
|
|
172
|
+
raise AssertionError(f"app child {child_pid} survived generated check script")
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_buildkit_check_custom_base_does_not_require_setsid(tmp_path):
|
|
176
|
+
from types import SimpleNamespace
|
|
177
|
+
|
|
178
|
+
from verulla_cli.buildkit import check_dockerfile
|
|
179
|
+
|
|
180
|
+
(tmp_path / "Dockerfile").write_text("FROM golang:1.24\n")
|
|
181
|
+
function = SimpleNamespace(
|
|
182
|
+
build_plan=SimpleNamespace(
|
|
183
|
+
dockerfile_path="Dockerfile", run_cmd=["./server"], port=8080, base_image="golang:1.24"
|
|
184
|
+
),
|
|
185
|
+
src_root=tmp_path,
|
|
186
|
+
name="web",
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
generated = tmp_path / check_dockerfile(function, [SimpleNamespace(path="/", function="web")])
|
|
190
|
+
content = generated.read_text()
|
|
191
|
+
run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
|
|
192
|
+
script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
|
|
193
|
+
|
|
194
|
+
assert "setsid sh -c" in script
|
|
195
|
+
assert "command -v setsid" in script
|
|
196
|
+
assert "app_group=1" in script
|
|
197
|
+
assert "app_group=0" in script
|
|
198
|
+
assert "app_pid=$!" in script
|
|
199
|
+
assert "kill -TERM \"$app_pid\"" in script
|
|
200
|
+
assert "probe_setup" not in content
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def test_buildkit_node_probe_uses_builtin_http_client_without_package_install(tmp_path):
|
|
204
|
+
from types import SimpleNamespace
|
|
205
|
+
|
|
206
|
+
from verulla_cli.buildkit import check_dockerfile
|
|
207
|
+
|
|
208
|
+
(tmp_path / "Dockerfile").write_text("FROM node:20-slim\nUSER 10001:10001\n")
|
|
209
|
+
function = SimpleNamespace(
|
|
210
|
+
build_plan=SimpleNamespace(
|
|
211
|
+
dockerfile_path="Dockerfile", run_cmd=["node", "index.js"],
|
|
212
|
+
port=8080, base_image="node:20-slim",
|
|
213
|
+
),
|
|
214
|
+
src_root=tmp_path,
|
|
215
|
+
name="web",
|
|
216
|
+
)
|
|
217
|
+
generated = tmp_path / check_dockerfile(
|
|
218
|
+
function, [SimpleNamespace(path="/", function="web")]
|
|
219
|
+
)
|
|
220
|
+
content = generated.read_text()
|
|
221
|
+
|
|
222
|
+
assert "apt-get update" not in content
|
|
223
|
+
assert "apk add" not in content
|
|
224
|
+
run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
|
|
225
|
+
script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
|
|
226
|
+
assert "node -e" in script
|
|
227
|
+
assert "wget" not in script
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_buildkit_python_probe_uses_stdlib_without_package_install(tmp_path):
|
|
117
231
|
from types import SimpleNamespace
|
|
118
232
|
|
|
119
233
|
from verulla_cli.buildkit import check_dockerfile
|
|
@@ -134,6 +248,9 @@ def test_buildkit_probe_installs_wget_as_root_then_drops_back_to_app_user(tmp_pa
|
|
|
134
248
|
)
|
|
135
249
|
content = generated.read_text()
|
|
136
250
|
|
|
137
|
-
assert
|
|
138
|
-
assert
|
|
139
|
-
|
|
251
|
+
assert "apt-get update" not in content
|
|
252
|
+
assert "apk add" not in content
|
|
253
|
+
run_line = next(line for line in content.splitlines() if line.startswith("RUN --network=none "))
|
|
254
|
+
script = json.loads(run_line.removeprefix("RUN --network=none "))[2]
|
|
255
|
+
assert "python -c" in script
|
|
256
|
+
assert "wget" not in script
|
|
@@ -173,6 +173,7 @@ def test_customers_export_file_is_private(tmp_path, monkeypatch) -> None:
|
|
|
173
173
|
def test_help_lists_all_commands() -> None:
|
|
174
174
|
result = runner.invoke(app, ["--help"])
|
|
175
175
|
assert result.exit_code == 0
|
|
176
|
+
assert "https://api.verulla.app" in result.output
|
|
176
177
|
for name in ("login", "dev", "deploy", "secrets", "logs", "apps", "status", "delete", "rollback", "live"):
|
|
177
178
|
assert name in result.output
|
|
178
179
|
|
|
@@ -204,14 +205,45 @@ def test_secrets_scope_rejects_conflicting_flags() -> None:
|
|
|
204
205
|
assert "either --app APP or --shared" in result.output
|
|
205
206
|
|
|
206
207
|
|
|
207
|
-
def
|
|
208
|
-
# Real device-code login landed in M4 T4.2 — login is no longer a stub.
|
|
209
|
-
# With neither --api-url nor VERULLA_API_URL set, Typer/Click's own
|
|
210
|
-
# required-option usage error fires (exit code 2), proving the option
|
|
211
|
-
# is genuinely required rather than silently defaulted.
|
|
208
|
+
def test_login_uses_default_api_url_when_flag_and_environment_are_missing(monkeypatch) -> None:
|
|
212
209
|
monkeypatch.delenv("VERULLA_API_URL", raising=False)
|
|
210
|
+
calls = []
|
|
211
|
+
monkeypatch.setattr("verulla_cli.main.run_device_login", lambda api_url: calls.append(api_url))
|
|
212
|
+
|
|
213
213
|
result = runner.invoke(app, ["login"])
|
|
214
|
-
|
|
214
|
+
|
|
215
|
+
assert result.exit_code == 0, result.output
|
|
216
|
+
assert calls == ["https://api.verulla.app"]
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def test_login_environment_and_flag_override_default_in_precedence_order(monkeypatch) -> None:
|
|
220
|
+
calls = []
|
|
221
|
+
monkeypatch.setattr("verulla_cli.main.run_device_login", lambda api_url: calls.append(api_url))
|
|
222
|
+
monkeypatch.setenv("VERULLA_API_URL", "https://sandbox.example/")
|
|
223
|
+
|
|
224
|
+
env_result = runner.invoke(app, ["login"])
|
|
225
|
+
flag_result = runner.invoke(app, ["login", "--api-url", "https://dev.example/"])
|
|
226
|
+
|
|
227
|
+
assert env_result.exit_code == flag_result.exit_code == 0
|
|
228
|
+
assert calls == ["https://sandbox.example", "https://dev.example"]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def test_every_api_url_option_uses_the_shared_default() -> None:
|
|
232
|
+
from typer.main import get_command
|
|
233
|
+
from verulla_cli.config import DEFAULT_API_URL
|
|
234
|
+
|
|
235
|
+
def api_url_parameters(command):
|
|
236
|
+
for parameter in command.params:
|
|
237
|
+
if "--api-url" in parameter.opts:
|
|
238
|
+
yield parameter
|
|
239
|
+
for child in getattr(command, "commands", {}).values():
|
|
240
|
+
yield from api_url_parameters(child)
|
|
241
|
+
|
|
242
|
+
parameters = list(api_url_parameters(get_command(app)))
|
|
243
|
+
assert len(parameters) > 1
|
|
244
|
+
assert all(parameter.default == DEFAULT_API_URL for parameter in parameters)
|
|
245
|
+
assert all(parameter.envvar == "VERULLA_API_URL" for parameter in parameters)
|
|
246
|
+
assert all(getattr(parameter, "show_default", False) for parameter in parameters)
|
|
215
247
|
|
|
216
248
|
|
|
217
249
|
def test_login_with_unreachable_api_url_fails_cleanly() -> None:
|
|
@@ -323,7 +355,7 @@ def test_deploy_wait_success_prints_sketch_handoff(tmp_path, monkeypatch) -> Non
|
|
|
323
355
|
})
|
|
324
356
|
states = iter([
|
|
325
357
|
{"status": "building", "build_log_tail": ""},
|
|
326
|
-
{"status": "deployed", "build_log_tail": ""},
|
|
358
|
+
{"status": "deployed", "runtime_health": "ready", "build_log_tail": ""},
|
|
327
359
|
])
|
|
328
360
|
monkeypatch.setattr("verulla_cli.main.get_deployment", lambda *args: next(states))
|
|
329
361
|
monkeypatch.setattr("verulla_cli.main.get_sketch_status", lambda *args: {
|
|
@@ -357,7 +389,25 @@ def test_deploy_wait_failure_exits_nonzero_and_shows_build_log_tail(tmp_path, mo
|
|
|
357
389
|
assert result.exit_code == 1
|
|
358
390
|
assert "verulla logs demo-app" in result.output
|
|
359
391
|
assert "build output tail" in result.output
|
|
360
|
-
assert "Runtime
|
|
392
|
+
assert "Runtime health is shown above" in result.output
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def test_deploy_wait_crashing_reports_runtime_reason_and_hint(tmp_path, monkeypatch) -> None:
|
|
396
|
+
monkeypatch.setattr("verulla_cli.main.get_token", lambda: "tok")
|
|
397
|
+
monkeypatch.setattr("verulla_cli.main.create_deployment", lambda *args: {
|
|
398
|
+
"id": "d-crash", "app": "demo-app", "status": "queued",
|
|
399
|
+
})
|
|
400
|
+
monkeypatch.setattr("verulla_cli.main.get_deployment", lambda *args: {
|
|
401
|
+
"id": "d-crash", "status": "deployed", "runtime_health": "crashing",
|
|
402
|
+
"runtime_health_reason": "Error (exit code 1); sqlite3.OperationalError: unable to open database file",
|
|
403
|
+
"effective_port": 8000,
|
|
404
|
+
})
|
|
405
|
+
result = runner.invoke(app, ["deploy", str(_valid_project(tmp_path)), "--api-url", "http://api.test", "--wait"])
|
|
406
|
+
assert result.exit_code == 1
|
|
407
|
+
assert "crashing" in result.output
|
|
408
|
+
assert "unable to open database file" in result.output
|
|
409
|
+
assert "filesystem is read-only except /tmp" in result.output
|
|
410
|
+
assert "make sure the app listens on the port set in verulla.yml (8000)" in result.output
|
|
361
411
|
|
|
362
412
|
|
|
363
413
|
def test_deploy_wait_timeout_exits_nonzero_with_inspection_action(tmp_path, monkeypatch) -> None:
|
|
@@ -365,13 +415,15 @@ def test_deploy_wait_timeout_exits_nonzero_with_inspection_action(tmp_path, monk
|
|
|
365
415
|
|
|
366
416
|
monkeypatch.setattr(cli_main, "get_token", lambda: "tok")
|
|
367
417
|
monkeypatch.setattr(cli_main, "create_deployment", lambda *args: {"id": "d-slow", "app": "demo-app", "status": "queued"})
|
|
368
|
-
monkeypatch.setattr(cli_main, "get_deployment", lambda *args: {"status": "building"
|
|
418
|
+
monkeypatch.setattr(cli_main, "get_deployment", lambda *args: {"status": "building", "runtime_health": "starting",
|
|
419
|
+
"runtime_health_reason": "app did not answer on port 8000; set port: in verulla.yml"})
|
|
369
420
|
monkeypatch.setattr(cli_main.time, "monotonic", iter([0.0, 0.0, 2.0]).__next__)
|
|
370
421
|
monkeypatch.setattr(cli_main.time, "sleep", lambda _: None)
|
|
371
422
|
result = runner.invoke(app, ["deploy", str(_valid_project(tmp_path)), "--api-url", "http://api.test", "--wait", "--wait-timeout", "1"])
|
|
372
423
|
assert result.exit_code == 1
|
|
373
424
|
assert "Timed out after 1s" in result.output
|
|
374
425
|
assert "verulla logs demo-app" in result.output
|
|
426
|
+
assert "app did not answer on port 8000" in result.output
|
|
375
427
|
|
|
376
428
|
|
|
377
429
|
def test_deploy_logged_in_unreachable_api_fails_cleanly(tmp_path, monkeypatch) -> None:
|
|
@@ -448,7 +500,7 @@ def test_logs_fetches_and_prints_build_log(monkeypatch) -> None:
|
|
|
448
500
|
assert result.exit_code == 0, result.output
|
|
449
501
|
assert "status: failed" in result.output
|
|
450
502
|
assert "compiler output" in result.output
|
|
451
|
-
assert "Runtime/pod logs are not
|
|
503
|
+
assert "Runtime/pod logs are not included" in result.output
|
|
452
504
|
|
|
453
505
|
|
|
454
506
|
def test_logs_reports_api_errors(monkeypatch) -> None:
|
|
@@ -495,10 +547,11 @@ def test_status_includes_plan_and_paid_term_fields(monkeypatch) -> None:
|
|
|
495
547
|
monkeypatch.setattr("verulla_cli.main.get_app", lambda *args: {
|
|
496
548
|
"app": "demo", "tier_id": "live", "pricing_version": "v1",
|
|
497
549
|
"paid_through": "2026-11-25T00:00:00+00:00", "renewal_date": "2026-11-25", "status": "deployed",
|
|
550
|
+
"runtime_health": "crashing", "runtime_health_reason": "exit code 1",
|
|
498
551
|
})
|
|
499
552
|
result = runner.invoke(app, ["status", "demo", "--api-url", "https://api.test"])
|
|
500
553
|
assert result.exit_code == 0, result.output
|
|
501
|
-
for field in ("tier_id: live", "pricing_version: v1", "paid_through:", "renewal_date: 2026-11-25"):
|
|
554
|
+
for field in ("tier_id: live", "pricing_version: v1", "paid_through:", "renewal_date: 2026-11-25", "runtime_health: crashing", "runtime_health_reason: exit code 1"):
|
|
502
555
|
assert field in result.output
|
|
503
556
|
|
|
504
557
|
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""BuildKit backend for local `verulla dev` builds."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import shlex
|
|
10
|
+
import uuid
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from verulla_cli.emulate import EmulationError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
BUILDKIT_BUILD_TIMEOUT_SECONDS = 600
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _safe_progress_summary(*parts: str | bytes | None) -> str:
|
|
20
|
+
"""Reduce plain progress output to bounded, non-command vertex metadata."""
|
|
21
|
+
records: list[str] = []
|
|
22
|
+
vertex_pattern = re.compile(r"^#(?P<id>\d+)\s+(?P<detail>.*)$")
|
|
23
|
+
for part in parts:
|
|
24
|
+
if isinstance(part, bytes):
|
|
25
|
+
part = part.decode("utf-8", errors="replace")
|
|
26
|
+
for raw_line in (part or "").splitlines():
|
|
27
|
+
match = vertex_pattern.match(raw_line)
|
|
28
|
+
if not match:
|
|
29
|
+
continue
|
|
30
|
+
detail = match.group("detail").strip()
|
|
31
|
+
status = "running"
|
|
32
|
+
for terminal in ("DONE", "CACHED", "ERROR", "CANCELED"):
|
|
33
|
+
if detail == terminal or detail.startswith(terminal + " "):
|
|
34
|
+
status = terminal.lower()
|
|
35
|
+
detail = ""
|
|
36
|
+
break
|
|
37
|
+
if detail.startswith("[") and "]" in detail:
|
|
38
|
+
detail = detail.split("]", 1)[1].strip()
|
|
39
|
+
command = detail.split(None, 1)[0].upper() if detail else ""
|
|
40
|
+
if command in {"RUN", "COPY", "ADD", "WORKDIR", "ENV", "USER", "ARG", "EXPOSE", "ENTRYPOINT", "CMD"}:
|
|
41
|
+
label = f"{command} instruction"
|
|
42
|
+
elif detail.startswith("load build definition"):
|
|
43
|
+
label = "load build definition"
|
|
44
|
+
elif detail.startswith("load .dockerignore"):
|
|
45
|
+
label = "load build metadata"
|
|
46
|
+
elif detail.startswith("load metadata") or detail.startswith("resolve image config"):
|
|
47
|
+
label = "resolve image metadata"
|
|
48
|
+
elif detail.startswith("load build context"):
|
|
49
|
+
label = "load build context"
|
|
50
|
+
elif detail.startswith("exporting") or detail.startswith("export "):
|
|
51
|
+
label = "export build result"
|
|
52
|
+
elif detail.startswith("unpacking"):
|
|
53
|
+
label = "unpack image"
|
|
54
|
+
else:
|
|
55
|
+
label = "BuildKit vertex"
|
|
56
|
+
records.append(f"vertex #{match.group('id')} {label} [{status}]")
|
|
57
|
+
return "\n".join(records[-40:])[-8000:]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def select_builder(requested: str, docker_available: bool) -> str:
|
|
61
|
+
if requested == "docker":
|
|
62
|
+
if not docker_available:
|
|
63
|
+
raise EmulationError("Docker requested but unavailable; set BUILDKIT_HOST or choose --builder buildkit")
|
|
64
|
+
return "docker"
|
|
65
|
+
if requested == "buildkit":
|
|
66
|
+
if not os.environ.get("BUILDKIT_HOST"):
|
|
67
|
+
raise EmulationError("BuildKit requested but BUILDKIT_HOST is not set")
|
|
68
|
+
return "buildkit"
|
|
69
|
+
if docker_available:
|
|
70
|
+
return "docker"
|
|
71
|
+
if os.environ.get("BUILDKIT_HOST"):
|
|
72
|
+
return "buildkit"
|
|
73
|
+
raise EmulationError("No builder available: choose --builder docker|buildkit, start Docker, or set BUILDKIT_HOST")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class BuildKitRunner:
|
|
77
|
+
def __init__(self, address: str | None = None):
|
|
78
|
+
self.address = address or os.environ.get("BUILDKIT_HOST")
|
|
79
|
+
if not self.address:
|
|
80
|
+
raise EmulationError("BUILDKIT_HOST is not set")
|
|
81
|
+
if shutil.which("buildctl") is None:
|
|
82
|
+
raise EmulationError("buildctl not found on PATH (required with BUILDKIT_HOST)")
|
|
83
|
+
|
|
84
|
+
def build(self, context_dir: Path, dockerfile_name: str, *, check: bool = False, dockerfile_dir: Path | None = None) -> str:
|
|
85
|
+
command = [
|
|
86
|
+
"buildctl", "--addr", self.address, "build", "--frontend", "dockerfile.v0",
|
|
87
|
+
"--local", f"context={context_dir}", "--local", f"dockerfile={dockerfile_dir or context_dir}",
|
|
88
|
+
"--opt", f"filename={dockerfile_name}",
|
|
89
|
+
]
|
|
90
|
+
tls_dir = os.environ.get("BUILDKIT_TLS_DIR", "/run/buildkit-client")
|
|
91
|
+
tls_servername = os.environ.get("BUILDKIT_TLS_SERVERNAME", "buildkitd.tools.svc.cluster.local")
|
|
92
|
+
if Path(tls_dir, "ca.crt").exists():
|
|
93
|
+
command += ["--tlsdir", tls_dir]
|
|
94
|
+
if tls_servername:
|
|
95
|
+
command += ["--tlsservername", tls_servername]
|
|
96
|
+
if check:
|
|
97
|
+
command += ["--no-cache", "--output", "type=oci,dest=/dev/null", "--progress=plain"]
|
|
98
|
+
try:
|
|
99
|
+
result = subprocess.run(
|
|
100
|
+
command,
|
|
101
|
+
text=True,
|
|
102
|
+
capture_output=True,
|
|
103
|
+
check=False,
|
|
104
|
+
timeout=BUILDKIT_BUILD_TIMEOUT_SECONDS,
|
|
105
|
+
)
|
|
106
|
+
except subprocess.TimeoutExpired as exc:
|
|
107
|
+
progress = _safe_progress_summary(exc.stdout or exc.output, exc.stderr)
|
|
108
|
+
detail = f"\nRecent BuildKit progress:\n{progress}" if progress else ""
|
|
109
|
+
raise EmulationError(
|
|
110
|
+
f"BuildKit build timed out after {BUILDKIT_BUILD_TIMEOUT_SECONDS} seconds{detail}"
|
|
111
|
+
) from None
|
|
112
|
+
except OSError as exc:
|
|
113
|
+
raise EmulationError(f"could not execute buildctl: {exc}") from exc
|
|
114
|
+
output = result.stdout + result.stderr
|
|
115
|
+
if result.returncode and not check:
|
|
116
|
+
raise EmulationError(f"BuildKit build failed (exit {result.returncode}): {output.strip()}")
|
|
117
|
+
return output
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def check_dockerfile(function, routes, output_dir: Path | None = None) -> str:
|
|
121
|
+
"""Create a BuildKit-only check Dockerfile which starts the app and probes routes."""
|
|
122
|
+
plan = function.build_plan
|
|
123
|
+
original = plan.dockerfile_path or ".verulla.Dockerfile"
|
|
124
|
+
source_path = (output_dir / original) if output_dir and (output_dir / original).is_file() else (function.src_root / original)
|
|
125
|
+
source = source_path.read_text()
|
|
126
|
+
run_cmd = plan.run_cmd
|
|
127
|
+
if run_cmd:
|
|
128
|
+
start = shlex.join(run_cmd)
|
|
129
|
+
process = f"sh -c {shlex.quote(start)}"
|
|
130
|
+
else:
|
|
131
|
+
process = "/docker-entrypoint.sh nginx -g 'daemon off;'"
|
|
132
|
+
# Use a separate process group when setsid exists. On custom bases without
|
|
133
|
+
# it, still launch and stop the foreground app process; daemonized children
|
|
134
|
+
# cannot be reliably grouped or reaped in that fallback.
|
|
135
|
+
pgid_file = f"/tmp/verulla-app-{uuid.uuid4().hex}.pgid"
|
|
136
|
+
group_process = f"echo $$ > {shlex.quote(pgid_file)}; exec {process}"
|
|
137
|
+
starter = (
|
|
138
|
+
"if command -v setsid >/dev/null 2>&1; then\n"
|
|
139
|
+
f" setsid sh -c {shlex.quote(group_process)} >/tmp/verulla-app.log 2>&1 &\n"
|
|
140
|
+
" app_pid=$!; app_group=1\n"
|
|
141
|
+
"else\n"
|
|
142
|
+
f" {process} >/tmp/verulla-app.log 2>&1 &\n"
|
|
143
|
+
" app_pid=$!; app_group=0\n"
|
|
144
|
+
"fi"
|
|
145
|
+
)
|
|
146
|
+
paths = [route.path for route in routes if route.function == function.name]
|
|
147
|
+
base_image = plan.base_image or ""
|
|
148
|
+
if base_image.startswith("node:"):
|
|
149
|
+
ready_js = (
|
|
150
|
+
"require('node:http').get('http://127.0.0.1:"
|
|
151
|
+
f"{plan.port}/',res=>{{res.resume();res.on('end',()=>process.exit(0))}})"
|
|
152
|
+
".on('error',()=>process.exit(1))"
|
|
153
|
+
)
|
|
154
|
+
ready_probe = f"node -e {shlex.quote(ready_js)}"
|
|
155
|
+
probes = []
|
|
156
|
+
for path in paths:
|
|
157
|
+
url = f"http://127.0.0.1:{plan.port}{path}"
|
|
158
|
+
js = (
|
|
159
|
+
"const http=require('node:http');"
|
|
160
|
+
f"http.get({json.dumps(url)},res=>{{"
|
|
161
|
+
f"const code=res.statusCode;console.log('ROUTE '+{json.dumps(path)}+' '+code);"
|
|
162
|
+
"res.resume();res.on('end',()=>process.exit(code>=200&&code<400?0:1));"
|
|
163
|
+
"}).on('error',()=>{console.log('ROUTE '+"
|
|
164
|
+
f"{json.dumps(path)}+' 0');process.exit(1)}})"
|
|
165
|
+
)
|
|
166
|
+
probes.append(f"node -e {shlex.quote(js)}")
|
|
167
|
+
probe = "\n".join(probes)
|
|
168
|
+
elif base_image.startswith("python:"):
|
|
169
|
+
ready_python = (
|
|
170
|
+
"import http.client; "
|
|
171
|
+
f"c=http.client.HTTPConnection('127.0.0.1',{plan.port}); "
|
|
172
|
+
"c.request('GET','/'); c.getresponse(); c.close()"
|
|
173
|
+
)
|
|
174
|
+
ready_probe = f"python -c {shlex.quote(ready_python)}"
|
|
175
|
+
probes = []
|
|
176
|
+
for path in paths:
|
|
177
|
+
python = (
|
|
178
|
+
"import http.client,sys; "
|
|
179
|
+
f"c=http.client.HTTPConnection('127.0.0.1',{plan.port}); "
|
|
180
|
+
f"c.request('GET',{path!r}); r=c.getresponse(); "
|
|
181
|
+
f"print('ROUTE '+{path!r}+' '+str(r.status)); "
|
|
182
|
+
"sys.exit(0 if 200<=r.status<400 else 1)"
|
|
183
|
+
)
|
|
184
|
+
probes.append(f"python -c {shlex.quote(python)}")
|
|
185
|
+
probe = "\n".join(probes)
|
|
186
|
+
else:
|
|
187
|
+
ready_probe = f"wget -q -O /dev/null http://127.0.0.1:{plan.port}/"
|
|
188
|
+
probe = "\n".join(
|
|
189
|
+
f"code=$(wget -S -O /dev/null http://127.0.0.1:{plan.port}{shlex.quote(path)} 2>&1 | awk '{{for (i=1;i<=NF;i++) if ($i ~ /^HTTP\\//) c=$(i+1)}} END {{print c+0}}'); echo ROUTE {shlex.quote(path)} $code; test $code -ge 200 -a $code -lt 400"
|
|
190
|
+
for path in paths
|
|
191
|
+
)
|
|
192
|
+
script = (
|
|
193
|
+
f"# check-{uuid.uuid4().hex}\n"
|
|
194
|
+
f"{starter}\n"
|
|
195
|
+
f"trap 'status=$?; trap - EXIT; if [ \"$app_group\" -eq 1 ] && [ -s {shlex.quote(pgid_file)} ]; then "
|
|
196
|
+
f"app_pgid=$(cat {shlex.quote(pgid_file)}); kill -TERM -\"$app_pgid\" 2>/dev/null || true; "
|
|
197
|
+
"for i in 1 2 3 4 5; do kill -0 -\"$app_pgid\" 2>/dev/null || break; sleep 1; done; "
|
|
198
|
+
"kill -KILL -\"$app_pgid\" 2>/dev/null || true; else "
|
|
199
|
+
"kill -TERM \"$app_pid\" 2>/dev/null || true; fi; "
|
|
200
|
+
"wait \"$app_pid\" 2>/dev/null || true; exit \"$status\"' EXIT\n"
|
|
201
|
+
f"for i in $(seq 1 60); do {ready_probe} >/dev/null 2>&1 && break; sleep 1; done\n"
|
|
202
|
+
f"{probe}\n"
|
|
203
|
+
)
|
|
204
|
+
output_dir = output_dir or function.src_root
|
|
205
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
206
|
+
check_name = ".verulla.Check.Dockerfile"
|
|
207
|
+
(output_dir / check_name).write_text(source + "\nRUN --network=none " + json.dumps(["/bin/sh", "-c", script]) + "\n")
|
|
208
|
+
return check_name
|
|
@@ -11,6 +11,7 @@ import uuid
|
|
|
11
11
|
|
|
12
12
|
import typer
|
|
13
13
|
|
|
14
|
+
from verulla_cli.config import DEFAULT_API_URL
|
|
14
15
|
from verulla_cli.auth import CREDENTIALS_PATH, DeviceLoginError, get_token, run_device_login, save_credentials
|
|
15
16
|
from verulla_manifest import load_manifest, translate
|
|
16
17
|
from verulla_cli.apps_client import (
|
|
@@ -53,7 +54,7 @@ from verulla_cli.secrets_client import SecretsError, delete_secret as api_delete
|
|
|
53
54
|
|
|
54
55
|
app = typer.Typer(
|
|
55
56
|
name="verulla",
|
|
56
|
-
help="Verulla: AI-agent-friendly deployment & hosting CLI.",
|
|
57
|
+
help=f"Verulla: AI-agent-friendly deployment & hosting CLI. API URL default: {DEFAULT_API_URL} (override with --api-url or VERULLA_API_URL).",
|
|
57
58
|
no_args_is_help=True,
|
|
58
59
|
)
|
|
59
60
|
sketch_app = typer.Typer(name="sketch", help="Inspect Sketch trial lifecycle status.", no_args_is_help=True)
|
|
@@ -80,9 +81,9 @@ def _not_implemented(command: str) -> None:
|
|
|
80
81
|
@app.command()
|
|
81
82
|
def login(
|
|
82
83
|
api_url: str = typer.Option(
|
|
83
|
-
|
|
84
|
+
DEFAULT_API_URL,
|
|
84
85
|
"--api-url",
|
|
85
|
-
envvar="VERULLA_API_URL",
|
|
86
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
86
87
|
help="Verulla control plane base URL.",
|
|
87
88
|
),
|
|
88
89
|
) -> None:
|
|
@@ -131,7 +132,7 @@ def signup(
|
|
|
131
132
|
display_name: str | None = typer.Option(None, "--display-name", help="Tenant display name."),
|
|
132
133
|
slug: str | None = typer.Option(None, "--slug", help="Safe tenant slug; generated when omitted."),
|
|
133
134
|
recover: bool = typer.Option(False, "--recover", help="Retry the saved interrupted signup request."),
|
|
134
|
-
api_url: str = typer.Option(
|
|
135
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane URL."),
|
|
135
136
|
json_output: bool = typer.Option(False, "--json", help="Print a redacted JSON receipt."),
|
|
136
137
|
) -> None:
|
|
137
138
|
"""Create a tenant and owner hand-off without a browser or interactive prompts."""
|
|
@@ -333,12 +334,12 @@ def _print_route_results(statuses: list[dict[str, int | str]], json_output: bool
|
|
|
333
334
|
def deploy(
|
|
334
335
|
path: str = typer.Argument(".", help="Path to the directory containing verulla.yml"),
|
|
335
336
|
api_url: str = typer.Option(
|
|
336
|
-
|
|
337
|
+
DEFAULT_API_URL,
|
|
337
338
|
"--api-url",
|
|
338
|
-
envvar="VERULLA_API_URL",
|
|
339
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
339
340
|
help="Verulla control plane base URL.",
|
|
340
341
|
),
|
|
341
|
-
wait: bool = typer.Option(False, "--wait", help="Wait for
|
|
342
|
+
wait: bool = typer.Option(False, "--wait", help="Wait for runtime health to be ready; fail with the crash cause and port hint otherwise."),
|
|
342
343
|
wait_timeout: int = typer.Option(600, "--wait-timeout", min=1, max=3600,
|
|
343
344
|
help="Maximum seconds to wait (1-3600; default 600)."),
|
|
344
345
|
) -> None:
|
|
@@ -377,7 +378,7 @@ def deploy(
|
|
|
377
378
|
for fn in deployment.get("functions", []):
|
|
378
379
|
typer.echo(f" {fn['name']} ({fn['adapter']})")
|
|
379
380
|
if wait:
|
|
380
|
-
terminal = {"
|
|
381
|
+
terminal = {"build_failed", "apply_failed", "failed", "deleted", "delete_failed", "superseded", "suspended"}
|
|
381
382
|
deadline = time.monotonic() + wait_timeout
|
|
382
383
|
while True:
|
|
383
384
|
try:
|
|
@@ -386,18 +387,37 @@ def deploy(
|
|
|
386
387
|
typer.echo(f"Error checking deployment status: {exc}", err=True)
|
|
387
388
|
raise typer.Exit(code=1) from exc
|
|
388
389
|
status = latest.get("status")
|
|
389
|
-
|
|
390
|
+
runtime_health = latest.get("runtime_health", "starting")
|
|
391
|
+
if status in terminal or runtime_health in {"crashing", "failed"} or (
|
|
392
|
+
status == "deployed" and runtime_health == "ready"
|
|
393
|
+
):
|
|
390
394
|
break
|
|
391
395
|
remaining = deadline - time.monotonic()
|
|
392
396
|
if remaining <= 0:
|
|
393
397
|
typer.echo(
|
|
394
|
-
f"Timed out after {wait_timeout}s waiting for deployment {deployment['id']}
|
|
398
|
+
f"Timed out after {wait_timeout}s waiting for deployment {deployment['id']} "
|
|
399
|
+
f"(last status: {status}, runtime health: {runtime_health}). "
|
|
400
|
+
f"Runtime reason: {latest.get('runtime_health_reason') or '(none reported)'}. "
|
|
395
401
|
f"Inspect with: verulla logs {deployment['app']}", err=True,
|
|
396
402
|
)
|
|
397
403
|
raise typer.Exit(code=1)
|
|
398
404
|
time.sleep(min(2, remaining))
|
|
399
|
-
if status != "deployed":
|
|
405
|
+
if status != "deployed" or runtime_health != "ready":
|
|
400
406
|
typer.echo(f"Deployment {deployment['id']} ended with status {status}.", err=True)
|
|
407
|
+
if runtime_health in {"crashing", "failed"}:
|
|
408
|
+
reason = latest.get("runtime_health_reason") or "no runtime details reported"
|
|
409
|
+
typer.echo(f"App exited at startup: {reason}", err=True)
|
|
410
|
+
typer.echo(f"Runtime health: {runtime_health}", err=True)
|
|
411
|
+
port = latest.get("effective_port")
|
|
412
|
+
hint = (
|
|
413
|
+
f"make sure the app listens on the port set in verulla.yml ({port})"
|
|
414
|
+
if isinstance(port, int)
|
|
415
|
+
else "make sure the app listens on the port set in verulla.yml (default 8080)"
|
|
416
|
+
)
|
|
417
|
+
typer.echo(
|
|
418
|
+
f"Hint: app exited at startup; the filesystem is read-only except /tmp; {hint}.",
|
|
419
|
+
err=True,
|
|
420
|
+
)
|
|
401
421
|
if latest.get("error"):
|
|
402
422
|
typer.echo(f"Error: {latest['error']}", err=True)
|
|
403
423
|
try:
|
|
@@ -409,7 +429,7 @@ def deploy(
|
|
|
409
429
|
typer.echo("build_log_tail:", err=True)
|
|
410
430
|
tail = logs.get("build_log_tail") if logs.get("deployment_id") == deployment["id"] else None
|
|
411
431
|
typer.echo(tail or "(no matching build log available)", err=True)
|
|
412
|
-
typer.echo("Runtime
|
|
432
|
+
typer.echo("Runtime health is shown above; pod log tails are not included in this output.", err=True)
|
|
413
433
|
raise typer.Exit(code=1)
|
|
414
434
|
try:
|
|
415
435
|
receipt = _safe_sketch_receipt(get_sketch_status(api_url.rstrip("/"), token, deployment["app"]))
|
|
@@ -453,9 +473,9 @@ def secrets_list(
|
|
|
453
473
|
app_name: str | None = typer.Option(None, "--app", help="Scope secrets to APP."),
|
|
454
474
|
shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
|
|
455
475
|
api_url: str = typer.Option(
|
|
456
|
-
|
|
476
|
+
DEFAULT_API_URL,
|
|
457
477
|
"--api-url",
|
|
458
|
-
envvar="VERULLA_API_URL",
|
|
478
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
459
479
|
help="Verulla control plane base URL.",
|
|
460
480
|
),
|
|
461
481
|
) -> None:
|
|
@@ -484,9 +504,9 @@ def secrets_set(
|
|
|
484
504
|
app_name: str | None = typer.Option(None, "--app", help="Scope secret to APP."),
|
|
485
505
|
shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
|
|
486
506
|
api_url: str = typer.Option(
|
|
487
|
-
|
|
507
|
+
DEFAULT_API_URL,
|
|
488
508
|
"--api-url",
|
|
489
|
-
envvar="VERULLA_API_URL",
|
|
509
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
490
510
|
help="Verulla control plane base URL.",
|
|
491
511
|
),
|
|
492
512
|
) -> None:
|
|
@@ -511,7 +531,7 @@ def secrets_delete(
|
|
|
511
531
|
key: str = typer.Argument(..., help="Secret key name"),
|
|
512
532
|
app_name: str | None = typer.Option(None, "--app", help="Scope secret to APP."),
|
|
513
533
|
shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
|
|
514
|
-
api_url: str = typer.Option(
|
|
534
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
515
535
|
) -> None:
|
|
516
536
|
"""Delete a secret without displaying its value."""
|
|
517
537
|
scope = _secret_scope(app_name, shared)
|
|
@@ -532,7 +552,7 @@ def secrets_delete(
|
|
|
532
552
|
def logs(
|
|
533
553
|
app_name: str = typer.Argument(..., metavar="APP", help="App name"),
|
|
534
554
|
function: str | None = typer.Argument(None, help="Optional function name (reserved for runtime logs)"),
|
|
535
|
-
api_url: str = typer.Option(
|
|
555
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
536
556
|
) -> None:
|
|
537
557
|
"""Show latest deployment status and build log tail (runtime logs are not available yet)."""
|
|
538
558
|
del function
|
|
@@ -546,11 +566,11 @@ def logs(
|
|
|
546
566
|
except AppsError as exc:
|
|
547
567
|
typer.echo(f"Error: {exc}", err=True)
|
|
548
568
|
raise typer.Exit(code=1) from exc
|
|
549
|
-
for key in ("app", "deployment_id", "status", "error"):
|
|
569
|
+
for key in ("app", "deployment_id", "status", "runtime_health", "runtime_health_reason", "error"):
|
|
550
570
|
typer.echo(f"{key}: {result.get(key)}")
|
|
551
571
|
typer.echo("build_log_tail:")
|
|
552
572
|
typer.echo(result.get("build_log_tail") or "(no build log available)")
|
|
553
|
-
typer.echo("Runtime/pod logs are not
|
|
573
|
+
typer.echo("Runtime/pod logs are not included; see runtime_health and runtime_health_reason above.")
|
|
554
574
|
|
|
555
575
|
|
|
556
576
|
def _resolve_app(name: str | None) -> str:
|
|
@@ -569,7 +589,7 @@ def _resolve_app(name: str | None) -> str:
|
|
|
569
589
|
|
|
570
590
|
@app.command()
|
|
571
591
|
def apps(
|
|
572
|
-
api_url: str = typer.Option(
|
|
592
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
573
593
|
) -> None:
|
|
574
594
|
"""List apps in your tenant."""
|
|
575
595
|
try:
|
|
@@ -586,12 +606,17 @@ def apps(
|
|
|
586
606
|
typer.echo("No apps.")
|
|
587
607
|
return
|
|
588
608
|
for row in rows:
|
|
589
|
-
typer.echo(
|
|
609
|
+
typer.echo(
|
|
610
|
+
f"{row['app']} {row['status']} runtime={row.get('runtime_health', 'starting')} "
|
|
611
|
+
f"{row.get('url') or '-'}"
|
|
612
|
+
)
|
|
613
|
+
if row.get("runtime_health_reason"):
|
|
614
|
+
typer.echo(f" runtime_health_reason: {row['runtime_health_reason']}")
|
|
590
615
|
|
|
591
616
|
|
|
592
617
|
@app.command()
|
|
593
618
|
def wallet(
|
|
594
|
-
api_url: str = typer.Option(
|
|
619
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
595
620
|
) -> None:
|
|
596
621
|
"""Show wallet balance, ledger and spending-limit summary as JSON."""
|
|
597
622
|
try:
|
|
@@ -605,7 +630,7 @@ def wallet(
|
|
|
605
630
|
def usage(
|
|
606
631
|
app_name: str | None = typer.Argument(None, help="Optional Live app name; omit to show all Live apps."),
|
|
607
632
|
month: str | None = typer.Option(None, "--month", help="Calendar usage month in YYYY-MM format (legacy view)."),
|
|
608
|
-
api_url: str = typer.Option(
|
|
633
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
609
634
|
) -> None:
|
|
610
635
|
"""Show Live term allowances, usage, projected costs and spending headroom."""
|
|
611
636
|
try:
|
|
@@ -621,7 +646,7 @@ def usage(
|
|
|
621
646
|
|
|
622
647
|
@app.command()
|
|
623
648
|
def spend(
|
|
624
|
-
api_url: str = typer.Option(
|
|
649
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
625
650
|
) -> None:
|
|
626
651
|
"""Show current spend and spending-limit headroom as JSON."""
|
|
627
652
|
try:
|
|
@@ -633,7 +658,7 @@ def spend(
|
|
|
633
658
|
|
|
634
659
|
@app.command()
|
|
635
660
|
def pricing(
|
|
636
|
-
api_url: str = typer.Option(
|
|
661
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
637
662
|
) -> None:
|
|
638
663
|
"""Show the USD/CAD fixed-price contract as JSON."""
|
|
639
664
|
try:
|
|
@@ -647,7 +672,7 @@ def pricing(
|
|
|
647
672
|
def topup(
|
|
648
673
|
amount_cents: int = typer.Argument(..., min=1, help="Top-up amount in minor units (cents)."),
|
|
649
674
|
currency: str = typer.Option("USD", "--currency", help="Wallet currency: USD or CAD (chosen on first top-up)."),
|
|
650
|
-
api_url: str = typer.Option(
|
|
675
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
651
676
|
) -> None:
|
|
652
677
|
"""Create a wallet top-up intent; currency becomes fixed after funding."""
|
|
653
678
|
if currency not in {"USD", "CAD"}:
|
|
@@ -665,7 +690,7 @@ def topup(
|
|
|
665
690
|
def live(
|
|
666
691
|
app_name: str = typer.Argument(..., metavar="APP", help="App to upgrade to Live."),
|
|
667
692
|
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation."),
|
|
668
|
-
api_url: str = typer.Option(
|
|
693
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
669
694
|
) -> None:
|
|
670
695
|
"""Upgrade an app to Live at the published price in its wallet currency."""
|
|
671
696
|
try:
|
|
@@ -714,7 +739,7 @@ def live(
|
|
|
714
739
|
@app.command()
|
|
715
740
|
def status(
|
|
716
741
|
app_name: str | None = typer.Argument(None, metavar="APP"),
|
|
717
|
-
api_url: str = typer.Option(
|
|
742
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
718
743
|
) -> None:
|
|
719
744
|
"""Show app overview, or detailed status for APP."""
|
|
720
745
|
try:
|
|
@@ -726,10 +751,15 @@ def status(
|
|
|
726
751
|
if app_name is None:
|
|
727
752
|
rows = list_apps(api_url.rstrip("/"), token)
|
|
728
753
|
for row in rows:
|
|
729
|
-
typer.echo(
|
|
754
|
+
typer.echo(
|
|
755
|
+
f"{row['app']} {row['status']} runtime={row.get('runtime_health', 'starting')} "
|
|
756
|
+
f"{row.get('url') or '-'}"
|
|
757
|
+
)
|
|
758
|
+
if row.get("runtime_health_reason"):
|
|
759
|
+
typer.echo(f" runtime_health_reason: {row['runtime_health_reason']}")
|
|
730
760
|
else:
|
|
731
761
|
row = get_app(api_url.rstrip("/"), token, app_name)
|
|
732
|
-
for key in ("app", "tier_id", "pricing_version", "paid_through", "renewal_date", "status", "latest_deployment_id", "source_sha", "function_count", "url", "updated_at", "error", "functions"):
|
|
762
|
+
for key in ("app", "tier_id", "pricing_version", "paid_through", "renewal_date", "status", "runtime_health", "runtime_health_reason", "latest_deployment_id", "source_sha", "function_count", "url", "updated_at", "error", "functions"):
|
|
733
763
|
if key in row:
|
|
734
764
|
typer.echo(f"{key}: {row[key]}")
|
|
735
765
|
except AppsError as exc:
|
|
@@ -743,7 +773,7 @@ def sketch_events(
|
|
|
743
773
|
cursor: str | None = typer.Option(None, "--cursor", help="Resume after this event cursor."),
|
|
744
774
|
limit: int = typer.Option(100, min=1, max=500),
|
|
745
775
|
json_output: bool = typer.Option(False, "--json", help="Print the shared API event envelope as JSON."),
|
|
746
|
-
api_url: str = typer.Option(
|
|
776
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True),
|
|
747
777
|
) -> None:
|
|
748
778
|
"""Poll durable Sketch countdown events after the supplied cursor."""
|
|
749
779
|
result = _auth_api_call(
|
|
@@ -762,7 +792,7 @@ def sketch_events(
|
|
|
762
792
|
def sketch_status(
|
|
763
793
|
app_name: str = typer.Argument(..., metavar="APP"),
|
|
764
794
|
json_output: bool = typer.Option(False, "--json", help="Print the receipt as JSON."),
|
|
765
|
-
api_url: str = typer.Option(
|
|
795
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
766
796
|
) -> None:
|
|
767
797
|
"""Show the shared Sketch lifecycle receipt for APP."""
|
|
768
798
|
try:
|
|
@@ -788,7 +818,7 @@ def owner_claim(
|
|
|
788
818
|
app_name: str = typer.Argument(..., metavar="APP"),
|
|
789
819
|
email: str = typer.Option(..., "--email", help="Verified owner's email address."),
|
|
790
820
|
json_output: bool = typer.Option(False, "--json", help="Print the one-time hand-off as JSON."),
|
|
791
|
-
api_url: str = typer.Option(
|
|
821
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
792
822
|
) -> None:
|
|
793
823
|
"""Issue a one-time claim link for the owner of APP's tenant."""
|
|
794
824
|
try:
|
|
@@ -825,7 +855,7 @@ def owner_claim(
|
|
|
825
855
|
def owner_status(
|
|
826
856
|
app_name: str = typer.Argument(..., metavar="APP"),
|
|
827
857
|
json_output: bool = typer.Option(False, "--json", help="Print safe claim status as JSON."),
|
|
828
|
-
api_url: str = typer.Option(
|
|
858
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
829
859
|
) -> None:
|
|
830
860
|
"""Show safe owner-claim status for APP without revealing its link or email."""
|
|
831
861
|
try:
|
|
@@ -852,7 +882,7 @@ def owner_status(
|
|
|
852
882
|
def delete(
|
|
853
883
|
app_name: str | None = typer.Argument(None, metavar="APP"),
|
|
854
884
|
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation."),
|
|
855
|
-
api_url: str = typer.Option(
|
|
885
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
856
886
|
) -> None:
|
|
857
887
|
"""Delete an app and its deployments."""
|
|
858
888
|
name = _resolve_app(app_name)
|
|
@@ -874,7 +904,7 @@ def delete(
|
|
|
874
904
|
@app.command()
|
|
875
905
|
def rollback(
|
|
876
906
|
app_name: str | None = typer.Argument(None, metavar="APP"),
|
|
877
|
-
api_url: str = typer.Option(
|
|
907
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
|
|
878
908
|
) -> None:
|
|
879
909
|
"""Redeploy the previous successful app snapshot."""
|
|
880
910
|
name = _resolve_app(app_name)
|
|
@@ -907,9 +937,9 @@ def keys_mint(
|
|
|
907
937
|
help="Key expiration in days (1-3650)",
|
|
908
938
|
),
|
|
909
939
|
api_url: str = typer.Option(
|
|
910
|
-
|
|
940
|
+
DEFAULT_API_URL,
|
|
911
941
|
"--api-url",
|
|
912
|
-
envvar="VERULLA_API_URL",
|
|
942
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
913
943
|
help="Verulla control plane base URL.",
|
|
914
944
|
),
|
|
915
945
|
) -> None:
|
|
@@ -965,9 +995,9 @@ def keys_mint(
|
|
|
965
995
|
def keys_revoke(
|
|
966
996
|
key_id: str = typer.Argument(..., help="ID of the key to revoke"),
|
|
967
997
|
api_url: str = typer.Option(
|
|
968
|
-
|
|
998
|
+
DEFAULT_API_URL,
|
|
969
999
|
"--api-url",
|
|
970
|
-
envvar="VERULLA_API_URL",
|
|
1000
|
+
envvar="VERULLA_API_URL", show_default=True,
|
|
971
1001
|
help="Verulla control plane base URL.",
|
|
972
1002
|
),
|
|
973
1003
|
) -> None:
|
|
@@ -1025,7 +1055,7 @@ def _auth_api_call(fn, *args, **kwargs):
|
|
|
1025
1055
|
|
|
1026
1056
|
|
|
1027
1057
|
@auth_app.command("show")
|
|
1028
|
-
def auth_show(app_name: str = typer.Argument(..., metavar="APP"), api_url: str = typer.Option(
|
|
1058
|
+
def auth_show(app_name: str = typer.Argument(..., metavar="APP"), api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1029
1059
|
"""Show the app's AuthPolicy and version."""
|
|
1030
1060
|
data = _auth_api_call(get_auth_policy, api_url.rstrip("/"), _agent_token(), app_name)
|
|
1031
1061
|
typer.echo(json.dumps(data, indent=2))
|
|
@@ -1033,7 +1063,7 @@ def auth_show(app_name: str = typer.Argument(..., metavar="APP"), api_url: str =
|
|
|
1033
1063
|
|
|
1034
1064
|
@auth_app.command("set")
|
|
1035
1065
|
def auth_set(app_name: str = typer.Argument(..., metavar="APP"), policy_file: Path = typer.Argument(..., exists=True, readable=True),
|
|
1036
|
-
api_url: str = typer.Option(
|
|
1066
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True),
|
|
1037
1067
|
version: int | None = typer.Option(None, "--version", min=0)) -> None:
|
|
1038
1068
|
"""Set policy from a JSON file, optionally pinning the expected version."""
|
|
1039
1069
|
try:
|
|
@@ -1058,27 +1088,27 @@ def auth_set(app_name: str = typer.Argument(..., metavar="APP"), policy_file: Pa
|
|
|
1058
1088
|
@customers_app.command("list")
|
|
1059
1089
|
def customers_list(app_name: str = typer.Argument(..., metavar="APP"), search: str | None = typer.Option(None, "--search"),
|
|
1060
1090
|
limit: int = typer.Option(50, min=1, max=100), offset: int = typer.Option(0, min=0),
|
|
1061
|
-
api_url: str = typer.Option(
|
|
1091
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1062
1092
|
"""List customers (requires auth:customers scope)."""
|
|
1063
1093
|
result = _auth_api_call(api_list_customers, api_url.rstrip("/"), _agent_token(), app_name, search=search, limit=limit, offset=offset)
|
|
1064
1094
|
typer.echo(json.dumps(result, indent=2))
|
|
1065
1095
|
|
|
1066
1096
|
|
|
1067
1097
|
@customers_app.command("lock")
|
|
1068
|
-
def customers_lock(app_name: str, customer_id: str, api_url: str = typer.Option(
|
|
1098
|
+
def customers_lock(app_name: str, customer_id: str, api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1069
1099
|
"""Lock a customer account."""
|
|
1070
1100
|
typer.echo(json.dumps(_auth_api_call(api_lock_customer, api_url.rstrip("/"), _agent_token(), app_name, customer_id), indent=2))
|
|
1071
1101
|
|
|
1072
1102
|
|
|
1073
1103
|
@customers_app.command("unlock")
|
|
1074
|
-
def customers_unlock(app_name: str, customer_id: str, api_url: str = typer.Option(
|
|
1104
|
+
def customers_unlock(app_name: str, customer_id: str, api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1075
1105
|
"""Unlock a customer account."""
|
|
1076
1106
|
typer.echo(json.dumps(_auth_api_call(api_unlock_customer, api_url.rstrip("/"), _agent_token(), app_name, customer_id), indent=2))
|
|
1077
1107
|
|
|
1078
1108
|
|
|
1079
1109
|
@customers_app.command("delete")
|
|
1080
1110
|
def customers_delete(app_name: str, customer_id: str, yes: bool = typer.Option(False, "--yes", "-y"),
|
|
1081
|
-
api_url: str = typer.Option(
|
|
1111
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1082
1112
|
"""Soft-delete a customer after confirmation."""
|
|
1083
1113
|
if not yes:
|
|
1084
1114
|
typer.confirm(f"Delete customer {customer_id!r} from {app_name!r}?", abort=True)
|
|
@@ -1088,7 +1118,7 @@ def customers_delete(app_name: str, customer_id: str, yes: bool = typer.Option(F
|
|
|
1088
1118
|
|
|
1089
1119
|
@customers_app.command("export")
|
|
1090
1120
|
def customers_export(app_name: str, output: Path = typer.Option(..., "--output", writable=True),
|
|
1091
|
-
api_url: str = typer.Option(
|
|
1121
|
+
api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1092
1122
|
"""Export customer PII as CSV to OUTPUT (requires auth:customers scope)."""
|
|
1093
1123
|
csv_data = _auth_api_call(api_export_customers, api_url.rstrip("/"), _agent_token(), app_name)
|
|
1094
1124
|
descriptor = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
|
@@ -1104,7 +1134,7 @@ def customers_export(app_name: str, output: Path = typer.Option(..., "--output",
|
|
|
1104
1134
|
|
|
1105
1135
|
|
|
1106
1136
|
@customers_app.command("invite")
|
|
1107
|
-
def customers_invite(app_name: str, email: str, api_url: str = typer.Option(
|
|
1137
|
+
def customers_invite(app_name: str, email: str, api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
|
|
1108
1138
|
"""Invite a customer; delivery may be logging-only until email is configured."""
|
|
1109
1139
|
typer.echo(json.dumps(_auth_api_call(api_invite_customer, api_url.rstrip("/"), _agent_token(), app_name, email), indent=2))
|
|
1110
1140
|
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"""BuildKit backend for local `verulla dev` builds."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import shutil
|
|
7
|
-
import subprocess
|
|
8
|
-
import shlex
|
|
9
|
-
import uuid
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
from verulla_cli.emulate import EmulationError
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
BUILDKIT_BUILD_TIMEOUT_SECONDS = 600
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def select_builder(requested: str, docker_available: bool) -> str:
|
|
19
|
-
if requested == "docker":
|
|
20
|
-
if not docker_available:
|
|
21
|
-
raise EmulationError("Docker requested but unavailable; set BUILDKIT_HOST or choose --builder buildkit")
|
|
22
|
-
return "docker"
|
|
23
|
-
if requested == "buildkit":
|
|
24
|
-
if not os.environ.get("BUILDKIT_HOST"):
|
|
25
|
-
raise EmulationError("BuildKit requested but BUILDKIT_HOST is not set")
|
|
26
|
-
return "buildkit"
|
|
27
|
-
if docker_available:
|
|
28
|
-
return "docker"
|
|
29
|
-
if os.environ.get("BUILDKIT_HOST"):
|
|
30
|
-
return "buildkit"
|
|
31
|
-
raise EmulationError("No builder available: choose --builder docker|buildkit, start Docker, or set BUILDKIT_HOST")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class BuildKitRunner:
|
|
35
|
-
def __init__(self, address: str | None = None):
|
|
36
|
-
self.address = address or os.environ.get("BUILDKIT_HOST")
|
|
37
|
-
if not self.address:
|
|
38
|
-
raise EmulationError("BUILDKIT_HOST is not set")
|
|
39
|
-
if shutil.which("buildctl") is None:
|
|
40
|
-
raise EmulationError("buildctl not found on PATH (required with BUILDKIT_HOST)")
|
|
41
|
-
|
|
42
|
-
def build(self, context_dir: Path, dockerfile_name: str, *, check: bool = False, dockerfile_dir: Path | None = None) -> str:
|
|
43
|
-
command = [
|
|
44
|
-
"buildctl", "--addr", self.address, "build", "--frontend", "dockerfile.v0",
|
|
45
|
-
"--local", f"context={context_dir}", "--local", f"dockerfile={dockerfile_dir or context_dir}",
|
|
46
|
-
"--opt", f"filename={dockerfile_name}",
|
|
47
|
-
]
|
|
48
|
-
tls_dir = os.environ.get("BUILDKIT_TLS_DIR", "/run/buildkit-client")
|
|
49
|
-
tls_servername = os.environ.get("BUILDKIT_TLS_SERVERNAME", "buildkitd.tools.svc.cluster.local")
|
|
50
|
-
if Path(tls_dir, "ca.crt").exists():
|
|
51
|
-
command += ["--tlsdir", tls_dir]
|
|
52
|
-
if tls_servername:
|
|
53
|
-
command += ["--tlsservername", tls_servername]
|
|
54
|
-
if check:
|
|
55
|
-
command += ["--no-cache", "--output", "type=oci,dest=/dev/null", "--progress=plain"]
|
|
56
|
-
try:
|
|
57
|
-
result = subprocess.run(
|
|
58
|
-
command,
|
|
59
|
-
text=True,
|
|
60
|
-
capture_output=True,
|
|
61
|
-
check=False,
|
|
62
|
-
timeout=BUILDKIT_BUILD_TIMEOUT_SECONDS,
|
|
63
|
-
)
|
|
64
|
-
except subprocess.TimeoutExpired:
|
|
65
|
-
raise EmulationError(
|
|
66
|
-
f"BuildKit build timed out after {BUILDKIT_BUILD_TIMEOUT_SECONDS} seconds"
|
|
67
|
-
) from None
|
|
68
|
-
except OSError as exc:
|
|
69
|
-
raise EmulationError(f"could not execute buildctl: {exc}") from exc
|
|
70
|
-
output = result.stdout + result.stderr
|
|
71
|
-
if result.returncode and not check:
|
|
72
|
-
raise EmulationError(f"BuildKit build failed (exit {result.returncode}): {output.strip()}")
|
|
73
|
-
return output
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def check_dockerfile(function, routes, output_dir: Path | None = None) -> str:
|
|
77
|
-
"""Create a BuildKit-only check Dockerfile which starts the app and probes routes."""
|
|
78
|
-
plan = function.build_plan
|
|
79
|
-
original = plan.dockerfile_path or ".verulla.Dockerfile"
|
|
80
|
-
source_path = (output_dir / original) if output_dir and (output_dir / original).is_file() else (function.src_root / original)
|
|
81
|
-
source = source_path.read_text()
|
|
82
|
-
run_cmd = plan.run_cmd
|
|
83
|
-
if run_cmd:
|
|
84
|
-
start = shlex.join(run_cmd)
|
|
85
|
-
starter = f"({start}) >/tmp/verulla-app.log 2>&1 &"
|
|
86
|
-
else:
|
|
87
|
-
starter = "(/docker-entrypoint.sh nginx -g 'daemon off;') >/tmp/verulla-app.log 2>&1 &"
|
|
88
|
-
paths = [route.path for route in routes if route.function == function.name]
|
|
89
|
-
probe = "\n".join(
|
|
90
|
-
f"code=$(wget -S -O /dev/null http://127.0.0.1:{plan.port}{shlex.quote(path)} 2>&1 | awk '{{for (i=1;i<=NF;i++) if ($i ~ /^HTTP\\//) c=$(i+1)}} END {{print c+0}}'); echo ROUTE {shlex.quote(path)} $code; test $code -ge 200 -a $code -lt 400"
|
|
91
|
-
for path in paths
|
|
92
|
-
)
|
|
93
|
-
script = f"# check-{uuid.uuid4().hex}\n{starter}\nfor i in $(seq 1 60); do wget -q -O /dev/null http://127.0.0.1:{plan.port}/ && break; sleep 1; done\n{probe}\n"
|
|
94
|
-
output_dir = output_dir or function.src_root
|
|
95
|
-
output_dir.mkdir(parents=True, exist_ok=True)
|
|
96
|
-
check_name = ".verulla.Check.Dockerfile"
|
|
97
|
-
# Python and Node slim images lack wget; install the probe dependency only
|
|
98
|
-
# in this disposable check image (the nginx static image already has it).
|
|
99
|
-
probe_setup = (
|
|
100
|
-
"USER root\n"
|
|
101
|
-
"RUN apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/*\n"
|
|
102
|
-
"USER 10001:10001\n"
|
|
103
|
-
if (plan.base_image or "").startswith(("python:", "node:"))
|
|
104
|
-
else ""
|
|
105
|
-
)
|
|
106
|
-
(output_dir / check_name).write_text(source + "\n" + probe_setup + "RUN --network=none " + json.dumps(["/bin/sh", "-c", script]) + "\n")
|
|
107
|
-
return check_name
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|