devzone 7.4.0 → 7.5.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 (48) hide show
  1. package/.devcontainer/devzone +18 -63
  2. package/.devcontainer/devzone-modules.sh +8 -3
  3. package/.devcontainer/devzone-repair.sh +7 -7
  4. package/.devcontainer/devzone-services.sh +21 -21
  5. package/.devcontainer/devzone-status.sh +12 -9
  6. package/.devcontainer/help.sh +5 -1
  7. package/.devcontainer/versions.env +8 -0
  8. package/.devcontainer/workspace-init.sh +8 -9
  9. package/.gitattributes +8 -0
  10. package/README.md +2 -2
  11. package/bin/SHA256SUMS +6 -6
  12. package/bin/devzone-darwin-amd64 +0 -0
  13. package/bin/devzone-darwin-arm64 +0 -0
  14. package/bin/devzone-linux-amd64 +0 -0
  15. package/bin/devzone-linux-arm64 +0 -0
  16. package/bin/devzone-windows-amd64.exe +0 -0
  17. package/bin/devzone-windows-arm64.exe +0 -0
  18. package/charts/devzone-mysql/values.yaml +1 -1
  19. package/charts/devzone-postgres/values.yaml +1 -1
  20. package/manage/devzone +6 -3
  21. package/manage/scripts/create-mode.sh +3 -3
  22. package/manage/scripts/uninstall.sh +4 -5
  23. package/manage/scripts/workspace/argocd-workspace.sh +2 -2
  24. package/manage/workspace.sh +1 -1
  25. package/package.json +1 -1
  26. package/.devcontainer/ai/host-check.sh +0 -173
  27. package/.devcontainer/ai/host-models.sh +0 -200
  28. package/.devcontainer/catalog/app.sh +0 -202
  29. package/.devcontainer/catalog/catalog-watcher.sh +0 -127
  30. package/.devcontainer/catalog.sh +0 -208
  31. package/.devcontainer/chart-direct.sh +0 -49
  32. package/.devcontainer/cluster.sh +0 -388
  33. package/.devcontainer/clusters.sh +0 -86
  34. package/.devcontainer/devzone-ai-guard.sh +0 -98
  35. package/.devcontainer/devzone-ai.sh +0 -201
  36. package/.devcontainer/devzone-cluster.sh +0 -209
  37. package/.devcontainer/devzone-skill.sh +0 -97
  38. package/.devcontainer/isolation.sh +0 -65
  39. package/.devcontainer/kube-account.sh +0 -107
  40. package/.devcontainer/kube-prompt.sh +0 -42
  41. package/.devcontainer/memory.sh +0 -113
  42. package/.devcontainer/metrics-server.sh +0 -100
  43. package/.devcontainer/packages.sh +0 -228
  44. package/.devcontainer/password.sh +0 -148
  45. package/.devcontainer/ports-json.sh +0 -31
  46. package/.devcontainer/ports.sh +0 -132
  47. package/manage/scripts/create-cluster.sh +0 -107
  48. package/manage/scripts/docker.sh +0 -43
