devzone 1.0.0 → 2.0.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.
Files changed (79) hide show
  1. package/.devcontainer/Dockerfile +4 -4
  2. package/.devcontainer/agent-errors.sh +154 -0
  3. package/.devcontainer/agent-local.sh +2 -2
  4. package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
  5. package/.devcontainer/{agent-modele.sh → agent-model.sh} +8 -8
  6. package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
  7. package/.devcontainer/agent-session.sh +122 -125
  8. package/.devcontainer/agent-state-json.sh +117 -0
  9. package/.devcontainer/agent-workspace.sh +53 -53
  10. package/.devcontainer/agent.sh +113 -115
  11. package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
  12. package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +4 -4
  13. package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +3 -3
  14. package/.devcontainer/argocd/argocd.sh +8 -8
  15. package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +1 -1
  16. package/.devcontainer/argocd/services-hook.sh +5 -5
  17. package/.devcontainer/{catalogue → catalog}/app.sh +4 -4
  18. package/.devcontainer/{catalogue/catalogue-veilleur.sh → catalog/catalog-watcher.sh} +7 -7
  19. package/.devcontainer/{catalogue → catalog}/mysql/mysql.sh +7 -7
  20. package/.devcontainer/{catalogue.sh → catalog.sh} +13 -13
  21. package/.devcontainer/cluster.sh +8 -8
  22. package/.devcontainer/devcontainer.json +1 -1
  23. package/.devcontainer/devzone +55 -54
  24. package/.devcontainer/{docker-relais.sh → docker-relay.sh} +2 -2
  25. package/.devcontainer/gitlab/argocd.sh +2 -2
  26. package/.devcontainer/gitlab/gitlab.sh +4 -4
  27. package/.devcontainer/gitlab/installation.sh +5 -5
  28. package/.devcontainer/gitlab/secrets.sh +1 -1
  29. package/.devcontainer/help.sh +1 -0
  30. package/.devcontainer/{kind-enveloppe.sh → kind-wrapper.sh} +5 -5
  31. package/.devcontainer/{kube-compte.sh → kube-account.sh} +3 -3
  32. package/.devcontainer/{kube-joignable.sh → kube-reachable.sh} +1 -1
  33. package/.devcontainer/memory.sh +113 -0
  34. package/.devcontainer/metrics-server.sh +52 -51
  35. package/.devcontainer/{paquets.sh → packages.sh} +4 -4
  36. package/.devcontainer/password.sh +88 -87
  37. package/.devcontainer/ports-auto.sh +7 -7
  38. package/.devcontainer/ports.sh +4 -4
  39. package/.devcontainer/post-create.sh +2 -2
  40. package/.devcontainer/postgres/postgres.sh +3 -3
  41. package/.devcontainer/services-admin.sh +5 -5
  42. package/.devcontainer/skills/devzone/SKILL.md +1 -1
  43. package/.devcontainer/{demarrage.sh → startup.sh} +5 -5
  44. package/.devcontainer/state-json.sh +308 -0
  45. package/.devcontainer/state-lock.sh +53 -0
  46. package/.devcontainer/state.sh +219 -0
  47. package/.devcontainer/workspace-init.sh +1 -1
  48. package/Makefile +7 -7
  49. package/README.md +2 -2
  50. package/charts/devzone-workspace/templates/statefulset.yaml +3 -0
  51. package/manage/devzone +3 -3
  52. package/manage/scripts/check-go-layout.sh +40 -0
  53. package/manage/scripts/check-names.sh +60 -0
  54. package/manage/scripts/devzone-create.sh +2 -2
  55. package/manage/scripts/devzone-manifest.sh +2 -2
  56. package/manage/scripts/docker-workstation.sh +2 -2
  57. package/manage/scripts/docker.sh +2 -2
  58. package/manage/scripts/{lancer.sh → launch.sh} +3 -3
  59. package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +1 -1
  60. package/manage/scripts/{migrer.sh → migrate.sh} +1 -1
  61. package/manage/workspace.sh +4 -4
  62. package/package.json +1 -1
  63. package/.devcontainer/agent-erreurs.sh +0 -138
  64. package/.devcontainer/agent-etat-json.sh +0 -115
  65. package/.devcontainer/etat-json.sh +0 -308
  66. package/.devcontainer/etat-verrou.sh +0 -52
  67. package/.devcontainer/etat.sh +0 -220
  68. package/.devcontainer/memoire.sh +0 -113
  69. /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
  70. /package/.devcontainer/{ia → ai}/host-check.message +0 -0
  71. /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
  72. /package/.devcontainer/{ia → ai}/host-models.sh +0 -0
  73. /package/.devcontainer/{catalogue → catalog}/mysql/app.conf +0 -0
  74. /package/.devcontainer/{catalogue/mysql/installer.sh → catalog/mysql/install.sh} +0 -0
  75. /package/.devcontainer/{catalogue → catalog}/mysql/volume.sh +0 -0
  76. /package/.devcontainer/{docker-sans-hote.sh → docker-without-host.sh} +0 -0
  77. /package/.devcontainer/{isolement.sh → isolation.sh} +0 -0
  78. /package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +0 -0
  79. /package/manage/scripts/{desinstaller.sh → uninstall.sh} +0 -0
