verulla-cli 0.0.3__tar.gz → 0.0.4__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.
Files changed (28) hide show
  1. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/PKG-INFO +1 -1
  2. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/pyproject.toml +1 -1
  3. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_buildkit.py +23 -16
  4. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_buildkit_real.py +1 -0
  5. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_dev_check.py +121 -4
  6. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_main.py +38 -6
  7. verulla_cli-0.0.4/verulla_cli/buildkit.py +208 -0
  8. verulla_cli-0.0.4/verulla_cli/config.py +3 -0
  9. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/main.py +39 -38
  10. verulla_cli-0.0.3/verulla_cli/buildkit.py +0 -107
  11. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/.gitignore +0 -0
  12. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_admin_cmd.py +0 -0
  13. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_apps_client.py +0 -0
  14. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_auth.py +0 -0
  15. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_cli_import.py +0 -0
  16. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_deploy_client.py +0 -0
  17. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_emulate.py +0 -0
  18. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_owner_commands.py +0 -0
  19. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_packaging.py +0 -0
  20. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_secrets_client.py +0 -0
  21. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/tests/test_sketch_status.py +0 -0
  22. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/__init__.py +0 -0
  23. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/apps_client.py +0 -0
  24. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/auth.py +0 -0
  25. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/deploy_client.py +0 -0
  26. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/emulate.py +0 -0
  27. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/packaging.py +0 -0
  28. {verulla_cli-0.0.3 → verulla_cli-0.0.4}/verulla_cli/secrets_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verulla-cli
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Requires-Python: >=3.12
5
5
  Requires-Dist: docker>=7
6
6
  Requires-Dist: httpx>=0.27
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "verulla-cli"
3
- version = "0.0.3"
3
+ version = "0.0.4"
4
4
  requires-python = ">=3.12"
