devzone 7.3.0 → 7.4.1
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/devcontainer.json +1 -1
- package/.devcontainer/devzone +13 -20
- package/.devcontainer/devzone-modules.sh +1 -1
- package/.devcontainer/devzone-repair.sh +2 -2
- package/.devcontainer/devzone-services.sh +7 -7
- package/.devcontainer/devzone-status.sh +5 -5
- package/.devcontainer/help.sh +3 -1
- package/.devcontainer/versions.env +3 -0
- package/.devcontainer/workspace-init.sh +8 -9
- package/.gitattributes +8 -0
- package/README.md +1 -1
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/charts/devzone-mysql/values.yaml +1 -1
- package/charts/devzone-postgres/values.yaml +1 -1
- package/manage/devzone +2 -2
- package/manage/scripts/uninstall.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +2 -2
- package/package.json +1 -1
- package/.devcontainer/agent-errors.sh +0 -156
- package/.devcontainer/agent-local.sh +0 -63
- package/.devcontainer/agent-model.sh +0 -113
- package/.devcontainer/agent-pod-egress.sh +0 -36
- package/.devcontainer/agent-pod-manifest.sh +0 -250
- package/.devcontainer/agent-pod.sh +0 -243
- package/.devcontainer/agent-session.sh +0 -242
- package/.devcontainer/agent-state-json.sh +0 -117
- package/.devcontainer/agent-workspace.sh +0 -97
- package/.devcontainer/agent.sh +0 -247
- package/.devcontainer/catalog/app.sh +0 -202
- package/.devcontainer/catalog/catalog-watcher.sh +0 -127
- package/.devcontainer/catalog.sh +0 -208
- package/.devcontainer/chart-direct.sh +0 -49
- package/.devcontainer/cluster.sh +0 -388
- package/.devcontainer/clusters.sh +0 -86
- package/.devcontainer/devzone-cluster.sh +0 -209
- package/.devcontainer/isolation.sh +0 -65
- package/.devcontainer/kube-account.sh +0 -107
- package/.devcontainer/kube-prompt.sh +0 -42
- package/.devcontainer/memory.sh +0 -113
- package/.devcontainer/metrics-server.sh +0 -100
- package/.devcontainer/packages.sh +0 -228
- package/.devcontainer/password.sh +0 -148
- package/.devcontainer/ports-json.sh +0 -31
- package/.devcontainer/ports.sh +0 -132
package/.devcontainer/agent.sh
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Drives opencode on a brief: rotation, silence at start, resume.
|
|
3
|
-
# ai module (#221). devzone agent <folder> <brief> | state | release.
|
|
4
|
-
# shellcheck disable=SC2034 # RACINE, FREE_MODELS, PAUSE_RANK: read by the sourced agent-*.sh
|
|
5
|
-
set -euo pipefail
|
|
6
|
-
# Folder of the script, symbolic links followed by hand: readlink -f does not exist
|
|
7
|
-
# on macOS (tests under bash 3.2).
|
|
8
|
-
SOURCE="${BASH_SOURCE[0]}"
|
|
9
|
-
while [ -L "$SOURCE" ]; do
|
|
10
|
-
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
11
|
-
SOURCE="$(readlink "$SOURCE")"
|
|
12
|
-
case "$SOURCE" in
|
|
13
|
-
/*) ;;
|
|
14
|
-
*) SOURCE="$DIR/$SOURCE" ;;
|
|
15
|
-
esac
|
|
16
|
-
done
|
|
17
|
-
ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
18
|
-
RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
|
|
19
|
-
# shellcheck source=agent-errors.sh disable=SC1091
|
|
20
|
-
. "$ICI/agent-errors.sh"
|
|
21
|
-
# shellcheck source=agent-rights.sh disable=SC1091
|
|
22
|
-
. "$ICI/agent-rights.sh"
|
|
23
|
-
# shellcheck source=SCRIPTDIR/agent-session.sh disable=SC1091
|
|
24
|
-
. "$ICI/agent-session.sh"
|
|
25
|
-
# shellcheck source=agent-workspace.sh disable=SC1091
|
|
26
|
-
. "$ICI/agent-workspace.sh"
|
|
27
|
-
# shellcheck source=agent-local.sh disable=SC1091
|
|
28
|
-
. "$ICI/agent-local.sh"
|
|
29
|
-
# shellcheck source=SCRIPTDIR/agent-model.sh disable=SC1091
|
|
30
|
-
. "$ICI/agent-model.sh"
|
|
31
|
-
FREE_MODELS=(big-pickle deepseek-v4.1-flash-free hy4-flash-free nemotron-3.5-super-vl-free
|
|
32
|
-
nemotron-3.5-lightning-free mimo-v2.6-flash-free beam-free flint-40b-free longcat-2.5-free)
|
|
33
|
-
# Ephemeral session pod (#222)
|
|
34
|
-
# shellcheck source=agent-pod.sh disable=SC1091
|
|
35
|
-
. "$ICI/agent-pod.sh"
|
|
36
|
-
SILENCE="${DEVZONE_AGENT_SILENCE:-45}"
|
|
37
|
-
FROZEN="${DEVZONE_AGENT_FROZEN:-600}"
|
|
38
|
-
AGENT_STATE="${DEVZONE_AGENT_STATE:-$HOME/.local/state/oc-lancer}"
|
|
39
|
-
# Pause between read and write of the rank (tests only): active only when
|
|
40
|
-
# DEVZONE_AGENT_PAUSE_RANK is set under bats; never a pause by default.
|
|
41
|
-
PAUSE_RANK=0
|
|
42
|
-
if [ -n "${DEVZONE_AGENT_PAUSE_RANK:-}" ] && [ -n "${BATS_TEST_TMPDIR:-}" ]; then PAUSE_RANK="$DEVZONE_AGENT_PAUSE_RANK"; fi
|
|
43
|
-
# Retries of the same session for a network cause, per model, before the next model
|
|
44
|
-
NETWORK_RETRIES=3
|
|
45
|
-
refuse() { echo "devzone agent: $*" >&2; exit 2; }
|
|
46
|
-
agent_launch() {
|
|
47
|
-
local folder="$1" brief="$2"
|
|
48
|
-
local journal state start m i pid code offset size started freeze discard new
|
|
49
|
-
local brief_current resumed=0 now last output recent cause start_t
|
|
50
|
-
local network_for="" network_n=0
|
|
51
|
-
# Paths relative to the calling folder: made absolute before any cd, lock or
|
|
52
|
-
# state write; the name of the brief is kept.
|
|
53
|
-
[ -d "$folder" ] || refuse "folder not found: $folder (searched from $(pwd))"
|
|
54
|
-
[ -r "$brief" ] || refuse "brief not found: $brief (searched from $(pwd))"
|
|
55
|
-
folder="$(cd "$folder" && pwd -P)"
|
|
56
|
-
brief="$(cd "$(dirname "$brief")" && pwd -P)/$(basename "$brief")"
|
|
57
|
-
# ai module required: without assistants, nothing to drive.
|
|
58
|
-
if ! bash "$ICI/devzone" is-enabled ai >/dev/null 2>&1; then
|
|
59
|
-
refuse "ai module disabled: devzone enable ai"
|
|
60
|
-
fi
|
|
61
|
-
configure
|
|
62
|
-
journal="$(journal_of "$folder")"
|
|
63
|
-
export AGENT_JOURNAL="$journal"
|
|
64
|
-
state="$AGENT_STATE"
|
|
65
|
-
mkdir -p "$(dirname "$journal")" "$state"
|
|
66
|
-
rights_snapshot "$folder"
|
|
67
|
-
models_load "$journal"
|
|
68
|
-
local_charge
|
|
69
|
-
start="$(rank_take "$state" "$journal")" || refuse "model rank locked: retry later"
|
|
70
|
-
brief_current="$brief"
|
|
71
|
-
# Resume: a new session restarts from the work already present (git status,
|
|
72
|
-
# diff, log), without conversation history.
|
|
73
|
-
resume() {
|
|
74
|
-
if [ "$resumed" = 1 ]; then return 0; fi
|
|
75
|
-
resumed=1
|
|
76
|
-
local c
|
|
77
|
-
c="$(mktemp)"
|
|
78
|
-
cat "$brief_current" >"$c"
|
|
79
|
-
printf '\n\nRESUME: a previous session was interrupted. Read git status, git diff and git log in the folder, check this work against the brief above, fix what deviates from it and finish what is missing.\n' >>"$c"
|
|
80
|
-
brief_current="$c"
|
|
81
|
-
}
|
|
82
|
-
model_order "$start"
|
|
83
|
-
i=0
|
|
84
|
-
while [ "$i" -lt "${#ORDER[@]}" ]; do
|
|
85
|
-
m="${ORDER[$i]}"
|
|
86
|
-
if [ "$m" != "$network_for" ]; then network_for="$m"; network_n=0; fi
|
|
87
|
-
if model_excluded "$m"; then
|
|
88
|
-
model_requested_excluded "$m" "$(model_exclusion_cause "$m")" "$journal"
|
|
89
|
-
i=$(( i + 1 ))
|
|
90
|
-
continue
|
|
91
|
-
fi
|
|
92
|
-
model_requested_chosen "$m" "$journal"
|
|
93
|
-
echo "=== model opencode/$m start $(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$journal"
|
|
94
|
-
offset="$(wc -c <"$journal")"
|
|
95
|
-
opencode_launch "$folder" "$m" "$brief_current" "$journal" "$state"
|
|
96
|
-
pid=$!
|
|
97
|
-
started=0
|
|
98
|
-
discard=0
|
|
99
|
-
start_t="$(date +%s)"
|
|
100
|
-
while kill -0 "$pid" 2>/dev/null; do
|
|
101
|
-
if session_fatal_error "$pid" "$journal" "$offset" "$m" "$folder"; then discard=1; break; fi
|
|
102
|
-
if [ "$(wc -c <"$journal")" -gt "$offset" ]; then
|
|
103
|
-
new="$(tail -c "+$(( offset + 1 ))" "$journal" 2>/dev/null || true)"
|
|
104
|
-
if [ "$(error_cause "$(error_lines "$new")")" != "quota" ]; then started=1; break; fi
|
|
105
|
-
fi
|
|
106
|
-
if [ $(( $(date +%s) - start_t )) -ge "$SILENCE" ]; then break; fi
|
|
107
|
-
sleep "${DEVZONE_AGENT_STEP:-1}"
|
|
108
|
-
done
|
|
109
|
-
if [ "$discard" = 1 ]; then resume; i=$(( i + 1 )); continue; fi
|
|
110
|
-
if kill -0 "$pid" 2>/dev/null && [ "$started" = 0 ]; then
|
|
111
|
-
pkill -P "$pid" 2>/dev/null || true
|
|
112
|
-
kill "$pid" 2>/dev/null || true
|
|
113
|
-
wait "$pid" 2>/dev/null || true
|
|
114
|
-
rights_verify "$folder"
|
|
115
|
-
echo "=== opencode/$m silent at start: excluded 1 h, next model" >>"$journal"
|
|
116
|
-
model_exclude "$m" mute
|
|
117
|
-
model_requested_excluded "$m" mute "$journal"
|
|
118
|
-
resume
|
|
119
|
-
i=$(( i + 1 ))
|
|
120
|
-
continue
|
|
121
|
-
fi
|
|
122
|
-
# Frozen session: nothing written for FROZEN seconds during the run -> stopped,
|
|
123
|
-
# then a new session with the resume brief.
|
|
124
|
-
freeze=0
|
|
125
|
-
if kill -0 "$pid" 2>/dev/null && [ "$started" = 1 ]; then
|
|
126
|
-
last="$(date +%s)"
|
|
127
|
-
size="$(wc -c <"$journal")"
|
|
128
|
-
while kill -0 "$pid" 2>/dev/null; do
|
|
129
|
-
if session_fatal_error "$pid" "$journal" "$offset" "$m" "$folder"; then discard=1; break; fi
|
|
130
|
-
sleep "${DEVZONE_AGENT_STEP:-1}"
|
|
131
|
-
now="$(date +%s)"
|
|
132
|
-
if [ "$(wc -c <"$journal")" -gt "$size" ]; then
|
|
133
|
-
size="$(wc -c <"$journal")"
|
|
134
|
-
last="$now"
|
|
135
|
-
fi
|
|
136
|
-
if [ $(( now - last )) -gt "$FROZEN" ]; then
|
|
137
|
-
pkill -P "$pid" 2>/dev/null || true
|
|
138
|
-
kill "$pid" 2>/dev/null || true
|
|
139
|
-
wait "$pid" 2>/dev/null || true
|
|
140
|
-
rights_verify "$folder"
|
|
141
|
-
freeze=1
|
|
142
|
-
break
|
|
143
|
-
fi
|
|
144
|
-
done
|
|
145
|
-
fi
|
|
146
|
-
if [ "$discard" = 1 ]; then resume; i=$(( i + 1 )); continue; fi
|
|
147
|
-
if [ "$freeze" = 1 ]; then
|
|
148
|
-
echo "=== opencode/$m frozen ($FROZEN s without writing): new session, next model" >>"$journal"
|
|
149
|
-
resume
|
|
150
|
-
i=$(( i + 1 ))
|
|
151
|
-
continue
|
|
152
|
-
fi
|
|
153
|
-
code=0
|
|
154
|
-
wait "$pid" || code=$?
|
|
155
|
-
rights_verify "$folder"
|
|
156
|
-
# Only the output of this attempt counts: an error of a previous model must not
|
|
157
|
-
# condemn the next one. Only its last 30 lines are read, and only when the exit
|
|
158
|
-
# code is non-zero or opencode wrote its own error line: a printed "Free usage
|
|
159
|
-
# limit" in text that ends normally is not a failure.
|
|
160
|
-
output="$(tail -c "+$(( offset + 1 ))" "$journal" 2>/dev/null || true)"
|
|
161
|
-
recent="$(printf '%s\n' "$output" | tail -n 30)"
|
|
162
|
-
if [ "$code" -ne 0 ] || printf '%s\n' "$recent" | grep -qE "$ERROR_LINE"; then
|
|
163
|
-
if printf '%s\n' "$recent" | grep -qE "$ERRORS"; then
|
|
164
|
-
cause="$(error_cause "$(printf '%s\n' "$recent" | grep -oE "$ERRORS" | tail -1)")"
|
|
165
|
-
# A network error is kept only if the network is down now: otherwise it
|
|
166
|
-
# would repeat endlessly on a good network.
|
|
167
|
-
if [ "$cause" = reseau ] && network_reachable; then
|
|
168
|
-
echo "=== network error reported but network reachable: treated as other" >>"$journal"
|
|
169
|
-
cause=autre
|
|
170
|
-
fi
|
|
171
|
-
if [ "$cause" = reseau ] && [ "$network_n" -ge "$NETWORK_RETRIES" ]; then
|
|
172
|
-
echo "=== opencode/$m network down $NETWORK_RETRIES times: next model, no exclusion" >>"$journal"
|
|
173
|
-
cause=autre
|
|
174
|
-
fi
|
|
175
|
-
if [ "$cause" = reseau ]; then
|
|
176
|
-
if network_wait; then
|
|
177
|
-
network_n=$(( network_n + 1 ))
|
|
178
|
-
resume
|
|
179
|
-
continue
|
|
180
|
-
fi
|
|
181
|
-
echo "=== network unavailable" >>"$journal"
|
|
182
|
-
exit 4
|
|
183
|
-
fi
|
|
184
|
-
if [ "$cause" = autre ]; then
|
|
185
|
-
echo "=== opencode/$m error, no exclusion: next model" >>"$journal"
|
|
186
|
-
else
|
|
187
|
-
model_exclude "$m" "$cause"
|
|
188
|
-
model_requested_excluded "$m" "$cause" "$journal"
|
|
189
|
-
echo "=== opencode/$m excluded ($(cause_label "$cause"), $(exclusion_label "$cause")): next model" >>"$journal"
|
|
190
|
-
fi
|
|
191
|
-
resume
|
|
192
|
-
i=$(( i + 1 ))
|
|
193
|
-
continue
|
|
194
|
-
fi
|
|
195
|
-
fi
|
|
196
|
-
if [ "$code" -ne 0 ]; then
|
|
197
|
-
echo "=== opencode/$m stopped on error (code $code): next model" >>"$journal"
|
|
198
|
-
resume
|
|
199
|
-
i=$(( i + 1 ))
|
|
200
|
-
continue
|
|
201
|
-
fi
|
|
202
|
-
echo "=== end with opencode/$m (code $code)" >>"$journal"
|
|
203
|
-
exit "$code"
|
|
204
|
-
done
|
|
205
|
-
echo "=== no free model available" >>"$journal"
|
|
206
|
-
exit 3
|
|
207
|
-
}
|
|
208
|
-
case "${1:-}" in
|
|
209
|
-
status) agent_pod_status ;;
|
|
210
|
-
state) if [ "${2:-}" = "--json" ]; then exec bash "$ICI/agent-state-json.sh"; else agent_state; fi ;;
|
|
211
|
-
release)
|
|
212
|
-
[ -n "${2:-}" ] || { agent_help >&2; exit 2; }
|
|
213
|
-
exclusion_clear "$2"
|
|
214
|
-
;;
|
|
215
|
-
-h | --help | help) agent_help ;;
|
|
216
|
-
"")
|
|
217
|
-
agent_help
|
|
218
|
-
exit 2
|
|
219
|
-
;;
|
|
220
|
-
*)
|
|
221
|
-
if [ "${1:-}" = "--model" ]; then [ -n "${2:-}" ] || { agent_help >&2; exit 2; }; MODEL_LIST="$2"; shift 2; fi
|
|
222
|
-
if [ "${1:-}" = "--pod" ]; then
|
|
223
|
-
[ -z "$MODEL_LIST" ] || refuse "--model is not supported with --pod"
|
|
224
|
-
shift
|
|
225
|
-
if [ -z "${1:-}" ] || [ -z "${2:-}" ]; then
|
|
226
|
-
agent_help >&2
|
|
227
|
-
exit 2
|
|
228
|
-
fi
|
|
229
|
-
agent_pod_launch "$1" "$2"
|
|
230
|
-
fi
|
|
231
|
-
local_mode=0
|
|
232
|
-
if [ "${1:-}" = "--local" ]; then
|
|
233
|
-
local_mode=1
|
|
234
|
-
shift
|
|
235
|
-
fi
|
|
236
|
-
if [ "$#" -lt 2 ]; then
|
|
237
|
-
agent_help >&2
|
|
238
|
-
exit 2
|
|
239
|
-
fi
|
|
240
|
-
if [ "$local_mode" = 0 ] && workspace_available; then
|
|
241
|
-
code=0
|
|
242
|
-
agent_workspace "$1" "$2" || code=$?
|
|
243
|
-
exit "$code"
|
|
244
|
-
fi
|
|
245
|
-
agent_launch "$1" "$2"
|
|
246
|
-
;;
|
|
247
|
-
esac
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Install operations of the catalog (#414): sourced by catalog.sh.
|
|
3
|
-
# With the argocd module on, the installed application is an Argo CD Application
|
|
4
|
-
# devzone-<app> (chart charts/devzone-<app> of the devzone repository, #538) instead
|
|
5
|
-
# of the manifest of the direct helm path.
|
|
6
|
-
|
|
7
|
-
WAIT_SECONDS="${DEVZONE_CATALOG_WAIT:-300}"
|
|
8
|
-
|
|
9
|
-
# shellcheck source=SCRIPTDIR/chart-direct.sh
|
|
10
|
-
# shellcheck disable=SC1091
|
|
11
|
-
. "$ICI/chart-direct.sh"
|
|
12
|
-
|
|
13
|
-
# Waits for the StatefulSet to be ready: a single rollout command on the manifest
|
|
14
|
-
# path, polled on the Argo CD path (the sync runs in the background)
|
|
15
|
-
app_wait() {
|
|
16
|
-
local app="$1" ns="$2" argo="$3" end=$((SECONDS + WAIT_SECONDS))
|
|
17
|
-
if [ "$argo" = 1 ]; then
|
|
18
|
-
while [ "$SECONDS" -lt "$end" ]; do
|
|
19
|
-
kubectl --context devzone -n "$ns" rollout status "statefulset/$app" --timeout=10s >/dev/null 2>&1 && return 0
|
|
20
|
-
sleep 5
|
|
21
|
-
done
|
|
22
|
-
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
23
|
-
return 1
|
|
24
|
-
fi
|
|
25
|
-
if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
|
|
26
|
-
--timeout="${WAIT_SECONDS}s" >/dev/null; then
|
|
27
|
-
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
28
|
-
return 1
|
|
29
|
-
fi
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
# Application secret: password generated once, local mirror
|
|
33
|
-
# (workspace/.$app/admin-password, 600, never shown). Re-run: a password already
|
|
34
|
-
# there (cluster secret or root.env) is kept, never regenerated.
|
|
35
|
-
app_secret() {
|
|
36
|
-
local app="$1" ns="$2" password file
|
|
37
|
-
file="$RACINE/workspace/.$app/admin-password"
|
|
38
|
-
mkdir -p "$(dirname "$file")"
|
|
39
|
-
chmod 700 "$(dirname "$file")"
|
|
40
|
-
if kubectl --context devzone -n "$ns" get secret "$app-admin" >/dev/null 2>&1; then
|
|
41
|
-
password="$(kubectl --context devzone -n "$ns" get secret "$app-admin" \
|
|
42
|
-
-o jsonpath='{.data.password}' | tr -d '\n')"
|
|
43
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
44
|
-
return 0
|
|
45
|
-
fi
|
|
46
|
-
password="$(sed -n 's/^\(MYSQL_\|\)PASSWORD=//p' "$RACINE/workspace/.$app/root.env" 2>/dev/null | tail -1 || true)"
|
|
47
|
-
if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
|
|
48
|
-
if [ -z "$password" ]; then
|
|
49
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
50
|
-
elif [ ! -s "$file" ]; then
|
|
51
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
52
|
-
fi
|
|
53
|
-
kubectl --context devzone -n "$ns" create secret generic "$app-admin" \
|
|
54
|
-
--from-file=password="$file" >/dev/null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Grouped view of the credentials: a failure never blocks the operation
|
|
58
|
-
regenerer_identifiants() {
|
|
59
|
-
password_regenerate ||
|
|
60
|
-
echo "devzone : catalog : grouped credentials not updated (devzone passwords)" >&2
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
# Installs an application: devzone context set (#396), namespace created and
|
|
64
|
-
# isolated (#396), secret generated, then the Argo CD Application (argocd module
|
|
65
|
-
# on, #538) or the manifest, wait until ready, relay started to 127.0.0.1:<port>
|
|
66
|
-
# of the container; returns non-zero on failure
|
|
67
|
-
app_install() {
|
|
68
|
-
local app="$1" ns port image CTX extra="" argo=0
|
|
69
|
-
ns="$(app_namespace "$app")"
|
|
70
|
-
port="$(app_read "$app" port)"
|
|
71
|
-
image="$(app_read "$app" image)"
|
|
72
|
-
CTX="$(cluster_saved)"
|
|
73
|
-
[ -n "$CTX" ] || refuse "no cluster chosen: devzone enable $app"
|
|
74
|
-
if ! devzone_context_set "$CTX"; then
|
|
75
|
-
echo "devzone : catalog : cannot set the devzone context on $CTX" >&2
|
|
76
|
-
return 1
|
|
77
|
-
fi
|
|
78
|
-
echo "▶ Application $app on cluster $CTX (namespace $ns)…"
|
|
79
|
-
# Namespace created and labelled by the administrator (#430), then the limited
|
|
80
|
-
# account allowed in the namespace
|
|
81
|
-
account_admin "$CTX" create namespace "$ns" --dry-run=client -o yaml |
|
|
82
|
-
account_admin "$CTX" apply -f - >/dev/null
|
|
83
|
-
account_admin "$CTX" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null
|
|
84
|
-
account_allow "$CTX" "$ns"
|
|
85
|
-
namespace_isolate "$ns" >/dev/null
|
|
86
|
-
app_secret "$app" "$ns"
|
|
87
|
-
local claim=donnees
|
|
88
|
-
if [ "$app" = mysql ]; then
|
|
89
|
-
claim="$(devzone mysql claim "$ns")" || return 2
|
|
90
|
-
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
91
|
-
fi
|
|
92
|
-
if "$ICI/devzone" argocd catalog-active "$app"; then
|
|
93
|
-
argo=1
|
|
94
|
-
echo "▶ Application $app through Argo CD (chart charts/devzone-$app)…"
|
|
95
|
-
"$ICI/devzone" argocd catalog-apply "$app" "$ns" "$image" "$port" "$(app_read "$app" memoire)" "$(app_read "$app" taille)" "$extra" || return 1
|
|
96
|
-
else
|
|
97
|
-
# Direct helm: the chart charts/devzone-<app>, the one definition (#559)
|
|
98
|
-
chart_install "$app" "$ns" "image=$image" "port=$port" \
|
|
99
|
-
"memory=$(app_read "$app" memoire)" "size=$(app_read "$app" taille)" "claim=$claim" || return 1
|
|
100
|
-
fi
|
|
101
|
-
app_wait "$app" "$ns" "$argo" || return 1
|
|
102
|
-
relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
|
|
103
|
-
echo "✔ $app ready: 127.0.0.1:$port in the container"
|
|
104
|
-
regenerer_identifiants
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
# Uninstalls an application: relay stopped, Argo CD Application removed (argocd
|
|
108
|
-
# module on, #538) or the manifest, failure marker forgotten. The volume (PVC) and
|
|
109
|
-
# the data stay (#441): deleting the data is confirmed apart (devzone mysql delete-data)
|
|
110
|
-
app_remove() {
|
|
111
|
-
local app="$1" ns claim pvc CTX
|
|
112
|
-
ns="$(app_namespace "$app")"
|
|
113
|
-
relay_stop "$app"
|
|
114
|
-
rm -f "$(failure_file "$app")"
|
|
115
|
-
# RoleBinding removed by the administrator (#430): the namespace and the volume
|
|
116
|
-
# stay, the account authorization must not linger
|
|
117
|
-
CTX="$(cluster_saved)" || true
|
|
118
|
-
if [ -n "$CTX" ]; then
|
|
119
|
-
account_remove "$CTX" "$ns" >/dev/null 2>&1 || true
|
|
120
|
-
fi
|
|
121
|
-
claim="$(kubectl --context devzone -n "$ns" get statefulset "$app" \
|
|
122
|
-
-o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
123
|
-
if "$ICI/devzone" argocd catalog-application-exists "$app"; then
|
|
124
|
-
"$ICI/devzone" argocd catalog-delete "$app" >/dev/null 2>&1 || true
|
|
125
|
-
kubectl --context devzone -n "$ns" delete "secret/$app-admin" >/dev/null 2>&1 || true
|
|
126
|
-
pvc="${claim:-donnees}-$app-0"
|
|
127
|
-
echo "✔ $app removed: Application deleted; volume $pvc and databases kept: devzone $app volume"
|
|
128
|
-
regenerer_identifiants
|
|
129
|
-
return 0
|
|
130
|
-
fi
|
|
131
|
-
kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
|
|
132
|
-
"secret/$app-admin" >/dev/null 2>&1 || true
|
|
133
|
-
pvc="${claim:-donnees}-$app-0"
|
|
134
|
-
echo "✔ $app removed from the cluster; volume $pvc and databases kept: devzone $app volume"
|
|
135
|
-
regenerer_identifiants
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
# Failure marker of an attempt: last line of the message kept and shown
|
|
139
|
-
app_failure() {
|
|
140
|
-
printf '%s\n' "$2" | tail -1 >"$(failure_file "$1")"
|
|
141
|
-
printf '%s\n' "$2" >&2
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
# Warns about the mysql PVCs not mounted by the StatefulSet (#440). Reading the
|
|
145
|
-
# namespaces is reserved to the administrator (#430).
|
|
146
|
-
app_unused_mysql_volumes() {
|
|
147
|
-
local ctx ns mounted pvc list
|
|
148
|
-
ctx="$(cluster_saved)"
|
|
149
|
-
[ -n "$ctx" ] || return 0
|
|
150
|
-
ns="$(app_namespace mysql)"
|
|
151
|
-
account_admin "$ctx" get namespace "$ns" >/dev/null 2>&1 || return 0
|
|
152
|
-
mounted="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
153
|
-
[ -n "$mounted" ] || return 0
|
|
154
|
-
list="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
155
|
-
while IFS= read -r pvc; do
|
|
156
|
-
[ -n "$pvc" ] || continue
|
|
157
|
-
[ "$pvc" != "${mounted}-mysql-0" ] || continue
|
|
158
|
-
printf ' ⚠ volume %s not used : devzone mysql volume\n' "$pvc"
|
|
159
|
-
done <<<"$list"
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
# Closes the gap between wanted and actual: installs, removes, restarts the
|
|
163
|
-
# permanent relay; marks the first failure then moves on
|
|
164
|
-
catalog_apply() {
|
|
165
|
-
local app output code=0 port CTX ns
|
|
166
|
-
while IFS= read -r app; do
|
|
167
|
-
[ -n "$app" ] || continue
|
|
168
|
-
port="$(app_read "$app" port)"
|
|
169
|
-
if [ "$(wanted "$app")" != on ] && present "$app"; then
|
|
170
|
-
if ! output="$(app_remove "$app" 2>&1)"; then
|
|
171
|
-
code=1; app_failure "$app" "$output"
|
|
172
|
-
else
|
|
173
|
-
printf '%s\n' "$output"
|
|
174
|
-
fi
|
|
175
|
-
elif [ "$(wanted "$app")" = on ] && present "$app"; then
|
|
176
|
-
if ! app_ready "$app"; then
|
|
177
|
-
code=1
|
|
178
|
-
echo "devzone : catalog : $app installed but not ready: devzone apply" >&2
|
|
179
|
-
echo "not ready" >"$(failure_file "$app")"
|
|
180
|
-
else
|
|
181
|
-
rm -f "$(failure_file "$app")"
|
|
182
|
-
fi
|
|
183
|
-
# Permanent relay: restarted if stopped
|
|
184
|
-
CTX="$(cluster_saved)" || true
|
|
185
|
-
ns="$(app_namespace "$app")"
|
|
186
|
-
if [ -n "$CTX" ]; then
|
|
187
|
-
if ! output="$(relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port" 2>&1)"; then
|
|
188
|
-
code=1; app_failure "$app" "$output"
|
|
189
|
-
else
|
|
190
|
-
[ -n "$output" ] && printf '%s\n' "$output"
|
|
191
|
-
fi
|
|
192
|
-
fi
|
|
193
|
-
elif [ "$(wanted "$app")" = on ]; then
|
|
194
|
-
if ! output="$(app_install "$app" 2>&1)"; then
|
|
195
|
-
code=1; app_failure "$app" "$output"
|
|
196
|
-
else
|
|
197
|
-
printf '%s\n' "$output"
|
|
198
|
-
fi
|
|
199
|
-
fi
|
|
200
|
-
done <<<"$(catalog_apps)"
|
|
201
|
-
return "$code"
|
|
202
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Catalog hot detection (#414): when .devzone.modules changes, catalog.sh apply
|
|
3
|
-
# runs. A single instance (lock, as #394).
|
|
4
|
-
# catalog-watcher.sh loop | start | stop | tick
|
|
5
|
-
set -euo pipefail
|
|
6
|
-
|
|
7
|
-
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
-
RACINE="${DEVZONE_ROOT:-$(cd "$ICI/../.." && pwd)}"
|
|
9
|
-
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
10
|
-
BASE="${DEVZONE_CATALOG_WATCHER_DIR:-$RACINE/.devzone.catalog-watcher}"
|
|
11
|
-
LOCK_DIR="$BASE/lock"
|
|
12
|
-
LAST_FILE="$BASE/dernier"
|
|
13
|
-
|
|
14
|
-
refuse() { echo "devzone : catalog-watcher : $*" >&2; exit 2; }
|
|
15
|
-
|
|
16
|
-
# Guard (#293): never under bats, only with DEVZONE_CATALOG_REAL=yes
|
|
17
|
-
guard_watcher() {
|
|
18
|
-
if [ "${DEVZONE_CATALOG_REAL:-}" != yes ]; then
|
|
19
|
-
echo "devzone : catalog-watcher : refused here (DEVZONE_CATALOG_REAL=yes)" >&2
|
|
20
|
-
return 2
|
|
21
|
-
fi
|
|
22
|
-
if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
|
|
23
|
-
echo "devzone : catalog-watcher : refused under bats (tests)" >&2
|
|
24
|
-
return 2
|
|
25
|
-
fi
|
|
26
|
-
return 0
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
# Exclusive lock (mkdir) with the pid; a single watcher instance
|
|
30
|
-
lock_take() {
|
|
31
|
-
local start now age pid
|
|
32
|
-
start="$(date +%s)"
|
|
33
|
-
while true; do
|
|
34
|
-
if mkdir "$LOCK_DIR" 2>/dev/null; then echo "$$" >"$LOCK_DIR/pid"; return 0; fi
|
|
35
|
-
now="$(date +%s)"
|
|
36
|
-
age=""; [ -d "$LOCK_DIR" ] && age="$(stat -c %Y "$LOCK_DIR" 2>/dev/null || stat -f %m "$LOCK_DIR" 2>/dev/null || true)"
|
|
37
|
-
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
38
|
-
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$LOCK_DIR"; continue; fi
|
|
39
|
-
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$LOCK_DIR"; continue; fi
|
|
40
|
-
[ "$(( now - start ))" -ge 5 ] && return 1
|
|
41
|
-
sleep 1
|
|
42
|
-
done
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
# Marks the live lock (date and pid up to date)
|
|
46
|
-
lock_refresh() { touch "$LOCK_DIR" 2>/dev/null || true; echo "$$" >"$LOCK_DIR/pid" 2>/dev/null || true; }
|
|
47
|
-
|
|
48
|
-
# One tick: if .devzone.modules changed since the last tick, apply
|
|
49
|
-
tick() {
|
|
50
|
-
local now previous
|
|
51
|
-
[ -f "$ETAT" ] || return 0
|
|
52
|
-
# Restored or rebuilt state: the watcher does not follow a doubtful state,
|
|
53
|
-
# and never uninstalls until devzone apply has confirmed it
|
|
54
|
-
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "$ICI")}/devzone" state recovery-wait && return 0
|
|
55
|
-
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "$ICI")}/devzone" state recovery-pending && return 0
|
|
56
|
-
mkdir -p "$BASE"
|
|
57
|
-
now="$(stat -c %Y "$ETAT" 2>/dev/null || stat -f %m "$ETAT" 2>/dev/null || true)"
|
|
58
|
-
[ -n "$now" ] || return 0
|
|
59
|
-
previous="$(cat "$LAST_FILE" 2>/dev/null || true)"
|
|
60
|
-
if [ "$now" != "$previous" ]; then
|
|
61
|
-
echo "$now" >"$LAST_FILE"
|
|
62
|
-
echo "devzone : catalog-watcher : .devzone.modules changed, applying" >&2
|
|
63
|
-
bash "$ICI/../catalog.sh" apply
|
|
64
|
-
fi
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
# Loop: one tick every 5 s, lock refreshed on each tick
|
|
68
|
-
loop() {
|
|
69
|
-
mkdir -p "$BASE"
|
|
70
|
-
if ! lock_take; then return 0; fi
|
|
71
|
-
trap 'rm -rf "$LOCK_DIR"' EXIT INT TERM
|
|
72
|
-
while true; do
|
|
73
|
-
[ -f "$ETAT" ] || { rm -rf "$LOCK_DIR"; break; }
|
|
74
|
-
lock_refresh
|
|
75
|
-
tick || true
|
|
76
|
-
sleep 5
|
|
77
|
-
done
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# Starts the detached loop (#435) and checks that its lock is alive
|
|
81
|
-
start_detached() {
|
|
82
|
-
local i pid stable=0 detache=()
|
|
83
|
-
mkdir -p "$BASE"
|
|
84
|
-
# Same detachment as relay_start: setsid when present, else nohup.
|
|
85
|
-
command -v setsid >/dev/null 2>&1 && detache=(setsid)
|
|
86
|
-
${detache[@]+"${detache[@]}"} nohup env DEVZONE_CATALOG_REAL=yes bash "$0" loop >"$BASE/veilleur.log" 2>&1 &
|
|
87
|
-
i=0
|
|
88
|
-
while [ "$i" -lt 20 ]; do
|
|
89
|
-
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
90
|
-
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
|
91
|
-
stable=$((stable + 1))
|
|
92
|
-
[ "$stable" -ge 5 ] && { echo "started"; return 0; }
|
|
93
|
-
else
|
|
94
|
-
stable=0
|
|
95
|
-
fi
|
|
96
|
-
sleep 0.1
|
|
97
|
-
i=$((i + 1))
|
|
98
|
-
done
|
|
99
|
-
echo "devzone : catalog-watcher : cannot start, see $BASE/veilleur.log" >&2
|
|
100
|
-
return 1
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
# Stops the watcher and removes the lock
|
|
104
|
-
stop_watcher() {
|
|
105
|
-
local pid
|
|
106
|
-
pid="$(cat "$LOCK_DIR/pid" 2>/dev/null || true)"
|
|
107
|
-
if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi
|
|
108
|
-
rm -rf "$LOCK_DIR"
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
case "${1:-}" in
|
|
112
|
-
loop) if ! guard_watcher; then exit 2; fi; loop ;;
|
|
113
|
-
start)
|
|
114
|
-
if ! guard_watcher; then exit 2; fi
|
|
115
|
-
if [ -f "$LOCK_DIR/pid" ] && kill -0 "$(cat "$LOCK_DIR/pid")" 2>/dev/null; then
|
|
116
|
-
echo "already running"
|
|
117
|
-
else
|
|
118
|
-
start_detached || exit 1
|
|
119
|
-
fi
|
|
120
|
-
;;
|
|
121
|
-
stop) stop_watcher ; echo "stopped" ;;
|
|
122
|
-
tick) tick ;;
|
|
123
|
-
*)
|
|
124
|
-
echo "devzone : catalog-watcher : loop | start | stop | tick" >&2
|
|
125
|
-
exit 2
|
|
126
|
-
;;
|
|
127
|
-
esac
|