@@ -0,0 +1,308 @@
1
+ #!/usr/bin/env bash
2
+ # Machine output of devzone status (--json): stable, versioned JSON object.
3
+ # Sourced by devzone: reuses its functions (valeur, description, …), does not
4
+ # rewrite etat(). Built only with jq. JSON keys are a contract: French names kept.
5
+
6
+ # Adds an entry to $errors: the section that failed and why.
7
+ add_error() {
8
+ errors="$(jq -c --arg k "$1" --arg v "$2" '. + {($k): $v}' <<<"$errors")"
9
+ }
10
+
11
+ # Adds an alert (code, message, devzone command to run) to $alerts_json.
12
+ append_alert() {
13
+ local code="$1" message="$2" command="${3:-}"
14
+ alerts_json="$(jq -c \
15
+ --arg code "$code" \
16
+ --arg message "$message" \
17
+ --arg command "$command" \
18
+ '. + [{code:$code,message:$message,commande:(if $command=="" then null else $command end)}]' \
19
+ <<<"$alerts_json")"
20
+ }
21
+
22
+ # Full state of the machine in JSON: repeats each section of etat() with the
23
+ # same commands, isolating each computation (failure → null value and errors).
24
+ state_json() {
25
+ local errors='{}'
26
+ local alerts_json='[]'
27
+ local dv_raw="" dvp_raw=""
28
+ local id_name="" id_email="" id_ok=false id_command=""
29
+ local platform_name platform_url="" github_json="null"
30
+ local tools_late_json='[]' tools_command=""
31
+ local modules_json='[]' m active desc failure_file content state_value failure_value command_value out argocd_repo=""
32
+ local docker_host=false docker_host_active=false relay_source
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 relay_marker packages_marker packages_names n path wt_out
41
+ local gh_status gh_code
42
+
43
+ if v="$(version_du_dossier 2>/dev/null)"; then
44
+ dv_raw="$v"
45
+ else
46
+ add_error devzone "version_du_dossier unavailable"
47
+ fi
48
+ dvp_raw="$(version_publiee 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="$(plateforme_lue)"
59
+ if [ "$platform_name" = gitlab ]; then
60
+ platform_url="$(url_gitlab_lue)"
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 '{connecte:true,workflow:false,commande:"gh auth refresh -h github.com -s workflow"}')"
72
+ else
73
+ github_json="$(jq -cn '{connecte:true,workflow:true,commande:null}')"
74
+ fi
75
+ fi
76
+ else
77
+ github_json="null"
78
+ fi
79
+
80
+ if late_out="$(outils_retard 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
+ '. + [{paquet:$p,figee:$f,installee:$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 outils "outils_retard unavailable"
99
+ fi
100
+
101
+ modules_json='[]'
102
+ for m in "${MODULES[@]}"; do
103
+ active=false
104
+ [ "$(valeur "$m")" = on ] && active=true
105
+ desc="$(description "$m")"
106
+ failure_value=""
107
+ state_value=""
108
+ command_value=""
109
+ if dans_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="$(fichier_echec "$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="$(bash "$ICI/gitlab/gitlab.sh" status 2>/dev/null)"; then
130
+ state_value="$out"
131
+ else
132
+ state_value=""
133
+ add_error modules "gitlab.sh 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="$(bash "$ICI/argocd/argocd.sh" status 2>/dev/null)"; then
144
+ state_value="$out"
145
+ else
146
+ state_value=""
147
+ add_error modules "argocd.sh status unavailable"
148
+ fi
149
+ elif [ "$m" = mysql ]; then
150
+ if out="$(bash "$ICI/catalog/mysql/mysql.sh" status 2>/dev/null)"; then
151
+ state_value="$out"
152
+ else
153
+ state_value=""
154
+ add_error modules "mysql.sh status unavailable"
155
+ fi
156
+ else
157
+ state_value="active"
158
+ fi
159
+ else
160
+ state_value="optional"
161
+ command_value="devzone enable $m"
162
+ fi
163
+ modules_json="$(jq -c \
164
+ --arg name "$m" \
165
+ --argjson active "$active" \
166
+ --arg description "$desc" \
167
+ --arg state "$state_value" \
168
+ --arg failure "$failure_value" \
169
+ --arg command "$command_value" \
170
+ '. + [{nom:$name,actif:$active,description:$description,etat:(if $state=="" then null else $state end),echec:(if $failure=="" then null else $failure end),commande:(if $command=="" then null else $command end)}]' \
171
+ <<<"$modules_json")"
172
+ done
173
+
174
+ # docker-hote option (#432): absent = on; socket really mounted (same
175
+ # source as docker-relay.sh), may differ until make rebuild
176
+ # In the Kubernetes workspace (DEVZONE_WORKSPACE=kubernetes), the pod has
177
+ # no Docker host socket: the socket is absent (#515)
178
+ if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
179
+ docker_host=false
180
+ docker_host_active=false
181
+ else
182
+ if [ "$(valeur docker-hote)" = on ]; then
183
+ docker_host=true
184
+ fi
185
+ relay_source="${DEVZONE_RELAIS_SOURCE:-/var/run/docker-host.sock}"
186
+ if [ -e "$relay_source" ]; then
187
+ docker_host_active=true
188
+ fi
189
+ fi
190
+
191
+ services_cluster="$(cluster_lu)"
192
+ if [ -n "$services_cluster" ] && ! cluster_est_local "$services_cluster"; then
193
+ services_remote=true
194
+ fi
195
+ clusters_services_raw="$services_cluster"
196
+ work_ctx="$(kubectl config current-context 2>/dev/null || true)"
197
+ case "$work_ctx" in
198
+ kind-gitlab* | kind-devzone*)
199
+ host_ctx="$(KUBECONFIG="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
200
+ if [ -n "$host_ctx" ] && cluster_joignable "$host_ctx" 2>/dev/null; then
201
+ work_internal=true
202
+ fi
203
+ ;;
204
+ esac
205
+ clusters_work_raw="$work_ctx"
206
+ if [ "$work_internal" = true ]; then
207
+ clusters_command="devzone use $host_ctx"
208
+ fi
209
+
210
+ if ports_out="$(bash "$ICI/ports.sh" list --json 2>/dev/null)"; then
211
+ if printf '%s' "$ports_out" | jq -e . >/dev/null 2>&1; then
212
+ ports_json="$ports_out"
213
+ else
214
+ ports_json="null"
215
+ add_error ports "ports output unreadable"
216
+ fi
217
+ else
218
+ ports_json="null"
219
+ add_error ports "ports.sh unavailable"
220
+ fi
221
+
222
+ applications_json="$(bash "$ICI/catalog.sh" json 2>/dev/null || echo '[]')"
223
+ if ! printf '%s' "$applications_json" | jq -e . >/dev/null 2>&1; then
224
+ applications_json='[]'
225
+ add_error modules "catalog.sh json unavailable"
226
+ fi
227
+
228
+ if [ -f "$RACINE/.password" ]; then
229
+ credentials_raw="$RACINE/.password"
230
+ fi
231
+
232
+ relay_marker="${DEVZONE_RELAIS_MARQUE:-/tmp/devzone-relais-docker.echec}"
233
+ if [ -f "$relay_marker" ]; then
234
+ msg="$(head -1 "$relay_marker" 2>/dev/null || true)"
235
+ append_alert relais_docker "$msg" "devzone repair"
236
+ fi
237
+ packages_marker="${DEVZONE_PAQUETS_MARQUE:-/tmp/devzone-paquets.echec}"
238
+ if [ -f "$packages_marker" ]; then
239
+ packages_names=""
240
+ while IFS= read -r n; do
241
+ [ -n "$n" ] || continue
242
+ packages_names="${packages_names:+$packages_names, }$n"
243
+ done < "$packages_marker"
244
+ append_alert paquets "$packages_names" "devzone packages"
245
+ fi
246
+ wt_out="$(worktrees_absents 2>/dev/null || true)"
247
+ while IFS= read -r path; do
248
+ [ -n "$path" ] || continue
249
+ append_alert worktree "$path missing here (created outside the container?)" ""
250
+ done <<<"$wt_out"
251
+ if [ -n "$services_cluster" ] && ! cluster_est_local "$services_cluster"; then
252
+ append_alert cluster_distant "remote cluster: $services_cluster — services on a remote cluster" ""
253
+ fi
254
+ if [ "$work_internal" = true ]; then
255
+ append_alert cluster_interne "work cluster: $work_ctx (devzone internal cluster)" "devzone use $host_ctx"
256
+ fi
257
+
258
+ argocd_repo="$(conf_get argocd repo)"
259
+
260
+ jq -n \
261
+ --argjson schema 1 \
262
+ --arg dv "$dv_raw" \
263
+ --arg dvp "$dvp_raw" \
264
+ --argjson id_ok "$id_ok" \
265
+ --arg id_name "$id_name" \
266
+ --arg id_email "$id_email" \
267
+ --arg id_command "$id_command" \
268
+ --arg platform_name "$platform_name" \
269
+ --arg platform_url "$platform_url" \
270
+ --argjson github "$github_json" \
271
+ --argjson tools_late "$tools_late_json" \
272
+ --arg tools_command "$tools_command" \
273
+ --argjson modules "$modules_json" \
274
+ --arg argocd_repo "$argocd_repo" \
275
+ --argjson docker_host "$docker_host" \
276
+ --argjson docker_host_active "$docker_host_active" \
277
+ --arg clusters_services "$clusters_services_raw" \
278
+ --argjson services_remote "$services_remote" \
279
+ --arg clusters_work "$clusters_work_raw" \
280
+ --argjson work_internal "$work_internal" \
281
+ --arg clusters_command "$clusters_command" \
282
+ --argjson ports "$ports_json" \
283
+ --argjson applications "$applications_json" \
284
+ --arg credentials "$credentials_raw" \
285
+ --argjson alerts "$alerts_json" \
286
+ --argjson errors "$errors" \
287
+ '{
288
+ schema: $schema,
289
+ devzone: { version: (if $dv=="" then null else $dv end), disponible: (if $dvp=="" then null else $dvp end) },
290
+ identite_git: { ok: $id_ok, nom: (if $id_name=="" then null else $id_name end), email: (if $id_email=="" then null else $id_email end), commande: (if $id_command=="" then null else $id_command end) },
291
+ plateforme: { nom: $platform_name, url: (if $platform_url=="" then null else $platform_url end), github: $github },
292
+ argocd_repo: (if $argocd_repo == "" then null else $argocd_repo end),
293
+ outils: { retards: $tools_late, commande: (if $tools_command=="" then null else $tools_command end) },
294
+ modules: $modules,
295
+ docker_hote: $docker_host,
296
+ docker_hote_actif: $docker_host_active,
297
+ clusters: { services: (if $clusters_services=="" then null else $clusters_services end), services_distant: $services_remote, travail: (if $clusters_work=="" then null else $clusters_work end), travail_interne: $work_internal, commande: (if $clusters_command=="" then null else $clusters_command end) },
298
+ ports: $ports,
299
+ applications: (if $applications=="" then null else $applications end),
300
+ identifiants: (if $credentials=="" then null else $credentials end),
301
+ alertes: $alerts,
302
+ erreurs: $errors
303
+ }'
304
+ }
305
+
306
+ if [ "${BASH_SOURCE[0]}" = "$0" ]; then
307
+ state_json
308
+ fi
@@ -0,0 +1,53 @@
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}.verrou" 2>/dev/null; do
14
+ age="$(stat -c %Y "${ETAT}.verrou" 2>/dev/null || stat -f %m "${ETAT}.verrou" 2>/dev/null || true)"
15
+ if [ -n "$age" ] && [ "$(( $(date +%s) - age ))" -gt 30 ]; then
16
+ rm -rf "${ETAT}.verrou"
17
+ continue
18
+ fi
19
+ if [ "$(( $(date +%s) - start ))" -ge 10 ]; then
20
+ echo "devzone : state locked elsewhere: ${ETAT}.verrou" >&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}.verrou" 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}.verrou" 2>/dev/null || true
52
+ return 0
53
+ }
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env bash
2
+ # Safe write of the module state (#417): the only place that sets, replaces
3
+ # or removes a line of $ETAT. A mkdir lock prevents two simultaneous writes,
4
+ # the temporary file is created in the state folder (the mv stays atomic: the
5
+ # file is never missing or incomplete for a reader) and a backup copy
6
+ # $ETAT.prec precedes each replacement. The same file creates the state when
7
+ # it is missing: former global state taken over once, backup copy restored,
8
+ # state rebuilt from the services cluster, otherwise first installation.
9
+ # Sourced library: the caller defines ETAT (file name kept: shared by callers).
10
+ # state_write <key> <value> sets or replaces the line <key>=<value>
11
+ # state_remove <key> removes the line <key>=
12
+ # state_replace <file> replaces the whole state with this file
13
+ # state_lock_take / state_lock_release write lock
14
+ # state_recovery_* state restored or rebuilt (step 4)
15
+ # state_init [modules…] creates the state if it is missing
16
+
17
+ # Write lock (#476): state_lock_take, state_lock_release
18
+ # shellcheck source=SCRIPTDIR/state-lock.sh
19
+ # shellcheck disable=SC1091
20
+ . "$(dirname "${BASH_SOURCE[0]}")/state-lock.sh"
21
+
22
+ # Abort under lock: the temporary file goes, the lock is released
23
+ state_abort() {
24
+ rm -f "${1:-}"
25
+ state_lock_release
26
+ return 1
27
+ }
28
+
29
+ # Backup copy of the current state, before replacement
30
+ state_backup() {
31
+ [ -f "$ETAT" ] || return 0
32
+ cp "$ETAT" "${ETAT}.prec"
33
+ }
34
+
35
+ # The state without the line $1, written to the temporary file $2
36
+ state_filter() {
37
+ local key="$1" dst="$2" code=0
38
+ [ -f "$ETAT" ] || return 0
39
+ grep -vE "^${key}=" "$ETAT" >"$dst" || code=$?
40
+ [ "$code" -le 1 ] || return 1
41
+ return 0
42
+ }
43
+
44
+ # Under lock: replaces the whole state with a file, $ETAT.prec backed up
45
+ state_replace() {
46
+ local src="$1" tmp
47
+ [ -f "$src" ] || return 1
48
+ state_lock_take || return 1
49
+ state_backup || { state_lock_release; return 1; }
50
+ tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
51
+ cat "$src" >"$tmp" || { state_abort "$tmp"; return 1; }
52
+ mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
53
+ state_lock_release
54
+ return 0
55
+ }
56
+
57
+ # Under lock: new value of a key, without losing the other lines
58
+ state_write() {
59
+ local key="$1" value="$2" tmp
60
+ state_lock_take || return 1
61
+ state_backup || { state_lock_release; return 1; }
62
+ tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
63
+ state_filter "$key" "$tmp" || { state_abort "$tmp"; return 1; }
64
+ printf '%s=%s\n' "$key" "$value" >>"$tmp" || { state_abort "$tmp"; return 1; }
65
+ mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
66
+ state_lock_release
67
+ return 0
68
+ }
69
+
70
+ # Under lock: removes a key (#417); without state, nothing to remove
71
+ state_remove() {
72
+ local key="$1" tmp
73
+ state_lock_take || return 1
74
+ [ -f "$ETAT" ] || { state_lock_release; return 0; }
75
+ state_backup || { state_lock_release; return 1; }
76
+ tmp="$(mktemp "${ETAT}.XXXXXX")" || { state_lock_release; return 1; }
77
+ state_filter "$key" "$tmp" || { state_abort "$tmp"; return 1; }
78
+ mv "$tmp" "$ETAT" || { state_abort "$tmp"; return 1; }
79
+ state_lock_release
80
+ return 0
81
+ }
82
+
83
+ # Marks a restored or rebuilt state: the watchers wait (#417)
84
+ state_recovery_mark() {
85
+ date +%s >"${ETAT}.recouvre" 2>/dev/null || true
86
+ }
87
+
88
+ # 0 (to wait) less than 60 s after a restore or a rebuild
89
+ state_recovery_wait() {
90
+ local mark
91
+ [ -f "${ETAT}.recouvre" ] || return 1
92
+ mark="$(cat "${ETAT}.recouvre" 2>/dev/null || true)"
93
+ case "$mark" in
94
+ '' | *[!0-9]*) return 1 ;;
95
+ esac
96
+ [ "$(( $(date +%s) - mark ))" -lt 60 ]
97
+ }
98
+
99
+ # 0 if the restored or rebuilt state is not yet confirmed (#417)
100
+ state_recovery_pending() {
101
+ [ -f "${ETAT}.recouvre" ]
102
+ }
103
+
104
+ # The user confirmed the state (devzone apply): no more guard
105
+ state_recovery_confirm() {
106
+ rm -f "${ETAT}.recouvre" 2>/dev/null || true
107
+ return 0
108
+ }
109
+
110
+ # First installation (#417): the default state, written in one go
111
+ state_default() {
112
+ local stage code=0
113
+ stage="$(mktemp)" || return 1
114
+ printf 'ia=off\nkubernetes=off\ngitlab=off\n' >"$stage"
115
+ state_replace "$stage" || code=$?
116
+ rm -f "$stage"
117
+ return "$code"
118
+ }
119
+
120
+ # Host context (host KUBECONFIG) that points to the given cluster: the
121
+ # cluster= line of the state expects this context, not "devzone" (services cluster)
122
+ host_context_of_cluster() {
123
+ local cluster="$1" host ctx
124
+ host="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}"
125
+ while IFS= read -r ctx; do
126
+ [ -n "$ctx" ] || continue
127
+ # The "devzone" context is set on the services cluster: we look for the
128
+ # host context that points to it
129
+ [ "$ctx" = devzone ] && continue
130
+ if [ "$(KUBECONFIG="$host" kubectl config view -o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)" = "$cluster" ]; then
131
+ echo "$ctx"
132
+ return 0
133
+ fi
134
+ done < <(KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null)
135
+ return 1
136
+ }
137
+
138
+ # State missing without backup copy (#417, step 3): rebuilt from the namespaces
139
+ # labelled devzone of the services cluster (module on if its namespace exists,
140
+ # cluster= of the devzone context); returns 1 otherwise.
141
+ state_rebuild() {
142
+ local namespaces m v stage seen=0 code=0 cluster_ctx cluster_host label
143
+ label="${CLUSTER_ETIQUETTE:-app.kubernetes.io/managed-by=devzone}"
144
+ command -v kubectl >/dev/null 2>&1 || return 1
145
+ namespaces="$(kubectl get namespaces -l "$label" -o name 2>/dev/null || true)"
146
+ [ -n "$namespaces" ] || return 1
147
+ stage="$(mktemp)" || return 1
148
+ for m in "$@"; do
149
+ v=off
150
+ printf '%s\n' "$namespaces" | grep -qx "namespace/devzone-$m" && { v=on; seen=1; }
151
+ printf '%s=%s\n' "$m" "$v" >>"$stage" || code=1
152
+ done
153
+ # devzone context -> services cluster; the cluster= expects the real host
154
+ # context that points to it (e.g. docker-desktop). Without host: no line.
155
+ cluster_ctx="$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"devzone\")].context.cluster}" 2>/dev/null || true)"
156
+ cluster_host=""
157
+ if [ -n "$cluster_ctx" ]; then
158
+ cluster_host="$(host_context_of_cluster "$cluster_ctx")"
159
+ if [ -n "$cluster_host" ]; then
160
+ printf 'cluster=%s\n' "$cluster_host" >>"$stage" || code=1
161
+ fi
162
+ fi
163
+ if [ "$code" -eq 0 ] && [ "$seen" -eq 1 ] && state_replace "$stage"; then
164
+ echo "devzone : state rebuilt from the namespaces of the services cluster: $ETAT (confirm with devzone apply)" >&2
165
+ [ -n "$cluster_host" ] || echo "devzone : no host context points to the services cluster: no cluster= line in $ETAT" >&2
166
+ rm -f "$stage"
167
+ return 0
168
+ fi
169
+ rm -f "$stage"
170
+ return 1
171
+ }
172
+
173
+ # First start (no state): former global state taken over once, otherwise backup
174
+ # copy restored, otherwise state rebuilt, otherwise everything disabled
175
+ state_init() {
176
+ [ -f "$ETAT" ] && return 0
177
+
178
+ # Migration: former global state (~/.config/devzone/modules) to the state of
179
+ # the instance; moved, not copied: the first devzone started after the update
180
+ # keeps its choices
181
+ if [ -f "$HOME/.config/devzone/modules" ]; then
182
+ if state_replace "$HOME/.config/devzone/modules"; then
183
+ rm -f "$HOME/.config/devzone/modules"
184
+ return 0
185
+ fi
186
+ fi
187
+
188
+ state_lock_take || return 1
189
+ if [ -f "$ETAT" ]; then
190
+ state_lock_release
191
+ return 0
192
+ fi
193
+ # 1. Backup copy left by the last write (#417)
194
+ if [ -f "${ETAT}.prec" ] && state_replace "${ETAT}.prec"; then
195
+ echo "devzone : state restored from the backup copy: $ETAT (confirm with devzone apply)" >&2
196
+ state_recovery_mark
197
+ state_lock_release
198
+ return 0
199
+ fi
200
+ # 2. Rebuild from the services cluster (#417)
201
+ if state_rebuild "$@"; then
202
+ state_recovery_mark
203
+ state_lock_release
204
+ return 0
205
+ fi
206
+ # 3. First installation: everything disabled (#417)
207
+ if ! state_default; then
208
+ state_lock_release
209
+ return 1
210
+ fi
211
+ state_lock_release
212
+ # Connection already set up by another devzone (shared volumes): reported
213
+ # once, when the state of this instance is created; stderr: init is also
214
+ # called inside $(value …)
215
+ if [ -f "$HOME/.claude/.credentials.json" ] || [ -f "$HOME/.local/share/opencode/auth.json" ]; then
216
+ echo "devzone : shared Claude Code/opencode connection found: devzone enable ia to use it here" >&2
217
+ fi
218
+ return 0
219
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Why: post-create.sh and demarrage.sh never run in the Kubernetes workspace
2
+ # Why: post-create.sh and startup.sh never run in the Kubernetes workspace
3
3
  # pod (#503). This script installs the devzone tools when the container starts.
4
4
  # Each step logs one "devzone init:" line, and a failure never stops the next
5
5
  # step. No Docker socket is used and no kubeconfig is fabricated.
package/Makefile CHANGED
@@ -19,13 +19,13 @@ help: ## Liste les commandes
19
19
  @grep -E '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " make %-16s %s\n", $$1, $$2}'
20
20
 
21
21
  # up et rebuild : étapes affichées, journal complet dans .devzone.log, question
22
- # posée dans le conteneur signalée au lieu d'attendre (manage/scripts/lancer.sh)
22
+ # posée dans le conteneur signalée au lieu d'attendre (manage/scripts/launch.sh)
23
23
  # En workspace Kubernetes, up/shell/stop pilotent le pod (#472).
24
24
  up: hors-conteneur ## Lance le conteneur (le crée si absent)
25
- @bash manage/scripts/poste.sh up "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/lancer.sh up "$(CURDIR)"
25
+ @bash manage/scripts/poste.sh up "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/launch.sh up "$(CURDIR)"
26
26
 
27
27
  shell: hors-conteneur ## Ouvre un shell dans le conteneur
28
- @bash manage/scripts/poste.sh shell "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/lancer.sh up "$(CURDIR)" && $(DC) exec $(WS) bash
28
+ @bash manage/scripts/poste.sh shell "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/launch.sh up "$(CURDIR)" && $(DC) exec $(WS) bash
29
29
 
30
30
  stop: hors-conteneur ## Arrête le conteneur (état conservé)
31
31
  @bash manage/scripts/poste.sh stop "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; ids=$$(docker ps -q $(FILTRE)); if [ -z "$$ids" ]; then echo "déjà arrêté"; else docker stop $$ids >/dev/null && echo "devzone arrêté"; fi
@@ -36,19 +36,19 @@ down: hors-conteneur ## Supprime le conteneur (volumes et image conservés)
36
36
  docker rm -f $$ids >/dev/null && echo "devzone supprimé (désinstallation complète : make desinstaller)"; fi
37
37
 
38
38
  rebuild: hors-conteneur ## Reconstruit de zéro (après modif de .devcontainer/)
39
- @bash manage/scripts/poste.sh rebuild "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/lancer.sh rebuild "$(CURDIR)"
39
+ @bash manage/scripts/poste.sh rebuild "$(CURDIR)"; c=$$?; [ $$c = 3 ] || exit $$c; bash manage/scripts/launch.sh rebuild "$(CURDIR)"
40
40
 
41
41
  status: hors-conteneur ## État du conteneur
42
42
  @docker ps -a $(FILTRE) --format '{{.Status}}' | grep . || echo "aucun conteneur"
43
43
 
44
44
  test-fonctionnel: hors-conteneur ## Tests fonctionnels : devzone isolé, construit puis supprimé (5 à 10 min)
45
- @bash manage/test/fonctionnel.sh
45
+ @bash manage/test/functional.sh
46
46
 
47
47
  test-cli: hors-conteneur ## Tests de la CLI dans un vrai terminal : devzone isolé, puis supprimé (10 à 15 min)
48
48
  @bash manage/test/cli-terminal.sh
49
49
 
50
50
  desinstaller: hors-conteneur ## Supprime tout ce que devzone a créé, après confirmation (GARDER=connexions : garde les connexions)
51
- @GARDER="$(GARDER)" bash manage/scripts/desinstaller.sh
51
+ @GARDER="$(GARDER)" bash manage/scripts/uninstall.sh
52
52
 
53
53
  uninstall: hors-conteneur ## Supprime tout ce que devzone a créé, après confirmation (alias de desinstaller)
54
- @GARDER="$(GARDER)" bash manage/scripts/desinstaller.sh
54
+ @GARDER="$(GARDER)" bash manage/scripts/uninstall.sh
package/README.md CHANGED
@@ -203,7 +203,7 @@ La liste vit dans `.devzone.paquets` à la racine du dossier devzone, hors du d
203
203
 
204
204
  Dans le mode Kubernetes (poste créé alors que le cluster répondait, ou après `devzone workspace migrate`), le même tableau s'applique au pod `devzone-workspace-0` : `make up`, `make shell` et `make stop` le pilotent, et `make rebuild` est refusé, car rien n'est à reconstruire sur la machine. `devzone workspace revert` rend le poste Docker (déprécié : un avertissement s'affiche, retrait prévu). Les services GitLab, PostgreSQL et Argo CD s'installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)). Tu peux aussi y développer : `devzone workspace clone <url>` fait un clone de travail dans le pod, `devzone ticket <n>` y crée le worktree d'un ticket et `devzone agent` y lance opencode sans copie ([développer dans le pod](manage/docs/reference.md#développer-devzone-et-repowarden-dans-le-pod)). Argo CD y est installé d'office et tient les déploiements : interface sur https://localhost:8443 (mot de passe `admin` dans `.password`), dépôt GitOps `<login>/devzone-argocd` créé sur ton GitHub, projets déclarés dans `.argocd.conf` (`devzone workspace argocd app add <dépôt>`) ; voir [Argo CD dans le workspace Kubernetes](manage/docs/reference.md#argo-cd-dans-le-workspace-kubernetes).