@@ -85,7 +85,7 @@ start_workspace() {
85
85
  image="$repo:$tag"
86
86
  # Argo CD first when wanted (#516): the workspace is then an Application
87
87
  argocd_ensure
88
- workspace_deploy "$repo" "$tag" "$with_image"
88
+ if [ -n "${DEVZONE_FROM_GO:-}" ] && argocd_active; then devzone workspace deploy "$repo" "$tag" "$with_image"; else workspace_deploy "$repo" "$tag" "$with_image"; fi
89
89
  # Projects of .argocd.conf held too (#516)
90
90
  argocd_reconcile || true
91
91
  wait_for_pod "$image" || return 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -1,173 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Update check and report for the host (Ollama) models (#668).
3
- # host-check.sh check per detected model: up to date, update available,
4
- # or not verifiable; never downloads anything
5
- # host-check.sh rapport sizes, update state, measurements and the chosen
6
- # default model with its reason
7
- # The registry manifest digest is compared with the local /api/tags digest: one
8
- # GET per model, no download, no "ollama pull" executed (the command is only
9
- # printed for the host). The registry is DEVZONE_OLLAMA_REGISTRY, else
10
- # https://registry.ollama.ai.
11
- # bash 3.2 (macOS). Code and comments in English; the user messages are French
12
- # and live in host-check.message, a data file outside the code check.
13
- set -euo pipefail
14
-
15
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
- # shellcheck source=SCRIPTDIR/host-models.sh
17
- # shellcheck disable=SC1091
18
- . "$SCRIPT_DIR/host-models.sh"
19
-
20
- REG="${DEVZONE_OLLAMA_REGISTRY:-https://registry.ollama.ai}"
21
- REG="${REG%/}"
22
- MESSAGE_FILE="$SCRIPT_DIR/host-check.message"
23
-
24
- # English fallbacks, overridden by the French message file.
25
- MSG_TITRE="host (Ollama) models detected:"
26
- MSG_AUCUN="devzone: no Ollama model detected on {url} (answer on /api/tags)"
27
- MSG_TAILLE="size"
28
- MSG_A_JOUR="up to date"
29
- MSG_MAJ="update available"
30
- MSG_NON="not verifiable"
31
- MSG_PULL="on the host: ollama pull {modele}"
32
- MSG_MESURE="measurement reussite {reussite}, tok_s {tok_s}"
33
- MSG_RETENU="chosen model: {modele} ({raison})"
34
- MSG_RAISON_VAR="DEVZONE_HOST_MODEL"
35
- MSG_RAISON_MESURE="measurement"
36
- MSG_RAISON_REGLE="rule"
37
-
38
- if [ -r "$MESSAGE_FILE" ]; then
39
- # shellcheck source=/dev/null
40
- . "$MESSAGE_FILE"
41
- fi
42
-
43
- # Lowercase hex sha256 of a file (sha256sum on Linux, shasum on macOS).
44
- sha256_fichier() {
45
- if command -v sha256sum >/dev/null 2>&1; then
46
- sha256sum "$1" | cut -d' ' -f1
47
- else
48
- shasum -a 256 "$1" | cut -d' ' -f1
49
- fi
50
- }
51
-
52
- # Prints the update state of one model: MSG_A_JOUR, MSG_MAJ or MSG_NON.
53
- # A name with a slash (hf.co/...), a 404, an unreachable registry or a missing
54
- # digest is not verifiable.
55
- etat_modele() {
56
- local nom="$1" digest="$2" court tag somme tmp
57
- case "$nom" in
58
- */*) printf '%s\n' "$MSG_NON"; return 0 ;;
59
- esac
60
- case "$nom" in
61
- *:*) court="${nom%:*}"; tag="${nom##*:}" ;;
62
- *) court="$nom"; tag="latest" ;;
63
- esac
64
- tmp="$(mktemp "${TMPDIR:-/tmp}/devzone-manifest.XXXXXX")"
65
- if ! curl -fsS --max-time 5 \
66
- -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
67
- -o "$tmp" "${REG}/v2/library/${court}/manifests/${tag}" 2>/dev/null; then
68
- rm -f "$tmp"
69
- printf '%s\n' "$MSG_NON"
70
- return 0
71
- fi
72
- somme="$(sha256_fichier "$tmp")"
73
- rm -f "$tmp"
74
- if [ -z "$digest" ]; then
75
- printf '%s\n' "$MSG_NON"
76
- return 0
77
- fi
78
- if [ "$(printf '%s' "$somme" | tr '[:upper:]' '[:lower:]')" = \
79
- "$(printf '%s' "${digest#sha256:}" | tr '[:upper:]' '[:lower:]')" ]; then
80
- printf '%s\n' "$MSG_A_JOUR"
81
- else
82
- printf '%s\n' "$MSG_MAJ"
83
- fi
84
- }
85
-
86
- # Prints "reussite tok_s" for a model, empty when it has no measurement.
87
- mesure_pour() {
88
- local nom="$1" data
89
- [ -f "$MEASURES" ] || return 0
90
- data="$(cat "$MEASURES" 2>/dev/null)" || return 0
91
- [ -n "$data" ] || return 0
92
- printf '%s' "$data" | jq -r --arg nom "$nom" '
93
- .[$nom] | if . == null then empty else "\(.reussite // 0) \(.tok_s // 0)" end
94
- ' 2>/dev/null || return 0
95
- }
96
-
97
- # Why the model is chosen: variable, measurement or rule.
98
- raison_choix() {
99
- local liste="$1" m
100
- if [ -n "${DEVZONE_HOST_MODEL:-}" ]; then
101
- printf '%s\n' "$MSG_RAISON_VAR"
102
- return 0
103
- fi
104
- m="$(mesure_choix "$liste")" || true
105
- if [ -n "$m" ]; then
106
- printf '%s\n' "$MSG_RAISON_MESURE"
107
- else
108
- printf '%s\n' "$MSG_RAISON_REGLE"
109
- fi
110
- }
111
-
112
- # Update check of every detected model. Nothing is downloaded, nothing changes.
113
- check() {
114
- local data ligne nom taille digest etat
115
- data="$(infos)" || true
116
- if [ -z "$data" ]; then
117
- printf '%s\n' "${MSG_AUCUN//\{url\}/$URL}"
118
- return 0
119
- fi
120
- printf '%s\n' "$data" | while IFS=$'\t' read -r nom taille digest; do
121
- [ -n "$nom" ] || continue
122
- etat="$(etat_modele "$nom" "$digest")"
123
- printf '%s : %s\n' "$nom" "$etat"
124
- if [ "$etat" = "$MSG_MAJ" ]; then
125
- printf '%s\n' "${MSG_PULL//\{modele\}/$nom}"
126
- fi
127
- done
128
- return 0
129
- }
130
-
131
- # Report: sizes, update state, measurements and the chosen model with its
132
- # reason. Proposes, changes nothing.
133
- rapport() {
134
- local data liste ligne nom taille digest etat mes r t def raison
135
- data="$(infos)" || true
136
- if [ -z "$data" ]; then
137
- printf '%s\n' "${MSG_AUCUN//\{url\}/$URL}"
138
- return 0
139
- fi
140
- liste="$(printf '%s\n' "$data" | cut -f1)"
141
- printf '%s\n' "$MSG_TITRE"
142
- printf '%s\n' "$data" | while IFS=$'\t' read -r nom taille digest; do
143
- [ -n "$nom" ] || continue
144
- etat="$(etat_modele "$nom" "$digest")"
145
- printf ' %s : %s ; %s %s\n' "$nom" "$etat" "$MSG_TAILLE" "$taille"
146
- mes="$(mesure_pour "$nom")"
147
- if [ -n "$mes" ]; then
148
- r="${mes%% *}"
149
- t="${mes#* }"
150
- ligne="${MSG_MESURE//\{reussite\}/$r}"
151
- ligne="${ligne//\{tok_s\}/$t}"
152
- printf ' %s\n' "$ligne"
153
- fi
154
- if [ "$etat" = "$MSG_MAJ" ]; then
155
- printf '%s\n' "${MSG_PULL//\{modele\}/$nom}"
156
- fi
157
- done
158
- def="$(choix "$liste")" || true
159
- raison="$(raison_choix "$liste")" || true
160
- ligne="${MSG_RETENU//\{modele\}/${def:-}}"
161
- ligne="${ligne//\{raison\}/$raison}"
162
- printf '%s\n' "$ligne"
163
- return 0
164
- }
165
-
166
- # When run directly (not sourced): dispatch the subcommands.
167
- if [ "${0##*/}" = "host-check.sh" ]; then
168
- case "${1:-}" in
169
- check) check ;;
170
- rapport) rapport ;;
171
- *) check ;;
172
- esac
173
- fi
@@ -1,200 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Detection of the models served by Ollama on the host (#665, #668).
3
- # devzone hosts no model: models live on the host (Ollama) and are detected here.
4
- # host-models.sh list the detected model names, one per line
5
- # host-models.sh first the model to use: DEVZONE_HOST_MODEL, else the best
6
- # measured model, else a deterministic rule
7
- # host-models.sh set merge the devzone-host provider into ~/.config/opencode/config.json
8
- # host-models.sh unset remove the devzone-host provider from that file
9
- # host-models.sh check update check of each model (delegates to host-check.sh)
10
- # host-models.sh rapport report (delegates to host-check.sh)
11
- # Default URL: http://host.docker.internal:11434, overridable with DEVZONE_OLLAMA_URL.
12
- # Measurements: DEVZONE_AI_MEASURES, else ~/.config/devzone/ai-measures.json
13
- # ({"<model>": {"reussite": 0..1, "tok_s": n, "date": "..."}}).
14
- # Short timeout; exits 0 and writes nothing when Ollama does not answer.
15
- # bash 3.2 (macOS). Code and comments in English.
16
- set -euo pipefail
17
-
18
- URL="${DEVZONE_OLLAMA_URL:-http://host.docker.internal:11434}"
19
- URL="${URL%/}"
20
- FILE="$HOME/.config/opencode/config.json"
21
- MEASURES="${DEVZONE_AI_MEASURES:-$HOME/.config/devzone/ai-measures.json}"
22
-
23
- # True when a model is an embedding model (Ollama details.type, or a name
24
- # containing "embed", case-insensitive).
25
- is_embedding() {
26
- local low
27
- low="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
28
- case "$low" in
29
- *embed*) return 0 ;;
30
- *) return 1 ;;
31
- esac
32
- }
33
-
34
- # Raw /api/tags payload, empty when Ollama does not answer.
35
- json_tags() {
36
- curl -fsS --max-time 3 "${URL}/api/tags" 2>/dev/null || return 0
37
- }
38
-
39
- # Prints the detected model names, one per line. Exits 0 and prints nothing
40
- # when Ollama does not answer or the payload is not usable.
41
- modeles() {
42
- local data
43
- data="$(json_tags)" || return 0
44
- [ -n "$data" ] || return 0
45
- # Ignore embedding models (Ollama details.type, or a name containing "embed").
46
- printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | .name' 2>/dev/null |
47
- while IFS= read -r name; do
48
- is_embedding "$name" || printf '%s\n' "$name"
49
- done || true
50
- return 0
51
- }
52
-
53
- # Prints the detected models as "name<TAB>size" (bytes), one per line.
54
- tailles() {
55
- local data line name
56
- data="$(json_tags)" || return 0
57
- [ -n "$data" ] || return 0
58
- printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | "\(.name)\t\(.size // 0)"' 2>/dev/null |
59
- while IFS= read -r line; do
60
- name="${line%%$'\t'*}"
61
- is_embedding "$name" || printf '%s\n' "$line"
62
- done || true
63
- return 0
64
- }
65
-
66
- # Prints the detected models as "name<TAB>size<TAB>digest", one per line.
67
- infos() {
68
- local data line name
69
- data="$(json_tags)" || return 0
70
- [ -n "$data" ] || return 0
71
- printf '%s' "$data" | jq -r '.models[] | select((.details.type // "") != "embedding") | "\(.name)\t\(.size // 0)\t\(.digest // "")"' 2>/dev/null |
72
- while IFS= read -r line; do
73
- name="${line%%$'\t'*}"
74
- is_embedding "$name" || printf '%s\n' "$line"
75
- done || true
76
- return 0
77
- }
78
-
79
- # Best measured model among the detected names ($1, one per line): highest
80
- # reussite, then highest tok_s. Prints nothing when the file is absent, invalid
81
- # or no detected model is measured.
82
- mesure_choix() {
83
- local liste="$1" data
84
- [ -f "$MEASURES" ] || return 0
85
- data="$(cat "$MEASURES" 2>/dev/null)" || return 0
86
- [ -n "$data" ] || return 0
87
- printf '%s' "$data" | jq -r --arg liste "$liste" '
88
- ($liste | split("\n") | map(select(length > 0))) as $d
89
- | [to_entries[] | select(.key as $k | $d | index($k))]
90
- | sort_by([-(.value.reussite // 0), -(.value.tok_s // 0)])
91
- | .[0].key // empty
92
- ' 2>/dev/null || return 0
93
- }
94
-
95
- # Deterministic fallback: a name containing "coder" first, then the smallest
96
- # size, then the name order.
97
- regle_choix() {
98
- tailles | LC_ALL=C awk -F'\t' '
99
- {
100
- low = tolower($1)
101
- coder = (index(low, "coder") > 0) ? 0 : 1
102
- size = ($2 + 0)
103
- if (best == "" || coder < bc || (coder == bc && size < bs) || (coder == bc && size == bs && $1 < bn)) {
104
- best = $1
105
- bc = coder
106
- bs = size
107
- bn = $1
108
- }
109
- }
110
- END { if (best != "") print best }
111
- '
112
- }
113
-
114
- # The model to use among the detected names: DEVZONE_HOST_MODEL when set, else
115
- # the best measured model, else the deterministic rule.
116
- choix() {
117
- local liste="$1" nom mesure
118
- [ -n "$liste" ] || return 0
119
- nom="${DEVZONE_HOST_MODEL:-}"
120
- if [ -n "$nom" ]; then
121
- printf '%s\n' "$nom"
122
- return 0
123
- fi
124
- mesure="$(mesure_choix "$liste")" || true
125
- if [ -n "$mesure" ]; then
126
- printf '%s\n' "$mesure"
127
- return 0
128
- fi
129
- regle_choix
130
- }
131
-
132
- # The model to use. Empty when Ollama did not answer or no model was detected.
133
- premier() {
134
- local liste
135
- liste="$(modeles)" || true
136
- [ -n "$liste" ] || return 0
137
- choix "$liste"
138
- }
139
-
140
- # jq program $1 applied to the file (or {}), written back atomically.
141
- # The file is removed when nothing remains but the schema.
142
- rewrite() {
143
- local current="{}" out
144
- [ ! -f "$FILE" ] || current="$(cat "$FILE")"
145
- mkdir -p "$(dirname "$FILE")"
146
- out="$(printf '%s' "$current" | jq "$1")" || {
147
- echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
148
- return 1
149
- }
150
- if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
151
- rm -f "$FILE"
152
- else
153
- printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
154
- fi
155
- }
156
-
157
- # Merges the devzone-host provider (the detected models) into the opencode
158
- # configuration file, keeping everything else. Does nothing when no model was
159
- # detected. baseURL = URL + /v1.
160
- set_provider() {
161
- local liste current="{}" out models baseurl
162
- liste="$(modeles)" || return 0
163
- [ -n "$liste" ] || return 0
164
- baseurl="${URL%/}/v1"
165
- models="$(printf '%s\n' "$liste" | jq -R -n '([inputs | select(length > 0)] | map({(.): {name: .}})) | add // {}')" || return 1
166
- [ ! -f "$FILE" ] || current="$(cat "$FILE")"
167
- mkdir -p "$(dirname "$FILE")"
168
- out="$(printf '%s' "$current" | jq --arg baseurl "$baseurl" --argjson models "$models" '
169
- ."$schema" = (."$schema" // "https://opencode.ai/config.json")
170
- | .provider["devzone-host"] = {npm: "@ai-sdk/openai-compatible", name: "devzone host models (Ollama)", options: {baseURL: $baseurl}, models: $models}
171
- ')" || {
172
- echo "devzone: host: $FILE is not valid JSON: provider not touched" >&2
173
- return 1
174
- }
175
- if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ]; then
176
- rm -f "$FILE"
177
- else
178
- printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
179
- fi
180
- }
181
-
182
- # Removes the devzone-host and devzone-llm providers from the opencode
183
- # configuration file, keeping everything else. No error when the file is absent.
184
- unset_provider() {
185
- [ ! -f "$FILE" ] && return 0
186
- rewrite 'if .provider then del(.provider["devzone-host"]) | del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
187
- }
188
-
189
- # When run directly (not sourced): dispatch the subcommands.
190
- if [ "${0##*/}" = "host-models.sh" ]; then
191
- case "${1:-}" in
192
- first) premier ;;
193
- set) set_provider ;;
194
- unset) unset_provider ;;
195
- check | rapport)
196
- exec bash "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/host-check.sh" "$@"
197
- ;;
198
- *) modeles ;;
199
- esac
200
- fi
@@ -1,202 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Install operations of the catalog (#414): sourced by catalog.sh.
3
- # With the argocd module on, the installed application is an Argo CD Application
4
- # devzone-<app> (chart charts/devzone-<app> of the devzone repository, #538) instead
5
- # of the manifest of the direct helm path.
6
-
7
- WAIT_SECONDS="${DEVZONE_CATALOG_WAIT:-300}"
8
-
9
- # shellcheck source=SCRIPTDIR/chart-direct.sh
10
- # shellcheck disable=SC1091
11
- . "$ICI/chart-direct.sh"
12
-
13
- # Waits for the StatefulSet to be ready: a single rollout command on the manifest
14
- # path, polled on the Argo CD path (the sync runs in the background)
15
- app_wait() {
16
- local app="$1" ns="$2" argo="$3" end=$((SECONDS + WAIT_SECONDS))
17
- if [ "$argo" = 1 ]; then
18
- while [ "$SECONDS" -lt "$end" ]; do
19
- kubectl --context devzone -n "$ns" rollout status "statefulset/$app" --timeout=10s >/dev/null 2>&1 && return 0
20
- sleep 5
21
- done
22
- echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
23
- return 1
24
- fi
25
- if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
26
- --timeout="${WAIT_SECONDS}s" >/dev/null; then
27
- echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
28
- return 1
29
- fi
30
- }
31
-
32
- # Application secret: password generated once, local mirror
33
- # (workspace/.$app/admin-password, 600, never shown). Re-run: a password already
34
- # there (cluster secret or root.env) is kept, never regenerated.
35
- app_secret() {
36
- local app="$1" ns="$2" password file
37
- file="$RACINE/workspace/.$app/admin-password"
38
- mkdir -p "$(dirname "$file")"
39
- chmod 700 "$(dirname "$file")"
40
- if kubectl --context devzone -n "$ns" get secret "$app-admin" >/dev/null 2>&1; then
41
- password="$(kubectl --context devzone -n "$ns" get secret "$app-admin" \
42
- -o jsonpath='{.data.password}' | tr -d '\n')"
43
- (umask 077 && printf '%s' "$password" >"$file")
44
- return 0
45
- fi
46
- password="$(sed -n 's/^\(MYSQL_\|\)PASSWORD=//p' "$RACINE/workspace/.$app/root.env" 2>/dev/null | tail -1 || true)"
47
- if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
48
- if [ -z "$password" ]; then
49
- (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
50
- elif [ ! -s "$file" ]; then
51
- (umask 077 && printf '%s' "$password" >"$file")
52
- fi
53
- kubectl --context devzone -n "$ns" create secret generic "$app-admin" \
54
- --from-file=password="$file" >/dev/null
55
- }
56
-
57
- # Grouped view of the credentials: a failure never blocks the operation
58
- regenerer_identifiants() {
59
- password_regenerate ||
60
- echo "devzone : catalog : grouped credentials not updated (devzone passwords)" >&2
61
- }
62
-
63
- # Installs an application: devzone context set (#396), namespace created and
64
- # isolated (#396), secret generated, then the Argo CD Application (argocd module
65
- # on, #538) or the manifest, wait until ready, relay started to 127.0.0.1:<port>
66
- # of the container; returns non-zero on failure
67
- app_install() {
68
- local app="$1" ns port image CTX extra="" argo=0
69
- ns="$(app_namespace "$app")"
70
- port="$(app_read "$app" port)"
71
- image="$(app_read "$app" image)"
72
- CTX="$(cluster_saved)"
73
- [ -n "$CTX" ] || refuse "no cluster chosen: devzone enable $app"
74
- if ! devzone_context_set "$CTX"; then
75
- echo "devzone : catalog : cannot set the devzone context on $CTX" >&2
76
- return 1
77
- fi
78
- echo "▶ Application $app on cluster $CTX (namespace $ns)…"
79
- # Namespace created and labelled by the administrator (#430), then the limited
80
- # account allowed in the namespace
81
- account_admin "$CTX" create namespace "$ns" --dry-run=client -o yaml |
82
- account_admin "$CTX" apply -f - >/dev/null
83
- account_admin "$CTX" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null
84
- account_allow "$CTX" "$ns"
85
- namespace_isolate "$ns" >/dev/null
86
- app_secret "$app" "$ns"
87
- local claim=donnees
88
- if [ "$app" = mysql ]; then
89
- claim="$(devzone mysql claim "$ns")" || return 2
90
- [ "$claim" = donnees ] || extra="claim=$claim"
91
- fi
92
- if "$ICI/devzone" argocd catalog-active "$app"; then
93
- argo=1
94
- echo "▶ Application $app through Argo CD (chart charts/devzone-$app)…"
95
- "$ICI/devzone" argocd catalog-apply "$app" "$ns" "$image" "$port" "$(app_read "$app" memoire)" "$(app_read "$app" taille)" "$extra" || return 1
96
- else
97
- # Direct helm: the chart charts/devzone-<app>, the one definition (#559)
98
- chart_install "$app" "$ns" "image=$image" "port=$port" \
99
- "memory=$(app_read "$app" memoire)" "size=$(app_read "$app" taille)" "claim=$claim" || return 1
100
- fi
101
- app_wait "$app" "$ns" "$argo" || return 1
102
- relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
103
- echo "✔ $app ready: 127.0.0.1:$port in the container"
104
- regenerer_identifiants
105
- }
106
-
107
- # Uninstalls an application: relay stopped, Argo CD Application removed (argocd
108
- # module on, #538) or the manifest, failure marker forgotten. The volume (PVC) and
109
- # the data stay (#441): deleting the data is confirmed apart (devzone mysql delete-data)
110
- app_remove() {
111
- local app="$1" ns claim pvc CTX
112
- ns="$(app_namespace "$app")"
113
- relay_stop "$app"
114
- rm -f "$(failure_file "$app")"
115
- # RoleBinding removed by the administrator (#430): the namespace and the volume
116
- # stay, the account authorization must not linger
117
- CTX="$(cluster_saved)" || true
118
- if [ -n "$CTX" ]; then
119
- account_remove "$CTX" "$ns" >/dev/null 2>&1 || true
120
- fi
121
- claim="$(kubectl --context devzone -n "$ns" get statefulset "$app" \
122
- -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
123
- if "$ICI/devzone" argocd catalog-application-exists "$app"; then
124
- "$ICI/devzone" argocd catalog-delete "$app" >/dev/null 2>&1 || true
125
- kubectl --context devzone -n "$ns" delete "secret/$app-admin" >/dev/null 2>&1 || true
126
- pvc="${claim:-donnees}-$app-0"
127
- echo "✔ $app removed: Application deleted; volume $pvc and databases kept: devzone $app volume"
128
- regenerer_identifiants
129
- return 0
130
- fi
131
- kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
132
- "secret/$app-admin" >/dev/null 2>&1 || true
133
- pvc="${claim:-donnees}-$app-0"
134
- echo "✔ $app removed from the cluster; volume $pvc and databases kept: devzone $app volume"
135
- regenerer_identifiants
136
- }
137
-
138
- # Failure marker of an attempt: last line of the message kept and shown
139
- app_failure() {
140
- printf '%s\n' "$2" | tail -1 >"$(failure_file "$1")"
141
- printf '%s\n' "$2" >&2
142
- }
143
-
144
- # Warns about the mysql PVCs not mounted by the StatefulSet (#440). Reading the
145
- # namespaces is reserved to the administrator (#430).
146
- app_unused_mysql_volumes() {
147
- local ctx ns mounted pvc list
148
- ctx="$(cluster_saved)"
149
- [ -n "$ctx" ] || return 0
150
- ns="$(app_namespace mysql)"
151
- account_admin "$ctx" get namespace "$ns" >/dev/null 2>&1 || return 0
152
- mounted="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
153
- [ -n "$mounted" ] || return 0
154
- list="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
155
- while IFS= read -r pvc; do
156
- [ -n "$pvc" ] || continue
157
- [ "$pvc" != "${mounted}-mysql-0" ] || continue
158
- printf ' ⚠ volume %s not used : devzone mysql volume\n' "$pvc"
159
- done <<<"$list"
160
- }
161
-
162
- # Closes the gap between wanted and actual: installs, removes, restarts the
163
- # permanent relay; marks the first failure then moves on
164
- catalog_apply() {
165
- local app output code=0 port CTX ns
166
- while IFS= read -r app; do
167
- [ -n "$app" ] || continue
168
- port="$(app_read "$app" port)"
169
- if [ "$(wanted "$app")" != on ] && present "$app"; then
170
- if ! output="$(app_remove "$app" 2>&1)"; then
171
- code=1; app_failure "$app" "$output"
172
- else
173
- printf '%s\n' "$output"
174
- fi
175
- elif [ "$(wanted "$app")" = on ] && present "$app"; then
176
- if ! app_ready "$app"; then
177
- code=1
178
- echo "devzone : catalog : $app installed but not ready: devzone apply" >&2
179
- echo "not ready" >"$(failure_file "$app")"
180
- else
181
- rm -f "$(failure_file "$app")"
182
- fi
183
- # Permanent relay: restarted if stopped
184
- CTX="$(cluster_saved)" || true
185
- ns="$(app_namespace "$app")"
186
- if [ -n "$CTX" ]; then
187
- if ! output="$(relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port" 2>&1)"; then
188
- code=1; app_failure "$app" "$output"
189
- else
190
- [ -n "$output" ] && printf '%s\n' "$output"
191
- fi
192
- fi
193
- elif [ "$(wanted "$app")" = on ]; then
194
- if ! output="$(app_install "$app" 2>&1)"; then
195
- code=1; app_failure "$app" "$output"
196
- else
197
- printf '%s\n' "$output"
198
- fi
199
- fi
200
- done <<<"$(catalog_apps)"
201
- return "$code"
202
- }