@kana-ai/edgar-ext-docker 0.1.2 → 0.1.4
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.
- package/README.md +29 -2
- package/dist/src/environment/steps.js +81 -28
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +4 -2
- package/dist/src/logs/lines.d.ts +9 -0
- package/dist/src/logs/lines.js +35 -0
- package/dist/src/logs/tool.d.ts +10 -0
- package/dist/src/logs/tool.js +41 -0
- package/dist/src/schemas/compose.d.ts +2 -1
- package/dist/src/schemas/compose.js +2 -2
- package/dist/src/schemas/config.d.ts +9 -2
- package/dist/src/schemas/config.js +35 -5
- package/dist/src/schemas/logs.d.ts +16 -0
- package/dist/src/schemas/logs.js +27 -0
- package/dist/src/stack/compose.d.ts +6 -0
- package/dist/src/stack/compose.js +33 -2
- package/edgar-extension.json +15 -3
- package/package.json +3 -3
- package/schemas/config.json +21 -0
- package/schemas/environment.compose.health.out.json +3 -0
- package/schemas/environment.compose.prepare.out.json +3 -0
- package/schemas/environment.compose.start.out.json +3 -0
- package/schemas/environment.compose.stop.out.json +3 -0
- package/schemas/read_logs.in.json +30 -0
- package/schemas/read_logs.out.json +15 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @kana-ai/edgar-ext-docker
|
|
2
2
|
|
|
3
|
-
The Docker extension of EDGAR. Its environment `compose` starts a service's Docker Compose stack before each `check` stage of the service, checks that the stack is healthy, and removes the stack after the checks. A service names it as `docker__compose`.
|
|
3
|
+
The Docker extension of EDGAR. Its environment `compose` starts a service's Docker Compose stack before each `check` stage of the service, checks that the stack is healthy, and removes the stack after the checks. A service names it as `docker__compose`. Its tool `read_logs` reads the log of a container that the project names.
|
|
4
4
|
|
|
5
5
|
## Steps
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ The engine runs the four steps around the checks of a `check` stage: `stop`, `pr
|
|
|
13
13
|
| `health` | `docker compose ps --all --format json` | A container is not running and healthy. A one-off job, such as a migration, may end with 0. |
|
|
14
14
|
| `stop` | `docker compose down --volumes --remove-orphans --rmi local` | Docker does not answer. A stack that is not up is already stopped, so `stop` is safe to repeat. |
|
|
15
15
|
|
|
16
|
-
Each stack is its own Compose project, `edgar-<service>-<run>`, so two runs never share a container, a network or a volume. One stack of a service is up at a time. A health check in the Compose file says when the service is ready, for example a `curl` of its address. `start` waits for it.
|
|
16
|
+
Each stack is its own Compose project, `edgar-<service>-<run>`, so two runs never share a container, a network or a volume. `start` answers the stack's default network, `edgar-<service>-<run>_default`, which the rules keep internal. With `[sandbox] kind = "container"`, each check of the stage joins that network, so a check reaches a service by its name, such as `curl -f http://api:8080/health`, and reaches nothing outside the stack. A stack with no service on its default network answers no network, and its checks stay on none. One stack of a service is up at a time. A health check in the Compose file says when the service is ready, for example a `curl` of its address. `start` waits for it.
|
|
17
17
|
|
|
18
18
|
The Compose file comes from the run's checkout, and a stage can change it on its branch, so `prepare` and `start` each read the file as `docker compose config --no-env-resolution` writes it, with each `env_file` kept as its path, and refuse what gives a container more than its own share of the machine. The rules are a list of what a stack may use, so a key that is not on it, including one that Compose adds later, is refused:
|
|
19
19
|
|
|
@@ -57,8 +57,32 @@ networks:
|
|
|
57
57
|
|
|
58
58
|
A file that breaks a rule fails the stage as `refused`, with each break named, and nothing is built or started.
|
|
59
59
|
|
|
60
|
+
## Save and restore a stack's data
|
|
61
|
+
|
|
62
|
+
A stack starts empty in each run, since `stop` removes its volumes. To start from the data that the last run left, such as a seeded database, name its volumes in `save`:
|
|
63
|
+
|
|
64
|
+
```toml
|
|
65
|
+
[extensions.docker.stacks.api]
|
|
66
|
+
save = ["db-data"] # volumes of the Compose file; none by default
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- `stop` saves: when every container of the stack is up, it runs `docker compose stop`, then copies each volume of `save` into a volume of the service, `edgar-<service>.saved_<volume>`, then removes the stack as before. A stack that is not up, before the checks or after a failed start, saves nothing, so its data never replaces the saved data. A save that fails still removes the stack, and fails the step.
|
|
70
|
+
- `start` restores: it runs `docker compose create`, copies each saved volume into the new stack's volume, then starts the stack. A volume never saved starts empty.
|
|
71
|
+
- The copy runs `docker run --rm --network none` on the image `busybox:1.37.0`, with the two volumes as its only mounts, so the machine needs that image or a way to pull it.
|
|
72
|
+
- `prepare` and `start` refuse a name in `save` that is not a volume of the Compose file.
|
|
73
|
+
|
|
74
|
+
The saved data is the service's, so each run of the service starts from the data the last saved run left. Remove it with `docker volume rm edgar-<service>.saved_<volume>`.
|
|
75
|
+
|
|
60
76
|
The engine gives each step 600 seconds. `wait_seconds` is at most 540, so `start` ends with the name of the container that is not up before the step's own limit stops it.
|
|
61
77
|
|
|
78
|
+
## Tools
|
|
79
|
+
|
|
80
|
+
| Tool | Input | Output | Notes |
|
|
81
|
+
| ------------------- | ----------------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| `docker__read_logs` | `container`; optional `since` (the whole log), `until` (now), `lines` (200, at most 1000) | `log`, `truncated` | Runs `docker logs --timestamps --tail <lines>` in the run's sandbox. With `until`, Docker would cut its tail before it reads the window, so the tool asks for the window and keeps the newest `lines` itself. Both streams, oldest first, each line with its time. At most 32 KiB: older lines are cut first. `truncated` is true when the line count or the byte cap was reached, so older lines may be left out. A container that `logs` does not name is refused, and nothing runs. |
|
|
83
|
+
|
|
84
|
+
A log can hold secrets and personal data, so the tool reads only the containers that `[extensions.docker] logs` names. Its answer passes through EDGAR's redaction like every tool's answer: each secret EDGAR holds, and each key of a known shape, is replaced before the role or any record sees it. The built-in role `investigate` gets the tool when the project enables `docker`. The tool never asks a person.
|
|
85
|
+
|
|
62
86
|
## Enable and approve
|
|
63
87
|
|
|
64
88
|
1. Add the package to the project, enable it, and name the stack of each service in `edgar/edgar.toml`:
|
|
@@ -67,6 +91,9 @@ The engine gives each step 600 seconds. `wait_seconds` is at most 540, so `start
|
|
|
67
91
|
[extensions]
|
|
68
92
|
enabled = ["docker"]
|
|
69
93
|
|
|
94
|
+
[extensions.docker]
|
|
95
|
+
logs = ["shop-api-1", "shop-worker-1"] # the containers read_logs may read; none by default
|
|
96
|
+
|
|
70
97
|
[extensions.docker.stacks.api]
|
|
71
98
|
file = "docker-compose.yml" # the default, relative to the checkout
|
|
72
99
|
wait_seconds = 300 # the default
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineEnvironment, defineTool, done, err, ok, permanentFailure, } from "@kana-ai/edgar-sdk";
|
|
3
|
-
import { container, composeConfig, stepInput, stepOutput } from "#schemas/compose";
|
|
4
|
-
import {
|
|
5
|
-
import { compose, json, project, realPaths, rows } from "#stack/compose";
|
|
3
|
+
import { container, composeConfig, stepInput, stepOutput, } from "#schemas/compose";
|
|
4
|
+
import { readConfig } from "#schemas/config";
|
|
5
|
+
import { compose, copyVolume, json, project, realPaths, rows, savedVolume, volumeExists, } from "#stack/compose";
|
|
6
6
|
import { hostPaths, notUp, refusals } from "#stack/rules";
|
|
7
7
|
/** The steps run `docker compose` in the checkout of the run, where the service's Compose file is. */
|
|
8
8
|
export const access = ["sandbox:read", "sandbox:write"];
|
|
9
|
-
/** The stack of the step's service
|
|
9
|
+
/** The stack of the step's service, its Compose project and the service, or the failure when the input or the `[extensions.docker]` table does not read, or the table names no stack for the service. */
|
|
10
10
|
function stackOf(raw, ctx) {
|
|
11
11
|
const input = stepInput.safeParse(raw);
|
|
12
12
|
if (!input.success)
|
|
13
13
|
return err(permanentFailure("invalid_input", input.error.message));
|
|
14
|
-
const settings =
|
|
15
|
-
if (!settings.
|
|
16
|
-
return
|
|
17
|
-
cause: settings.error.issues.map((issue) => issue.message).join("; "),
|
|
18
|
-
}));
|
|
14
|
+
const settings = readConfig(ctx.config);
|
|
15
|
+
if (!settings.ok)
|
|
16
|
+
return settings;
|
|
19
17
|
const { service, run } = input.data;
|
|
20
|
-
const stack = Object.hasOwn(settings.
|
|
21
|
-
? settings.
|
|
18
|
+
const stack = Object.hasOwn(settings.value.stacks, service)
|
|
19
|
+
? settings.value.stacks[service]
|
|
22
20
|
: undefined;
|
|
23
21
|
if (stack === undefined)
|
|
24
22
|
return err(permanentFailure("invalid", `[extensions.docker] stacks has no stack for the service \`${service}\``));
|
|
25
|
-
return ok({ stack, name: project(service, String(run)) });
|
|
23
|
+
return ok({ stack, name: project(service, String(run)), service });
|
|
26
24
|
}
|
|
27
25
|
/** A step of the environment as a tool: it reads its stack, runs `step` and answers the Compose project. */
|
|
28
26
|
function stepTool(description, step) {
|
|
@@ -35,13 +33,13 @@ function stepTool(description, step) {
|
|
|
35
33
|
const found = stackOf(raw, ctx);
|
|
36
34
|
if (!found.ok)
|
|
37
35
|
return found.error;
|
|
38
|
-
const ran = await step(found.value.stack, found.value.name, ctx);
|
|
39
|
-
return ran.ok ? done({ project: found.value.name }) : ran.error;
|
|
36
|
+
const ran = await step(found.value.stack, found.value.name, ctx, found.value.service);
|
|
37
|
+
return ran.ok ? done({ project: found.value.name, ...ran.value }) : ran.error;
|
|
40
38
|
},
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
|
-
/** Reads the Compose file as `docker compose config --no-env-resolution` writes it, with each env file kept as its path so the rules judge it, and refuses it when it breaks a rule of `refusals
|
|
44
|
-
async function checked(stack, name, ctx) {
|
|
41
|
+
/** Reads the Compose file as `docker compose config --no-env-resolution` writes it, with each env file kept as its path so the rules judge it, and refuses it when it breaks a rule of `refusals`, or when `save` names a volume the file does not declare. Both `prepare` and `start` run it, so a file is judged again right before Docker starts it. */
|
|
42
|
+
async function checked(stack, name, ctx, service) {
|
|
45
43
|
const read = await compose(ctx, stack, name, [
|
|
46
44
|
"config",
|
|
47
45
|
"--format",
|
|
@@ -53,30 +51,42 @@ async function checked(stack, name, ctx) {
|
|
|
53
51
|
const parsed = composeConfig.safeParse(json(read.value));
|
|
54
52
|
if (!parsed.success)
|
|
55
53
|
return err(permanentFailure("tool_error", "docker compose config printed no Compose file"));
|
|
54
|
+
const volumes = parsed.data.volumes ?? {};
|
|
55
|
+
const unknown = stack.save.find((key) => !Object.hasOwn(volumes, key));
|
|
56
|
+
if (unknown !== undefined)
|
|
57
|
+
return err(permanentFailure("invalid", `[extensions.docker] stacks.${service} save names \`${unknown}\`, which is not a volume of the Compose file`));
|
|
56
58
|
const paths = await realPaths(ctx, hostPaths(parsed.data));
|
|
57
59
|
if (!paths.ok)
|
|
58
60
|
return paths;
|
|
59
61
|
const broken = refusals(parsed.data, name, paths.value.checkout, paths.value.real);
|
|
60
62
|
return broken.length === 0
|
|
61
|
-
? ok(
|
|
63
|
+
? ok(parsed.data)
|
|
62
64
|
: err(permanentFailure("refused", `the Compose file of the stack breaks a rule: ${broken.join("; ")}`));
|
|
63
65
|
}
|
|
64
66
|
/** Refuses a Compose file that breaks a rule, then builds the images that the file builds. */
|
|
65
|
-
const prepare = async (stack, name, ctx) => {
|
|
66
|
-
const check = await checked(stack, name, ctx);
|
|
67
|
+
const prepare = async (stack, name, ctx, service) => {
|
|
68
|
+
const check = await checked(stack, name, ctx, service);
|
|
67
69
|
if (!check.ok)
|
|
68
70
|
return check;
|
|
69
71
|
const built = await compose(ctx, stack, name, ["build", "--quiet"]);
|
|
70
|
-
return built.ok ? ok(
|
|
72
|
+
return built.ok ? ok({}) : built;
|
|
71
73
|
};
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
const
|
|
74
|
+
/** The default network of a checked Compose file, which the rules keep internal, or none when no service is on it. */
|
|
75
|
+
function internalNetwork(file) {
|
|
76
|
+
const network = file.networks?.["default"];
|
|
77
|
+
return network?.internal === true && network.name !== undefined ? { network: network.name } : {};
|
|
78
|
+
}
|
|
79
|
+
/** Refuses a Compose file that breaks a rule, restores the saved data of each volume of `save` into the new stack, then starts the stack and waits until each container runs and each health check passes. */
|
|
80
|
+
const start = async (stack, name, ctx, service) => {
|
|
81
|
+
const check = await checked(stack, name, ctx, service);
|
|
75
82
|
if (!check.ok)
|
|
76
83
|
return check;
|
|
84
|
+
const restored = await restore(stack, name, ctx, service);
|
|
85
|
+
if (!restored.ok)
|
|
86
|
+
return restored;
|
|
77
87
|
const wait = String(stack.wait_seconds);
|
|
78
88
|
const up = await compose(ctx, stack, name, ["up", "--detach", "--wait", "--wait-timeout", wait]);
|
|
79
|
-
return up.ok ? ok(
|
|
89
|
+
return up.ok ? ok(internalNetwork(check.value)) : up;
|
|
80
90
|
};
|
|
81
91
|
/** Checks that each container of the stack is up, as `notUp` says. */
|
|
82
92
|
const health = async (stack, name, ctx) => {
|
|
@@ -88,11 +98,52 @@ const health = async (stack, name, ctx) => {
|
|
|
88
98
|
return err(permanentFailure("tool_error", "docker compose ps listed no container"));
|
|
89
99
|
const down = notUp(containers.data);
|
|
90
100
|
return down.length === 0
|
|
91
|
-
? ok(
|
|
101
|
+
? ok({})
|
|
92
102
|
: err(permanentFailure("tool_error", `the stack is not up: ${down.join("; ")}`));
|
|
93
103
|
};
|
|
94
|
-
/**
|
|
95
|
-
|
|
104
|
+
/** Creates the stack's containers and volumes without starting them, and copies the saved data of each volume of `save` into its new volume. A volume never saved starts empty. */
|
|
105
|
+
async function restore(stack, name, ctx, service) {
|
|
106
|
+
if (stack.save.length === 0)
|
|
107
|
+
return ok(undefined);
|
|
108
|
+
const created = await compose(ctx, stack, name, ["create"]);
|
|
109
|
+
if (!created.ok)
|
|
110
|
+
return created;
|
|
111
|
+
for (const key of stack.save) {
|
|
112
|
+
const saved = savedVolume(service, key);
|
|
113
|
+
const exists = await volumeExists(ctx, saved);
|
|
114
|
+
if (!exists.ok)
|
|
115
|
+
return exists;
|
|
116
|
+
if (!exists.value)
|
|
117
|
+
continue;
|
|
118
|
+
const copied = await copyVolume(ctx, saved, `${name}_${key}`);
|
|
119
|
+
if (!copied.ok)
|
|
120
|
+
return copied;
|
|
121
|
+
}
|
|
122
|
+
return ok(undefined);
|
|
123
|
+
}
|
|
124
|
+
/** Stops the containers of a stack that is up, then copies each volume of `save` into its saved volume. A stack that is not up, before the checks or after a failed start, saves nothing, so its data never replaces the saved data. */
|
|
125
|
+
async function save(stack, name, ctx, service) {
|
|
126
|
+
if (stack.save.length === 0)
|
|
127
|
+
return ok(undefined);
|
|
128
|
+
const listed = await compose(ctx, stack, name, ["ps", "--all", "--format", "json"]);
|
|
129
|
+
if (!listed.ok)
|
|
130
|
+
return listed;
|
|
131
|
+
const containers = z.array(container).safeParse(rows(listed.value));
|
|
132
|
+
if (!containers.success || containers.data.length === 0 || notUp(containers.data).length > 0)
|
|
133
|
+
return ok(undefined);
|
|
134
|
+
const stopped = await compose(ctx, stack, name, ["stop", "--timeout", "30"]);
|
|
135
|
+
if (!stopped.ok)
|
|
136
|
+
return stopped;
|
|
137
|
+
for (const key of stack.save) {
|
|
138
|
+
const copied = await copyVolume(ctx, `${name}_${key}`, savedVolume(service, key));
|
|
139
|
+
if (!copied.ok)
|
|
140
|
+
return copied;
|
|
141
|
+
}
|
|
142
|
+
return ok(undefined);
|
|
143
|
+
}
|
|
144
|
+
/** Saves the volumes of `save`, then removes the stack's containers, networks, volumes and the images it built, also when the save failed. A stack that is not up is already stopped. */
|
|
145
|
+
const stop = async (stack, name, ctx, service) => {
|
|
146
|
+
const saved = await save(stack, name, ctx, service);
|
|
96
147
|
const removed = await compose(ctx, stack, name, [
|
|
97
148
|
"down",
|
|
98
149
|
"--volumes",
|
|
@@ -102,7 +153,9 @@ const stop = async (stack, name, ctx) => {
|
|
|
102
153
|
"--timeout",
|
|
103
154
|
"30",
|
|
104
155
|
]);
|
|
105
|
-
|
|
156
|
+
if (!saved.ok)
|
|
157
|
+
return saved;
|
|
158
|
+
return removed.ok ? ok({}) : removed;
|
|
106
159
|
};
|
|
107
160
|
/** The `compose` environment: a service's Docker Compose stack, up while the stage's checks run. */
|
|
108
161
|
export const composeEnvironment = defineEnvironment({
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/** The Docker extension: the environment `compose`, which brings a service's Docker Compose stack up for its checks and removes it after. A service names
|
|
1
|
+
/** The Docker extension: the environment `compose`, which brings a service's Docker Compose stack up for its checks and removes it after, and the tool `read_logs`, which reads the log of a container the project names. A service names the environment with `environment = { provider = "docker__compose" }`. */
|
|
2
2
|
declare const _default: import("@kana-ai/edgar-sdk").Extension;
|
|
3
3
|
export default _default;
|
package/dist/src/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { defineExtension } from "@kana-ai/edgar-sdk";
|
|
2
2
|
import { access, composeEnvironment } from "#environment/steps";
|
|
3
|
+
import { readLogs } from "#logs/tool";
|
|
3
4
|
import { config } from "#schemas/config";
|
|
4
|
-
/** The Docker extension: the environment `compose`, which brings a service's Docker Compose stack up for its checks and removes it after. A service names
|
|
5
|
+
/** The Docker extension: the environment `compose`, which brings a service's Docker Compose stack up for its checks and removes it after, and the tool `read_logs`, which reads the log of a container the project names. A service names the environment with `environment = { provider = "docker__compose" }`. */
|
|
5
6
|
export default defineExtension({
|
|
6
7
|
name: "docker",
|
|
7
8
|
config,
|
|
8
9
|
capabilities: [...access],
|
|
10
|
+
tools: { read_logs: readLogs },
|
|
9
11
|
environments: { compose: composeEnvironment },
|
|
10
12
|
executables: {
|
|
11
13
|
requires: [
|
|
12
14
|
{
|
|
13
15
|
name: "docker",
|
|
14
|
-
reason: "The environment compose runs docker compose in the sandbox of the run.",
|
|
16
|
+
reason: "The environment compose runs docker compose, and read_logs runs docker logs, in the sandbox of the run.",
|
|
15
17
|
},
|
|
16
18
|
],
|
|
17
19
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The most bytes of log one answer holds, so a few reads fit in a session's context. */
|
|
2
|
+
export declare const MAX_BYTES = 32768;
|
|
3
|
+
/** The lines of both streams of `docker logs --timestamps`, oldest first; lines of one time keep their stream's order. */
|
|
4
|
+
export declare function merged(stdout: string, stderr: string): readonly string[];
|
|
5
|
+
/** The newest whole lines that fit in `max` bytes, and whether older ones were cut. A newest line longer than `max` keeps its end, less a character the cut split. */
|
|
6
|
+
export declare function newest(lines: readonly string[], max: number): {
|
|
7
|
+
readonly log: string;
|
|
8
|
+
readonly truncated: boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The most bytes of log one answer holds, so a few reads fit in a session's context. */
|
|
2
|
+
export const MAX_BYTES = 32_768;
|
|
3
|
+
/** The time a line of `docker logs --timestamps` starts with. Docker writes it fixed-width, so the text order of two times is their order. A line of Docker's own, such as a warning, has none and sorts first, so it never reads as the newest line. */
|
|
4
|
+
function timeOf(line) {
|
|
5
|
+
return /^\d{4}-\d\d-\d\dT\S*/.exec(line)?.[0] ?? "";
|
|
6
|
+
}
|
|
7
|
+
/** The lines of both streams of `docker logs --timestamps`, oldest first; lines of one time keep their stream's order. */
|
|
8
|
+
export function merged(stdout, stderr) {
|
|
9
|
+
const lines = [...stdout.split("\n"), ...stderr.split("\n")].filter((line) => line !== "");
|
|
10
|
+
return lines.sort((a, b) => {
|
|
11
|
+
const [x, y] = [timeOf(a), timeOf(b)];
|
|
12
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/** The newest whole lines that fit in `max` bytes, and whether older ones were cut. A newest line longer than `max` keeps its end, less a character the cut split. */
|
|
16
|
+
export function newest(lines, max) {
|
|
17
|
+
let from = lines.length;
|
|
18
|
+
let bytes = 0;
|
|
19
|
+
for (let at = lines.length - 1; at >= 0; at -= 1) {
|
|
20
|
+
bytes += Buffer.byteLength(lines[at] ?? "") + (at === lines.length - 1 ? 0 : 1);
|
|
21
|
+
if (bytes > max)
|
|
22
|
+
break;
|
|
23
|
+
from = at;
|
|
24
|
+
}
|
|
25
|
+
const last = lines.at(-1);
|
|
26
|
+
if (from === lines.length && last !== undefined)
|
|
27
|
+
return {
|
|
28
|
+
log: Buffer.from(last)
|
|
29
|
+
.subarray(-max)
|
|
30
|
+
.toString()
|
|
31
|
+
.replace(/^\uFFFD+/, ""),
|
|
32
|
+
truncated: true,
|
|
33
|
+
};
|
|
34
|
+
return { log: lines.slice(from).join("\n"), truncated: from > 0 };
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** `read_logs`: the newest lines of a container that the project names, read with `docker logs` in the run's sandbox. Only the containers of `[extensions.docker] logs`, since a log can hold what other containers must keep to themselves. */
|
|
2
|
+
export declare const readLogs: import("@kana-ai/edgar-sdk").Tool<{
|
|
3
|
+
container: string;
|
|
4
|
+
since?: string | undefined;
|
|
5
|
+
until?: string | undefined;
|
|
6
|
+
lines?: number | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
log: string;
|
|
9
|
+
truncated: boolean;
|
|
10
|
+
}, never>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineTool, done, permanentFailure, portFailure } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { MAX_BYTES, merged, newest } from "#logs/lines";
|
|
3
|
+
import { readConfig } from "#schemas/config";
|
|
4
|
+
import { LINES, readLogsTool } from "#schemas/logs";
|
|
5
|
+
/** Docker cuts its tail before it reads `--until`, so a window that ends in the past would come back empty: with an end, the tool keeps the newest lines itself. */
|
|
6
|
+
function tailOf(until, lines) {
|
|
7
|
+
return until === undefined ? ["--tail", String(lines)] : [];
|
|
8
|
+
}
|
|
9
|
+
/** `read_logs`: the newest lines of a container that the project names, read with `docker logs` in the run's sandbox. Only the containers of `[extensions.docker] logs`, since a log can hold what other containers must keep to themselves. */
|
|
10
|
+
export const readLogs = defineTool({
|
|
11
|
+
description: `The newest lines of the log of a container that [extensions.docker] logs names, both streams in time order with each line's time: at most \`lines\` (${String(LINES)} when absent) between \`since\` and \`until\`, and at most 32 KiB; \`truncated\` says older lines may be left out. EDGAR redacts each secret it holds from the answer`,
|
|
12
|
+
input: readLogsTool.input,
|
|
13
|
+
output: readLogsTool.output,
|
|
14
|
+
capabilities: ["sandbox:write"],
|
|
15
|
+
execute: async (input, ctx) => {
|
|
16
|
+
const settings = readConfig(ctx.config);
|
|
17
|
+
if (!settings.ok)
|
|
18
|
+
return settings.error;
|
|
19
|
+
if (!settings.value.logs.includes(input.container))
|
|
20
|
+
return permanentFailure("refused", `[extensions.docker] logs does not name the container \`${input.container}\`; it names: ${settings.value.logs.join(", ") || "none"}`);
|
|
21
|
+
const lines = input.lines ?? LINES;
|
|
22
|
+
const ran = await ctx.sandbox.exec("docker", [
|
|
23
|
+
"logs",
|
|
24
|
+
"--timestamps",
|
|
25
|
+
...tailOf(input.until, lines),
|
|
26
|
+
...(input.since === undefined ? [] : ["--since", input.since]),
|
|
27
|
+
...(input.until === undefined ? [] : ["--until", input.until]),
|
|
28
|
+
"--",
|
|
29
|
+
input.container,
|
|
30
|
+
]);
|
|
31
|
+
if (!ran.ok)
|
|
32
|
+
return portFailure(ran.error);
|
|
33
|
+
if (ran.value.exit_code !== 0)
|
|
34
|
+
return permanentFailure("tool_error", `docker logs ${input.container} failed`, {
|
|
35
|
+
cause: `exit ${String(ran.value.exit_code)}: ${ran.value.stderr.trim().slice(-2000)}`,
|
|
36
|
+
});
|
|
37
|
+
const read = merged(ran.value.stdout, ran.value.stderr);
|
|
38
|
+
const kept = newest(read.slice(-lines), MAX_BYTES);
|
|
39
|
+
return done({ log: kept.log, truncated: kept.truncated || read.length >= lines });
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -69,9 +69,10 @@ export declare const stepInput: z.ZodObject<{
|
|
|
69
69
|
slot: z.ZodNumber;
|
|
70
70
|
run: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
71
71
|
}, z.core.$loose>;
|
|
72
|
-
/** The output of each step: the Compose project of the stack. */
|
|
72
|
+
/** The output of each step: the Compose project of the stack, and from `start` the stack's internal default network, which a check in a container sandbox joins. */
|
|
73
73
|
export declare const stepOutput: z.ZodObject<{
|
|
74
74
|
project: z.ZodString;
|
|
75
|
+
network: z.ZodExactOptional<z.ZodString>;
|
|
75
76
|
}, z.core.$strip>;
|
|
76
77
|
export type ComposeConfig = z.output<typeof composeConfig>;
|
|
77
78
|
export type Container = z.output<typeof container>;
|
|
@@ -63,5 +63,5 @@ export const stepInput = z.looseObject({
|
|
|
63
63
|
slot: z.number().int().min(1),
|
|
64
64
|
run: z.union([z.string().min(1), z.number().int()]),
|
|
65
65
|
});
|
|
66
|
-
/** The output of each step: the Compose project of the stack. */
|
|
67
|
-
export const stepOutput = z.object({ project: z.string() });
|
|
66
|
+
/** The output of each step: the Compose project of the stack, and from `start` the stack's internal default network, which a check in a container sandbox joins. */
|
|
67
|
+
export const stepOutput = z.object({ project: z.string(), network: z.string().exactOptional() });
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type Failure, type Result } from "@kana-ai/edgar-sdk";
|
|
2
3
|
/** The seconds the engine gives each step of an environment, and so its `docker compose` command. */
|
|
3
4
|
export declare const STEP_SECONDS = 600;
|
|
4
|
-
/** One stack of `[extensions.docker] stacks`: its Compose file, relative to the checkout of the service,
|
|
5
|
+
/** One stack of `[extensions.docker] stacks`: its Compose file, relative to the checkout of the service, the most seconds `start` waits for each container to be running and healthy, and the volumes of the file whose data `stop` saves and the next `start` restores. The wait ends a minute before the step's own limit, so `start` says which container is not up. */
|
|
5
6
|
export declare const stack: z.ZodObject<{
|
|
6
7
|
file: z.ZodDefault<z.ZodString>;
|
|
7
8
|
wait_seconds: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
save: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
8
10
|
}, z.core.$strict>;
|
|
9
|
-
/** The extension's `[extensions.docker]` table: a stack for each service, by the service's name. */
|
|
11
|
+
/** The extension's `[extensions.docker]` table: a stack for each service, by the service's name, and the containers whose logs `read_logs` may read. */
|
|
10
12
|
export declare const config: z.ZodObject<{
|
|
11
13
|
stacks: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
12
14
|
file: z.ZodDefault<z.ZodString>;
|
|
13
15
|
wait_seconds: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
save: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
14
17
|
}, z.core.$strict>>>;
|
|
18
|
+
logs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
15
19
|
}, z.core.$strict>;
|
|
16
20
|
export type Stack = z.output<typeof stack>;
|
|
21
|
+
export type Config = z.output<typeof config>;
|
|
22
|
+
/** The `[extensions.docker]` table a call receives, or the failure when it does not match its schema. */
|
|
23
|
+
export declare function readConfig(raw: unknown): Result<Config, Failure>;
|
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { err, ok, permanentFailure } from "@kana-ai/edgar-sdk";
|
|
2
3
|
/** The seconds the engine gives each step of an environment, and so its `docker compose` command. */
|
|
3
4
|
export const STEP_SECONDS = 600;
|
|
4
|
-
/**
|
|
5
|
+
/** A container's or a volume's name as Docker allows it; it never starts with `-`, so it is never read as an option. */
|
|
6
|
+
const containerName = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/);
|
|
7
|
+
/** One stack of `[extensions.docker] stacks`: its Compose file, relative to the checkout of the service, the most seconds `start` waits for each container to be running and healthy, and the volumes of the file whose data `stop` saves and the next `start` restores. The wait ends a minute before the step's own limit, so `start` says which container is not up. */
|
|
5
8
|
export const stack = z.strictObject({
|
|
6
|
-
file: z
|
|
9
|
+
file: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.default("docker-compose.yml")
|
|
13
|
+
.describe("The stack's Compose file, relative to the service's checkout. Default docker-compose.yml."),
|
|
7
14
|
wait_seconds: z
|
|
8
15
|
.number()
|
|
9
16
|
.int()
|
|
10
17
|
.min(1)
|
|
11
18
|
.max(STEP_SECONDS - 60)
|
|
12
|
-
.default(300)
|
|
19
|
+
.default(300)
|
|
20
|
+
.describe("The longest start waits for each container to be running and healthy, in seconds. Default 300."),
|
|
21
|
+
save: z
|
|
22
|
+
.array(containerName)
|
|
23
|
+
.default([])
|
|
24
|
+
.describe("The volumes of the Compose file whose data stop saves and the next start restores. None by default."),
|
|
25
|
+
});
|
|
26
|
+
/** The extension's `[extensions.docker]` table: a stack for each service, by the service's name, and the containers whose logs `read_logs` may read. */
|
|
27
|
+
export const config = z.strictObject({
|
|
28
|
+
stacks: z
|
|
29
|
+
.record(z.string().min(1), stack)
|
|
30
|
+
.default({})
|
|
31
|
+
.describe("The Docker Compose stack of each service, by service name. None by default."),
|
|
32
|
+
logs: z
|
|
33
|
+
.array(containerName)
|
|
34
|
+
.default([])
|
|
35
|
+
.describe("The containers whose logs read_logs may read. None by default."),
|
|
13
36
|
});
|
|
14
|
-
/** The
|
|
15
|
-
export
|
|
37
|
+
/** The `[extensions.docker]` table a call receives, or the failure when it does not match its schema. */
|
|
38
|
+
export function readConfig(raw) {
|
|
39
|
+
const settings = config.safeParse(raw ?? {});
|
|
40
|
+
if (settings.success)
|
|
41
|
+
return ok(settings.data);
|
|
42
|
+
return err(permanentFailure("invalid", "the [extensions.docker] table does not match its schema", {
|
|
43
|
+
cause: settings.error.issues.map((issue) => issue.message).join("; "),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The lines `read_logs` reads when the call names no number. */
|
|
3
|
+
export declare const LINES = 200;
|
|
4
|
+
/** The input and output of `read_logs`: the newest lines of one named container's log in a window. */
|
|
5
|
+
export declare const readLogsTool: {
|
|
6
|
+
input: z.ZodObject<{
|
|
7
|
+
container: z.ZodString;
|
|
8
|
+
since: z.ZodOptional<z.ZodISODateTime>;
|
|
9
|
+
until: z.ZodOptional<z.ZodISODateTime>;
|
|
10
|
+
lines: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
output: z.ZodObject<{
|
|
13
|
+
log: z.ZodString;
|
|
14
|
+
truncated: z.ZodBoolean;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The lines `read_logs` reads when the call names no number. */
|
|
3
|
+
export const LINES = 200;
|
|
4
|
+
/** The input and output of `read_logs`: the newest lines of one named container's log in a window. */
|
|
5
|
+
export const readLogsTool = {
|
|
6
|
+
input: z.object({
|
|
7
|
+
container: z.string().min(1).describe("a container that [extensions.docker] logs names"),
|
|
8
|
+
since: z.iso
|
|
9
|
+
.datetime({ offset: true })
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("the time of the first line; the whole log when absent"),
|
|
12
|
+
until: z.iso.datetime({ offset: true }).optional().describe("now when absent"),
|
|
13
|
+
lines: z
|
|
14
|
+
.number()
|
|
15
|
+
.int()
|
|
16
|
+
.min(1)
|
|
17
|
+
.max(1000)
|
|
18
|
+
.optional()
|
|
19
|
+
.describe(`${String(LINES)} when absent`),
|
|
20
|
+
}),
|
|
21
|
+
output: z.object({
|
|
22
|
+
log: z.string().describe("each line with its time, oldest first, both streams"),
|
|
23
|
+
truncated: z
|
|
24
|
+
.boolean()
|
|
25
|
+
.describe("true when the line count or the byte cap was reached, so older lines may be left out"),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
@@ -6,6 +6,12 @@ export declare function project(service: string, run: string): string;
|
|
|
6
6
|
export declare function composeArgs(stack: Stack, name: string, command: readonly string[]): readonly string[];
|
|
7
7
|
/** Runs one `docker compose` command of a stack in the run's checkout; its standard output, or the failure with the end of its standard error. */
|
|
8
8
|
export declare function compose<S extends string>(ctx: Ctx<S>, stack: Stack, name: string, command: readonly string[]): Promise<Result<string, Failure>>;
|
|
9
|
+
/** The volume that keeps the saved data of the volume `key` of the stack of `service`, across runs. A `.` never comes out of `project`, so no run's volume has this name. */
|
|
10
|
+
export declare function savedVolume(service: string, key: string): string;
|
|
11
|
+
/** Whether the volume `name` exists, as `docker volume inspect` says by its exit code. */
|
|
12
|
+
export declare function volumeExists<S extends string>(ctx: Ctx<S>, name: string): Promise<Result<boolean, Failure>>;
|
|
13
|
+
/** Replaces the data of the volume `to` with a copy of the volume `from`, in a container with no network that mounts the two volumes only. */
|
|
14
|
+
export declare function copyVolume<S extends string>(ctx: Ctx<S>, from: string, to: string): Promise<Result<undefined, Failure>>;
|
|
9
15
|
/** A JSON text as a value; `undefined` when it does not parse. */
|
|
10
16
|
export declare function json(text: string): unknown;
|
|
11
17
|
/** The containers of `docker compose ps --format json`, which prints one object per line, or one array in older versions. */
|
|
@@ -9,15 +9,46 @@ export function composeArgs(stack, name, command) {
|
|
|
9
9
|
}
|
|
10
10
|
/** Runs one `docker compose` command of a stack in the run's checkout; its standard output, or the failure with the end of its standard error. */
|
|
11
11
|
export async function compose(ctx, stack, name, command) {
|
|
12
|
-
|
|
12
|
+
return await docker(ctx, composeArgs(stack, name, command), `docker compose ${command.join(" ")}`);
|
|
13
|
+
}
|
|
14
|
+
/** Runs one `docker` command in the run's checkout; its standard output, or the failure, named as `what`, with the end of its standard error. */
|
|
15
|
+
async function docker(ctx, args, what) {
|
|
16
|
+
const ran = await ctx.sandbox.exec("docker", args);
|
|
13
17
|
if (!ran.ok)
|
|
14
18
|
return err(portFailure(ran.error));
|
|
15
19
|
if (ran.value.exit_code === 0)
|
|
16
20
|
return ok(ran.value.stdout);
|
|
17
|
-
return err(permanentFailure("tool_error",
|
|
21
|
+
return err(permanentFailure("tool_error", `${what} failed`, {
|
|
18
22
|
cause: `exit ${String(ran.value.exit_code)}: ${ran.value.stderr.trim().slice(-2000)}`,
|
|
19
23
|
}));
|
|
20
24
|
}
|
|
25
|
+
/** The volume that keeps the saved data of the volume `key` of the stack of `service`, across runs. A `.` never comes out of `project`, so no run's volume has this name. */
|
|
26
|
+
export function savedVolume(service, key) {
|
|
27
|
+
return `${project(service, "").slice(0, -1)}.saved_${key}`;
|
|
28
|
+
}
|
|
29
|
+
/** Whether the volume `name` exists, as `docker volume inspect` says by its exit code. */
|
|
30
|
+
export async function volumeExists(ctx, name) {
|
|
31
|
+
const ran = await ctx.sandbox.exec("docker", ["volume", "inspect", name]);
|
|
32
|
+
return ran.ok ? ok(ran.value.exit_code === 0) : err(portFailure(ran.error));
|
|
33
|
+
}
|
|
34
|
+
/** Replaces the data of the volume `to` with a copy of the volume `from`, in a container with no network that mounts the two volumes only. */
|
|
35
|
+
export async function copyVolume(ctx, from, to) {
|
|
36
|
+
const copied = await docker(ctx, [
|
|
37
|
+
"run",
|
|
38
|
+
"--rm",
|
|
39
|
+
"--network",
|
|
40
|
+
"none",
|
|
41
|
+
"--volume",
|
|
42
|
+
`${from}:/from:ro`,
|
|
43
|
+
"--volume",
|
|
44
|
+
`${to}:/to`,
|
|
45
|
+
"busybox:1.37.0",
|
|
46
|
+
"sh",
|
|
47
|
+
"-c",
|
|
48
|
+
"find /to -mindepth 1 -delete && cp -a /from/. /to/",
|
|
49
|
+
], "docker run");
|
|
50
|
+
return copied.ok ? ok(undefined) : copied;
|
|
51
|
+
}
|
|
21
52
|
/** A JSON text as a value; `undefined` when it does not parse. */
|
|
22
53
|
export function json(text) {
|
|
23
54
|
return unwrapOr(attempt(() => JSON.parse(text), () => undefined), undefined);
|
package/edgar-extension.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"contract": 1,
|
|
3
3
|
"name": "docker",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"config_schema": "schemas/config.json",
|
|
6
6
|
"secrets": [],
|
|
7
7
|
"capabilities": ["sandbox:read", "sandbox:write"],
|
|
8
|
-
"tools": [
|
|
8
|
+
"tools": [
|
|
9
|
+
{
|
|
10
|
+
"name": "read_logs",
|
|
11
|
+
"description": "The newest lines of the log of a container that [extensions.docker] logs names, both streams in time order with each line's time: at most `lines` (200 when absent) between `since` and `until`, and at most 32 KiB; `truncated` says older lines may be left out. EDGAR redacts each secret it holds from the answer",
|
|
12
|
+
"input_schema": "schemas/read_logs.in.json",
|
|
13
|
+
"output_schema": "schemas/read_logs.out.json",
|
|
14
|
+
"secrets": [],
|
|
15
|
+
"capabilities": ["sandbox:write"],
|
|
16
|
+
"side_effect": false,
|
|
17
|
+
"approval": "never",
|
|
18
|
+
"disabled": false
|
|
19
|
+
}
|
|
20
|
+
],
|
|
9
21
|
"webhooks": [],
|
|
10
22
|
"workflows": [],
|
|
11
23
|
"roles": [],
|
|
@@ -49,7 +61,7 @@
|
|
|
49
61
|
"requires": [
|
|
50
62
|
{
|
|
51
63
|
"name": "docker",
|
|
52
|
-
"reason": "The environment compose runs docker compose in the sandbox of the run."
|
|
64
|
+
"reason": "The environment compose runs docker compose, and read_logs runs docker logs, in the sandbox of the run."
|
|
53
65
|
}
|
|
54
66
|
],
|
|
55
67
|
"provides": []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kana-ai/edgar-ext-docker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "EDGAR extension for Docker: a service's Docker Compose stack as the environment that its checks run against.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
".": "./dist/src/index.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@kana-ai/edgar-sdk": "0.1.
|
|
24
|
+
"@kana-ai/edgar-sdk": "0.1.4",
|
|
25
25
|
"zod": "4.6.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@kana-ai/edgar-contracts": "0.1.
|
|
28
|
+
"@kana-ai/edgar-contracts": "0.1.4",
|
|
29
29
|
"@types/node": "24.19.2",
|
|
30
30
|
"oxfmt": "0.76.0",
|
|
31
31
|
"oxlint": "1.91.0",
|
package/schemas/config.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"properties": {
|
|
5
5
|
"stacks": {
|
|
6
6
|
"default": {},
|
|
7
|
+
"description": "The Docker Compose stack of each service, by service name. None by default.",
|
|
7
8
|
"type": "object",
|
|
8
9
|
"propertyNames": {
|
|
9
10
|
"type": "string",
|
|
@@ -14,18 +15,38 @@
|
|
|
14
15
|
"properties": {
|
|
15
16
|
"file": {
|
|
16
17
|
"default": "docker-compose.yml",
|
|
18
|
+
"description": "The stack's Compose file, relative to the service's checkout. Default docker-compose.yml.",
|
|
17
19
|
"type": "string",
|
|
18
20
|
"minLength": 1
|
|
19
21
|
},
|
|
20
22
|
"wait_seconds": {
|
|
21
23
|
"default": 300,
|
|
24
|
+
"description": "The longest start waits for each container to be running and healthy, in seconds. Default 300.",
|
|
22
25
|
"type": "integer",
|
|
23
26
|
"minimum": 1,
|
|
24
27
|
"maximum": 540
|
|
28
|
+
},
|
|
29
|
+
"save": {
|
|
30
|
+
"default": [],
|
|
31
|
+
"description": "The volumes of the Compose file whose data stop saves and the next start restores. None by default.",
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]*$"
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
38
|
},
|
|
27
39
|
"additionalProperties": false
|
|
28
40
|
}
|
|
41
|
+
},
|
|
42
|
+
"logs": {
|
|
43
|
+
"default": [],
|
|
44
|
+
"description": "The containers whose logs read_logs may read. None by default.",
|
|
45
|
+
"type": "array",
|
|
46
|
+
"items": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.-]*$"
|
|
49
|
+
}
|
|
29
50
|
}
|
|
30
51
|
},
|
|
31
52
|
"additionalProperties": false
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"container": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"minLength": 1,
|
|
8
|
+
"description": "a container that [extensions.docker] logs names"
|
|
9
|
+
},
|
|
10
|
+
"since": {
|
|
11
|
+
"description": "the time of the first line; the whole log when absent",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"format": "date-time",
|
|
14
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
|
|
15
|
+
},
|
|
16
|
+
"until": {
|
|
17
|
+
"description": "now when absent",
|
|
18
|
+
"type": "string",
|
|
19
|
+
"format": "date-time",
|
|
20
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
|
|
21
|
+
},
|
|
22
|
+
"lines": {
|
|
23
|
+
"description": "200 when absent",
|
|
24
|
+
"type": "integer",
|
|
25
|
+
"minimum": 1,
|
|
26
|
+
"maximum": 1000
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"required": ["container"]
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"log": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"description": "each line with its time, oldest first, both streams"
|
|
8
|
+
},
|
|
9
|
+
"truncated": {
|
|
10
|
+
"type": "boolean",
|
|
11
|
+
"description": "true when the line count or the byte cap was reached, so older lines may be left out"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": ["log", "truncated"]
|
|
15
|
+
}
|