205
205
 
206
- Dans le conteneur, `devzone --help` liste toutes les commandes. Extrait :
206
+ Dans le conteneur, `devzone --version` affiche la version de l'image du workspace, et `devzone --help` liste toutes les commandes. Extrait :
207
207
 
208
208
  ```text
209
209
  devzone enable <module> enable and apply at once
@@ -264,7 +264,7 @@ La commande `devzone` s'écrit en anglais, sous-commandes et options comprises (
264
264
  Les comptes créés par devzone sont regroupés dans `.password`, à la racine de devzone (à côté de `.devzone.modules`). Une ligne par compte, colonnes séparées par des tabulations :
265
265
 
266
266
  ```text
267
- # service adresse utilisateur mot de passe
267
+ # service address user password
268
268
  gitlab http://gitlab.localhost:8929 root …
269
269
  postgres 127.0.0.1:5432 postgres …
270
270
  postgres:monprojet 127.0.0.1:5432/monprojet monprojet …
@@ -159,6 +159,9 @@ spec:
159
159
  # Marker of the Kubernetes workspace: devzone agent runs opencode here (#431)
160
160
  - name: DEVZONE_WORKSPACE
161
161
  value: kubernetes
162
+ # Version of the workspace image, shown by devzone --version (#707)
163
+ - name: DEVZONE_VERSION
164
+ value: {{ .Values.image.tag | default .Chart.AppVersion | quote }}
162
165
  # Root of the devzone projects in the Kubernetes workspace (#503)
163
166
  - name: DEVZONE_RACINE
164
167
  value: /workspaces/projets