devzone 7.4.0 → 7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.devcontainer/devzone +13 -17
  2. package/.devcontainer/devzone-modules.sh +1 -1
  3. package/.devcontainer/devzone-repair.sh +2 -2
  4. package/.devcontainer/devzone-services.sh +7 -7
  5. package/.devcontainer/devzone-status.sh +5 -5
  6. package/.devcontainer/help.sh +3 -1
  7. package/.devcontainer/versions.env +3 -0
  8. package/.devcontainer/workspace-init.sh +8 -9
  9. package/.gitattributes +8 -0
  10. package/bin/SHA256SUMS +6 -6
  11. package/bin/devzone-darwin-amd64 +0 -0
  12. package/bin/devzone-darwin-arm64 +0 -0
  13. package/bin/devzone-linux-amd64 +0 -0
  14. package/bin/devzone-linux-arm64 +0 -0
  15. package/bin/devzone-windows-amd64.exe +0 -0
  16. package/bin/devzone-windows-arm64.exe +0 -0
  17. package/charts/devzone-mysql/values.yaml +1 -1
  18. package/charts/devzone-postgres/values.yaml +1 -1
  19. package/manage/devzone +2 -2
  20. package/manage/scripts/uninstall.sh +1 -1
  21. package/manage/scripts/workspace/argocd-workspace.sh +2 -2
  22. package/package.json +1 -1
  23. package/.devcontainer/catalog/app.sh +0 -202
  24. package/.devcontainer/catalog/catalog-watcher.sh +0 -127
  25. package/.devcontainer/catalog.sh +0 -208
  26. package/.devcontainer/chart-direct.sh +0 -49
  27. package/.devcontainer/cluster.sh +0 -388
  28. package/.devcontainer/clusters.sh +0 -86
  29. package/.devcontainer/devzone-cluster.sh +0 -209
  30. package/.devcontainer/isolation.sh +0 -65
  31. package/.devcontainer/kube-account.sh +0 -107
  32. package/.devcontainer/kube-prompt.sh +0 -42
  33. package/.devcontainer/memory.sh +0 -113
  34. package/.devcontainer/metrics-server.sh +0 -100
  35. package/.devcontainer/packages.sh +0 -228
  36. package/.devcontainer/password.sh +0 -148
  37. package/.devcontainer/ports-json.sh +0 -31
  38. package/.devcontainer/ports.sh +0 -132
@@ -46,9 +46,8 @@ RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
46
46
  # Default state of the instance; DEVZONE_STATE takes precedence (tests, CI)
47
47
  ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
48
48
  MODULES=(ai kubernetes gitlab postgres argocd mysql)
49
- # shellcheck source=SCRIPTDIR/cluster.sh
50
- # shellcheck disable=SC1091
51
- . "$ICI/cluster.sh"
49
+ INSTANCE_SUFFIX=""
50
+ [ "${DEVZONE_INSTANCE:-devzone}" = devzone ] || INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
52
51
  # .argocd.conf of the instance: the GitOps repository designation (#539)
53
52
  # shellcheck source=SCRIPTDIR/argocd/conf.sh
54
53
  # shellcheck disable=SC1091
@@ -106,9 +105,6 @@ GITLAB_URL_MODULE=http://gitlab.localhost:8929
106
105
  # shellcheck source=SCRIPTDIR/devzone-services.sh
107
106
  # shellcheck disable=SC1091
108
107
  . "$ICI/devzone-services.sh"
109
- # shellcheck source=SCRIPTDIR/devzone-cluster.sh
110
- # shellcheck disable=SC1091
111
- . "$ICI/devzone-cluster.sh"
112
108
  # shellcheck source=SCRIPTDIR/devzone-repair.sh
113
109
  # shellcheck disable=SC1091
114
110
  . "$ICI/devzone-repair.sh"
@@ -199,27 +195,27 @@ case "${1:-}" in
199
195
  bash "$ICI/workspace-build.sh" "${@:2}"
200
196
  ;;
201
197
  repair) repair_workstation ;;
202
- metrics) bash "$ICI/metrics-server.sh" "${@:2}" ;;
203
- use) use_cluster "${@:2}" ;;
204
- clusters) DEVZONE_STATE="$ETAT" bash "$ICI/clusters.sh" "${@:2}" ;;
205
- cluster) change_cluster "${@:2}" ;;
206
198
  # Go only: reached when the binary did not take the call. Never call
207
199
  # "devzone" again from here, it would loop forever, see #864
