devzone 0.47.0 → 0.48.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/.devcontainer/agent-pod-manifest.sh +247 -0
- package/.devcontainer/agent-pod.sh +213 -0
- package/.devcontainer/agent.sh +14 -15
- package/.devcontainer/devzone +1 -1
- package/README.md +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Manifest and validation helpers for the ephemeral session pod (#222).
|
|
3
|
+
# Sourced by agent-pod.sh.
|
|
4
|
+
# bash 3.2 compatible ; shellcheck -x clean.
|
|
5
|
+
|
|
6
|
+
# --- Defaults ---
|
|
7
|
+
|
|
8
|
+
DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS="${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS:-1800}"
|
|
9
|
+
DEVZONE_AGENT_POD_CPU_LIMIT="${DEVZONE_AGENT_POD_CPU_LIMIT:-2}"
|
|
10
|
+
DEVZONE_AGENT_POD_MEM_LIMIT="${DEVZONE_AGENT_POD_MEM_LIMIT:-4Gi}"
|
|
11
|
+
DEVZONE_AGENT_POD_TIMEOUT="${DEVZONE_AGENT_POD_TIMEOUT:-$((DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS + 120))}"
|
|
12
|
+
# Projects root, read by the launcher only (no trailing slash). The pod keeps
|
|
13
|
+
# /workspaces/projets in its own environment (DEVZONE_RACINE in the manifest).
|
|
14
|
+
AGENT_POD_ROOT="${DEVZONE_RACINE:-/workspaces/projets}"
|
|
15
|
+
# Module state file on the workspace volume (subPath .devzone.modules, read-only in the pod).
|
|
16
|
+
# shellcheck disable=SC2034 # read by agent-pod.sh
|
|
17
|
+
AGENT_POD_MODULES_FILE="${DEVZONE_AGENT_POD_MODULES_FILE:-${AGENT_POD_ROOT}/.devzone.modules}"
|
|
18
|
+
|
|
19
|
+
# --- Path check : under AGENT_POD_ROOT, only [A-Za-z0-9._/-], no . or .. part ---
|
|
20
|
+
|
|
21
|
+
agent_pod_path_ok() {
|
|
22
|
+
printf '%s' "$AGENT_POD_ROOT" | grep -Eq '^/[A-Za-z0-9._/-]*[A-Za-z0-9._-]$' || return 1
|
|
23
|
+
case "$1" in "$AGENT_POD_ROOT"/*) ;; *) return 1 ;; esac
|
|
24
|
+
printf '%s' "$1" | grep -Eq '^[A-Za-z0-9._/-]+$' || return 1
|
|
25
|
+
case "$1/" in */./* | */../* | *//*) return 1 ;; esac
|
|
26
|
+
return 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# --- State filled by agent_pod_validate_folder ---
|
|
30
|
+
|
|
31
|
+
AGENT_POD_WORKTREE_SUBPATH=""
|
|
32
|
+
AGENT_POD_WORKTREE_MOUNTPATH=""
|
|
33
|
+
AGENT_POD_GIT_SUBPATH=""
|
|
34
|
+
AGENT_POD_GIT_MOUNTPATH=""
|
|
35
|
+
AGENT_POD_SESSION_LABEL=""
|
|
36
|
+
AGENT_POD_TICKET=""
|
|
37
|
+
|
|
38
|
+
# --- Helpers : read the workspace pod (devzone-workspace-0, container workspace) ---
|
|
39
|
+
|
|
40
|
+
agent_pod_image_workspace() {
|
|
41
|
+
local result
|
|
42
|
+
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].image}' 2>/dev/null)" || true
|
|
43
|
+
echo "${result:-ghcr.io/simbienvenuehoulboumi/devzone-workspace:latest}"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
agent_pod_path_workspace() {
|
|
47
|
+
local result
|
|
48
|
+
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.containers[?(@.name=="workspace")].env[?(@.name=="PATH")].value}' 2>/dev/null)" || true
|
|
49
|
+
echo "${result:-/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
agent_pod_pvc_workspace() {
|
|
53
|
+
local result
|
|
54
|
+
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="workspace")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
|
|
55
|
+
echo "${result:-workspace-devzone-workspace-0}"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
agent_pod_pvc_etat() {
|
|
59
|
+
local result
|
|
60
|
+
result="$(kubectl get pod devzone-workspace-0 -o jsonpath='{.spec.volumes[?(@.name=="etat")].persistentVolumeClaim.claimName}' 2>/dev/null)" || true
|
|
61
|
+
echo "${result:-etat-devzone-workspace-0}"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# --- Validation of the folder to session ---
|
|
65
|
+
|
|
66
|
+
agent_pod_validate_folder() {
|
|
67
|
+
local folder="$1" gitfile gitdir common base
|
|
68
|
+
if [ -z "$folder" ]; then
|
|
69
|
+
echo "devzone agent --pod : folder missing" >&2
|
|
70
|
+
return 1
|
|
71
|
+
fi
|
|
72
|
+
case "$folder" in
|
|
73
|
+
"$AGENT_POD_ROOT"/*) ;;
|
|
74
|
+
*)
|
|
75
|
+
echo "devzone agent --pod : folder outside the projects root $AGENT_POD_ROOT : $folder" >&2
|
|
76
|
+
return 1
|
|
77
|
+
;;
|
|
78
|
+
esac
|
|
79
|
+
if ! agent_pod_path_ok "$folder"; then
|
|
80
|
+
echo "devzone agent --pod : invalid folder path : $folder" >&2
|
|
81
|
+
return 1
|
|
82
|
+
fi
|
|
83
|
+
gitfile="$folder/.git"
|
|
84
|
+
if [ ! -f "$gitfile" ]; then
|
|
85
|
+
echo "devzone agent --pod : no .git file (not a git worktree) : $folder" >&2
|
|
86
|
+
return 1
|
|
87
|
+
fi
|
|
88
|
+
gitdir="$(grep '^gitdir:' "$gitfile" 2>/dev/null | head -1 | sed 's/^gitdir:[[:space:]]*//;s/[[:space:]]*$//')"
|
|
89
|
+
if [ -z "$gitdir" ]; then
|
|
90
|
+
echo "devzone agent --pod : .git without gitdir line : $folder" >&2
|
|
91
|
+
return 1
|
|
92
|
+
fi
|
|
93
|
+
case "$gitdir" in
|
|
94
|
+
*/worktrees/*) common="${gitdir%/worktrees/*}" ;;
|
|
95
|
+
*)
|
|
96
|
+
echo "devzone agent --pod : gitdir is not a worktree : $gitdir" >&2
|
|
97
|
+
return 1
|
|
98
|
+
;;
|
|
99
|
+
esac
|
|
100
|
+
case "$common" in
|
|
101
|
+
"$AGENT_POD_ROOT"/*) ;;
|
|
102
|
+
*)
|
|
103
|
+
echo "devzone agent --pod : worktree depot outside the projects root $AGENT_POD_ROOT : $common" >&2
|
|
104
|
+
return 1
|
|
105
|
+
;;
|
|
106
|
+
esac
|
|
107
|
+
if ! agent_pod_path_ok "$common"; then
|
|
108
|
+
echo "devzone agent --pod : invalid depot path : $common" >&2
|
|
109
|
+
return 1
|
|
110
|
+
fi
|
|
111
|
+
base="$(basename "$folder")"
|
|
112
|
+
if ! printf '%s' "$base" | grep -Eq '^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$'; then
|
|
113
|
+
echo "devzone agent --pod : invalid label value : $base" >&2
|
|
114
|
+
return 1
|
|
115
|
+
fi
|
|
116
|
+
if [ "${#base}" -gt 63 ]; then
|
|
117
|
+
echo "devzone agent --pod : label value too long : $base" >&2
|
|
118
|
+
return 1
|
|
119
|
+
fi
|
|
120
|
+
AGENT_POD_WORKTREE_MOUNTPATH="$folder"
|
|
121
|
+
AGENT_POD_WORKTREE_SUBPATH="${folder#"$AGENT_POD_ROOT"/}"
|
|
122
|
+
AGENT_POD_GIT_MOUNTPATH="$common"
|
|
123
|
+
AGENT_POD_GIT_SUBPATH="${common#"$AGENT_POD_ROOT"/}"
|
|
124
|
+
AGENT_POD_SESSION_LABEL="$base"
|
|
125
|
+
# Keep the ticket only for an exact dz-<number> name.
|
|
126
|
+
if ! printf '%s' "$base" | grep -Eq '^dz-[0-9]+$'; then
|
|
127
|
+
AGENT_POD_TICKET=""
|
|
128
|
+
else
|
|
129
|
+
AGENT_POD_TICKET="${base#dz-}"
|
|
130
|
+
fi
|
|
131
|
+
return 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# --- Build the session pod manifest ---
|
|
135
|
+
|
|
136
|
+
agent_pod_build_manifest() {
|
|
137
|
+
# $2 (the consigne) is never written here: it only goes to the ConfigMap.
|
|
138
|
+
local folder="$1" pod_name="$3"
|
|
139
|
+
local ws_image ws_path pvc_workspace pvc_etat manifest_file ticket_block=""
|
|
140
|
+
|
|
141
|
+
ws_image="$(agent_pod_image_workspace)"
|
|
142
|
+
ws_path="$(agent_pod_path_workspace)"
|
|
143
|
+
pvc_workspace="$(agent_pod_pvc_workspace)"
|
|
144
|
+
pvc_etat="$(agent_pod_pvc_etat)"
|
|
145
|
+
|
|
146
|
+
if [ -n "$AGENT_POD_TICKET" ]; then
|
|
147
|
+
ticket_block=" devzone.io/agent-ticket: \"${AGENT_POD_TICKET}\""
|
|
148
|
+
fi
|
|
149
|
+
|
|
150
|
+
manifest_file="$(mktemp "${TMPDIR:-/tmp}/devzone-agent-pod-manifest.XXXXXX.yaml")"
|
|
151
|
+
|
|
152
|
+
{
|
|
153
|
+
printf '%s\n' "apiVersion: v1"
|
|
154
|
+
printf '%s\n' "kind: Pod"
|
|
155
|
+
printf '%s\n' "metadata:"
|
|
156
|
+
printf '%s\n' " name: ${pod_name}"
|
|
157
|
+
printf '%s\n' " labels:"
|
|
158
|
+
printf '%s\n' " devzone.io/agent-session: ${AGENT_POD_SESSION_LABEL}"
|
|
159
|
+
if [ -n "$ticket_block" ]; then
|
|
160
|
+
printf '%s\n' "$ticket_block"
|
|
161
|
+
fi
|
|
162
|
+
printf '%s\n' "spec:"
|
|
163
|
+
printf '%s\n' " restartPolicy: Never"
|
|
164
|
+
printf '%s\n' " activeDeadlineSeconds: ${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS}"
|
|
165
|
+
printf '%s\n' " automountServiceAccountToken: false"
|
|
166
|
+
printf '%s\n' " securityContext:"
|
|
167
|
+
printf '%s\n' " runAsUser: 1000"
|
|
168
|
+
printf '%s\n' " runAsGroup: 1000"
|
|
169
|
+
printf '%s\n' " runAsNonRoot: true"
|
|
170
|
+
printf '%s\n' " fsGroup: 1000"
|
|
171
|
+
printf '%s\n' " affinity:"
|
|
172
|
+
printf '%s\n' " podAffinity:"
|
|
173
|
+
printf '%s\n' " requiredDuringSchedulingIgnoredDuringExecution:"
|
|
174
|
+
printf '%s\n' " - labelSelector:"
|
|
175
|
+
printf '%s\n' " matchExpressions:"
|
|
176
|
+
printf '%s\n' " - key: statefulset.kubernetes.io/pod-name"
|
|
177
|
+
printf '%s\n' " operator: In"
|
|
178
|
+
printf '%s\n' " values:"
|
|
179
|
+
printf '%s\n' " - devzone-workspace-0"
|
|
180
|
+
printf '%s\n' " topologyKey: kubernetes.io/hostname"
|
|
181
|
+
printf '%s\n' " containers:"
|
|
182
|
+
printf '%s\n' " - name: agent"
|
|
183
|
+
printf '%s\n' " image: ${ws_image}"
|
|
184
|
+
printf '%s\n' " env:"
|
|
185
|
+
printf '%s\n' " - name: HOME"
|
|
186
|
+
printf '%s\n' " value: \"/home/vscode\""
|
|
187
|
+
printf '%s\n' " - name: NPM_CONFIG_PREFIX"
|
|
188
|
+
printf '%s\n' " value: \"/home/vscode/.local/npm\""
|
|
189
|
+
printf '%s\n' " - name: PATH"
|
|
190
|
+
printf '%s\n' " value: \"${ws_path}\""
|
|
191
|
+
printf '%s\n' " - name: DEVZONE_WORKSPACE"
|
|
192
|
+
printf '%s\n' " value: \"kubernetes\""
|
|
193
|
+
printf '%s\n' " - name: DEVZONE_RACINE"
|
|
194
|
+
printf '%s\n' " value: \"/workspaces/projets\""
|
|
195
|
+
printf '%s\n' " resources:"
|
|
196
|
+
printf '%s\n' " limits:"
|
|
197
|
+
printf '%s\n' " cpu: ${DEVZONE_AGENT_POD_CPU_LIMIT}"
|
|
198
|
+
printf '%s\n' " memory: ${DEVZONE_AGENT_POD_MEM_LIMIT}"
|
|
199
|
+
printf '%s\n' " volumeMounts:"
|
|
200
|
+
printf '%s\n' " - name: workspace"
|
|
201
|
+
printf '%s\n' " mountPath: ${AGENT_POD_WORKTREE_MOUNTPATH}"
|
|
202
|
+
printf '%s\n' " subPath: ${AGENT_POD_WORKTREE_SUBPATH}"
|
|
203
|
+
printf '%s\n' " - name: workspace"
|
|
204
|
+
printf '%s\n' " mountPath: ${AGENT_POD_GIT_MOUNTPATH}"
|
|
205
|
+
printf '%s\n' " subPath: ${AGENT_POD_GIT_SUBPATH}"
|
|
206
|
+
printf '%s\n' " - name: workspace"
|
|
207
|
+
printf '%s\n' " mountPath: /workspaces/projets/.devzone.modules"
|
|
208
|
+
printf '%s\n' " subPath: .devzone.modules"
|
|
209
|
+
printf '%s\n' " readOnly: true"
|
|
210
|
+
printf '%s\n' " - name: etat"
|
|
211
|
+
printf '%s\n' " mountPath: /home/vscode/.config/opencode"
|
|
212
|
+
printf '%s\n' " subPath: .config/opencode"
|
|
213
|
+
printf '%s\n' " - name: etat"
|
|
214
|
+
printf '%s\n' " mountPath: /home/vscode/.local/share/opencode"
|
|
215
|
+
printf '%s\n' " subPath: .local/share/opencode"
|
|
216
|
+
printf '%s\n' " - name: etat"
|
|
217
|
+
printf '%s\n' " mountPath: /home/vscode/.local/state/oc-lancer"
|
|
218
|
+
printf '%s\n' " subPath: .local/state/oc-lancer"
|
|
219
|
+
printf '%s\n' " - name: etat"
|
|
220
|
+
printf '%s\n' " mountPath: /home/vscode/.local/npm"
|
|
221
|
+
printf '%s\n' " subPath: .local/npm"
|
|
222
|
+
printf '%s\n' " readOnly: true"
|
|
223
|
+
printf '%s\n' " - name: consigne"
|
|
224
|
+
printf '%s\n' " mountPath: /agent-consigne"
|
|
225
|
+
printf '%s\n' " readOnly: true"
|
|
226
|
+
printf '%s\n' " - name: session-workspace"
|
|
227
|
+
printf '%s\n' " mountPath: /workspaces/projets/workspace"
|
|
228
|
+
printf '%s\n' " command: [\"/bin/bash\", \"-lc\"]"
|
|
229
|
+
printf '%s\n' " args:"
|
|
230
|
+
printf '%s\n' " - 'devzone agent --local ${folder} /agent-consigne/consigne.md; code=\$?; cat \"\$DEVZONE_RACINE/workspace/.agents/${AGENT_POD_SESSION_LABEL}.log\" 2>/dev/null; exit \$code'"
|
|
231
|
+
printf '%s\n' " volumes:"
|
|
232
|
+
printf '%s\n' " - name: workspace"
|
|
233
|
+
printf '%s\n' " persistentVolumeClaim:"
|
|
234
|
+
printf '%s\n' " claimName: ${pvc_workspace}"
|
|
235
|
+
printf '%s\n' " - name: etat"
|
|
236
|
+
printf '%s\n' " persistentVolumeClaim:"
|
|
237
|
+
printf '%s\n' " claimName: ${pvc_etat}"
|
|
238
|
+
printf '%s\n' " - name: consigne"
|
|
239
|
+
printf '%s\n' " configMap:"
|
|
240
|
+
printf '%s\n' " name: ${pod_name}-consigne"
|
|
241
|
+
printf '%s\n' " - name: session-workspace"
|
|
242
|
+
printf '%s\n' " emptyDir:"
|
|
243
|
+
printf '%s\n' " sizeLimit: 256Mi"
|
|
244
|
+
} >"$manifest_file"
|
|
245
|
+
|
|
246
|
+
echo "$manifest_file"
|
|
247
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Ephemeral session pod for devzone agent (#222).
|
|
3
|
+
# Sourced by agent.sh: launches the session pod (devzone agent --pod), waits for
|
|
4
|
+
# its end, keeps its log, deletes the pod and its ConfigMap, lists session pods (status).
|
|
5
|
+
#
|
|
6
|
+
# Constraints:
|
|
7
|
+
# - bash 3.2 compatible
|
|
8
|
+
# - shellcheck -x clean
|
|
9
|
+
# - no real cluster: kubectl is faked in tests
|
|
10
|
+
# - the pod and its ConfigMap are always deleted (EXIT, INT, TERM trap)
|
|
11
|
+
|
|
12
|
+
ICI="${ICI:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
|
13
|
+
# shellcheck source=agent-pod-manifest.sh disable=SC1091
|
|
14
|
+
. "${ICI}/agent-pod-manifest.sh"
|
|
15
|
+
|
|
16
|
+
# Resources of the current launch, read by the cleanup trap.
|
|
17
|
+
AGENT_POD_ACTIVE_NAME=""
|
|
18
|
+
AGENT_POD_ACTIVE_MANIFEST=""
|
|
19
|
+
AGENT_POD_CLEANED=0
|
|
20
|
+
|
|
21
|
+
# --- Pod and ConfigMap names ---
|
|
22
|
+
|
|
23
|
+
agent_pod_name() {
|
|
24
|
+
local base="${1:-}"
|
|
25
|
+
if [ -z "$base" ]; then
|
|
26
|
+
base="${AGENT_POD_SESSION_LABEL:-session}"
|
|
27
|
+
else
|
|
28
|
+
base="$(basename "$base")"
|
|
29
|
+
fi
|
|
30
|
+
# Kubernetes object names must be lowercase.
|
|
31
|
+
base="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]')"
|
|
32
|
+
echo "agent-${base}-$RANDOM"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
agent_pod_configmap_name() {
|
|
36
|
+
echo "$1-consigne"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
agent_pod_create_configmap() {
|
|
40
|
+
local pod_name="$1" consigne_file="$2"
|
|
41
|
+
kubectl create configmap "$(agent_pod_configmap_name "$pod_name")" \
|
|
42
|
+
--from-file=consigne.md="$consigne_file" >/dev/null 2>&1
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
agent_pod_delete_configmap() {
|
|
46
|
+
local pod_name="$1"
|
|
47
|
+
kubectl delete configmap "$(agent_pod_configmap_name "$pod_name")" >/dev/null 2>&1 || true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# --- Create the pod ---
|
|
51
|
+
|
|
52
|
+
agent_pod_create() {
|
|
53
|
+
local manifest_file="$1"
|
|
54
|
+
kubectl create -f "$manifest_file" >/dev/null 2>&1
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# --- Wait for the pod to finish ---
|
|
58
|
+
|
|
59
|
+
agent_pod_wait() {
|
|
60
|
+
local pod_name="$1"
|
|
61
|
+
local elapsed=0
|
|
62
|
+
local max_wait="$DEVZONE_AGENT_POD_TIMEOUT"
|
|
63
|
+
local phase=""
|
|
64
|
+
|
|
65
|
+
while [ "$elapsed" -lt "$max_wait" ]; do
|
|
66
|
+
phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
|
|
67
|
+
if [ "$phase" = "Succeeded" ] || [ "$phase" = "Failed" ]; then
|
|
68
|
+
echo "$phase"
|
|
69
|
+
return 0
|
|
70
|
+
fi
|
|
71
|
+
sleep 1
|
|
72
|
+
elapsed=$((elapsed + 1))
|
|
73
|
+
done
|
|
74
|
+
|
|
75
|
+
phase="$(kubectl get pod "$pod_name" -o jsonpath='{.status.phase}' 2>/dev/null)" || true
|
|
76
|
+
echo "${phase:-Unknown}"
|
|
77
|
+
return 1
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# --- Keep the log of the session ---
|
|
81
|
+
|
|
82
|
+
agent_pod_fetch_logs() {
|
|
83
|
+
local pod_name="$1" journal_file="$2"
|
|
84
|
+
kubectl logs "$pod_name" >>"$journal_file" 2>/dev/null || true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Last lines of the log on stderr: the cause of a failure is there.
|
|
88
|
+
agent_pod_show_tail() {
|
|
89
|
+
local journal_file="$1"
|
|
90
|
+
tail -n 15 "$journal_file" >&2 || true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# --- Delete the pod ---
|
|
94
|
+
|
|
95
|
+
agent_pod_delete() {
|
|
96
|
+
local pod_name="$1"
|
|
97
|
+
kubectl delete pod "$pod_name" >/dev/null 2>&1 || true
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# --- Status : list session pods with their limits ---
|
|
101
|
+
|
|
102
|
+
agent_pod_status() {
|
|
103
|
+
kubectl get pods -l "devzone.io/agent-session" \
|
|
104
|
+
-o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].resources.limits.cpu}{"\t"}{.spec.containers[0].resources.limits.memory}{"\n"}{end}' 2>/dev/null || true
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# --- Cleanup trap: pod, ConfigMap, temporary manifest (not the log) ---
|
|
108
|
+
|
|
109
|
+
agent_pod_cleanup() {
|
|
110
|
+
if [ "$AGENT_POD_CLEANED" = 1 ]; then
|
|
111
|
+
return 0
|
|
112
|
+
fi
|
|
113
|
+
AGENT_POD_CLEANED=1
|
|
114
|
+
if [ -n "$AGENT_POD_ACTIVE_NAME" ]; then
|
|
115
|
+
agent_pod_delete "$AGENT_POD_ACTIVE_NAME"
|
|
116
|
+
agent_pod_delete_configmap "$AGENT_POD_ACTIVE_NAME"
|
|
117
|
+
fi
|
|
118
|
+
if [ -n "$AGENT_POD_ACTIVE_MANIFEST" ]; then
|
|
119
|
+
rm -f "$AGENT_POD_ACTIVE_MANIFEST"
|
|
120
|
+
fi
|
|
121
|
+
return 0
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
# Set before any object is created. INT and TERM leave with 130 / 143;
|
|
125
|
+
# EXIT keeps the exit code of the script.
|
|
126
|
+
agent_pod_set_trap() {
|
|
127
|
+
trap 'agent_pod_cleanup' EXIT
|
|
128
|
+
trap 'agent_pod_cleanup; exit 130' INT
|
|
129
|
+
trap 'agent_pod_cleanup; exit 143' TERM
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# --- Launch a session agent in an ephemeral pod (devzone agent --pod) ---
|
|
133
|
+
|
|
134
|
+
agent_pod_lancer() {
|
|
135
|
+
local folder_raw="${1:-}" consigne_raw="${2:-}"
|
|
136
|
+
local folder consigne pod_name journal_file phase manifest_file etat
|
|
137
|
+
local rc=0
|
|
138
|
+
|
|
139
|
+
if [ "${DEVZONE_WORKSPACE:-}" != "kubernetes" ]; then
|
|
140
|
+
echo "devzone agent --pod : must be called from the workspace pod (DEVZONE_WORKSPACE=kubernetes)" >&2
|
|
141
|
+
exit 1
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
if ! agent_pod_path_ok "$folder_raw"; then
|
|
145
|
+
echo "devzone agent --pod : invalid folder path : ${folder_raw:-}" >&2
|
|
146
|
+
exit 1
|
|
147
|
+
fi
|
|
148
|
+
if [ ! -d "$folder_raw" ]; then
|
|
149
|
+
echo "devzone agent --pod : folder not found : $folder_raw" >&2
|
|
150
|
+
exit 1
|
|
151
|
+
fi
|
|
152
|
+
folder="$(cd "$folder_raw" && pwd -P)" || {
|
|
153
|
+
echo "devzone agent --pod : folder not found : $folder_raw" >&2
|
|
154
|
+
exit 1
|
|
155
|
+
}
|
|
156
|
+
if [ ! -r "${consigne_raw:-}" ]; then
|
|
157
|
+
echo "devzone agent --pod : consigne not found : ${consigne_raw:-}" >&2
|
|
158
|
+
exit 1
|
|
159
|
+
fi
|
|
160
|
+
consigne="$(cd "$(dirname "$consigne_raw")" && pwd -P)/$(basename "$consigne_raw")"
|
|
161
|
+
|
|
162
|
+
if ! agent_pod_validate_folder "$folder"; then
|
|
163
|
+
exit 1
|
|
164
|
+
fi
|
|
165
|
+
# The pod mounts this file read-only: refuse before any object is created.
|
|
166
|
+
if [ ! -f "$AGENT_POD_MODULES_FILE" ]; then
|
|
167
|
+
echo "devzone agent --pod : modules file missing : $AGENT_POD_MODULES_FILE (run devzone enable ia on the workspace)" >&2
|
|
168
|
+
exit 1
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
# The log of the session stays in the agent state directory (shared with the pod).
|
|
172
|
+
etat="${AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
|
|
173
|
+
mkdir -p "$etat"
|
|
174
|
+
journal_file="$etat/${AGENT_POD_SESSION_LABEL}.pod.log"
|
|
175
|
+
: >"$journal_file"
|
|
176
|
+
|
|
177
|
+
pod_name="$(agent_pod_name "$folder")"
|
|
178
|
+
AGENT_POD_ACTIVE_NAME="$pod_name"
|
|
179
|
+
agent_pod_set_trap
|
|
180
|
+
|
|
181
|
+
if ! agent_pod_create_configmap "$pod_name" "$consigne"; then
|
|
182
|
+
echo "devzone agent --pod : unable to create the configmap" >&2
|
|
183
|
+
exit 1
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
manifest_file="$(agent_pod_build_manifest "$folder" "$consigne" "$pod_name")" || {
|
|
187
|
+
echo "devzone agent --pod : unable to build the manifest" >&2
|
|
188
|
+
exit 1
|
|
189
|
+
}
|
|
190
|
+
AGENT_POD_ACTIVE_MANIFEST="$manifest_file"
|
|
191
|
+
|
|
192
|
+
if ! agent_pod_create "$manifest_file"; then
|
|
193
|
+
echo "devzone agent --pod : unable to create the pod (kubectl create -f)" >&2
|
|
194
|
+
echo "devzone agent --pod : try again without --pod" >&2
|
|
195
|
+
exit 1
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
phase="$(agent_pod_wait "$pod_name")" || rc=$?
|
|
199
|
+
agent_pod_fetch_logs "$pod_name" "$journal_file"
|
|
200
|
+
echo "=== end of agent session in pod (phase: ${phase:-Unknown})" >>"$journal_file"
|
|
201
|
+
agent_pod_show_tail "$journal_file"
|
|
202
|
+
|
|
203
|
+
if [ "$rc" -ne 0 ]; then
|
|
204
|
+
echo "devzone agent --pod : pod did not finish in time (phase: ${phase:-Unknown}) ; log : $journal_file" >&2
|
|
205
|
+
exit 1
|
|
206
|
+
fi
|
|
207
|
+
if [ "$phase" = "Failed" ]; then
|
|
208
|
+
echo "devzone agent --pod : session ended in failure ; log : $journal_file" >&2
|
|
209
|
+
exit 1
|
|
210
|
+
fi
|
|
211
|
+
echo "devzone agent --pod : session ended (phase: $phase) ; log : $journal_file" >&2
|
|
212
|
+
exit 0
|
|
213
|
+
}
|
package/.devcontainer/agent.sh
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Dirige opencode sur une consigne : rotation
|
|
3
|
-
#
|
|
4
|
-
# reprise sur une session neuve, permissions sûres. Module ia (#221).
|
|
5
|
-
# devzone agent <dossier> <fichier-consigne>
|
|
6
|
-
# devzone agent etat
|
|
7
|
-
# devzone agent liberer [<modèle>|--tous]
|
|
8
|
-
# Au premier plan ; & ou nohup pour plusieurs sessions en parallèle, une par
|
|
9
|
-
# dossier (le journal et le rang des modèles sont partagés par instance).
|
|
2
|
+
# Dirige opencode sur une consigne : rotation, silence au depart, reprise.
|
|
3
|
+
# Module ia (#221). devzone agent <dossier> <consigne> | etat | liberer.
|
|
10
4
|
set -euo pipefail
|
|
11
5
|
# Dossier du script, liens symboliques suivis à la main : readlink -f n'existe
|
|
12
6
|
# pas sur macOS (tests sous bash 3.2).
|
|
@@ -22,25 +16,21 @@ done
|
|
|
22
16
|
ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
23
17
|
# shellcheck disable=SC2034 # lue par agent-session.sh
|
|
24
18
|
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
25
|
-
# Écarts de modèles et attente du réseau (#328)
|
|
26
19
|
# shellcheck source=agent-erreurs.sh disable=SC1091
|
|
27
20
|
. "$ICI/agent-erreurs.sh"
|
|
28
|
-
# Fichiers de droits des agents protégés (#361)
|
|
29
21
|
# shellcheck source=agent-droits.sh disable=SC1091
|
|
30
22
|
. "$ICI/agent-droits.sh"
|
|
31
|
-
# Configuration, rang partagé, journal et état (#328)
|
|
32
23
|
# shellcheck source=agent-session.sh disable=SC1091
|
|
33
24
|
. "$ICI/agent-session.sh"
|
|
34
|
-
# Workspace Kubernetes : projet et journal dans le pod (#431)
|
|
35
25
|
# shellcheck source=agent-workspace.sh disable=SC1091
|
|
36
26
|
. "$ICI/agent-workspace.sh"
|
|
37
|
-
# Modèle local en dernier de la rotation (#586)
|
|
38
27
|
# shellcheck source=agent-local.sh disable=SC1091
|
|
39
28
|
. "$ICI/agent-local.sh"
|
|
40
|
-
# Liste de secours si « opencode models opencode » ne répond pas : même ordre
|
|
41
|
-
# que la configuration opencode livrée par devzone.
|
|
42
29
|
FREE_MODELS=(big-pickle deepseek-v4.1-flash-free glm-5.3-flash-free nemotron-3.5-super-vl-free
|
|
43
30
|
nemotron-3.5-lightning-free mimo-v2.6-flash-free beam-free flint-40b-free nemotron-3-ultra-free)
|
|
31
|
+
# Session pod ephemere (#222)
|
|
32
|
+
# shellcheck source=agent-pod.sh disable=SC1091
|
|
33
|
+
. "$ICI/agent-pod.sh"
|
|
44
34
|
SILENCE="${DEVZONE_AGENT_SILENCE:-45}"
|
|
45
35
|
FIGEE="${DEVZONE_AGENT_FIGEE:-600}"
|
|
46
36
|
AGENT_ETAT="${DEVZONE_AGENT_ETAT:-$HOME/.local/state/oc-lancer}"
|
|
@@ -220,6 +210,7 @@ agent_lancer() {
|
|
|
220
210
|
exit 3
|
|
221
211
|
}
|
|
222
212
|
case "${1:-}" in
|
|
213
|
+
status) agent_pod_status ;;
|
|
223
214
|
etat) if [ "${2:-}" = "--json" ]; then exec bash "$ICI/agent-etat-json.sh"; else agent_etat; fi ;;
|
|
224
215
|
liberer)
|
|
225
216
|
[ -n "${2:-}" ] || { agent_aide >&2; exit 2; }
|
|
@@ -231,6 +222,14 @@ case "${1:-}" in
|
|
|
231
222
|
exit 2
|
|
232
223
|
;;
|
|
233
224
|
*)
|
|
225
|
+
if [ "${1:-}" = "--pod" ]; then
|
|
226
|
+
shift
|
|
227
|
+
if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
|
|
228
|
+
agent_aide >&2
|
|
229
|
+
exit 2
|
|
230
|
+
fi
|
|
231
|
+
agent_pod_lancer "$1" "$2"
|
|
232
|
+
fi
|
|
234
233
|
mode_local=0
|
|
235
234
|
if [ "${1:-}" = "--local" ]; then
|
|
236
235
|
mode_local=1
|
package/.devcontainer/devzone
CHANGED
|
@@ -52,7 +52,7 @@ fi
|
|
|
52
52
|
# change pas : deux montées simultanées (workflow versions) se fusionnent sans
|
|
53
53
|
# conflit, git n'en signalant qu'entre lignes voisines modifiées.
|
|
54
54
|
# Claude Code
|
|
55
|
-
IA_CLAUDE=@anthropic-ai/claude-code@2.1.
|
|
55
|
+
IA_CLAUDE=@anthropic-ai/claude-code@2.1.326
|
|
56
56
|
# opencode
|
|
57
57
|
IA_OPENCODE=opencode-ai@1.19.5
|
|
58
58
|
IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
|
package/README.md
CHANGED
|
@@ -254,6 +254,8 @@ Dans le conteneur, le récapitulatif `devzone` signale une version publiée plus
|
|
|
254
254
|
|
|
255
255
|
**Module `argocd`** : Argo CD sur le cluster de devzone, interface sur https://127.0.0.1:8443 dans le conteneur (voir [Argo CD](manage/docs/reference.md#argo-cd)). Pour l'activer : `devzone enable argocd`.
|
|
256
256
|
|
|
257
|
+
**Option `devzone agent --pod`** : lance une session agent dans un pod éphémère isolé (ticket #222). Le pod est créé avec des ressources limitées (2 CPU, 4 Gi mémoire), des montages restreints du workspace et de l'état, et une affinité obligatoire vers le pod workspace. Isole : worktree du ticket au même chemin que dans le workspace, .git du dépôt, et sous-dossiers d'état (.config/opencode, .local/share/opencode, .local/state/oc-lancer, .local/npm en lecture seule). N'isole pas : le réseau (non filtré, c'est #220), le kubeconfig de l'hôte, `~/.config/gh`, `~/.claude`, les autres worktrees, et, comme le `.git` du dépôt est monté, les références git des autres branches y restent lisibles et modifiables. Sans `--pod`, le comportement `devzone agent` actuel est strictement inchangé.
|
|
258
|
+
|
|
257
259
|
Ces modules sont désactivés par défaut, activables à la demande depuis le conteneur (sans rebuild), et leur choix est conservé d'un démarrage à l'autre.
|
|
258
260
|
|
|
259
261
|
La commande `devzone` s'écrit en anglais, sous-commandes et options comprises (`enable`, `disable`, `platform`, `packages`, `update`, `uninstall`, `status`, `use` ; `postgres create`, `packages add`, `gitlab new-password`, `port --close`, `cluster --yes`). Les anciens noms français restent acceptés et écrivent un avertissement ; la table complète est dans [Anciens noms des commandes](manage/docs/reference.md#anciens-noms-des-commandes).
|