@exagone313/dsh-podman 1.2.1 → 1.4.0
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/dist/card-route.d.ts +8 -0
- package/dist/card-route.js +19 -8
- package/dist/client/ContainerCard.js +147 -110
- package/dist/client/card-protocol.d.ts +4 -0
- package/dist/client/card-protocol.js +34 -0
- package/dist/client/container-card-caches.d.ts +1 -1
- package/dist/client/container-card-caches.js +19 -17
- package/dist/client/container-card-config.d.ts +47 -0
- package/dist/client/container-card-config.js +160 -0
- package/dist/client/container-card-controller.d.ts +35 -3
- package/dist/client/container-card-controller.js +263 -41
- package/dist/client/container-card-create-modal.d.ts +5 -1
- package/dist/client/container-card-create-modal.js +111 -94
- package/dist/client/container-card-defaults.d.ts +16 -0
- package/dist/client/container-card-defaults.js +147 -0
- package/dist/client/container-card-dialog-styles.d.ts +7 -0
- package/dist/client/container-card-dialog-styles.js +70 -0
- package/dist/client/container-card-dialog.d.ts +12 -0
- package/dist/client/container-card-dialog.js +47 -0
- package/dist/client/container-card-directory-styles.d.ts +1 -1
- package/dist/client/container-card-directory-styles.js +5 -5
- package/dist/client/container-card-directory.js +8 -7
- package/dist/client/container-card-edit-modal.d.ts +39 -0
- package/dist/client/container-card-edit-modal.js +29 -0
- package/dist/client/container-card-editors.d.ts +5 -2
- package/dist/client/container-card-editors.js +109 -134
- package/dist/client/container-card-field-styles.d.ts +7 -0
- package/dist/client/container-card-field-styles.js +63 -0
- package/dist/client/container-card-form.d.ts +47 -0
- package/dist/client/container-card-form.js +61 -0
- package/dist/client/container-card-group.d.ts +9 -0
- package/dist/client/container-card-group.js +22 -0
- package/dist/client/container-card-images.d.ts +6 -2
- package/dist/client/container-card-images.js +63 -23
- package/dist/client/container-card-paths.js +43 -52
- package/dist/client/container-card-ports.d.ts +3 -4
- package/dist/client/container-card-ports.js +74 -38
- package/dist/client/container-card-resources.d.ts +38 -0
- package/dist/client/container-card-resources.js +73 -0
- package/dist/client/container-card-row.d.ts +11 -19
- package/dist/client/container-card-row.js +122 -122
- package/dist/client/container-card-secrets.d.ts +31 -3
- package/dist/client/container-card-secrets.js +174 -56
- package/dist/client/container-card-shared.d.ts +173 -6
- package/dist/client/container-card-shared.js +616 -57
- package/dist/client/container-card-status.d.ts +18 -0
- package/dist/client/container-card-status.js +166 -0
- package/dist/client/container-card-styles.d.ts +49 -7
- package/dist/client/container-card-styles.js +396 -40
- package/dist/client/container-card-table-styles.d.ts +15 -0
- package/dist/client/container-card-table-styles.js +237 -0
- package/dist/client/container-card-tabs-styles.d.ts +5 -0
- package/dist/client/container-card-tabs-styles.js +46 -0
- package/dist/client/container-card-toast.d.ts +5 -0
- package/dist/client/container-card-toast.js +10 -0
- package/dist/client/container-card-volumes.d.ts +1 -0
- package/dist/client/container-card-volumes.js +14 -19
- package/dist/client/container-card-workspace.d.ts +8 -12
- package/dist/client/container-card-workspace.js +76 -14
- package/dist/client/index.js +6491 -3474
- package/dist/client/locales.d.ts +10 -1
- package/dist/client/locales.js +270 -114
- package/dist/client/relative-time.d.ts +10 -0
- package/dist/client/relative-time.js +74 -0
- package/dist/client/slot-contract.d.ts +8 -0
- package/dist/client/tool-views.js +2 -1
- package/dist/container-env.js +1 -1
- package/dist/env-rows.d.ts +9 -11
- package/dist/env-rows.js +72 -40
- package/dist/generated/version.d.ts +2 -2
- package/dist/generated/version.js +2 -2
- package/dist/guest-terminal.js +1 -1
- package/dist/mount-enums.d.ts +11 -0
- package/dist/mount-enums.js +60 -0
- package/dist/subprocess.js +1 -1
- package/dist/terminal-sessions.js +2 -2
- package/dist/terminal-shells.js +1 -1
- package/dist/tool-handlers.js +1 -1
- package/dist/workspace-binding.js +2 -2
- package/docs/architecture.md +4 -4
- package/docs/architecture.zh.md +1 -1
- package/docs/configuration.md +26 -25
- package/docs/configuration.zh.md +13 -11
- package/docs/development-prompt.md +7 -7
- package/docs/development-prompt.zh.md +7 -7
- package/docs/development.md +20 -16
- package/docs/development.zh.md +17 -16
- package/docs/install-dsh-and-dsh-podman.md +13 -12
- package/docs/install-dsh-and-dsh-podman.zh.md +13 -9
- package/docs/usage.md +189 -39
- package/docs/usage.zh.md +148 -29
- package/package.json +35 -31
- package/dist/client/container-card-default-env.d.ts +0 -10
- package/dist/client/container-card-default-env.js +0 -69
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
import { mountViewToInput } from "./container-card-shared.js";
|
|
5
|
+
export function containerConfigFrom(container) {
|
|
6
|
+
return {
|
|
7
|
+
image: container.imageId,
|
|
8
|
+
env: { ...container.env },
|
|
9
|
+
mounts: container.mounts.map(mountViewToInput),
|
|
10
|
+
paths: [...container.paths],
|
|
11
|
+
secretEnv: { ...container.secretEnv },
|
|
12
|
+
ports: container.publishedPorts.map((published) => ({
|
|
13
|
+
port: published.port,
|
|
14
|
+
protocol: published.protocol,
|
|
15
|
+
endpoint: published.endpoint,
|
|
16
|
+
suggestedHostPort: 0,
|
|
17
|
+
hostPort: published.hostPort,
|
|
18
|
+
})),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function recordsEqual(a, b) {
|
|
22
|
+
const keys = Object.keys(a);
|
|
23
|
+
return keys.length === Object.keys(b).length &&
|
|
24
|
+
keys.every((key) => a[key] === b[key]);
|
|
25
|
+
}
|
|
26
|
+
// The identity a mount keeps across an edit: its source and destination, but
|
|
27
|
+
// not its mode, which the row changes in place.
|
|
28
|
+
export function mountKey(mount) {
|
|
29
|
+
if (mount.kind === "tmpfs")
|
|
30
|
+
return `tmpfs|${mount.destination}`;
|
|
31
|
+
if (mount.kind === "volume") {
|
|
32
|
+
return `volume|${mount.volume}|${mount.destination}`;
|
|
33
|
+
}
|
|
34
|
+
if (mount.kind === "secret") {
|
|
35
|
+
return `secret|${mount.secret}|${mount.destination}`;
|
|
36
|
+
}
|
|
37
|
+
return `project|${mount.project}|${mount.destination}`;
|
|
38
|
+
}
|
|
39
|
+
export function mountInputsEqual(a, b) {
|
|
40
|
+
return mountKey(a) === mountKey(b) && a.mode === b.mode;
|
|
41
|
+
}
|
|
42
|
+
export function mountsEqual(a, b) {
|
|
43
|
+
return a.length === b.length &&
|
|
44
|
+
a.every((mount, index) => mountInputsEqual(mount, b[index]));
|
|
45
|
+
}
|
|
46
|
+
export function pathsEqual(a, b) {
|
|
47
|
+
return a.length === b.length && a.every((path, index) => path === b[index]);
|
|
48
|
+
}
|
|
49
|
+
// Ports are compared by identity only: an endpoint is host bookkeeping, not a
|
|
50
|
+
// user edit, so a staged publish that the gateway bound is not dirty.
|
|
51
|
+
export function portsEqual(a, b) {
|
|
52
|
+
return a.length === b.length &&
|
|
53
|
+
a.every((port, index) => port.port === b[index].port && port.protocol === b[index].protocol);
|
|
54
|
+
}
|
|
55
|
+
export function configsEqual(a, b) {
|
|
56
|
+
return a.image === b.image &&
|
|
57
|
+
recordsEqual(a.env, b.env) &&
|
|
58
|
+
mountsEqual(a.mounts, b.mounts) &&
|
|
59
|
+
pathsEqual(a.paths, b.paths) &&
|
|
60
|
+
recordsEqual(a.secretEnv, b.secretEnv) &&
|
|
61
|
+
portsEqual(a.ports, b.ports);
|
|
62
|
+
}
|
|
63
|
+
// The label each group reads with in the staged marker, keyed by the group's
|
|
64
|
+
// stable id.
|
|
65
|
+
export const configGroupLabels = {
|
|
66
|
+
image: "image",
|
|
67
|
+
env: "envTitle",
|
|
68
|
+
mounts: "mountsTitle",
|
|
69
|
+
paths: "pathsTitle",
|
|
70
|
+
secretEnv: "containerSecretsTitle",
|
|
71
|
+
ports: "portsTitle",
|
|
72
|
+
};
|
|
73
|
+
// The field groups that differ between the live configuration and the staged
|
|
74
|
+
// one, by their stable ids, in the order the recreate label names them.
|
|
75
|
+
export function configChangedKeys(base, next) {
|
|
76
|
+
const groups = [];
|
|
77
|
+
if (base.image !== next.image)
|
|
78
|
+
groups.push("image");
|
|
79
|
+
if (!recordsEqual(base.env, next.env))
|
|
80
|
+
groups.push("env");
|
|
81
|
+
if (!mountsEqual(base.mounts, next.mounts))
|
|
82
|
+
groups.push("mounts");
|
|
83
|
+
if (!pathsEqual(base.paths, next.paths))
|
|
84
|
+
groups.push("paths");
|
|
85
|
+
if (!recordsEqual(base.secretEnv, next.secretEnv))
|
|
86
|
+
groups.push("secretEnv");
|
|
87
|
+
if (!portsEqual(base.ports, next.ports))
|
|
88
|
+
groups.push("ports");
|
|
89
|
+
return groups;
|
|
90
|
+
}
|
|
91
|
+
// The groups whose change rebuilds the container: the recreate command carries
|
|
92
|
+
// a new image or environment, and a mount or a secret environment variable is
|
|
93
|
+
// applied by a command that recreates the container itself. A PATH addition and
|
|
94
|
+
// a published port are the two groups the running container takes on its own.
|
|
95
|
+
const REBUILD_GROUPS = [
|
|
96
|
+
"image",
|
|
97
|
+
"env",
|
|
98
|
+
"mounts",
|
|
99
|
+
"secretEnv",
|
|
100
|
+
];
|
|
101
|
+
// Whether applying a staged copy rebuilds the container, terminating what runs
|
|
102
|
+
// inside it. It names the rebuilds-container groups by their stable ids, never
|
|
103
|
+
// by a locale key, so a PATH-only change can never be mistaken for one.
|
|
104
|
+
export function configRebuildsContainer(base, next) {
|
|
105
|
+
return configChangedKeys(base, next).some((id) => REBUILD_GROUPS.includes(id));
|
|
106
|
+
}
|
|
107
|
+
// Whether applying a staged copy needs the recreate command itself, which is
|
|
108
|
+
// what carries the new image and environment. Every other group is either
|
|
109
|
+
// applied in place or recreated by its own command, so the apply never sends a
|
|
110
|
+
// redundant recreate.
|
|
111
|
+
export function configNeedsRecreate(base, next) {
|
|
112
|
+
return base.image !== next.image || !recordsEqual(base.env, next.env);
|
|
113
|
+
}
|
|
114
|
+
// Pair each staged mount with a live one by identity, so an added, removed, or
|
|
115
|
+
// mode-changed mount is recognised even when its neighbours shifted.
|
|
116
|
+
export function mountDiff(base, next) {
|
|
117
|
+
const used = base.map(() => false);
|
|
118
|
+
const added = [];
|
|
119
|
+
const updated = [];
|
|
120
|
+
for (const mount of next) {
|
|
121
|
+
const index = base.findIndex((live, at) => !used[at] && mountKey(live) === mountKey(mount));
|
|
122
|
+
if (index === -1) {
|
|
123
|
+
added.push(mount);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
used[index] = true;
|
|
127
|
+
if (base[index].mode !== mount.mode)
|
|
128
|
+
updated.push(mount);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
added,
|
|
132
|
+
removed: base.filter((_, index) => !used[index]),
|
|
133
|
+
updated,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export function envDiff(base, next) {
|
|
137
|
+
const added = [];
|
|
138
|
+
const changed = [];
|
|
139
|
+
const removed = [];
|
|
140
|
+
for (const [key, value] of Object.entries(next)) {
|
|
141
|
+
if (!(key in base))
|
|
142
|
+
added.push([key, value]);
|
|
143
|
+
else if (base[key] !== value)
|
|
144
|
+
changed.push([key, value]);
|
|
145
|
+
}
|
|
146
|
+
for (const key of Object.keys(base)) {
|
|
147
|
+
if (!(key in next))
|
|
148
|
+
removed.push(key);
|
|
149
|
+
}
|
|
150
|
+
return { added, removed, changed };
|
|
151
|
+
}
|
|
152
|
+
export function portDiff(base, next) {
|
|
153
|
+
const key = (port) => `${port.port}/${port.protocol}`;
|
|
154
|
+
const baseKeys = new Set(base.map(key));
|
|
155
|
+
const nextKeys = new Set(next.map(key));
|
|
156
|
+
return {
|
|
157
|
+
added: next.filter((port) => !baseKeys.has(key(port))),
|
|
158
|
+
removed: base.filter((port) => !nextKeys.has(key(port))),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type SnapshotStore } from "@deepseek-ai/dsh-client-store";
|
|
2
2
|
import type { ConfigForm, ConfigFormSnapshot } from "@deepseek-ai/dsh-client-ui-settings/client";
|
|
3
|
-
import type
|
|
3
|
+
import { type CacheView, type ContainerView, type ImageView, type MountInput, type PublishedPortView, type SecretView, type VolumeView, type WorkspaceView } from "./card-protocol.js";
|
|
4
4
|
import { type CardClient } from "./card-client.js";
|
|
5
|
+
import { type ContainerConfig, type PortConfig } from "./container-card-config.js";
|
|
5
6
|
import { type DirectoryPickerFace } from "./directory-picker.js";
|
|
6
7
|
export declare const CONTAINER_NS = "podman";
|
|
7
8
|
export interface ContainerSettings {
|
|
@@ -23,13 +24,23 @@ export interface ContainerCreateConfig {
|
|
|
23
24
|
mounts?: readonly MountInput[];
|
|
24
25
|
paths?: readonly string[];
|
|
25
26
|
secretEnv?: Record<string, string>;
|
|
27
|
+
ports?: readonly PortConfig[];
|
|
28
|
+
}
|
|
29
|
+
export type { CacheView, ContainerConfig, ContainerView, ImageView, MountInput, PublishedPortView, SecretView, VolumeView, WorkspaceView, };
|
|
30
|
+
export interface CardToast {
|
|
31
|
+
seq: number;
|
|
32
|
+
kind: "ok" | "error";
|
|
33
|
+
text: string;
|
|
26
34
|
}
|
|
27
|
-
export type { CacheView, ContainerView, ImageView, MountInput, PublishedPortView, SecretView, VolumeView, WorkspaceView, };
|
|
28
35
|
export interface CardState {
|
|
29
36
|
available: boolean;
|
|
37
|
+
loadState: "loading" | "ready" | "unavailable";
|
|
30
38
|
writable: boolean;
|
|
31
39
|
busy: boolean;
|
|
40
|
+
pendingActions: readonly string[];
|
|
41
|
+
toast: CardToast | null;
|
|
32
42
|
notice: string;
|
|
43
|
+
noticeIsError: boolean;
|
|
33
44
|
version: string;
|
|
34
45
|
commit: string;
|
|
35
46
|
dshVersion: string;
|
|
@@ -40,7 +51,10 @@ export interface CardState {
|
|
|
40
51
|
gatewayVersion: string;
|
|
41
52
|
gatewayCommit: string;
|
|
42
53
|
gatewayVersionState: "ok" | "minor-mismatch" | "major-mismatch";
|
|
54
|
+
orchestratorReady: boolean;
|
|
55
|
+
orchestratorKnown: boolean;
|
|
43
56
|
defaultImage: string;
|
|
57
|
+
locale: string;
|
|
44
58
|
containerEnv: Record<string, string>;
|
|
45
59
|
projectsRoot: string;
|
|
46
60
|
directoryPicker?: DirectoryPickerFace;
|
|
@@ -56,6 +70,7 @@ export interface ContainerCardFace {
|
|
|
56
70
|
containerCard: SnapshotStore<CardState>;
|
|
57
71
|
};
|
|
58
72
|
reload: () => void;
|
|
73
|
+
dismissToast: () => void;
|
|
59
74
|
remove: (workspace: string, container: string) => void;
|
|
60
75
|
cleanCaches: (mode: string) => void;
|
|
61
76
|
removeWorkspace: (workspace: string) => void;
|
|
@@ -83,7 +98,8 @@ export interface ContainerCardFace {
|
|
|
83
98
|
addContainerSecret: (workspace: string, container: string, envVar: string, secret: string) => void;
|
|
84
99
|
removeContainerSecret: (workspace: string, container: string, envVar: string) => void;
|
|
85
100
|
saveContainerEnv: (env: Record<string, string>) => void;
|
|
86
|
-
|
|
101
|
+
applyDefaultEnv: (workspace: string) => void;
|
|
102
|
+
applyContainerConfig: (workspace: string, container: string, base: ContainerConfig, next: ContainerConfig) => void;
|
|
87
103
|
}
|
|
88
104
|
export declare class ContainerCardController {
|
|
89
105
|
private readonly scope;
|
|
@@ -92,20 +108,36 @@ export declare class ContainerCardController {
|
|
|
92
108
|
private readonly client;
|
|
93
109
|
private snapshot;
|
|
94
110
|
private pending;
|
|
111
|
+
private readonly pendingKeys;
|
|
112
|
+
private pendingActions;
|
|
95
113
|
private generation;
|
|
96
114
|
private notice;
|
|
115
|
+
private orchestratorReady;
|
|
116
|
+
private orchestratorKnown;
|
|
117
|
+
private toast;
|
|
118
|
+
private toastSeq;
|
|
97
119
|
private directoryPicker;
|
|
120
|
+
private locale;
|
|
121
|
+
private noticeIsError;
|
|
98
122
|
constructor(scope: ConfigForm<ContainerSettings>, client?: CardClient);
|
|
99
123
|
private draft;
|
|
100
124
|
private project;
|
|
101
125
|
private publish;
|
|
102
126
|
setDirectoryPicker(picker: DirectoryPickerFace | undefined): void;
|
|
127
|
+
setLocale(locale: string): void;
|
|
128
|
+
private beginAction;
|
|
129
|
+
private endAction;
|
|
130
|
+
private showToast;
|
|
131
|
+
private request;
|
|
103
132
|
private command;
|
|
133
|
+
private createExtra;
|
|
134
|
+
private create;
|
|
104
135
|
private dispatch;
|
|
105
136
|
private reload;
|
|
106
137
|
private edit;
|
|
107
138
|
private save;
|
|
108
139
|
private discard;
|
|
140
|
+
private applyConfig;
|
|
109
141
|
inject(): ContainerCardFace;
|
|
110
142
|
private defaultImage;
|
|
111
143
|
}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
import { createSnapshotStore, } from "@deepseek-ai/dsh-client-store";
|
|
5
|
+
import { bareActionKey, containerActionKey, scopedActionKey, } from "./card-protocol.js";
|
|
5
6
|
import { createCardClient } from "./card-client.js";
|
|
7
|
+
import { configNeedsRecreate, envDiff, mountDiff, pathsEqual, portDiff, } from "./container-card-config.js";
|
|
8
|
+
import { versionState as pluginVersionState } from "../version-compat.js";
|
|
6
9
|
export const CONTAINER_NS = "podman";
|
|
7
10
|
const EMPTY_SNAPSHOT = {
|
|
8
11
|
version: "",
|
|
@@ -23,6 +26,47 @@ const EMPTY_SNAPSHOT = {
|
|
|
23
26
|
secrets: [],
|
|
24
27
|
caches: [],
|
|
25
28
|
};
|
|
29
|
+
// The key a dispatched command is tracked under; see the builders in
|
|
30
|
+
// card-protocol.ts. The switch is exhaustive, so adding a CommandOp without a
|
|
31
|
+
// key is a compile error. Naming operations carry their single identifier in
|
|
32
|
+
// the request's `workspace` field, mirroring how the face methods dispatch them.
|
|
33
|
+
function commandKey(request) {
|
|
34
|
+
switch (request.op) {
|
|
35
|
+
case "remove":
|
|
36
|
+
case "recreate":
|
|
37
|
+
case "create":
|
|
38
|
+
case "container_mount_add":
|
|
39
|
+
case "container_mount_remove":
|
|
40
|
+
case "container_mount_update":
|
|
41
|
+
case "container_path_set":
|
|
42
|
+
case "container_secret_add":
|
|
43
|
+
case "container_secret_remove":
|
|
44
|
+
case "container_publish_port":
|
|
45
|
+
case "container_unpublish_port":
|
|
46
|
+
return containerActionKey(request.op, request.workspace, request.container);
|
|
47
|
+
case "cache_clean":
|
|
48
|
+
return scopedActionKey(request.op, request.cacheMode);
|
|
49
|
+
case "image_rebuild_all":
|
|
50
|
+
return bareActionKey(request.op);
|
|
51
|
+
case "default_env_sync":
|
|
52
|
+
// A sync names the workspace it targets, and an empty workspace means
|
|
53
|
+
// every container; keying the two apart keeps the in-flight set stable
|
|
54
|
+
// whichever the dialog asks for.
|
|
55
|
+
return scopedActionKey(request.op, request.workspace === "" ? "all" : request.workspace);
|
|
56
|
+
case "workspace_remove":
|
|
57
|
+
case "volume_create":
|
|
58
|
+
case "volume_remove":
|
|
59
|
+
case "image_remove":
|
|
60
|
+
case "image_rebuild":
|
|
61
|
+
case "image_build":
|
|
62
|
+
case "image_base_rebuild":
|
|
63
|
+
case "image_base_pull":
|
|
64
|
+
case "secret_create":
|
|
65
|
+
case "secret_remove":
|
|
66
|
+
case "secret_set":
|
|
67
|
+
return scopedActionKey(request.op, request.workspace);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
26
70
|
// The card reads its live state from the host route and its preferences from
|
|
27
71
|
// the settings namespace. A command is one request, so nothing is re-delivered
|
|
28
72
|
// and no document round-trip is involved.
|
|
@@ -35,9 +79,27 @@ export class ContainerCardController {
|
|
|
35
79
|
// Counts in-flight commands, so overlapping ones cannot clear the busy state
|
|
36
80
|
// early; generation makes a superseded response drop its stale snapshot.
|
|
37
81
|
pending = 0;
|
|
82
|
+
// How many in-flight commands share each action key, plus the sorted key list
|
|
83
|
+
// published on CardState (stable identity while the set is unchanged).
|
|
84
|
+
pendingKeys = new Map();
|
|
85
|
+
pendingActions = [];
|
|
38
86
|
generation = 0;
|
|
39
87
|
notice = "";
|
|
88
|
+
// Whether the last snapshot fetch (a reload or a finished command) reached
|
|
89
|
+
// the orchestrator.
|
|
90
|
+
orchestratorReady = false;
|
|
91
|
+
// Whether any fetch has settled, which is what turns the orchestrator's
|
|
92
|
+
// readiness from unknown into a fact.
|
|
93
|
+
orchestratorKnown = false;
|
|
94
|
+
toast = null;
|
|
95
|
+
toastSeq = 0;
|
|
40
96
|
directoryPicker;
|
|
97
|
+
// The plugin's active locale, recorded from the client locale service so a
|
|
98
|
+
// row can date itself in the reader's own language.
|
|
99
|
+
locale = "";
|
|
100
|
+
// Whether the notice currently published reports a failure rather than a
|
|
101
|
+
// result, so the card can announce it as an alert.
|
|
102
|
+
noticeIsError = false;
|
|
41
103
|
constructor(scope, client = createCardClient()) {
|
|
42
104
|
this.scope = scope;
|
|
43
105
|
this.client = client;
|
|
@@ -55,9 +117,17 @@ export class ContainerCardController {
|
|
|
55
117
|
const value = snapshot.value;
|
|
56
118
|
return {
|
|
57
119
|
available: snapshot.status === "ready" && value !== undefined,
|
|
120
|
+
loadState: snapshot.status === "ready" && value !== undefined
|
|
121
|
+
? "ready"
|
|
122
|
+
: snapshot.status === "loading"
|
|
123
|
+
? "loading"
|
|
124
|
+
: "unavailable",
|
|
58
125
|
writable: snapshot.writable,
|
|
59
126
|
busy: this.pending > 0,
|
|
127
|
+
pendingActions: this.pendingActions,
|
|
128
|
+
toast: this.toast,
|
|
60
129
|
notice: this.notice,
|
|
130
|
+
noticeIsError: this.noticeIsError,
|
|
61
131
|
version: this.snapshot.version,
|
|
62
132
|
commit: this.snapshot.commit,
|
|
63
133
|
dshVersion: this.snapshot.dshVersion,
|
|
@@ -67,8 +137,13 @@ export class ContainerCardController {
|
|
|
67
137
|
gatewayState: this.snapshot.gatewayState,
|
|
68
138
|
gatewayVersion: this.snapshot.gatewayVersion,
|
|
69
139
|
gatewayCommit: this.snapshot.gatewayCommit,
|
|
70
|
-
gatewayVersionState: this.snapshot.
|
|
140
|
+
gatewayVersionState: this.snapshot.gatewayVersion === ""
|
|
141
|
+
? "ok"
|
|
142
|
+
: pluginVersionState(this.snapshot.version, this.snapshot.gatewayVersion),
|
|
143
|
+
orchestratorReady: this.orchestratorReady,
|
|
144
|
+
orchestratorKnown: this.orchestratorKnown,
|
|
71
145
|
defaultImage: value?.defaultImage ?? "",
|
|
146
|
+
locale: this.locale,
|
|
72
147
|
containerEnv: value?.containerEnv ?? {},
|
|
73
148
|
projectsRoot: this.snapshot.projectsRoot,
|
|
74
149
|
...(this.directoryPicker === undefined
|
|
@@ -91,8 +166,36 @@ export class ContainerCardController {
|
|
|
91
166
|
this.directoryPicker = picker;
|
|
92
167
|
this.publish();
|
|
93
168
|
}
|
|
94
|
-
|
|
95
|
-
|
|
169
|
+
// setLocale records the active locale (the browser default included) and
|
|
170
|
+
// republishes, so every dated row is re-rendered in it.
|
|
171
|
+
setLocale(locale) {
|
|
172
|
+
if (this.locale === locale)
|
|
173
|
+
return;
|
|
174
|
+
this.locale = locale;
|
|
175
|
+
this.publish();
|
|
176
|
+
}
|
|
177
|
+
beginAction(key) {
|
|
178
|
+
this.pendingKeys.set(key, (this.pendingKeys.get(key) ?? 0) + 1);
|
|
179
|
+
this.pendingActions = [...this.pendingKeys.keys()].sort();
|
|
180
|
+
}
|
|
181
|
+
endAction(key) {
|
|
182
|
+
const remaining = (this.pendingKeys.get(key) ?? 0) - 1;
|
|
183
|
+
if (remaining > 0)
|
|
184
|
+
this.pendingKeys.set(key, remaining);
|
|
185
|
+
else
|
|
186
|
+
this.pendingKeys.delete(key);
|
|
187
|
+
this.pendingActions = [...this.pendingKeys.keys()].sort();
|
|
188
|
+
}
|
|
189
|
+
// showToast publishes one command report; an empty notice means there is
|
|
190
|
+
// nothing to say (a successful command that reported no result).
|
|
191
|
+
showToast(kind, text) {
|
|
192
|
+
if (text === "")
|
|
193
|
+
return;
|
|
194
|
+
this.toastSeq += 1;
|
|
195
|
+
this.toast = { seq: this.toastSeq, kind, text };
|
|
196
|
+
}
|
|
197
|
+
request(op, workspace, image, extra = {}) {
|
|
198
|
+
return this.dispatch({
|
|
96
199
|
op,
|
|
97
200
|
workspace,
|
|
98
201
|
image,
|
|
@@ -115,28 +218,78 @@ export class ContainerCardController {
|
|
|
115
218
|
suggestedHostPort: extra.suggestedHostPort ?? 0,
|
|
116
219
|
});
|
|
117
220
|
}
|
|
221
|
+
command(op, workspace, image, extra = {}) {
|
|
222
|
+
void this.request(op, workspace, image, extra);
|
|
223
|
+
}
|
|
224
|
+
// The create request's optional fields, taken from a dialog draft: an empty
|
|
225
|
+
// group is omitted rather than sent, so the orchestrator keeps its own
|
|
226
|
+
// default.
|
|
227
|
+
createExtra(config, base) {
|
|
228
|
+
return {
|
|
229
|
+
...base,
|
|
230
|
+
...(config?.mounts && config.mounts.length > 0
|
|
231
|
+
? { mounts: config.mounts }
|
|
232
|
+
: {}),
|
|
233
|
+
...(config?.env && Object.keys(config.env).length > 0
|
|
234
|
+
? { env: config.env }
|
|
235
|
+
: {}),
|
|
236
|
+
...(config?.paths && config.paths.length > 0
|
|
237
|
+
? { paths: config.paths }
|
|
238
|
+
: {}),
|
|
239
|
+
...(config?.secretEnv && Object.keys(config.secretEnv).length > 0
|
|
240
|
+
? { secretEnv: config.secretEnv }
|
|
241
|
+
: {}),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
// Create a container from a dialog draft and publish the ports that draft
|
|
245
|
+
// staged: publishing needs the container to exist, so it waits for the create
|
|
246
|
+
// to answer, and a refused create publishes nothing.
|
|
247
|
+
create(workspace, image, extra, ports) {
|
|
248
|
+
void this.request("create", workspace, image, extra).then((ok) => {
|
|
249
|
+
if (!ok)
|
|
250
|
+
return;
|
|
251
|
+
for (const port of ports) {
|
|
252
|
+
this.command("container_publish_port", workspace, "", {
|
|
253
|
+
container: extra.container ?? "",
|
|
254
|
+
port: port.port,
|
|
255
|
+
protocol: port.protocol,
|
|
256
|
+
...(port.suggestedHostPort > 0
|
|
257
|
+
? { suggestedHostPort: port.suggestedHostPort }
|
|
258
|
+
: {}),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
118
263
|
async dispatch(request) {
|
|
264
|
+
const key = commandKey(request);
|
|
119
265
|
const generation = ++this.generation;
|
|
120
266
|
this.pending++;
|
|
121
|
-
this.
|
|
267
|
+
this.beginAction(key);
|
|
122
268
|
this.publish();
|
|
123
269
|
try {
|
|
124
270
|
const result = await this.client.command(request);
|
|
125
271
|
const snapshot = await this.client.snapshot();
|
|
272
|
+
// The fetch itself succeeded, so the orchestrator answered, whatever the
|
|
273
|
+
// generation check below decides about applying its snapshot.
|
|
274
|
+
this.orchestratorReady = true;
|
|
275
|
+
this.orchestratorKnown = true;
|
|
126
276
|
// A reload (or another command) started after this one wins: applying
|
|
127
277
|
// this response would overwrite the fresher state with a stale snapshot.
|
|
128
278
|
if (generation !== this.generation)
|
|
129
|
-
return;
|
|
130
|
-
this.notice = result.notice ?? "";
|
|
279
|
+
return true;
|
|
131
280
|
this.snapshot = snapshot;
|
|
281
|
+
this.showToast("ok", result.notice ?? "");
|
|
282
|
+
return true;
|
|
132
283
|
}
|
|
133
284
|
catch (error) {
|
|
134
285
|
if (generation === this.generation) {
|
|
135
|
-
this.
|
|
286
|
+
this.showToast("error", error instanceof Error ? error.message : String(error));
|
|
136
287
|
}
|
|
288
|
+
return false;
|
|
137
289
|
}
|
|
138
290
|
finally {
|
|
139
291
|
this.pending--;
|
|
292
|
+
this.endAction(key);
|
|
140
293
|
this.publish();
|
|
141
294
|
}
|
|
142
295
|
}
|
|
@@ -146,16 +299,26 @@ export class ContainerCardController {
|
|
|
146
299
|
this.publish();
|
|
147
300
|
try {
|
|
148
301
|
const snapshot = await this.client.snapshot();
|
|
302
|
+
this.orchestratorReady = true;
|
|
303
|
+
this.orchestratorKnown = true;
|
|
149
304
|
if (generation !== this.generation)
|
|
150
305
|
return;
|
|
151
306
|
this.snapshot = snapshot;
|
|
152
|
-
// A refresh clears the previous
|
|
153
|
-
//
|
|
307
|
+
// A refresh clears the previous load failure, so reopening the settings
|
|
308
|
+
// does not replay feedback from an earlier session.
|
|
154
309
|
this.notice = "";
|
|
310
|
+
this.noticeIsError = false;
|
|
155
311
|
}
|
|
156
312
|
catch (error) {
|
|
157
313
|
if (generation === this.generation) {
|
|
158
|
-
|
|
314
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
315
|
+
// The banner keeps the load failure visible for as long as the card
|
|
316
|
+
// lasts; the toast announces it once.
|
|
317
|
+
this.orchestratorReady = false;
|
|
318
|
+
this.orchestratorKnown = true;
|
|
319
|
+
this.notice = text;
|
|
320
|
+
this.noticeIsError = true;
|
|
321
|
+
this.showToast("error", text);
|
|
159
322
|
}
|
|
160
323
|
}
|
|
161
324
|
finally {
|
|
@@ -177,12 +340,96 @@ export class ContainerCardController {
|
|
|
177
340
|
this.drafts.delete(field);
|
|
178
341
|
this.publish();
|
|
179
342
|
}
|
|
343
|
+
// Apply a container's draft on the host, one group at a time, so the change
|
|
344
|
+
// takes effect. Each dispatch reports its own failure and never rejects, so
|
|
345
|
+
// one refused change does not strand the rest; the recreate runs last, only
|
|
346
|
+
// when the image or the environment changed, since those are the two fields
|
|
347
|
+
// it carries.
|
|
348
|
+
async applyConfig(workspace, container, base, next) {
|
|
349
|
+
const mounts = mountDiff(base.mounts, next.mounts);
|
|
350
|
+
for (const mount of mounts.removed) {
|
|
351
|
+
await this.request("container_mount_remove", workspace, "", {
|
|
352
|
+
container,
|
|
353
|
+
mount,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
for (const mount of mounts.updated) {
|
|
357
|
+
await this.request("container_mount_update", workspace, "", {
|
|
358
|
+
container,
|
|
359
|
+
mount,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
for (const mount of mounts.added) {
|
|
363
|
+
await this.request("container_mount_add", workspace, "", {
|
|
364
|
+
container,
|
|
365
|
+
mount,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
// A secret env var has no in-place update: a changed value is detached and
|
|
369
|
+
// reattached, so the variable never keeps a stale secret name.
|
|
370
|
+
const secrets = envDiff(base.secretEnv, next.secretEnv);
|
|
371
|
+
const detach = [
|
|
372
|
+
...secrets.removed,
|
|
373
|
+
...secrets.changed.map(([envVar]) => envVar),
|
|
374
|
+
];
|
|
375
|
+
for (const secretEnvName of detach) {
|
|
376
|
+
await this.request("container_secret_remove", workspace, "", {
|
|
377
|
+
container,
|
|
378
|
+
secretEnvName,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
for (const [secretEnvName, secret] of [...secrets.added, ...secrets.changed]) {
|
|
382
|
+
await this.request("container_secret_add", workspace, "", {
|
|
383
|
+
container,
|
|
384
|
+
secretEnvName,
|
|
385
|
+
secret,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (!pathsEqual(base.paths, next.paths)) {
|
|
389
|
+
await this.request("container_path_set", workspace, "", {
|
|
390
|
+
container,
|
|
391
|
+
paths: [...next.paths],
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
const ports = portDiff(base.ports, next.ports);
|
|
395
|
+
for (const published of ports.removed) {
|
|
396
|
+
await this.request("container_unpublish_port", workspace, "", {
|
|
397
|
+
container,
|
|
398
|
+
port: published.port,
|
|
399
|
+
protocol: published.protocol,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
for (const published of ports.added) {
|
|
403
|
+
await this.request("container_publish_port", workspace, "", {
|
|
404
|
+
container,
|
|
405
|
+
port: published.port,
|
|
406
|
+
protocol: published.protocol,
|
|
407
|
+
...(published.suggestedHostPort > 0
|
|
408
|
+
? { suggestedHostPort: published.suggestedHostPort }
|
|
409
|
+
: {}),
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
// The recreate command is what carries a new image or environment. Every
|
|
413
|
+
// other group is applied by the commands above, and a mount or a secret
|
|
414
|
+
// environment variable recreates the container on its own, so the recreate
|
|
415
|
+
// only runs when one of the two fields it applies changed.
|
|
416
|
+
if (configNeedsRecreate(base, next)) {
|
|
417
|
+
await this.request("recreate", workspace, next.image, {
|
|
418
|
+
container,
|
|
419
|
+
env: next.env,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
180
423
|
inject() {
|
|
181
424
|
return {
|
|
182
425
|
hooks: { containerCard: this.store },
|
|
183
426
|
reload: () => {
|
|
184
427
|
void this.reload();
|
|
185
428
|
},
|
|
429
|
+
dismissToast: () => {
|
|
430
|
+
this.toast = null;
|
|
431
|
+
this.publish();
|
|
432
|
+
},
|
|
186
433
|
remove: (workspace, container) => this.command("remove", workspace, "", { container }),
|
|
187
434
|
cleanCaches: (mode) => this.command("cache_clean", "", "", { cacheMode: mode }),
|
|
188
435
|
removeWorkspace: (workspace) => this.command("workspace_remove", workspace, ""),
|
|
@@ -190,36 +437,8 @@ export class ContainerCardController {
|
|
|
190
437
|
container,
|
|
191
438
|
...(env ? { env } : {}),
|
|
192
439
|
}),
|
|
193
|
-
createContainer: (workspace, config) => this.
|
|
194
|
-
|
|
195
|
-
...(config?.mounts && config.mounts.length > 0
|
|
196
|
-
? { mounts: config.mounts }
|
|
197
|
-
: {}),
|
|
198
|
-
...(config?.env && Object.keys(config.env).length > 0
|
|
199
|
-
? { env: config.env }
|
|
200
|
-
: {}),
|
|
201
|
-
...(config?.paths && config.paths.length > 0
|
|
202
|
-
? { paths: config.paths }
|
|
203
|
-
: {}),
|
|
204
|
-
...(config?.secretEnv && Object.keys(config.secretEnv).length > 0
|
|
205
|
-
? { secretEnv: config.secretEnv }
|
|
206
|
-
: {}),
|
|
207
|
-
}),
|
|
208
|
-
startContainer: (workspace, container, config) => this.command("create", workspace.workspaceSlug, config?.image ?? (workspace.imageId || this.defaultImage() || ""), {
|
|
209
|
-
container,
|
|
210
|
-
...(config?.mounts && config.mounts.length > 0
|
|
211
|
-
? { mounts: config.mounts }
|
|
212
|
-
: {}),
|
|
213
|
-
...(config?.env && Object.keys(config.env).length > 0
|
|
214
|
-
? { env: config.env }
|
|
215
|
-
: {}),
|
|
216
|
-
...(config?.paths && config.paths.length > 0
|
|
217
|
-
? { paths: config.paths }
|
|
218
|
-
: {}),
|
|
219
|
-
...(config?.secretEnv && Object.keys(config.secretEnv).length > 0
|
|
220
|
-
? { secretEnv: config.secretEnv }
|
|
221
|
-
: {}),
|
|
222
|
-
}),
|
|
440
|
+
createContainer: (workspace, config) => this.create(workspace.workspaceSlug, config?.image ?? (workspace.imageId || this.defaultImage() || ""), this.createExtra(config, { projectName: workspace.projectName }), config?.ports ?? []),
|
|
441
|
+
startContainer: (workspace, container, config) => this.create(workspace.workspaceSlug, config?.image ?? (workspace.imageId || this.defaultImage() || ""), this.createExtra(config, { container }), config?.ports ?? []),
|
|
223
442
|
addContainerMount: (workspace, container, mount) => this.command("container_mount_add", workspace, "", {
|
|
224
443
|
container,
|
|
225
444
|
mount,
|
|
@@ -273,7 +492,10 @@ export class ContainerCardController {
|
|
|
273
492
|
saveContainerEnv: (env) => {
|
|
274
493
|
void this.scope.set("containerEnv", env);
|
|
275
494
|
},
|
|
276
|
-
|
|
495
|
+
applyDefaultEnv: (workspace) => this.command("default_env_sync", workspace, ""),
|
|
496
|
+
applyContainerConfig: (workspace, container, base, next) => {
|
|
497
|
+
void this.applyConfig(workspace, container, base, next);
|
|
498
|
+
},
|
|
277
499
|
};
|
|
278
500
|
}
|
|
279
501
|
defaultImage() {
|