208
- agent | postgres | mysql | gitlab | test-gitlab)
200
+ cluster | clusters | metrics | use | kube | agent | postgres | mysql | gitlab | test-gitlab | catalog | catalog-watcher)
209
201
  echo "devzone $1: Go binary of the pod unavailable (.devcontainer/bin)" >&2
210
202
  exit 1
211
203
  ;;
212
- catalog) DEVZONE_STATE="$ETAT" bash "$ICI/catalog.sh" list ;;
213
204
  argocd)
214
205
  echo "devzone argocd: Go binary of the pod unavailable (.devcontainer/bin)" >&2
215
206
  exit 1
216
207
  ;;
217
- port) DEVZONE_STATE="$ETAT" bash "$ICI/ports.sh" "${@:2}" ;;
218
- packages) bash "$ICI/packages.sh" "${@:2}" ;;
208
+ port)
209
+ echo "devzone port: Go binary of the pod unavailable (.devcontainer/bin)" >&2
210
+ exit 1
211
+ ;;
212
+ packages)
213
+ echo "devzone packages: Go binary of the pod unavailable (.devcontainer/bin)" >&2
214
+ exit 1
215
+ ;;
219
216
  passwords)
220
- bash "$ICI/password.sh" regenerate ||
221
- echo "devzone : grouped credentials not updated" >&2
222
- bash "$ICI/password.sh" path
217
+ echo "devzone passwords: Go binary of the pod unavailable (.devcontainer/bin)" >&2
218
+ exit 1
223
219
  ;;
224
220
  -h | --help | help) devzone_aide ;;
225
221
  test-bash32) bash "$RACINE/manage/test/bash32.sh" ;;
