devzone 7.2.0 → 7.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/.devcontainer/catalog/catalog-watcher.sh +2 -5
- package/.devcontainer/catalog.sh +4 -27
- package/.devcontainer/cluster.sh +1 -4
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +26 -15
- package/.devcontainer/devzone-modules.sh +9 -20
- package/.devcontainer/devzone-status.sh +1 -1
- package/.devcontainer/ports.sh +2 -5
- package/.devcontainer/services-admin.sh +3 -6
- 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/manage/devzone +3 -1
- 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/state-gitops.sh +0 -23
- package/.devcontainer/state-json.sh +0 -282
- package/.devcontainer/state-lock.sh +0 -53
- package/.devcontainer/state.sh +0 -219
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,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# GitOps repository line of the state in the Kubernetes workspace pod (#639).
|
|
3
|
-
# The pod has no kubeconfig and its service account cannot read Applications
|
|
4
|
-
# today: one short read of the root Application tells whether Argo CD manages
|
|
5
|
-
# the cluster from Git; a refusal or an absence falls back to the workstation
|
|
6
|
-
# state. Sourced by devzone, called only when in_pod is true.
|
|
7
|
-
|
|
8
|
-
# Namespace of the Argo CD of devzone: GITOPS_NS when the includer knows it
|
|
9
|
-
# (argocd/gitops.sh), otherwise the namespace of the module.
|
|
10
|
-
: "${GITOPS_NS:=devzone-argocd}"
|
|
11
|
-
|
|
12
|
-
# State line of the GitOps repository: the URL of the root Application when
|
|
13
|
-
# the pod can read it, otherwise the workstation command that shows the state
|
|
14
|
-
gitops_state_line() {
|
|
15
|
-
local url
|
|
16
|
-
url="$(kubectl get application devzone -n "$GITOPS_NS" \
|
|
17
|
-
-o jsonpath='{.spec.source.repoURL}' --request-timeout=5s 2>/dev/null || true)"
|
|
18
|
-
if [ -n "$url" ]; then
|
|
19
|
-
printf ' ○ argocd GitOps repository: %s\n' "$url"
|
|
20
|
-
else
|
|
21
|
-
printf ' ○ argocd managed from the workstation: devzone workspace argocd status\n'
|
|
22
|
-
fi
|
|
23
|
-
}
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Machine output of devzone status (--json): stable, versioned JSON object.
|
|
3
|
-
# Sourced by devzone: reuses its functions (value_of, description, …), does not
|
|
4
|
-
# rewrite etat(). Built only with jq. JSON keys are a contract: English names
|
|
5
|
-
# (#733), listed in manage/docs/reference.md.
|
|
6
|
-
|
|
7
|
-
# Adds an entry to $errors: the section that failed and why.
|
|
8
|
-
add_error() {
|
|
9
|
-
errors="$(jq -c --arg k "$1" --arg v "$2" '. + {($k): $v}' <<<"$errors")"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
# Adds an alert (code, message, devzone command to run) to $alerts_json.
|
|
13
|
-
append_alert() {
|
|
14
|
-
local code="$1" message="$2" command="${3:-}"
|
|
15
|
-
alerts_json="$(jq -c \
|
|
16
|
-
--arg code "$code" \
|
|
17
|
-
--arg message "$message" \
|
|
18
|
-
--arg command "$command" \
|
|
19
|
-
'. + [{code:$code,message:$message,command:(if $command=="" then null else $command end)}]' \
|
|
20
|
-
<<<"$alerts_json")"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
# Full state of the machine in JSON: repeats each section of etat() with the
|
|
24
|
-
# same commands, isolating each computation (failure → null value and errors).
|
|
25
|
-
state_json() {
|
|
26
|
-
local errors='{}'
|
|
27
|
-
local alerts_json='[]'
|
|
28
|
-
local dv_raw="" dvp_raw=""
|
|
29
|
-
local id_name="" id_email="" id_ok=false id_command=""
|
|
30
|
-
local platform_name platform_url="" github_json="null"
|
|
31
|
-
local tools_late_json='[]' tools_command=""
|
|
32
|
-
local modules_json='[]' m active desc failure_file content state_value failure_value command_value out argocd_repo=""
|
|
33
|
-
local services_cluster="" services_remote=false
|
|
34
|
-
local work_ctx="" work_internal=false host_ctx=""
|
|
35
|
-
local clusters_services_raw="" clusters_work_raw="" clusters_command=""
|
|
36
|
-
local ports_json='[]' ports_out
|
|
37
|
-
local applications_json='[]'
|
|
38
|
-
local credentials_raw=""
|
|
39
|
-
local late_out package frozen installed count
|
|
40
|
-
local packages_marker packages_names n path wt_out
|
|
41
|
-
local gh_status gh_code
|
|
42
|
-
|
|
43
|
-
if v="$(folder_version 2>/dev/null)"; then
|
|
44
|
-
dv_raw="$v"
|
|
45
|
-
else
|
|
46
|
-
add_error devzone "folder_version unavailable"
|
|
47
|
-
fi
|
|
48
|
-
dvp_raw="$(published_version 2>/dev/null || true)"
|
|
49
|
-
|
|
50
|
-
id_name="$(git config --get user.name 2>/dev/null || true)"
|
|
51
|
-
id_email="$(git config --get user.email 2>/dev/null || true)"
|
|
52
|
-
if [ -n "$id_name" ] && [ -n "$id_email" ]; then
|
|
53
|
-
id_ok=true
|
|
54
|
-
else
|
|
55
|
-
id_command='gh auth login -s workflow (automatic), or git config --file ~/.config/git/config user.name "<name>" and user.email "<email>"'
|
|
56
|
-
fi
|
|
57
|
-
|
|
58
|
-
platform_name="$(platform_read)"
|
|
59
|
-
if [ "$platform_name" = gitlab ]; then
|
|
60
|
-
platform_url="$(gitlab_url_read)"
|
|
61
|
-
else
|
|
62
|
-
platform_url=""
|
|
63
|
-
fi
|
|
64
|
-
if [ "$platform_name" = github ]; then
|
|
65
|
-
gh_status="$(gh auth status 2>&1)" && gh_code=0 || gh_code=$?
|
|
66
|
-
if [ "$gh_code" -ne 0 ]; then
|
|
67
|
-
github_json="null"
|
|
68
|
-
add_error github "gh auth status failed"
|
|
69
|
-
else
|
|
70
|
-
if printf '%s\n' "$gh_status" | grep -q "Token scopes:" && ! printf '%s\n' "$gh_status" | grep -q "'workflow'"; then
|
|
71
|
-
github_json="$(jq -cn '{connected:true,workflow:false,command:"gh auth refresh -h github.com -s workflow"}')"
|
|
72
|
-
else
|
|
73
|
-
github_json="$(jq -cn '{connected:true,workflow:true,command:null}')"
|
|
74
|
-
fi
|
|
75
|
-
fi
|
|
76
|
-
else
|
|
77
|
-
github_json="null"
|
|
78
|
-
fi
|
|
79
|
-
|
|
80
|
-
if late_out="$(outdated_tools 2>/dev/null)"; then
|
|
81
|
-
tools_late_json='[]'
|
|
82
|
-
while IFS= read -r line; do
|
|
83
|
-
[ -n "$line" ] || continue
|
|
84
|
-
# shellcheck disable=SC2086
|
|
85
|
-
set -- $line
|
|
86
|
-
package="${1:-}"; frozen="${2:-}"; installed="${3:-}"
|
|
87
|
-
[ -n "$package" ] || continue
|
|
88
|
-
tools_late_json="$(jq -c \
|
|
89
|
-
--arg p "$package" --arg f "$frozen" --arg i "$installed" \
|
|
90
|
-
'. + [{package:$p,frozen:$f,installed:$i}]' <<<"$tools_late_json")"
|
|
91
|
-
done <<<"$late_out"
|
|
92
|
-
count="$(jq 'length' <<<"$tools_late_json" 2>/dev/null || echo 0)"
|
|
93
|
-
if [ "$count" -gt 0 ]; then
|
|
94
|
-
tools_command="devzone apply"
|
|
95
|
-
fi
|
|
96
|
-
else
|
|
97
|
-
tools_late_json="null"
|
|
98
|
-
add_error tools "outdated_tools unavailable"
|
|
99
|
-
fi
|
|
100
|
-
|
|
101
|
-
modules_json='[]'
|
|
102
|
-
for m in "${MODULES[@]}"; do
|
|
103
|
-
active=false
|
|
104
|
-
[ "$(value_of "$m")" = on ] && active=true
|
|
105
|
-
desc="$(description "$m")"
|
|
106
|
-
failure_value=""
|
|
107
|
-
state_value=""
|
|
108
|
-
command_value=""
|
|
109
|
-
if in_pod && service_module "$m"; then
|
|
110
|
-
# Kubernetes workspace pod (#528): presence by the cluster DNS,
|
|
111
|
-
# installation from the workstation; no failure marker read here
|
|
112
|
-
if service_present "$m"; then
|
|
113
|
-
state_value="active: $(service_dns "$m")"
|
|
114
|
-
elif [ "$active" = true ]; then
|
|
115
|
-
state_value="not in the cluster"
|
|
116
|
-
command_value="devzone workspace services enable $m"
|
|
117
|
-
else
|
|
118
|
-
state_value="optional"
|
|
119
|
-
command_value="devzone workspace services enable $m"
|
|
120
|
-
fi
|
|
121
|
-
elif [ "$active" = true ]; then
|
|
122
|
-
failure_file="$(failure_marker_file "$m")"
|
|
123
|
-
if [ -f "$failure_file" ]; then
|
|
124
|
-
content="$(cat "$failure_file" 2>/dev/null || true)"
|
|
125
|
-
failure_value="$content"
|
|
126
|
-
state_value="failed"
|
|
127
|
-
command_value="devzone apply"
|
|
128
|
-
elif [ "$m" = gitlab ]; then
|
|
129
|
-
if out="$(devzone gitlab status 2>/dev/null)"; then
|
|
130
|
-
state_value="$out"
|
|
131
|
-
else
|
|
132
|
-
state_value=""
|
|
133
|
-
add_error modules "gitlab status unavailable"
|
|
134
|
-
fi
|
|
135
|
-
elif [ "$m" = postgres ] || [ "$m" = llm ]; then
|
|
136
|
-
if out="$(bash "$ICI/$m/$m.sh" status 2>/dev/null)"; then
|
|
137
|
-
state_value="$out"
|
|
138
|
-
else
|
|
139
|
-
state_value=""
|
|
140
|
-
add_error modules "$m.sh state unavailable"
|
|
141
|
-
fi
|
|
142
|
-
elif [ "$m" = argocd ]; then
|
|
143
|
-
if out="$("$ICI/devzone" argocd status 2>/dev/null)"; then
|
|
144
|
-
state_value="$out"
|
|
145
|
-
else
|
|
146
|
-
state_value=""
|
|
147
|
-
fi
|
|
148
|
-
elif [ "$m" = mysql ]; then
|
|
149
|
-
if out="$(devzone mysql status 2>/dev/null)"; then
|
|
150
|
-
state_value="$out"
|
|
151
|
-
else
|
|
152
|
-
state_value=""
|
|
153
|
-
add_error modules "mysql.sh status unavailable"
|
|
154
|
-
fi
|
|
155
|
-
else
|
|
156
|
-
state_value="active"
|
|
157
|
-
fi
|
|
158
|
-
else
|
|
159
|
-
state_value="optional"
|
|
160
|
-
command_value="devzone enable $m"
|
|
161
|
-
fi
|
|
162
|
-
modules_json="$(jq -c \
|
|
163
|
-
--arg name "$m" \
|
|
164
|
-
--argjson active "$active" \
|
|
165
|
-
--arg description "$desc" \
|
|
166
|
-
--arg state "$state_value" \
|
|
167
|
-
--arg failure "$failure_value" \
|
|
168
|
-
--arg command "$command_value" \
|
|
169
|
-
'. + [{name:$name,active:$active,description:$description,state:(if $state=="" then null else $state end),failed:(if $failure=="" then null else $failure end),command:(if $command=="" then null else $command end)}]' \
|
|
170
|
-
<<<"$modules_json")"
|
|
171
|
-
done
|
|
172
|
-
|
|
173
|
-
services_cluster="$(cluster_saved)"
|
|
174
|
-
if [ -n "$services_cluster" ] && ! cluster_is_local "$services_cluster"; then
|
|
175
|
-
services_remote=true
|
|
176
|
-
fi
|
|
177
|
-
clusters_services_raw="$services_cluster"
|
|
178
|
-
work_ctx="$(kubectl config current-context 2>/dev/null || true)"
|
|
179
|
-
case "$work_ctx" in
|
|
180
|
-
kind-gitlab* | kind-devzone*)
|
|
181
|
-
host_ctx="$(KUBECONFIG="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
|
|
182
|
-
if [ -n "$host_ctx" ] && cluster_reachable "$host_ctx" 2>/dev/null; then
|
|
183
|
-
work_internal=true
|
|
184
|
-
fi
|
|
185
|
-
;;
|
|
186
|
-
esac
|
|
187
|
-
clusters_work_raw="$work_ctx"
|
|
188
|
-
if [ "$work_internal" = true ]; then
|
|
189
|
-
clusters_command="devzone use $host_ctx"
|
|
190
|
-
fi
|
|
191
|
-
|
|
192
|
-
devzone cluster clean --quiet >/dev/null 2>&1 || [ $? -ne 3 ] || append_alert cluster_disk "cluster disk almost full" "devzone repair"
|
|
193
|
-
if ports_out="$(bash "$ICI/ports.sh" list --json 2>/dev/null)"; then
|
|
194
|
-
if printf '%s' "$ports_out" | jq -e . >/dev/null 2>&1; then
|
|
195
|
-
ports_json="$ports_out"
|
|
196
|
-
else
|
|
197
|
-
ports_json="null"
|
|
198
|
-
add_error ports "ports output unreadable"
|
|
199
|
-
fi
|
|
200
|
-
else
|
|
201
|
-
ports_json="null"
|
|
202
|
-
add_error ports "ports.sh unavailable"
|
|
203
|
-
fi
|
|
204
|
-
|
|
205
|
-
applications_json="$(bash "$ICI/catalog.sh" json 2>/dev/null || echo '[]')"
|
|
206
|
-
if ! printf '%s' "$applications_json" | jq -e . >/dev/null 2>&1; then
|
|
207
|
-
applications_json='[]'
|
|
208
|
-
add_error modules "catalog.sh json unavailable"
|
|
209
|
-
fi
|
|
210
|
-
|
|
211
|
-
if [ -f "$RACINE/.password" ]; then
|
|
212
|
-
credentials_raw="$RACINE/.password"
|
|
213
|
-
fi
|
|
214
|
-
|
|
215
|
-
packages_marker="${DEVZONE_PACKAGES_MARKER:-/tmp/devzone-packages.failed}"
|
|
216
|
-
if [ -f "$packages_marker" ]; then
|
|
217
|
-
packages_names=""
|
|
218
|
-
while IFS= read -r n; do
|
|
219
|
-
[ -n "$n" ] || continue
|
|
220
|
-
packages_names="${packages_names:+$packages_names, }$n"
|
|
221
|
-
done < "$packages_marker"
|
|
222
|
-
append_alert packages "$packages_names" "devzone packages"
|
|
223
|
-
fi
|
|
224
|
-
wt_out="$(missing_worktrees 2>/dev/null || true)"
|
|
225
|
-
while IFS= read -r path; do
|
|
226
|
-
[ -n "$path" ] || continue
|
|
227
|
-
append_alert worktree "$path missing here (created outside the container?)" ""
|
|
228
|
-
done <<<"$wt_out"
|
|
229
|
-
if [ -n "$services_cluster" ] && ! cluster_is_local "$services_cluster"; then
|
|
230
|
-
append_alert cluster_distant "remote cluster: $services_cluster — services on a remote cluster" ""
|
|
231
|
-
fi
|
|
232
|
-
if [ "$work_internal" = true ]; then
|
|
233
|
-
append_alert cluster_interne "work cluster: $work_ctx (devzone internal cluster)" "devzone use $host_ctx"
|
|
234
|
-
fi
|
|
235
|
-
|
|
236
|
-
argocd_repo="$(conf_get argocd repo)"
|
|
237
|
-
|
|
238
|
-
jq -n \
|
|
239
|
-
--argjson schema 3 \
|
|
240
|
-
--arg dv "$dv_raw" \
|
|
241
|
-
--arg dvp "$dvp_raw" \
|
|
242
|
-
--argjson id_ok "$id_ok" \
|
|
243
|
-
--arg id_name "$id_name" \
|
|
244
|
-
--arg id_email "$id_email" \
|
|
245
|
-
--arg id_command "$id_command" \
|
|
246
|
-
--arg platform_name "$platform_name" \
|
|
247
|
-
--arg platform_url "$platform_url" \
|
|
248
|
-
--argjson github "$github_json" \
|
|
249
|
-
--argjson tools_late "$tools_late_json" \
|
|
250
|
-
--arg tools_command "$tools_command" \
|
|
251
|
-
--argjson modules "$modules_json" \
|
|
252
|
-
--arg argocd_repo "$argocd_repo" \
|
|
253
|
-
--arg clusters_services "$clusters_services_raw" \
|
|
254
|
-
--argjson services_remote "$services_remote" \
|
|
255
|
-
--arg clusters_work "$clusters_work_raw" \
|
|
256
|
-
--argjson work_internal "$work_internal" \
|
|
257
|
-
--arg clusters_command "$clusters_command" \
|
|
258
|
-
--argjson ports "$ports_json" \
|
|
259
|
-
--argjson applications "$applications_json" \
|
|
260
|
-
--arg credentials "$credentials_raw" \
|
|
261
|
-
--argjson alerts "$alerts_json" \
|
|
262
|
-
--argjson errors "$errors" \
|
|
263
|
-
'{
|
|
264
|
-
schema: $schema,
|
|
265
|
-
devzone: { version: (if $dv=="" then null else $dv end), available: (if $dvp=="" then null else $dvp end) },
|
|
266
|
-
git_identity: { ok: $id_ok, name: (if $id_name=="" then null else $id_name end), email: (if $id_email=="" then null else $id_email end), command: (if $id_command=="" then null else $id_command end) },
|
|
267
|
-
platform: { name: $platform_name, url: (if $platform_url=="" then null else $platform_url end), github: $github },
|
|
268
|
-
argocd_repo: (if $argocd_repo == "" then null else $argocd_repo end),
|
|
269
|
-
tools: { outdated: $tools_late, command: (if $tools_command=="" then null else $tools_command end) },
|
|
270
|
-
modules: $modules,
|
|
271
|
-
clusters: { services: (if $clusters_services=="" then null else $clusters_services end), services_remote: $services_remote, work: (if $clusters_work=="" then null else $clusters_work end), internal_work: $work_internal, command: (if $clusters_command=="" then null else $clusters_command end) },
|
|
272
|
-
ports: $ports,
|
|
273
|
-
applications: (if $applications=="" then null else $applications end),
|
|
274
|
-
credentials: (if $credentials=="" then null else $credentials end),
|
|
275
|
-
alerts: $alerts,
|
|
276
|
-
errors: $errors
|
|
277
|
-
}'
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
281
|
-
state_json
|
|
282
|
-
fi
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Write lock of the module state, sourced by state.sh (#417 and #476)
|
|
3
|
-
# state_lock_take / state_lock_release write lock
|
|
4
|
-
|
|
5
|
-
# Exclusive lock (mkdir): one write at a time. A vanished holder is guessed
|
|
6
|
-
# from the age of the folder (no kill) and the depth counter makes the lock
|
|
7
|
-
# re-takeable within the same process (init then write).
|
|
8
|
-
state_lock_take() {
|
|
9
|
-
local age start
|
|
10
|
-
[ "${STATE_LOCK_DEPTH:-0}" -gt 0 ] && { STATE_LOCK_DEPTH=$((STATE_LOCK_DEPTH + 1)); return 0; }
|
|
11
|
-
mkdir -p "$(dirname "$ETAT")" || return 1
|
|
12
|
-
start="$(date +%s)"
|
|
13
|
-
while ! mkdir "${ETAT}.lockdir" 2>/dev/null; do
|
|
14
|
-
age="$(stat -c %Y "${ETAT}.lockdir" 2>/dev/null || stat -f %m "${ETAT}.lockdir" 2>/dev/null || true)"
|
|
15
|
-
if [ -n "$age" ] && [ "$(( $(date +%s) - age ))" -gt 30 ]; then
|
|
16
|
-
rm -rf "${ETAT}.lockdir"
|
|
17
|
-
continue
|
|
18
|
-
fi
|
|
19
|
-
if [ "$(( $(date +%s) - start ))" -ge 10 ]; then
|
|
20
|
-
echo "devzone : state locked elsewhere: ${ETAT}.lockdir" >&2
|
|
21
|
-
return 1
|
|
22
|
-
fi
|
|
23
|
-
sleep 1
|
|
24
|
-
done
|
|
25
|
-
# flock serializes the write when it exists (Linux); mkdir stays the only
|
|
26
|
-
# guard on macOS (#476, same pattern as #461).
|
|
27
|
-
if command -v flock >/dev/null 2>&1; then
|
|
28
|
-
if { exec 8>"${ETAT}.lock"; } && flock -w 10 8; then
|
|
29
|
-
STATE_LOCK_FLOCK=1
|
|
30
|
-
else
|
|
31
|
-
rm -rf "${ETAT}.lockdir" 2>/dev/null || true
|
|
32
|
-
echo "devzone : state locked elsewhere (flock): ${ETAT}.lock" >&2
|
|
33
|
-
return 1
|
|
34
|
-
fi
|
|
35
|
-
fi
|
|
36
|
-
STATE_LOCK_DEPTH=1
|
|
37
|
-
return 0
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
# Releases the lock taken by this process; depth > 1: still held
|
|
41
|
-
state_lock_release() {
|
|
42
|
-
local depth="${STATE_LOCK_DEPTH:-0}"
|
|
43
|
-
[ "$depth" -gt 0 ] || return 0
|
|
44
|
-
[ "$depth" -gt 1 ] && { STATE_LOCK_DEPTH=$((depth - 1)); return 0; }
|
|
45
|
-
STATE_LOCK_DEPTH=0
|
|
46
|
-
if [ "${STATE_LOCK_FLOCK:-0}" = 1 ]; then
|
|
47
|
-
flock -u 8 2>/dev/null || true
|
|
48
|
-
exec 8>&-
|
|
49
|
-
STATE_LOCK_FLOCK=0
|
|
50
|
-
fi
|
|
51
|
-
rm -rf "${ETAT}.lockdir" 2>/dev/null || true
|
|
52
|
-
return 0
|
|
53
|
-
}
|