devzone 7.2.0 → 7.3.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/devzone +25 -11
- 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/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/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
|
@@ -7,9 +7,6 @@ set -euo pipefail
|
|
|
7
7
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
8
8
|
RACINE="${DEVZONE_ROOT:-$(cd "$ICI/../.." && pwd)}"
|
|
9
9
|
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
10
|
-
# shellcheck source=SCRIPTDIR/state.sh
|
|
11
|
-
# shellcheck disable=SC1091
|
|
12
|
-
. "$(dirname "$ICI")/state.sh"
|
|
13
10
|
BASE="${DEVZONE_CATALOG_WATCHER_DIR:-$RACINE/.devzone.catalog-watcher}"
|
|
14
11
|
LOCK_DIR="$BASE/lock"
|
|
15
12
|
LAST_FILE="$BASE/dernier"
|
|
@@ -54,8 +51,8 @@ tick() {
|
|
|
54
51
|
[ -f "$ETAT" ] || return 0
|
|
55
52
|
# Restored or rebuilt state: the watcher does not follow a doubtful state,
|
|
56
53
|
# and never uninstalls until devzone apply has confirmed it
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
59
56
|
mkdir -p "$BASE"
|
|
60
57
|
now="$(stat -c %Y "$ETAT" 2>/dev/null || stat -f %m "$ETAT" 2>/dev/null || true)"
|
|
61
58
|
[ -n "$now" ] || return 0
|
package/.devcontainer/catalog.sh
CHANGED
|
@@ -12,9 +12,6 @@ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
|
12
12
|
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
13
13
|
# shellcheck disable=SC1091
|
|
14
14
|
. "$ICI/cluster.sh"
|
|
15
|
-
# shellcheck source=SCRIPTDIR/state.sh
|
|
16
|
-
# shellcheck disable=SC1091
|
|
17
|
-
. "$ICI/state.sh"
|
|
18
15
|
# shellcheck source=SCRIPTDIR/password.sh
|
|
19
16
|
# shellcheck disable=SC1091
|
|
20
17
|
. "$ICI/password.sh"
|
|
@@ -92,30 +89,10 @@ app_ready() {
|
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
# Adds to the state the <app>=off lines of the absent applications (once each,
|
|
95
|
-
# an existing line is never changed),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[ -f "$ETAT" ] || return 0
|
|
100
|
-
header="# Catalog applications: set to on to install (devzone catalog)"
|
|
101
|
-
state_lock_take || return 1
|
|
102
|
-
# The lock is released on exit, including on an error under set -e
|
|
103
|
-
trap 'state_lock_release' EXIT
|
|
104
|
-
while IFS= read -r app; do
|
|
105
|
-
[ -n "$app" ] || continue
|
|
106
|
-
grep -qE "^${app}=" "$ETAT" 2>/dev/null && continue
|
|
107
|
-
missing="${missing}${missing:+$'\n'}${app}=off"
|
|
108
|
-
done <<<"$(catalog_apps)"
|
|
109
|
-
[ -n "$missing" ] || return 0
|
|
110
|
-
tmp="$(mktemp)"
|
|
111
|
-
{
|
|
112
|
-
cat "$ETAT"
|
|
113
|
-
grep -qF -e "$header" "$ETAT" || echo "$header"
|
|
114
|
-
echo "$missing"
|
|
115
|
-
} >"$tmp"
|
|
116
|
-
state_replace "$tmp"
|
|
117
|
-
rm -f "$tmp"
|
|
118
|
-
)
|
|
92
|
+
# an existing line is never changed), under the Go state lock (#879).
|
|
93
|
+
catalog_sync() {
|
|
94
|
+
DEVZONE_STATE="$ETAT" bash "$ICI/devzone" state catalog-sync
|
|
95
|
+
}
|
|
119
96
|
|
|
120
97
|
# Real state of an application: available, expected, installed, failed. These
|
|
121
98
|
# values are the etat field of devzone status --json: keep them
|
package/.devcontainer/cluster.sh
CHANGED
|
@@ -29,9 +29,6 @@ export KUBECONFIG
|
|
|
29
29
|
|
|
30
30
|
# Safe state write (#417): lock, temporary file in the state folder, backup copy
|
|
31
31
|
# .prev — shared by devzone, ports
|
|
32
|
-
# shellcheck source=SCRIPTDIR/state.sh
|
|
33
|
-
# shellcheck disable=SC1091
|
|
34
|
-
. "$(dirname "${BASH_SOURCE[0]}")/state.sh"
|
|
35
32
|
|
|
36
33
|
# Instance name: empty or « devzone » = default instance (no suffix)
|
|
37
34
|
: "${DEVZONE_INSTANCE:=}"
|
|
@@ -57,7 +54,7 @@ cluster_saved() {
|
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
cluster_save() {
|
|
60
|
-
|
|
57
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state write cluster "$1"
|
|
61
58
|
}
|
|
62
59
|
|
|
63
60
|
cluster_is_dedicated() {
|
package/.devcontainer/devzone
CHANGED
|
@@ -32,7 +32,7 @@ if [ -z "${DEVZONE_NO_GO:-}" ] && [ -z "$FROM_GO" ]; then
|
|
|
32
32
|
aarch64 | arm64) POD_GO_ARCH=arm64 ;;
|
|
33
33
|
*) POD_GO_ARCH="" ;;
|
|
34
34
|
esac
|
|
35
|
-
POD_GO="$ICI/bin/devzone-pod-
|
|
35
|
+
POD_GO="$ICI/bin/devzone-pod-$(uname -s | tr '[:upper:]' '[:lower:]')-$POD_GO_ARCH"
|
|
36
36
|
if [ -n "$POD_GO_ARCH" ] && [ -x "$POD_GO" ] && "$POD_GO" handles "${1:-}" >/dev/null 2>&1; then
|
|
37
37
|
DEVZONE_POD_SCRIPT="$ICI/devzone" exec "$POD_GO" "$@"
|
|
38
38
|
fi
|
|
@@ -58,9 +58,6 @@ if [ -f "$ICI/argocd/conf.sh" ]; then
|
|
|
58
58
|
. "$ICI/argocd/conf.sh"
|
|
59
59
|
fi
|
|
60
60
|
# GitOps repository line in the Kubernetes workspace pod (#639)
|
|
61
|
-
# shellcheck source=SCRIPTDIR/state-gitops.sh
|
|
62
|
-
# shellcheck disable=SC1091
|
|
63
|
-
. "$ICI/state-gitops.sh"
|
|
64
61
|
# Detection of the host (Ollama) models and the devzone-host opencode provider (#665).
|
|
65
62
|
# shellcheck source=SCRIPTDIR/ai/host-models.sh
|
|
66
63
|
# shellcheck disable=SC1091
|
|
@@ -125,21 +122,38 @@ GITLAB_URL_MODULE=http://gitlab.localhost:8929
|
|
|
125
122
|
# shellcheck disable=SC1091
|
|
126
123
|
. "$ICI/devzone-status.sh"
|
|
127
124
|
|
|
128
|
-
# shellcheck source=state-json.sh
|
|
129
|
-
# shellcheck disable=SC1091
|
|
130
|
-
if [ -f "$ICI/state-json.sh" ]; then
|
|
131
|
-
. "$ICI/state-json.sh"
|
|
132
|
-
fi
|
|
133
125
|
|
|
134
126
|
case "${1:-}" in
|
|
135
|
-
"" | status | modules) if [ "${2:-}" = "--json" ]; then
|
|
127
|
+
"" | status | modules) if [ "${2:-}" = "--json" ]; then DEVZONE_STATE="$ETAT" bash "$ICI/devzone" state json; else show_state; fi ;;
|
|
128
|
+
state)
|
|
129
|
+
export DEVZONE_STATE="$ETAT"
|
|
130
|
+
case "${2:-}" in
|
|
131
|
+
write|remove|replace|init|recovery-mark|recovery-wait|recovery-pending|recovery-confirm|catalog-sync|gitops-line|json)
|
|
132
|
+
# shellcheck disable=SC2034 # DEVZONE_STATE used by state helpers
|
|
133
|
+
ETAT="$DEVZONE_STATE"
|
|
134
|
+
;;
|
|
135
|
+
*) echo "devzone state: write|remove|replace|init|recovery-mark|recovery-wait|recovery-pending|recovery-confirm|catalog-sync|gitops-line|json" >&2; exit 1 ;;
|
|
136
|
+
esac
|
|
137
|
+
ici_state="$ICI"
|
|
138
|
+
pod_state=""
|
|
139
|
+
case "$(uname -m)" in
|
|
140
|
+
x86_64) pod_state="$ici_state/bin/devzone-pod-linux-amd64" ;;
|
|
141
|
+
aarch64 | arm64) pod_state="$ici_state/bin/devzone-pod-linux-arm64" ;;
|
|
142
|
+
esac
|
|
143
|
+
if [ -n "$pod_state" ] && [ -x "$pod_state" ]; then
|
|
144
|
+
"$pod_state" "$@"
|
|
145
|
+
else
|
|
146
|
+
echo "devzone : state: Go pod binary unavailable" >&2
|
|
147
|
+
exit 127
|
|
148
|
+
fi
|
|
149
|
+
;;
|
|
136
150
|
enable) change_module on "${2:-}" "${@:3}" ;;
|
|
137
151
|
disable) change_module off "${2:-}" "${@:3}" ;;
|
|
138
152
|
apply)
|
|
139
153
|
migrate_llm
|
|
140
154
|
# The user confirms the current state (#417, step 4): the watchers
|
|
141
155
|
# may uninstall again
|
|
142
|
-
|
|
156
|
+
DEVZONE_STATE="$ETAT" bash "$ICI/devzone" state recovery-confirm
|
|
143
157
|
apply_repowarden
|
|
144
158
|
[ "$(value_of ai)" = off ] || apply_ai on
|
|
145
159
|
# gitlab, postgres, argocd: installed from the workstation in the
|
|
@@ -21,11 +21,11 @@ is_known() {
|
|
|
21
21
|
return 1
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
# First start (no state): the state is created by state
|
|
24
|
+
# First start (no state): the state is created by Go state command (#879): old global
|
|
25
25
|
# state taken over, backup copy restored, state rebuilt from the services
|
|
26
26
|
# cluster, otherwise first installation
|
|
27
27
|
init_state() {
|
|
28
|
-
|
|
28
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state init "${MODULES[@]}"
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
value_of() {
|
|
@@ -35,28 +35,17 @@ value_of() {
|
|
|
35
35
|
[ "$v" = on ] && echo on || echo off
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
# State-file
|
|
39
|
-
# recreated empty between the two
|
|
38
|
+
# State-file write delegated to Go (#879): lock, backup and atomic replace.
|
|
40
39
|
write_value() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
state_lock_release
|
|
44
|
-
return 1
|
|
45
|
-
fi
|
|
46
|
-
state_lock_release
|
|
47
|
-
return 0
|
|
40
|
+
init_state || return 1
|
|
41
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state write "$1" "$2"
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
# Removes a key from the state file: the configuration of a service only exists
|
|
51
45
|
# while it is chosen (#242)
|
|
52
46
|
remove_key() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
state_lock_release
|
|
56
|
-
return 1
|
|
57
|
-
fi
|
|
58
|
-
state_lock_release
|
|
59
|
-
return 0
|
|
47
|
+
init_state || return 1
|
|
48
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state remove "$1"
|
|
60
49
|
}
|
|
61
50
|
|
|
62
51
|
# True if the file only holds the $schema key (created by opencode by default)
|
|
@@ -75,7 +64,7 @@ llm_removed_msg() {
|
|
|
75
64
|
migrate_llm() {
|
|
76
65
|
[ -f "$ETAT" ] || return 0
|
|
77
66
|
grep -qE '^llm=' "$ETAT" 2>/dev/null || return 0
|
|
78
|
-
|
|
67
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state remove llm
|
|
79
68
|
llm_removed_msg
|
|
80
69
|
}
|
|
81
70
|
|
|
@@ -89,7 +78,7 @@ change_module() {
|
|
|
89
78
|
if [ "$m" = llm ]; then
|
|
90
79
|
init_state 2>/dev/null || true
|
|
91
80
|
if [ -f "$ETAT" ] && grep -qE '^llm=' "$ETAT" 2>/dev/null; then
|
|
92
|
-
|
|
81
|
+
DEVZONE_STATE="$ETAT" bash "${ICI:-$(dirname "${BASH_SOURCE[0]}")}/devzone" state remove llm
|
|
93
82
|
fi
|
|
94
83
|
llm_removed_msg
|
|
95
84
|
return 1
|
|
@@ -81,7 +81,7 @@ show_state() {
|
|
|
81
81
|
if [ -n "$argocd_repo" ] && [ "$argocd_repo" != none ]; then
|
|
82
82
|
printf ' ○ argocd GitOps repository: %s\n' "$argocd_repo"
|
|
83
83
|
elif in_pod; then
|
|
84
|
-
|
|
84
|
+
DEVZONE_STATE="$ETAT" bash "$ICI/devzone" state gitops-line
|
|
85
85
|
else
|
|
86
86
|
printf ' ○ argocd no GitOps repository: devzone argocd init\n'
|
|
87
87
|
fi
|
package/.devcontainer/ports.sh
CHANGED
|
@@ -14,9 +14,6 @@ ETAT="${DEVZONE_STATE:-$ROOT/.devzone.modules}"
|
|
|
14
14
|
INSTANCE="${DEVZONE_INSTANCE:-devzone}"
|
|
15
15
|
|
|
16
16
|
# Safe state write (#417): lock, temporary file in the state folder, backup copy
|
|
17
|
-
# shellcheck source=SCRIPTDIR/state.sh
|
|
18
|
-
# shellcheck disable=SC1091
|
|
19
|
-
. "$HERE/state.sh"
|
|
20
17
|
|
|
21
18
|
refuse() { echo "devzone : port : $*" >&2; exit 1; }
|
|
22
19
|
|
|
@@ -41,9 +38,9 @@ sort_ports() {
|
|
|
41
38
|
printf '%s\n' "${1:-}" | tr ',' '\n' | awk 'NF && $0 ~ /^[0-9]+$/ { print }' | sort -n -u | paste -sd, -
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
# Writes the ports= line of the state (#417: never mv outside state
|
|
41
|
+
# Writes the ports= line of the state (#417: never mv outside Go state command)
|
|
45
42
|
write_ports() {
|
|
46
|
-
|
|
43
|
+
DEVZONE_STATE="$ETAT" bash "$HERE/devzone" state write ports "${1:-}" || { echo "devzone : port : state not saved : $ETAT" >&2; exit 1; }
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
add_port() {
|
|
@@ -34,9 +34,6 @@ refuse() {
|
|
|
34
34
|
exit 2
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
# shellcheck source=SCRIPTDIR/state.sh
|
|
38
|
-
# shellcheck disable=SC1091
|
|
39
|
-
. "$HERE/state.sh"
|
|
40
37
|
|
|
41
38
|
action="${1:-}"
|
|
42
39
|
service="${2:-}"
|
|
@@ -73,9 +70,9 @@ cleanup() {
|
|
|
73
70
|
rm -f "$kubeconfig"
|
|
74
71
|
"$DEVZONE_CMD" "$service" relay-stop >/dev/null 2>&1 || true
|
|
75
72
|
if [ -n "$cluster_before" ]; then
|
|
76
|
-
|
|
73
|
+
DEVZONE_STATE="$ETAT" bash "$HERE/devzone" state write cluster "$cluster_before" || true
|
|
77
74
|
else
|
|
78
|
-
|
|
75
|
+
DEVZONE_STATE="$ETAT" bash "$HERE/devzone" state remove cluster || true
|
|
79
76
|
fi
|
|
80
77
|
}
|
|
81
78
|
trap cleanup EXIT
|
|
@@ -109,7 +106,7 @@ unset token ca_data
|
|
|
109
106
|
export KUBECONFIG="$kubeconfig"
|
|
110
107
|
export DEVZONE_KUBE_CONFIG="$kubeconfig"
|
|
111
108
|
export DEVZONE_SERVICES_ADMIN=1
|
|
112
|
-
|
|
109
|
+
DEVZONE_STATE="$ETAT" bash "$HERE/devzone" state write cluster "$ADMIN_CONTEXT" || refuse "cannot write the state: $ETAT"
|
|
113
110
|
echo "devzone services: $action $service in the cluster of the pod (temporary administrator)"
|
|
114
111
|
case "$action" in
|
|
115
112
|
# The seed is a module command: devzone gitlab seed (#538)
|
package/bin/SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
e6babceeed9fcd0bfbfbde50e16e3ae6713c47383383a5e8842a6aa198c7c67b devzone-linux-amd64
|
|
2
|
+
9bb7cdffbbb897b757d123faca2ca3caf77568162a5f63b7e2d76713814946e6 devzone-linux-arm64
|
|
3
|
+
b3c4f85f0f1366083418c88f76ed74d6afd4cb26bc0d2203e48ee2f94a2b5279 devzone-darwin-amd64
|
|
4
|
+
bb5e358f993f44cd6540155edc26c8176e3de66e1911f91e47ae5bbe3279d269 devzone-darwin-arm64
|
|
5
|
+
29c33aee6503737830218008995b90a9bfac6147ed9e7137ae42214a2474c116 devzone-windows-amd64.exe
|
|
6
|
+
8adfaf2cb97d721213589497c24f37f81d3485799dc5e8eca8aef4a244ac50e0 devzone-windows-arm64.exe
|
package/bin/devzone-darwin-amd64
CHANGED
|
Binary file
|
package/bin/devzone-darwin-arm64
CHANGED
|
Binary file
|
package/bin/devzone-linux-amd64
CHANGED
|
Binary file
|
package/bin/devzone-linux-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/manage/devzone
CHANGED
|
@@ -171,6 +171,8 @@ devzone $(version): development workspace in a Kubernetes cluster
|
|
|
171
171
|
(start installs it, stop removes it from the cluster)
|
|
172
172
|
devzone workspace services enable|disable <service>|status
|
|
173
173
|
services (gitlab, postgres, argocd) of the Kubernetes workspace
|
|
174
|
+
devzone workspace ports enable|disable
|
|
175
|
+
automatic start of the port watcher on the workstation
|
|
174
176
|
devzone workspace argocd status|init|apply|app add|list|remove
|
|
175
177
|
Argo CD of the workspace: GitOps repository, .argocd.conf, projects
|
|
176
178
|
devzone --version
|
|
@@ -183,7 +185,7 @@ container_command() {
|
|
|
183
185
|
case "$1" in
|
|
184
186
|
ai | agent | apply | argocd | build | catalog | cluster | clusters | disable | \
|
|
185
187
|
enable | gitlab | is-enabled | llm | metrics | modules | mysql | packages | \
|
|
186
|
-
passwords | platform | port | postgres | repair | start | status | \
|
|
188
|
+
passwords | platform | port | postgres | repair | start | state | status | \
|
|
187
189
|
test-bash32 | test-gitlab | ticket | use) return 0 ;;
|
|
188
190
|
*) return 1 ;;
|
|
189
191
|
esac
|
package/package.json
CHANGED
|
@@ -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
|
-
}
|
package/.devcontainer/state.sh
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
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.prev 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}.prev"
|
|
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.prev 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 'ai=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_HOST:-$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_LABEL:-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}.prev" ] && state_replace "${ETAT}.prev"; 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 ai to use it here" >&2
|
|
217
|
-
fi
|
|
218
|
-
return 0
|
|
219
|
-
}
|