@@ -88,7 +88,7 @@ change_module() {
88
88
  # An application of the catalog: the line is written, then applied
89
89
  if [ -f "$ICI/catalog/$m/app.conf" ]; then
90
90
  write_value "$m" "$1"
91
- bash "$ICI/catalog.sh" apply
91
+ DEVZONE_STATE="$ETAT" devzone catalog apply
92
92
  return
93
93
  fi
94
94
  echo "devzone : unknown module : $m ; modules : ${MODULES[*]}" >&2
@@ -78,8 +78,8 @@ repair_workstation() {
78
78
  if [ "$(value_of mysql)" = on ]; then
79
79
  repair_item "mysql relay" devzone mysql relay-start
80
80
  fi
81
- repair_item "catalog watcher" env DEVZONE_CATALOG_REAL=yes bash "$ICI/catalog/catalog-watcher.sh" start
82
- repair_item "credentials" bash "$ICI/password.sh" regenerate
81
+ repair_item "catalog watcher" env DEVZONE_STATE="$ETAT" DEVZONE_CATALOG_REAL=yes devzone catalog-watcher start
82
+ repair_item "credentials" devzone passwords regenerate
83
83
  devzone cluster clean || true
84
84
  return "$repair_failed"
85
85
  }
@@ -87,8 +87,8 @@ apply_kubernetes() {
87
87
  else
88
88
  rm -f "$HOME/.kube/hote.config"
89
89
  # metrics-server removed from the clusters where devzone installed it
90
- # (devzone=installe marker set by metrics-server.sh); via its subcommand
91
- bash "$ICI/metrics-server.sh" retirer || true
90
+ # (devzone=installe marker set by the Go command); via its subcommand
91
+ devzone metrics remove || true
92
92
  echo "devzone : kubernetes disabled"
93
93
  fi
94
94
  }
@@ -152,19 +152,19 @@ apply_postgres() {
152
152
  write_value postgres off
153
153
  return 2
154
154
  fi
155
- actual="$(cluster_saved)"
155
+ actual="$(devzone kube saved)"
156
156
  if [ -n "$wanted" ] && [ -n "$actual" ] && [ "$wanted" != "$actual" ]; then
157
157
  echo "devzone : devzone services are on $actual; to change: devzone cluster $wanted" >&2
158
158
  write_value postgres off
159
159
  return 2
160
160
  fi
161
161
  if [ -n "$confirm_ctx" ]; then
162
- ctx="$(cluster_choose "$wanted" --confirm "$confirm_ctx")" || { write_value postgres off; return 2; }
162
+ ctx="$(devzone kube choose "$wanted" --confirm "$confirm_ctx")" || { write_value postgres off; return 2; }
163
163
  else
164
- ctx="$(cluster_choose "$wanted")" || { write_value postgres off; return 2; }
164
+ ctx="$(devzone kube choose "$wanted")" || { write_value postgres off; return 2; }
165
165
  fi
166
166
  # Choice kept before the installation: a resume targets the same cluster
167
- cluster_save "$ctx"
167
+ devzone kube save "$ctx"
168
168
  current_state="$(devzone postgres status)"
169
169
  # "relay stopped" first: this line also starts with "ready on"
170
170
  if [[ "$current_state" == *"relay stopped"* ]]; then
@@ -233,7 +233,7 @@ apply_mysql() {
233
233
  else
234
234
  # Removal without deleting the data: volume kept (#441); the databases
235
235
  # only leave with a yes (confirm_removal)
236
- bash "$ICI/catalog.sh" remove mysql
236
+ DEVZONE_STATE="$ETAT" devzone catalog remove mysql
237
237
  if [ -n "${DELETE_DATA:-}" ]; then
238
238
  devzone mysql delete-data --yes
239
239
  fi
@@ -87,15 +87,15 @@ show_state() {
87
87
  fi
88
88
  # Catalog applications (#414)
89
89
  if [ -d "$ICI/catalog" ]; then
90
- bash "$ICI/catalog.sh" resume
90
+ DEVZONE_STATE="$ETAT" devzone catalog resume
91
91
  fi
92
92
  # GitLab Rails secret (#347): warning if the secrets were lost
93
93
  if [ "$(value_of gitlab)" = on ] && [ ! -f "$RACINE/workspace/.gitlab/rails-secret.yaml" ]; then
94
94
  echo " ⚠ gitlab GitLab reinstalled: if the browser shows 422, delete the site data of gitlab.localhost"
95
95
  fi
96
96
  # Remote devzone cluster: warning in the summary
97
- current_cluster="$(cluster_saved)"
98
- if [ -n "$current_cluster" ] && ! cluster_is_local "$current_cluster"; then
97
+ current_cluster="$(devzone kube saved)"
98
+ if [ -n "$current_cluster" ] && ! devzone kube local "$current_cluster"; then
99
99
  printf ' ⚠ cluster remote: %s — services on a remote cluster\n' "$current_cluster"
100
100
  fi
101
101
  devzone cluster clean --quiet || true
@@ -108,7 +108,7 @@ show_state() {
108
108
  case "$ctx_work" in
109
109
  kind-gitlab* | kind-devzone*)
110
110
  ctx_host="$(KUBECONFIG="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}" kubectl config current-context 2>/dev/null || true)"
111
- if [ -n "$ctx_host" ] && cluster_reachable "$ctx_host"; then
111
+ if [ -n "$ctx_host" ] && devzone kube reachable "$ctx_host"; then
112
112
  printf ' ⚠ working cluster: %s (devzone internal cluster); go back: devzone use %s\n' "$ctx_work" "$ctx_host"
113
113
  fi
114
114
  ;;
@@ -118,7 +118,7 @@ show_state() {
118
118
  if [ "$ctx_rbac" = "yes" ]; then
119
119
  printf ' ⚠ rbac : access to devzone-postgres secrets not restricted\n'
120
120
  fi
121
- ports_state="$(bash "$ICI/ports.sh" resume 2>/dev/null || true)"
121
+ ports_state="$(DEVZONE_STATE="$ETAT" devzone port resume 2>/dev/null || echo none)"
122
122
  case "$ports_state" in
123
123
  none*) printf ' ○ ports to the workstation %s\n' "$ports_state" ;;
124
124
  *) printf ' ✔ ports to the workstation %s\n' "$ports_state" ;;
@@ -14,9 +14,11 @@ devzone_aide() {
14
14
  devzone disable <module> [--yes] disable and apply at once (--yes: also deletes the data)
15
15
  devzone apply install what is enabled
16
16
  devzone repair repair gitlab, postgres, ports, passwords
17
- devzone metrics [context…] install metrics-server (kubectl top, k9s)
17
+ devzone catalog [list|apply|sync|resume|json|remove <app>] applications of the catalog
18
+ devzone metrics [context…] | remove [context…] install or remove metrics-server (kubectl top, k9s)
18
19
  devzone use CTX [--confirm CTX] switch the kubectl working cluster
19
20
  devzone clusters view of the connected clusters (work and services)
21
+ devzone kube saved|choose|save|local|reachable|prompt cluster helpers, in Go
20
22
  devzone is-enabled <module> code 0 if enabled
21
23
  devzone test-bash32 run the bats tests under bash 3.2 (Docker container)
22
24
  devzone test-gitlab end-to-end test of the GitLab module and platform
@@ -1,6 +1,9 @@
1
1
  # Single source for the repowarden version used by workspace-init.sh and manage/scripts/ci/versions.sh.
2
2
  REPOWARDEN_VERSION=4.18.1
3
3
 
4
+ # Pinned metrics-server release installed on the local clusters by devzone.
5
+ METRICS_SERVER_VERSION=v0.9.0
6
+
4
7
  # BuildKit client version installed in the workspace image (#514). Must match
5
8
  # buildkit.image in charts/devzone-workspace/values.yaml.
6
9
  BUILDKIT_VERSION=0.34.2
@@ -63,12 +63,13 @@ init_prompt() {
63
63
  log "prompt: cannot write $bashrc"
64
64
  return 0
65
65
  fi
66
- # Block written before the rename invite-kube.sh -> kube-prompt.sh: the file
67
- # no longer exists, every prompt would fail (migration, idempotent)
68
- if grep -qE 'invite-kube\.sh|devzone_invite_kube' "$bashrc" 2>/dev/null; then
69
- sed -i -e 's#/\.devcontainer/invite-kube\.sh#/.devcontainer/kube-prompt.sh#' \
70
- -e 's#devzone_invite_kube#devzone_kube_prompt#' "$bashrc"
71
- log "prompt block migrated to kube-prompt.sh"
66
+ # Blocks written before the Go prompt sourced a shell library that no longer
67
+ # exists: drop them, the new block below takes over (migration, idempotent)
68
+ if grep -qE 'invite-kube\.sh|kube-prompt\.sh' "$bashrc" 2>/dev/null; then
69
+ sed -i -e '/devzone prompt >>>/d' -e '/devzone prompt <</d' \
70
+ -e '/invite-kube\.sh/d' -e '/kube-prompt\.sh/d' \
71
+ -e '/devzone_invite_kube/d' -e '/devzone_kube_prompt/d' "$bashrc"
72
+ log "prompt block migrated to the Go command"
72
73
  fi
73
74
  if grep -qF "$PROMPT_START" "$bashrc" 2>/dev/null; then
74
75
  log "prompt block already present"
@@ -76,9 +77,7 @@ init_prompt() {
76
77
  fi
77
78
  cat >>"$bashrc" <<'PROMPT'
78
79
  # >>> devzone prompt >>>
79
- # shellcheck source=/dev/null
80
- . /usr/local/share/devzone/.devcontainer/kube-prompt.sh
81
- PS1='$(devzone_kube_prompt) '"$PS1"
80
+ PS1='$(devzone kube prompt) '"$PS1"
82
81
  # <<< devzone prompt <<<
83
82
  PROMPT
84
83
  log "prompt block added to $bashrc"
package/.gitattributes CHANGED
@@ -14,3 +14,11 @@ manage/devzone text eol=lf
14
14
  *.yml text eol=lf
15
15
  *.md text eol=lf
16
16
  charts/** text eol=lf
17
+ # Reference files keep LF bytes on every workstation: with core.autocrlf a
18
+ # CRLF reference no longer matches the LF text from the program, and embedded
19
+ # CRLF data is baked into binaries built on Windows.
20
+ **/testdata/** text eol=lf
21
+ **/golden/** text eol=lf
22
+ **/goldens/** text eol=lf
23
+ *.golden text eol=lf
24
+ *.txt text eol=lf
package/bin/SHA256SUMS CHANGED
@@ -1,6 +1,6 @@
1
- 9b7d99ffa3a8420bca697c1c568f04ae4a282a71ea3d9f37202a02fc46601050 devzone-linux-amd64
2
- d2e87e6498668026ad8591475cb0336af72a8aef845f235fb5466ca121cd50ff devzone-linux-arm64
3
- c2a71b049e542c41ec627cd773f5ebdea676c4d2a5e3f02271fe04610245e3b9 devzone-darwin-amd64
4
- e615af41aba2eb1e4b3d4a9d7bd7e7423f793bb72319c5fe7e96ff0e3221eb2d devzone-darwin-arm64
5
- d6a3251e678bd5a35239d175ef7024be585602118cb85dc78d91ba3e94d74224 devzone-windows-amd64.exe
6
- e82d667af1d00c9e8eebc96fa1a039b8032fa0d20ab51eea95dbc8abf75328e9 devzone-windows-arm64.exe
1
+ da866140afd70f74357e1873c55c5a376443fd6991d4afad92cf12afd08ec09c devzone-linux-amd64
2
+ cb54b8971528165e10775e1cbe3622d4567d274854cb9378446bccdec11cbd36 devzone-linux-arm64
3
+ 1b51f6136b3b5d53495a10d81ed4461d87bfbd15c91fb4a0be074c3defb5face devzone-darwin-amd64
4
+ 0c062cfcd30734673a5c0572a41436e56bdde30b67fc5a80c33c14424d51b1ba devzone-darwin-arm64
5
+ 6faab20cd349abc04711f0ed340304ad491eaf98f6bcbe83fe8747a0e40ed31e devzone-windows-amd64.exe
6
+ 62b0a6eb4804a8afcb6b37662681c63ff218b2eb59021015100b8b1b620e2cbe devzone-windows-arm64.exe
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # The one definition of MySQL: the helm-direct path of the catalogue (#414)
2
- # installs this chart (.devcontainer/chart-direct.sh). The secret <name>-admin
2
+ # installs this chart (internal/platform/helm). The secret <name>-admin
3
3
  # (root password) is created apart by
4
4
  # devzone, never by the chart (#538: secrets out of Git).
5
5
  # Name of the application (Service, StatefulSet and secret ref): mysql of the
@@ -1,5 +1,5 @@
1
1
  # The one definition of PostgreSQL: the helm-direct path installs this chart
2
- # (.devcontainer/chart-direct.sh) as the release postgres. The
2
+ # (internal/platform/helm) as the release postgres. The
3
3
  # secret postgres-admin (superuser password) is created apart by devzone,
4
4
  # never by the chart (#516: secrets out of Git).
5
5
  image: postgres:16.15-alpine
package/manage/devzone CHANGED
@@ -183,8 +183,8 @@ EOT
183
183
  # of .devcontainer/devzone (consistency test in manage/test/cli.bats)
184
184
  container_command() {
185
185
  case "$1" in
186
- ai | agent | apply | argocd | build | catalog | cluster | clusters | disable | \
187
- enable | gitlab | is-enabled | llm | metrics | modules | mysql | packages | \
186
+ ai | agent | apply | argocd | build | catalog | catalog-watcher | cluster | clusters | disable | \
187
+ enable | gitlab | is-enabled | kube | llm | metrics | modules | mysql | packages | \
188
188
  passwords | platform | port | postgres | repair | start | state | status | \
189
189
  test-bash32 | test-gitlab | ticket | use) return 0 ;;
190
190
  *) return 1 ;;
@@ -185,7 +185,7 @@ else
185
185
  for i in ${images[@]+"${images[@]}"}; do docker rmi "$i" >/dev/null && echo "✔ image removed: $i"; done
186
186
  for v in ${dind[@]+"${dind[@]}"} ${volumes[@]+"${volumes[@]}"}; do docker volume rm "$v" >/dev/null && echo "✔ volume removed: $v"; done
187
187
  if [ "${#metrics[@]}" -gt 0 ]; then
188
- version="$(sed -n 's/^VERSION=//p' "$HERE/.devcontainer/metrics-server.sh")"
188
+ version="$(sed -n 's/^METRICS_SERVER_VERSION=//p' "$HERE/.devcontainer/versions.env" | head -1)"
189
189
  manifest="https://github.com/kubernetes-sigs/metrics-server/releases/download/${version}/components.yaml"
190
190
  for ctx in "${metrics[@]}"; do
191
191
  kubectl --context "$ctx" delete -f "$manifest" --ignore-not-found >/dev/null &&
@@ -131,8 +131,8 @@ argocd_save_admin_password() {
131
131
 
132
132
  # .password of the workstation regenerated from workspace/.*/ (password.sh of the package)
133
133
  argocd_passwords_refresh() {
134
- DEVZONE_ROOT="$PWD" bash "$RACINE/.devcontainer/password.sh" regenerate 2>/dev/null ||
135
- echo "⚠ .password not updated (bash .devcontainer/password.sh regenerate)" >&2
134
+ DEVZONE_ROOT="$PWD" devzone passwords regenerate 2>/dev/null ||
135
+ echo "⚠ .password not updated (devzone passwords regenerate)" >&2
136
136
  }
137
137
 
138
138
  # Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "7.4.0",
3
+ "version": "7.4.1",
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,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
- }