5
5
  dependencies = [
6
6
  "verulla-manifest==0.0.2",
@@ -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 test_buildkit_timeout_is_bounded_and_does_not_leak_process_details(tmp_path, monkeypatch):
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
- monkeypatch.setenv("BUILDKIT_HOST", "tcp://private-builder:1234")
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="private build output",
42
- stderr="secret environment value",
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
- assert str(error.value) == "BuildKit build timed out after 600 seconds"
51
- assert "private build output" not in str(error.value)
52
- assert "secret environment value" not in str(error.value)
53
- assert "private-builder" not in str(error.value)
54
-
55
- import traceback
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 error.value.__suppress_context__
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 "private-builder" not in formatted_traceback
62
- assert "TimeoutExpired" not in formatted_traceback
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 test_buildkit_probe_installs_wget_as_root_then_drops_back_to_app_user(tmp_path):
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 content.index("USER root") < content.index("apt-get update")
138
- assert content.index("apt-get update") < content.rindex("USER 10001:10001")
139
- assert content.rindex("USER 10001:10001") < content.index("RUN --network=none")
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 test_login_requires_api_url(monkeypatch) -> None:
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
- assert result.exit_code == 2
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:
@@ -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
@@ -0,0 +1,3 @@
1
+ """Shared CLI configuration."""
2
+
3
+ DEFAULT_API_URL = "https://api.verulla.app"
@@ -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(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane URL."),
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,9 +334,9 @@ 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
342
  wait: bool = typer.Option(False, "--wait", help="Wait for build/apply to finish, then print the Sketch hand-off."),
@@ -453,9 +454,9 @@ def secrets_list(
453
454
  app_name: str | None = typer.Option(None, "--app", help="Scope secrets to APP."),
454
455
  shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
455
456
  api_url: str = typer.Option(
456
- ...,
457
+ DEFAULT_API_URL,
457
458
  "--api-url",
458
- envvar="VERULLA_API_URL",
459
+ envvar="VERULLA_API_URL", show_default=True,
459
460
  help="Verulla control plane base URL.",
460
461
  ),
461
462
  ) -> None:
@@ -484,9 +485,9 @@ def secrets_set(
484
485
  app_name: str | None = typer.Option(None, "--app", help="Scope secret to APP."),
485
486
  shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
486
487
  api_url: str = typer.Option(
487
- ...,
488
+ DEFAULT_API_URL,
488
489
  "--api-url",
489
- envvar="VERULLA_API_URL",
490
+ envvar="VERULLA_API_URL", show_default=True,
490
491
  help="Verulla control plane base URL.",
491
492
  ),
492
493
  ) -> None:
@@ -511,7 +512,7 @@ def secrets_delete(
511
512
  key: str = typer.Argument(..., help="Secret key name"),
512
513
  app_name: str | None = typer.Option(None, "--app", help="Scope secret to APP."),
513
514
  shared: bool = typer.Option(False, "--shared", help="Use tenant-shared scope."),
514
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
515
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
515
516
  ) -> None:
516
517
  """Delete a secret without displaying its value."""
517
518
  scope = _secret_scope(app_name, shared)
@@ -532,7 +533,7 @@ def secrets_delete(
532
533
  def logs(
533
534
  app_name: str = typer.Argument(..., metavar="APP", help="App name"),
534
535
  function: str | None = typer.Argument(None, help="Optional function name (reserved for runtime logs)"),
535
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
536
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
536
537
  ) -> None:
537
538
  """Show latest deployment status and build log tail (runtime logs are not available yet)."""
538
539
  del function
@@ -569,7 +570,7 @@ def _resolve_app(name: str | None) -> str:
569
570
 
570
571
  @app.command()
571
572
  def apps(
572
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
573
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
573
574
  ) -> None:
574
575
  """List apps in your tenant."""
575
576
  try:
@@ -591,7 +592,7 @@ def apps(
591
592
 
592
593
  @app.command()
593
594
  def wallet(
594
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
595
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
595
596
  ) -> None:
596
597
  """Show wallet balance, ledger and spending-limit summary as JSON."""
597
598
  try:
@@ -605,7 +606,7 @@ def wallet(
605
606
  def usage(
606
607
  app_name: str | None = typer.Argument(None, help="Optional Live app name; omit to show all Live apps."),
607
608
  month: str | None = typer.Option(None, "--month", help="Calendar usage month in YYYY-MM format (legacy view)."),
608
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
609
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
609
610
  ) -> None:
610
611
  """Show Live term allowances, usage, projected costs and spending headroom."""
611
612
  try:
@@ -621,7 +622,7 @@ def usage(
621
622
 
622
623
  @app.command()
623
624
  def spend(
624
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
625
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
625
626
  ) -> None:
626
627
  """Show current spend and spending-limit headroom as JSON."""
627
628
  try:
@@ -633,7 +634,7 @@ def spend(
633
634
 
634
635
  @app.command()
635
636
  def pricing(
636
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
637
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
637
638
  ) -> None:
638
639
  """Show the USD/CAD fixed-price contract as JSON."""
639
640
  try:
@@ -647,7 +648,7 @@ def pricing(
647
648
  def topup(
648
649
  amount_cents: int = typer.Argument(..., min=1, help="Top-up amount in minor units (cents)."),
649
650
  currency: str = typer.Option("USD", "--currency", help="Wallet currency: USD or CAD (chosen on first top-up)."),
650
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
651
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
651
652
  ) -> None:
652
653
  """Create a wallet top-up intent; currency becomes fixed after funding."""
653
654
  if currency not in {"USD", "CAD"}:
@@ -665,7 +666,7 @@ def topup(
665
666
  def live(
666
667
  app_name: str = typer.Argument(..., metavar="APP", help="App to upgrade to Live."),
667
668
  yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation."),
668
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
669
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
669
670
  ) -> None:
670
671
  """Upgrade an app to Live at the published price in its wallet currency."""
671
672
  try:
@@ -714,7 +715,7 @@ def live(
714
715
  @app.command()
715
716
  def status(
716
717
  app_name: str | None = typer.Argument(None, metavar="APP"),
717
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
718
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
718
719
  ) -> None:
719
720
  """Show app overview, or detailed status for APP."""
720
721
  try:
@@ -743,7 +744,7 @@ def sketch_events(
743
744
  cursor: str | None = typer.Option(None, "--cursor", help="Resume after this event cursor."),
744
745
  limit: int = typer.Option(100, min=1, max=500),
745
746
  json_output: bool = typer.Option(False, "--json", help="Print the shared API event envelope as JSON."),
746
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL"),
747
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True),
747
748
  ) -> None:
748
749
  """Poll durable Sketch countdown events after the supplied cursor."""
749
750
  result = _auth_api_call(
@@ -762,7 +763,7 @@ def sketch_events(
762
763
  def sketch_status(
763
764
  app_name: str = typer.Argument(..., metavar="APP"),
764
765
  json_output: bool = typer.Option(False, "--json", help="Print the receipt as JSON."),
765
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
766
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
766
767
  ) -> None:
767
768
  """Show the shared Sketch lifecycle receipt for APP."""
768
769
  try:
@@ -788,7 +789,7 @@ def owner_claim(
788
789
  app_name: str = typer.Argument(..., metavar="APP"),
789
790
  email: str = typer.Option(..., "--email", help="Verified owner's email address."),
790
791
  json_output: bool = typer.Option(False, "--json", help="Print the one-time hand-off as JSON."),
791
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
792
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
792
793
  ) -> None:
793
794
  """Issue a one-time claim link for the owner of APP's tenant."""
794
795
  try:
@@ -825,7 +826,7 @@ def owner_claim(
825
826
  def owner_status(
826
827
  app_name: str = typer.Argument(..., metavar="APP"),
827
828
  json_output: bool = typer.Option(False, "--json", help="Print safe claim status as JSON."),
828
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
829
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
829
830
  ) -> None:
830
831
  """Show safe owner-claim status for APP without revealing its link or email."""
831
832
  try:
@@ -852,7 +853,7 @@ def owner_status(
852
853
  def delete(
853
854
  app_name: str | None = typer.Argument(None, metavar="APP"),
854
855
  yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation."),
855
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
856
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
856
857
  ) -> None:
857
858
  """Delete an app and its deployments."""
858
859
  name = _resolve_app(app_name)
@@ -874,7 +875,7 @@ def delete(
874
875
  @app.command()
875
876
  def rollback(
876
877
  app_name: str | None = typer.Argument(None, metavar="APP"),
877
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL", help="Verulla control plane base URL."),
878
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True, help="Verulla control plane base URL."),
878
879
  ) -> None:
879
880
  """Redeploy the previous successful app snapshot."""
880
881
  name = _resolve_app(app_name)
@@ -907,9 +908,9 @@ def keys_mint(
907
908
  help="Key expiration in days (1-3650)",
908
909
  ),
909
910
  api_url: str = typer.Option(
910
- ...,
911
+ DEFAULT_API_URL,
911
912
  "--api-url",
912
- envvar="VERULLA_API_URL",
913
+ envvar="VERULLA_API_URL", show_default=True,
913
914
  help="Verulla control plane base URL.",
914
915
  ),
915
916
  ) -> None:
@@ -965,9 +966,9 @@ def keys_mint(
965
966
  def keys_revoke(
966
967
  key_id: str = typer.Argument(..., help="ID of the key to revoke"),
967
968
  api_url: str = typer.Option(
968
- ...,
969
+ DEFAULT_API_URL,
969
970
  "--api-url",
970
- envvar="VERULLA_API_URL",
971
+ envvar="VERULLA_API_URL", show_default=True,
971
972
  help="Verulla control plane base URL.",
972
973
  ),
973
974
  ) -> None:
@@ -1025,7 +1026,7 @@ def _auth_api_call(fn, *args, **kwargs):
1025
1026
 
1026
1027
 
1027
1028
  @auth_app.command("show")
1028
- def auth_show(app_name: str = typer.Argument(..., metavar="APP"), api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1029
+ 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
1030
  """Show the app's AuthPolicy and version."""
1030
1031
  data = _auth_api_call(get_auth_policy, api_url.rstrip("/"), _agent_token(), app_name)
1031
1032
  typer.echo(json.dumps(data, indent=2))
@@ -1033,7 +1034,7 @@ def auth_show(app_name: str = typer.Argument(..., metavar="APP"), api_url: str =
1033
1034
 
1034
1035
  @auth_app.command("set")
1035
1036
  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(..., "--api-url", envvar="VERULLA_API_URL"),
1037
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True),
1037
1038
  version: int | None = typer.Option(None, "--version", min=0)) -> None:
1038
1039
  """Set policy from a JSON file, optionally pinning the expected version."""
1039
1040
  try:
@@ -1058,27 +1059,27 @@ def auth_set(app_name: str = typer.Argument(..., metavar="APP"), policy_file: Pa
1058
1059
  @customers_app.command("list")
1059
1060
  def customers_list(app_name: str = typer.Argument(..., metavar="APP"), search: str | None = typer.Option(None, "--search"),
1060
1061
  limit: int = typer.Option(50, min=1, max=100), offset: int = typer.Option(0, min=0),
1061
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1062
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
1062
1063
  """List customers (requires auth:customers scope)."""
1063
1064
  result = _auth_api_call(api_list_customers, api_url.rstrip("/"), _agent_token(), app_name, search=search, limit=limit, offset=offset)
1064
1065
  typer.echo(json.dumps(result, indent=2))
1065
1066
 
1066
1067
 
1067
1068
  @customers_app.command("lock")
1068
- def customers_lock(app_name: str, customer_id: str, api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1069
+ 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
1070
  """Lock a customer account."""
1070
1071
  typer.echo(json.dumps(_auth_api_call(api_lock_customer, api_url.rstrip("/"), _agent_token(), app_name, customer_id), indent=2))
1071
1072
 
1072
1073
 
1073
1074
  @customers_app.command("unlock")
1074
- def customers_unlock(app_name: str, customer_id: str, api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1075
+ 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
1076
  """Unlock a customer account."""
1076
1077
  typer.echo(json.dumps(_auth_api_call(api_unlock_customer, api_url.rstrip("/"), _agent_token(), app_name, customer_id), indent=2))
1077
1078
 
1078
1079
 
1079
1080
  @customers_app.command("delete")
1080
1081
  def customers_delete(app_name: str, customer_id: str, yes: bool = typer.Option(False, "--yes", "-y"),
1081
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1082
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
1082
1083
  """Soft-delete a customer after confirmation."""
1083
1084
  if not yes:
1084
1085
  typer.confirm(f"Delete customer {customer_id!r} from {app_name!r}?", abort=True)
@@ -1088,7 +1089,7 @@ def customers_delete(app_name: str, customer_id: str, yes: bool = typer.Option(F
1088
1089
 
1089
1090
  @customers_app.command("export")
1090
1091
  def customers_export(app_name: str, output: Path = typer.Option(..., "--output", writable=True),
1091
- api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1092
+ api_url: str = typer.Option(DEFAULT_API_URL, "--api-url", envvar="VERULLA_API_URL", show_default=True)) -> None:
1092
1093
  """Export customer PII as CSV to OUTPUT (requires auth:customers scope)."""
1093
1094
  csv_data = _auth_api_call(api_export_customers, api_url.rstrip("/"), _agent_token(), app_name)
1094
1095
  descriptor = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
@@ -1104,7 +1105,7 @@ def customers_export(app_name: str, output: Path = typer.Option(..., "--output",
1104
1105
 
1105
1106
 
1106
1107
  @customers_app.command("invite")
1107
- def customers_invite(app_name: str, email: str, api_url: str = typer.Option(..., "--api-url", envvar="VERULLA_API_URL")) -> None:
1108
+ 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
1109
  """Invite a customer; delivery may be logging-only until email is configured."""
1109
1110
  typer.echo(json.dumps(_auth_api_call(api_invite_customer, api_url.rstrip("/"), _agent_token(), app_name, email), indent=2))
1110
1111
 
@@ -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