devzone 0.42.0 → 0.43.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 (64) hide show
  1. package/.devcontainer/Dockerfile +1 -1
  2. package/.devcontainer/agent.sh +1 -1
  3. package/.devcontainer/argocd/apps.sh +2 -2
  4. package/.devcontainer/argocd/argocd.sh +22 -10
  5. package/.devcontainer/argocd/catalogue-argocd.sh +4 -0
  6. package/.devcontainer/argocd/gitops-gitlab.sh +127 -0
  7. package/.devcontainer/argocd/gitops.sh +12 -2
  8. package/.devcontainer/argocd/services-hook.sh +181 -0
  9. package/.devcontainer/catalogue/app.sh +29 -12
  10. package/.devcontainer/catalogue/catalogue-veilleur.sh +2 -2
  11. package/.devcontainer/catalogue/mysql/installer.sh +9 -8
  12. package/.devcontainer/catalogue/mysql/mysql.sh +42 -29
  13. package/.devcontainer/catalogue/mysql/volume.sh +5 -5
  14. package/.devcontainer/catalogue.sh +30 -36
  15. package/.devcontainer/chart-direct.sh +49 -0
  16. package/.devcontainer/cluster.sh +11 -11
  17. package/.devcontainer/clusters.sh +1 -1
  18. package/.devcontainer/command-aliases.sh +152 -2
  19. package/.devcontainer/demarrage.sh +18 -15
  20. package/.devcontainer/devcontainer.json +1 -1
  21. package/.devcontainer/devzone +114 -122
  22. package/.devcontainer/docker-relais.sh +2 -2
  23. package/.devcontainer/docker-sans-hote.sh +1 -1
  24. package/.devcontainer/etat-json.sh +16 -16
  25. package/.devcontainer/etat.sh +4 -4
  26. package/.devcontainer/gitlab/argocd.sh +54 -0
  27. package/.devcontainer/gitlab/chart.sh +39 -0
  28. package/.devcontainer/gitlab/gitlab.sh +35 -180
  29. package/.devcontainer/gitlab/installation.sh +34 -47
  30. package/.devcontainer/gitlab/secrets.sh +2 -2
  31. package/.devcontainer/gitlab/seed.sh +204 -0
  32. package/.devcontainer/gitlab/test-gitlab-restes.sh +16 -0
  33. package/.devcontainer/gitlab/test-gitlab.sh +14 -13
  34. package/.devcontainer/help.sh +40 -0
  35. package/.devcontainer/kube-compte.sh +2 -2
  36. package/.devcontainer/kube-config.sh +1 -1
  37. package/.devcontainer/kube-joignable.sh +2 -0
  38. package/.devcontainer/opencode.jsonc +1 -1
  39. package/.devcontainer/paquets.sh +31 -18
  40. package/.devcontainer/ports-auto.sh +6 -6
  41. package/.devcontainer/ports-json.sh +34 -0
  42. package/.devcontainer/ports.sh +34 -43
  43. package/.devcontainer/post-create.sh +3 -3
  44. package/.devcontainer/postgres/postgres.sh +46 -32
  45. package/.devcontainer/services-admin.sh +13 -3
  46. package/.devcontainer/skills/devzone/SKILL.md +16 -16
  47. package/.devcontainer/versions.env +1 -1
  48. package/README.md +72 -40
  49. package/charts/devzone-gitlab/Chart.lock +9 -0
  50. package/charts/devzone-gitlab/Chart.yaml +15 -0
  51. package/charts/devzone-gitlab/values.yaml +94 -0
  52. package/charts/devzone-mysql/values.yaml +3 -3
  53. package/charts/devzone-postgres/values.yaml +2 -2
  54. package/manage/scripts/check-charts.sh +67 -19
  55. package/manage/scripts/docker-workstation.sh +73 -0
  56. package/manage/scripts/lancer.sh +1 -1
  57. package/manage/scripts/migrer-retour.sh +1 -0
  58. package/manage/scripts/migrer.sh +6 -0
  59. package/manage/scripts/services-workspace.sh +11 -3
  60. package/package.json +1 -1
  61. package/.devcontainer/catalogue/mysql/manifeste.yaml +0 -81
  62. package/.devcontainer/gitlab/runner-values.yaml +0 -27
  63. package/.devcontainer/gitlab/values.yaml +0 -83
  64. package/.devcontainer/postgres/postgres.yaml +0 -84
@@ -29,7 +29,7 @@ ARG BUILDKIT_SHA256_ARM64=a4ad483a33b2f1544c5ccce1c5956c559e1a6e84b8bf6cedd847d6
29
29
  SHELL ["/bin/bash", "-o", "pipefail", "-c"]
30
30
 
31
31
  # Contrôles shell de repowarden ; jq : lu par son garde-fou des agents IA
32
- # (repowarden garde, module ia), qui sans lui ne vérifie rien
32
+ # (repowarden guard, module ia), qui sans lui ne vérifie rien
33
33
  # Python 3.12 d Ubuntu 24.04, paquets signés par apt, aucun serveur de clés (#464)
34
34
  RUN apt-get -o Acquire::Retries=5 update \
35
35
  && apt-get -o Acquire::Retries=5 install -y --no-install-recommends shellcheck bats jq python3 python3-venv python3-pip python-is-python3 \
@@ -65,7 +65,7 @@ agent_lancer() {
65
65
  consigne="$(cd "$(dirname "$consigne")" && pwd -P)/$(basename "$consigne")"
66
66
  # Module ia requis : sans assistants, rien à diriger.
67
67
  if ! bash "$ICI/devzone" is-enabled ia >/dev/null 2>&1; then
68
- refuse "module ia désactivé : devzone activer ia"
68
+ refuse "module ia désactivé : devzone enable ia"
69
69
  fi
70
70
  configurer
71
71
  journal="$(journal_de "$dossier")"
@@ -100,11 +100,11 @@ EOF
100
100
  }
101
101
 
102
102
  # Ingress of the GitLab namespace opened to the devzone namespaces (Argo CD
103
- # repo-server among them): same rule as devzone postgres autoriser
103
+ # repo-server among them): same rule as devzone postgres authorize
104
104
  apps_gitlab_allow_argocd() {
105
105
  argocd_kubectl -n "$APPS_GITLAB_NS" patch networkpolicy devzone-meme-namespace --type merge \
106
106
  -p '{"spec":{"ingress":[{"from":[{"podSelector":{},"namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}' >/dev/null 2>&1 ||
107
- echo "⚠ NetworkPolicy of $APPS_GITLAB_NS not opened to Argo CD: devzone postgres autoriser $APPS_NS, or the sync will fail" >&2
107
+ echo "⚠ NetworkPolicy of $APPS_GITLAB_NS not opened to Argo CD: devzone postgres authorize $APPS_NS, or the sync will fail" >&2
108
108
  }
109
109
 
110
110
  # One [app N] of .argocd.conf applied: Secret when a token exists, then the Application
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # Module argocd (#411) : Argo CD dans le cluster des services de devzone.
3
- # argocd.sh installer | desinstaller | etat | relais-lancer | relais-arreter
3
+ # argocd.sh install | uninstall | status | relay-start | relay-stop
4
4
  # argocd.sh app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>
5
5
  # Namespace devzone-argocd isolé, relais 127.0.0.1:8443 dans le conteneur.
6
6
  # Mot de passe admin dans workspace/.argocd/admin.env (600), repris dans
@@ -35,7 +35,7 @@ refuse() { echo "devzone : argocd : $*" >&2; exit 2; }
35
35
  # Vue regroupée des identifiants : un échec n'empêche jamais l'opération
36
36
  regenerer_identifiants() {
37
37
  password_regenerer ||
38
- echo "devzone : argocd : identifiants regroupés non mis à jour (devzone mots-de-passe)" >&2
38
+ echo "devzone : argocd : identifiants regroupés non mis à jour (devzone passwords)" >&2
39
39
  }
40
40
 
41
41
  # Convertit une quantité de mémoire Kubernetes (Ki, Mi, Gi, K, M, G, octets)
@@ -83,7 +83,7 @@ verifier_memoire() {
83
83
  return 2
84
84
  fi
85
85
  if [ "$memoire" -lt 1048576 ]; then
86
- echo "devzone : argocd : il faut au moins 1 Go de mémoire allouable dans le cluster (disponible : $((memoire / 1024)) Mo) ; agrandir le cluster (Docker Desktop → Settings → Resources) puis relancer : devzone activer argocd" >&2
86
+ echo "devzone : argocd : il faut au moins 1 Go de mémoire allouable dans le cluster (disponible : $((memoire / 1024)) Mo) ; agrandir le cluster (Docker Desktop → Settings → Resources) puis relancer : devzone enable argocd" >&2
87
87
  return 2
88
88
  fi
89
89
  }
@@ -182,7 +182,7 @@ etat() {
182
182
  return 0
183
183
  fi
184
184
  if ! relais_actif argocd; then
185
- echo "prêt, relais arrêté : devzone appliquer"
185
+ echo "prêt, relais arrêté : devzone apply"
186
186
  else
187
187
  echo "prêt : https://127.0.0.1:$ARGOCD_PORT"
188
188
  fi
@@ -221,13 +221,25 @@ ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
221
221
  # shellcheck disable=SC1091
222
222
  . "$ICI/apps.sh"
223
223
  argocd_kubectl() { kubectl --context devzone "$@"; }
224
+ # English command names are accepted (#557) : a copied script may miss the file
225
+ # shellcheck source=SCRIPTDIR/../command-aliases.sh
226
+ # shellcheck disable=SC1091
227
+ if [ -f "$ICI/../command-aliases.sh" ]; then
228
+ . "$ICI/../command-aliases.sh"
229
+ fi
230
+ # Subcommand and options become their canonical English names ; the old
231
+ # French names warn on use (#557)
232
+ if command -v canonical_args >/dev/null 2>&1; then
233
+ canonical_args argocd "$@"
234
+ set -- "${ARGS_CANONICAL[@]+"${ARGS_CANONICAL[@]}"}"
235
+ fi
224
236
 
225
237
  case "${1:-}" in
226
- installer) installer ;;
227
- desinstaller) desinstaller ;;
228
- etat) etat ;;
229
- relais-lancer) relais ;;
230
- relais-arreter) relais_arreter argocd ;;
238
+ install) installer ;;
239
+ uninstall) desinstaller ;;
240
+ status) etat ;;
241
+ relay-start) relais ;;
242
+ relay-stop) relais_arreter argocd ;;
231
243
  init)
232
244
  # GitOps repository of the user (#516): created or designated, then
233
245
  # the root Application when the module is installed
@@ -246,7 +258,7 @@ case "${1:-}" in
246
258
  argocd_app "${@:2}"
247
259
  ;;
248
260
  *)
249
- echo "devzone argocd : installer | desinstaller | etat | init [--repo <url>|--none] | apply | app add|list|remove" >&2
261
+ echo "devzone argocd : install | uninstall | status | init [--repo <url>|--none] | apply | app add|list|remove" >&2
250
262
  exit 1
251
263
  ;;
252
264
  esac
@@ -44,6 +44,10 @@ argocd_revision() {
44
44
  # container (limited devzone context)
45
45
  catalogue_argocd_load() {
46
46
  [ -n "$CATALOGUE_ARGOCD_WIRED" ] && return 0
47
+ # The Applications are applied with the devzone context, the only one the
48
+ # container holds (services.sh and gitops.sh call argocd_kubectl)
49
+ # shellcheck disable=SC2317 # called by services.sh and gitops.sh
50
+ argocd_kubectl() { kubectl --context devzone "$@"; }
47
51
  # shellcheck disable=SC2034 # read by apps.sh
48
52
  APPS_CMD="devzone argocd app"
49
53
  # shellcheck disable=SC2034 # read by apps.sh and services.sh
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env bash
2
+ # GitLab as the GitOps repository of Argo CD (#559, step 6): devzone/devzone-argocd
3
+ # on the devzone GitLab, written through its API (files endpoint, no clone). The
4
+ # repository is designated with provider = gitlab in [argocd] of .argocd.conf;
5
+ # the repository URL is the internal one (Argo CD reads it in the cluster).
6
+ # The root token is read from workspace/.gitlab/root-token, sent through a curl
7
+ # config file (never on the command line) and never printed.
8
+ # Sourced by gitops.sh, which dispatches its put, sha, delete and root functions
9
+ # here when gitops_is_gitlab holds. The includer defines RACINE, conf_set and
10
+ # conf_get (conf.sh). GITLAB_GITOPS_API: base URL of the API seen by this
11
+ # process (the relay of the container by default). bash 3.2 (macOS).
12
+ # gitlab_gitops_init project created by the API, repository designated
13
+ # gitlab_gitops_sha <path> blob id of a file, empty when absent
14
+ # gitlab_gitops_put <path> <file> <message> create or update, same blob skipped
15
+ # gitlab_gitops_delete <path> <message> file removed
16
+ # gitlab_gitops_root_token the token of the Argo CD repository Secret
17
+
18
+ GITLAB_GITOPS_GROUP="${GITLAB_GITOPS_GROUP:-devzone}"
19
+ GITLAB_GITOPS_PROJECT="${GITLAB_GITOPS_PROJECT:-devzone-argocd}"
20
+ GITLAB_GITOPS_BRANCH="${GITLAB_GITOPS_BRANCH:-main}"
21
+ GITLAB_GITOPS_API="${GITLAB_GITOPS_API:-http://gitlab.localhost:8929}"
22
+ # Internal URL of the repository for Argo CD (the webservice of devzone-gitlab)
23
+ GITLAB_GITOPS_URL_INTERNE="${GITLAB_GITOPS_URL_INTERNE:-http://gitlab-webservice-default.devzone-gitlab.svc:8181/$GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT.git}"
24
+
25
+ # Root token of the devzone GitLab; refused when absent (devzone enable gitlab)
26
+ gitlab_gitops_root_token() {
27
+ local file="$RACINE/workspace/.gitlab/root-token" token=""
28
+ [ -s "$file" ] && token="$(cat "$file")"
29
+ if [ -z "$token" ]; then
30
+ echo "✖ GitLab root token missing ($file): devzone enable gitlab" >&2
31
+ return 1
32
+ fi
33
+ printf '%s' "$token"
34
+ }
35
+
36
+ # One API call: METHOD PATH [curl options]; the token goes through a config file
37
+ # (mode 600, removed right after), so it never shows in the process list
38
+ gitlab_gitops_api() {
39
+ local method="$1" path="$2" cfg token rc=0
40
+ shift 2
41
+ token="$(gitlab_gitops_root_token)" || return 1
42
+ cfg="$(mktemp)"
43
+ chmod 600 "$cfg"
44
+ printf 'header = "PRIVATE-TOKEN: %s"\n' "$token" >"$cfg" || { rm -f "$cfg"; return 1; }
45
+ curl -s --config "$cfg" --request "$method" "$GITLAB_GITOPS_API/api/v4$path" "$@" || rc=$?
46
+ rm -f "$cfg"
47
+ return "$rc"
48
+ }
49
+
50
+ # The project path, URL-encoded for the API (devzone%2Fdevzone-argocd)
51
+ gitlab_gitops_projet() {
52
+ printf '%s' "$GITLAB_GITOPS_GROUP%2F$GITLAB_GITOPS_PROJECT"
53
+ }
54
+
55
+ # Numeric id of the project, empty when it does not exist
56
+ gitlab_gitops_id() {
57
+ gitlab_gitops_api GET "/projects/$(gitlab_gitops_projet)" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true
58
+ }
59
+
60
+ # A file path URL-encoded for the files endpoint (apps/x.yaml -> apps%2Fx.yaml)
61
+ gitlab_gitops_chemin() {
62
+ printf '%s' "$1" | jq -sRr '@uri'
63
+ }
64
+
65
+ # Blob id of a file on the branch (the files endpoint), empty when absent
66
+ gitlab_gitops_sha() {
67
+ local id
68
+ id="$(gitlab_gitops_id)"
69
+ [ -n "$id" ] || return 0
70
+ gitlab_gitops_api GET "/projects/$id/repository/files/$(gitlab_gitops_chemin "$1")?ref=$GITLAB_GITOPS_BRANCH" 2>/dev/null |
71
+ jq -r '.blob_id // empty' 2>/dev/null || true
72
+ }
73
+
74
+ # Creates or updates a file: PUT when the file exists, POST when it is new
75
+ gitlab_gitops_put() {
76
+ local path="$1" file="$2" message="$3" id sha content verb
77
+ id="$(gitlab_gitops_id)"
78
+ [ -n "$id" ] || { echo "✖ GitLab project $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT missing: devzone argocd init --gitlab" >&2; return 1; }
79
+ sha="$(gitlab_gitops_sha "$path")"
80
+ if [ -n "$sha" ] && [ "$sha" = "$(git hash-object "$file" 2>/dev/null || true)" ]; then
81
+ return 0
82
+ fi
83
+ content="$(base64 <"$file" | tr -d '\n')"
84
+ verb=POST
85
+ [ -z "$sha" ] || verb=PUT
86
+ gitlab_gitops_api "$verb" "/projects/$id/repository/files/$(gitlab_gitops_chemin "$path")" \
87
+ --data-urlencode "branch=$GITLAB_GITOPS_BRANCH" \
88
+ --data-urlencode "encoding=base64" \
89
+ --data-urlencode "content=$content" \
90
+ --data-urlencode "commit_message=$message" >/dev/null
91
+ }
92
+
93
+ # Removes a file on the branch; nothing to do when it is absent
94
+ gitlab_gitops_delete() {
95
+ local path="$1" message="$2" id
96
+ id="$(gitlab_gitops_id)"
97
+ [ -n "$id" ] || return 0
98
+ [ -n "$(gitlab_gitops_sha "$path")" ] || return 0
99
+ gitlab_gitops_api DELETE "/projects/$id/repository/files/$(gitlab_gitops_chemin "$path")" \
100
+ --data-urlencode "branch=$GITLAB_GITOPS_BRANCH" \
101
+ --data-urlencode "commit_message=$message" >/dev/null
102
+ }
103
+
104
+ # The group devzone (created by the seed when missing), then the project
105
+ # devzone/devzone-argocd with a first commit (README) so that the files can be
106
+ # written; the repository is designated in [argocd] (internal URL, provider)
107
+ gitlab_gitops_init() {
108
+ local group id
109
+ gitlab_gitops_root_token >/dev/null || return 1
110
+ group="$(gitlab_gitops_api GET "/groups/$GITLAB_GITOPS_GROUP" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
111
+ if [ -z "$group" ]; then
112
+ group="$(gitlab_gitops_api POST /groups --data-urlencode "name=$GITLAB_GITOPS_GROUP" \
113
+ --data-urlencode "path=$GITLAB_GITOPS_GROUP" --data "visibility=private" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
114
+ fi
115
+ [ -n "$group" ] || { echo "✖ GitLab group $GITLAB_GITOPS_GROUP not created" >&2; return 1; }
116
+ id="$(gitlab_gitops_id)"
117
+ if [ -z "$id" ]; then
118
+ id="$(gitlab_gitops_api POST /projects --data-urlencode "name=$GITLAB_GITOPS_PROJECT" \
119
+ --data "namespace_id=$group" --data "visibility=private" --data "initialize_with_readme=true" \
120
+ --data-urlencode "default_branch=$GITLAB_GITOPS_BRANCH" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
121
+ [ -n "$id" ] || { echo "✖ GitLab project $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT not created" >&2; return 1; }
122
+ echo "✔ GitOps repository created on GitLab: $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT (private)"
123
+ gitops_put_text apps/.gitkeep "" "devzone: apps folder"
124
+ fi
125
+ conf_set argocd "repo=$GITLAB_GITOPS_URL_INTERNE" "provider=gitlab"
126
+ echo "✔ GitOps repository: GitLab $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT (internal URL in Argo CD)"
127
+ }
@@ -23,9 +23,14 @@ GITOPS_NS="devzone-argocd"
23
23
  GITOPS_ROOT_APP="devzone"
24
24
  GITOPS_REPO_NAME="${DEVZONE_GITOPS_REPO_NAME:-devzone-argocd}"
25
25
  : "${GITOPS_CMD:=devzone argocd init}"
26
+ # shellcheck source=SCRIPTDIR/gitops-gitlab.sh
27
+ # shellcheck disable=SC1091
28
+ . "$(dirname "${BASH_SOURCE[0]}")/gitops-gitlab.sh"
26
29
 
27
30
  gitops_repo() { conf_get argocd repo; }
28
31
  gitops_repo_note() { conf_set argocd "repo=$1"; }
32
+ # GitLab designated (provider = gitlab, #559): the files go through its API
33
+ gitops_is_gitlab() { [ "$(conf_get argocd provider)" = gitlab ]; }
29
34
 
30
35
  gitops_enabled() {
31
36
  local r
@@ -49,6 +54,7 @@ gitops_init() {
49
54
  for arg in "$@"; do
50
55
  if [ "$expect" = repo ]; then repo="$arg"; expect=""; continue; fi
51
56
  case "$arg" in
57
+ --gitlab) gitlab_gitops_init; return ;;
52
58
  --none)
53
59
  gitops_repo_note none
54
60
  echo "✔ no GitOps repository: the Applications are applied directly ($GITOPS_CMD to change)"
@@ -121,12 +127,14 @@ GitOps repository of devzone, written by the devzone commands (never by hand): t
121
127
  gitops_blob() { git hash-object "$1" 2>/dev/null || true; }
122
128
 
123
129
  gitops_sha() {
130
+ if gitops_is_gitlab; then gitlab_gitops_sha "$@"; return; fi
124
131
  gh api "repos/$(gitops_slug)/contents/$1" --jq .sha 2>/dev/null || true
125
132
  }
126
133
 
127
134
  # Writes <file> at <path> of the repository (create or update), <message>
128
135
  gitops_put() {
129
136
  local path="$1" file="$2" message="$3" slug sha content
137
+ if gitops_is_gitlab; then gitlab_gitops_put "$@"; return; fi
130
138
  slug="$(gitops_slug)"
131
139
  sha="$(gitops_sha "$path")"
132
140
  if [ -n "$sha" ] && [ "$sha" = "$(gitops_blob "$file")" ]; then
@@ -150,6 +158,7 @@ gitops_put_text() {
150
158
 
151
159
  gitops_delete() {
152
160
  local path="$1" message="$2" sha
161
+ if gitops_is_gitlab; then gitlab_gitops_delete "$@"; return; fi
153
162
  sha="$(gitops_sha "$path")"
154
163
  [ -n "$sha" ] || return 0
155
164
  gh api -X DELETE "repos/$(gitops_slug)/contents/$path" -f message="$message" -f sha="$sha" >/dev/null
@@ -157,10 +166,11 @@ gitops_delete() {
157
166
 
158
167
  # Repository Secret (token of gh) and root Application "devzone" on apps/
159
168
  gitops_root() {
160
- local url token
169
+ local url token user=devzone
161
170
  gitops_enabled || return 0
162
171
  url="$(gitops_repo)"
163
172
  token="${DEVZONE_GITOPS_TOKEN:-$(gh auth token 2>/dev/null || true)}"
173
+ if gitops_is_gitlab; then user=oauth2; token="$(gitlab_gitops_root_token 2>/dev/null || true)"; fi
164
174
  if [ -n "$token" ]; then
165
175
  argocd_kubectl -n "$GITOPS_NS" apply -f - >/dev/null <<EOF
166
176
  apiVersion: v1
@@ -175,7 +185,7 @@ type: Opaque
175
185
  stringData:
176
186
  type: git
177
187
  url: $url
178
- username: devzone
188
+ username: $user
179
189
  password: $token
180
190
  EOF
181
191
  else
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env bash
2
+ # Services of the container held by Argo CD (#559, step 5). Called by devzone
3
+ # (changer) after the state line is written, before the helm-direct path:
4
+ # services-hook.sh <svc> <on|off>
5
+ # postgres and mysql with the module argocd installed and held: enable writes
6
+ # [services] <svc> = on and reconciles it (services_reconcile, services.sh),
7
+ # then waits for the pods and starts the relay; disable removes the
8
+ # Application (its resources leave with it, namespace and volumes stay).
9
+ # argocd off: the Applications of postgres, mysql and gitlab leave with their
10
+ # finalizer dropped first, so the resources stay for the helm-direct path
11
+ # (adoption, no recreation); then devzone removes Argo CD.
12
+ # Exit codes read by devzone: 0 done through Argo CD (devzone stops there),
13
+ # 3 not concerned or released (devzone goes on as before), 1 failed.
14
+ # gitlab is not held here: its Application comes from gitlab/argocd.sh (step 4).
15
+ # Sourced by the tests with stubs; run as a script by devzone. bash 3.2.
16
+
17
+ ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
+ # RACINE: the code tree (libraries, charts); STATE_RACINE: the devzone folder
19
+ # (workspace/ secrets, .argocd.conf), the same folder unless DEVZONE_RACINE says so
20
+ RACINE="$(dirname "$(dirname "$ICI")")"
21
+ STATE_RACINE="${DEVZONE_RACINE:-$RACINE}"
22
+ # shellcheck disable=SC2034 # read by catalogue-argocd.sh
23
+ ETAT="${DEVZONE_ETAT:-$STATE_RACINE/.devzone.modules}"
24
+ APP_CONF="$RACINE/.devcontainer/catalogue/mysql/app.conf"
25
+ HOOK_SERVICES="postgres mysql"
26
+
27
+ # shellcheck source=SCRIPTDIR/../cluster.sh
28
+ # shellcheck disable=SC1091
29
+ . "$ICI/../cluster.sh"
30
+ # shellcheck source=SCRIPTDIR/catalogue-argocd.sh
31
+ # shellcheck disable=SC1091
32
+ . "$ICI/catalogue-argocd.sh"
33
+
34
+ # Loads the Argo CD pieces (conf, gitops, services with the context devzone)
35
+ # and the list of services reconciled here
36
+ hook_load() {
37
+ DEVZONE_ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$STATE_RACINE/.argocd.conf}"
38
+ export DEVZONE_ARGOCD_CONF
39
+ catalogue_argocd_load
40
+ # shellcheck disable=SC2034 # read by services.sh (services_reconcile)
41
+ SERVICES_LIST="$HOOK_SERVICES"
42
+ }
43
+
44
+ # The relay script of a service (started once its pods are ready)
45
+ hook_script() {
46
+ case "$1" in
47
+ postgres) printf '%s' "$ICI/../postgres/postgres.sh" ;;
48
+ mysql) printf '%s' "$ICI/../catalogue/mysql/mysql.sh" ;;
49
+ esac
50
+ }
51
+
52
+ # Waits for the pods of devzone-<svc> to be ready (the Application syncs
53
+ # within a few minutes); the relay needs a ready pod to forward to
54
+ hook_wait() {
55
+ local ns="devzone-$1" tour=0
56
+ while [ "$tour" -lt 60 ]; do
57
+ if argocd_kubectl -n "$ns" get pods -o name 2>/dev/null | grep -q .; then
58
+ argocd_kubectl -n "$ns" wait --for=condition=Ready pod --all --timeout=300s >/dev/null 2>&1 && return 0
59
+ fi
60
+ tour=$((tour + 1))
61
+ sleep 5
62
+ done
63
+ echo "✖ $1 : pods not ready in devzone-$1 (devzone argocd status)" >&2
64
+ return 1
65
+ }
66
+
67
+ # Starts the relay of the service, after the pods are ready
68
+ hook_relay() {
69
+ bash "$(hook_script "$1")" relay-start
70
+ }
71
+
72
+ # Admin secret <svc>-admin of the namespace, created apart and mirrored in
73
+ # workspace/.<svc>/admin-password (600); an existing secret is kept, never
74
+ # printed. The same mirror the helm-direct installers read.
75
+ services_secret_admin() {
76
+ local svc="$1" ns="$2" secret="$3" dir file password=""
77
+ dir="$STATE_RACINE/workspace/.$svc"
78
+ file="$dir/admin-password"
79
+ mkdir -p "$dir"
80
+ chmod 700 "$dir"
81
+ password="$(argocd_kubectl -n "$ns" get secret "$secret" -o jsonpath='{.data.password}' 2>/dev/null | base64 -d 2>/dev/null)" || password=""
82
+ if [ -n "$password" ]; then
83
+ (umask 077 && printf '%s' "$password" >"$file")
84
+ else
85
+ if [ ! -s "$file" ]; then
86
+ (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
87
+ fi
88
+ argocd_kubectl -n "$ns" create secret generic "$secret" --from-file=password="$file" >/dev/null
89
+ fi
90
+ chmod 600 "$file"
91
+ }
92
+
93
+ # Secret hooks of services_reconcile: the superuser secret of each service
94
+ services_secret_postgres() { services_secret_admin postgres devzone-postgres postgres-admin; }
95
+ # The superuser secret of MySQL, the same way
96
+ services_secret_mysql() { services_secret_admin mysql devzone-mysql mysql-admin; }
97
+
98
+ # Value of a key of the MySQL application file (app.conf, read as text)
99
+ app_value() { sed -n "s/^$1=//p" "$APP_CONF" 2>/dev/null | tail -1; }
100
+
101
+ # Parameters of the MySQL chart: image, port, memory and size of app.conf, and
102
+ # the claim of the one existing volume (*-mysql-0); several volumes: refused,
103
+ # as the helm-direct installer does (#440)
104
+ services_chart_mysql() {
105
+ local liste claim="" image port memoire taille
106
+ image="$(app_value image)"
107
+ port="$(app_value port)"
108
+ memoire="$(app_value memoire)"
109
+ taille="$(app_value taille)"
110
+ liste="$(argocd_kubectl -n devzone-mysql get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
111
+ if [ -n "$liste" ]; then
112
+ if [ "$(printf '%s\n' "$liste" | grep -c .)" -gt 1 ]; then
113
+ echo "✖ several MySQL volumes in devzone-mysql: devzone mysql volume <name> picks the mounted one" >&2
114
+ return 2
115
+ fi
116
+ claim=" claim=${liste%-mysql-0}"
117
+ fi
118
+ printf 'image=%s port=%s memory=%s size=%s%s' "${image:-mysql:8.4}" "${port:-3306}" \
119
+ "${memoire:-1Gi}" "${taille:-5Gi}" "$claim"
120
+ }
121
+
122
+ # Enable: through Argo CD only when the module is held (installed, chart and
123
+ # revision known); otherwise 3, the helm-direct installer runs as before
124
+ hook_on() {
125
+ local svc="$1"
126
+ catalogue_argocd_active "$svc" || return 3
127
+ services_note "$svc" on || return 1
128
+ services_reconcile || return 1
129
+ echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
130
+ hook_wait "$svc" || return 1
131
+ hook_relay "$svc" || return 1
132
+ echo "✔ $svc held by Argo CD ([services] $svc = on in .argocd.conf)"
133
+ return 0
134
+ }
135
+
136
+ # Disable: the Application leaves with its resources (cascade); 3 so that the
137
+ # usual uninstall of the service goes on and keeps its data rules
138
+ hook_off() {
139
+ local svc="$1"
140
+ catalogue_argocd_application_exists "$svc" || return 3
141
+ services_note "$svc" off || return 1
142
+ gitops_delete_application "devzone-$svc" || return 1
143
+ echo "✔ Application devzone-$svc removed (its resources leave with it)"
144
+ return 3
145
+ }
146
+
147
+ # argocd off: each Application of the services leaves with its finalizer
148
+ # dropped first (gitops_delete_application keep): the resources stay for the
149
+ # helm-direct path. The module is already off when this runs, so the check
150
+ # is on the Application itself, not on the module state.
151
+ hook_release() {
152
+ local svc app
153
+ for svc in postgres mysql gitlab; do
154
+ app="devzone-$svc"
155
+ argocd_kubectl -n devzone-argocd get application.argoproj.io "$app" >/dev/null 2>&1 || continue
156
+ argocd_kubectl -n devzone-argocd patch application.argoproj.io "$app" --type merge \
157
+ -p '{"metadata":{"finalizers":null}}' >/dev/null 2>&1 || true
158
+ gitops_delete_application "$app" keep || return 1
159
+ case "$svc" in
160
+ postgres | mysql) services_note "$svc" off || return 1 ;;
161
+ esac
162
+ echo "✔ Application $app released: its resources stay for the helm-direct path"
163
+ done
164
+ return 3
165
+ }
166
+
167
+ # Dispatch: the pair service and action decides; anything else is not concerned
168
+ hook_main() {
169
+ local svc="${1:-}" action="${2:-}"
170
+ case "$svc:$action" in
171
+ argocd:off) hook_load && hook_release ;;
172
+ postgres:on | mysql:on) hook_load && hook_on "$svc" ;;
173
+ postgres:off | mysql:off) hook_load && hook_off "$svc" ;;
174
+ *) return 3 ;;
175
+ esac
176
+ }
177
+
178
+ if [ "${BASH_SOURCE[0]}" = "$0" ]; then
179
+ hook_main "$@"
180
+ exit $?
181
+ fi
@@ -9,6 +9,9 @@ ATTENTE="${DEVZONE_CATALOGUE_ATTENTE:-300}"
9
9
  # shellcheck source=SCRIPTDIR/argocd/catalogue-argocd.sh
10
10
  # shellcheck disable=SC1091
11
11
  . "$ICI/argocd/catalogue-argocd.sh"
12
+ # shellcheck source=SCRIPTDIR/chart-direct.sh
13
+ # shellcheck disable=SC1091
14
+ . "$ICI/chart-direct.sh"
12
15
 
13
16
  # Attente du StatefulSet prêt : une seule commande rollout sur la voie
14
17
  # manifeste, sondée sur la voie Argo CD (la synchronisation est en tâche de
@@ -58,7 +61,7 @@ app_secret() {
58
61
  # Vue regroupée des identifiants : un échec n'empêche jamais l'opération
59
62
  regenerer_identifiants() {
60
63
  password_regenerer ||
61
- echo "devzone : catalogue : identifiants regroupés non mis à jour (devzone mots-de-passe)" >&2
64
+ echo "devzone : catalogue : identifiants regroupés non mis à jour (devzone passwords)" >&2
62
65
  }
63
66
 
64
67
  # Installe une application : contexte devzone posé (#396), namespace créé et
@@ -66,12 +69,12 @@ regenerer_identifiants() {
66
69
  # #538) ou manifeste, attente prête, relais lancé vers 127.0.0.1:<port> du
67
70
  # conteneur ; rend non nul en échec
68
71
  app_installer() {
69
- local app="$1" ns port image CTX man extra="" argo=0
72
+ local app="$1" ns port image CTX extra="" argo=0
70
73
  ns="$(app_ns "$app")"
71
74
  port="$(app_lire "$app" port)"
72
75
  image="$(app_lire "$app" image)"
73
76
  CTX="$(cluster_lu)"
74
- [ -n "$CTX" ] || refuse "aucun cluster choisi : devzone activer $app"
77
+ [ -n "$CTX" ] || refuse "aucun cluster choisi : devzone enable $app"
75
78
  if ! contexte_devzone_poser "$CTX"; then
76
79
  echo "devzone : catalogue : impossible de poser le contexte devzone sur $CTX" >&2
77
80
  return 1
@@ -99,13 +102,9 @@ app_installer() {
99
102
  catalogue_argocd_apply "$app" "$ns" "$image" "$port" \
100
103
  "$(app_lire "$app" memoire)" "$(app_lire "$app" taille)" "$extra" || return 1
101
104
  else
102
- man="$(mktemp)"
103
- sed -e "s|__APP__|$app|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$image|g" \
104
- -e "s|__PORT__|$port|g" -e "s|__MEMOIRE__|$(app_lire "$app" memoire)|g" \
105
- -e "s|__TAILLE__|$(app_lire "$app" taille)|g" -e "s|__CLAIM__|$claim|g" \
106
- "$(dossier_catalogue)/$app/manifeste.yaml" >"$man" &&
107
- kubectl --context devzone -n "$ns" apply -f "$man" >/dev/null
108
- rm -f "$man"
105
+ # Helm direct: the chart charts/devzone-<app>, the one definition (#559)
106
+ chart_install "$app" "$ns" "image=$image" "port=$port" \
107
+ "memory=$(app_lire "$app" memoire)" "size=$(app_lire "$app" taille)" "claim=$claim" || return 1
109
108
  fi
110
109
  app_attendre "$app" "$ns" "$argo" || return 1
111
110
  relais_lancer "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
@@ -116,7 +115,7 @@ app_installer() {
116
115
  # Désinstalle une application : relais coupé, Application Argo CD retirée
117
116
  # (module argocd actif, #538) ou manifeste, marque oubliée ; le volume (PVC)
118
117
  # et les données restent (#441) : la suppression des données est confirmée à
119
- # part (devzone mysql supprimer-donnees)
118
+ # part (devzone mysql delete-data)
120
119
  app_desinstaller() {
121
120
  local app="$1" ns claim pvc CTX
122
121
  ns="$(app_ns "$app")"
@@ -151,6 +150,24 @@ app_echec() {
151
150
  printf '%s\n' "$2" >&2
152
151
  }
153
152
 
153
+ # Avertit des PVC mysql non montés par le StatefulSet (#440). Lecture des
154
+ # namespaces réservée à l'administrateur (#430).
155
+ app_mysql_volumes_inutilises() {
156
+ local ctx ns monte pvc liste
157
+ ctx="$(cluster_lu)"
158
+ [ -n "$ctx" ] || return 0
159
+ ns="$(app_ns mysql)"
160
+ compte_admin "$ctx" get namespace "$ns" >/dev/null 2>&1 || return 0
161
+ monte="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
162
+ [ -n "$monte" ] || return 0
163
+ liste="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
164
+ while IFS= read -r pvc; do
165
+ [ -n "$pvc" ] || continue
166
+ [ "$pvc" != "${monte}-mysql-0" ] || continue
167
+ printf ' ⚠ volume %s non utilisé : devzone mysql volume\n' "$pvc"
168
+ done <<<"$liste"
169
+ }
170
+
154
171
  # Comble l'écart entre le voulu et le réel : installe, retire, relance le
155
172
  # relais permanent ; marque l'échec au premier problème puis passe à la suite
156
173
  catalogue_appliquer() {
@@ -167,7 +184,7 @@ catalogue_appliquer() {
167
184
  elif [ "$(voulu "$app")" = on ] && presente "$app"; then
168
185
  if ! app_prete "$app"; then
169
186
  code=1
170
- echo "devzone : catalogue : $app installé mais pas prêt : devzone appliquer" >&2
187
+ echo "devzone : catalogue : $app installé mais pas prêt : devzone apply" >&2
171
188
  echo "pas prêt" >"$(fichier_echec "$app")"
172
189
  else
173
190
  rm -f "$(fichier_echec "$app")"
@@ -53,7 +53,7 @@ tour() {
53
53
  local maintenant ancien
54
54
  [ -f "$ETAT" ] || return 0
55
55
  # État restauré ou reconstruit : le veilleur ne suit pas un état douteux,
56
- # et ne désinstalle jamais tant que devzone appliquer ne l'a pas confirmé
56
+ # et ne désinstalle jamais tant que devzone apply ne l'a pas confirmé
57
57
  etat_recouvrement_attente && return 0
58
58
  etat_recouvrement_en_attente && return 0
59
59
  mkdir -p "$BASE"
@@ -63,7 +63,7 @@ tour() {
63
63
  if [ "$maintenant" != "$ancien" ]; then
64
64
  echo "$maintenant" >"$DERNIER"
65
65
  echo "devzone : catalogue-veilleur : .devzone.modules modifié, application" >&2
66
- bash "$ICI/../catalogue.sh" appliquer
66
+ bash "$ICI/../catalogue.sh" apply
67
67
  fi
68
68
  }
69
69
 
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Installation MySQL (#440) : secret, manifeste et réinstallation sur un volume.
2
+ # Installation MySQL (#440) : secret, chart et réinstallation sur un volume.
3
+ # shellcheck source=SCRIPTDIR/../../chart-direct.sh
4
+ # shellcheck disable=SC1091
5
+ . "$ICI/../../chart-direct.sh"
3
6
 
4
7
  # Secret admin (mysql-admin) : root.env ou secret existant, jamais régénéré.
5
8
  mysql_secret() {
@@ -52,13 +55,11 @@ mysql_installer_argocd() {
52
55
  regenerer_identifiants
53
56
  }
54
57
 
55
- # Applique le manifeste avec le préfixe de claim choisi (#440)
56
- mysql_appliquer_manifeste() {
58
+ # Installe le chart charts/devzone-mysql avec le claim choisi (#440, #559)
59
+ mysql_appliquer_chart() {
57
60
  local ns="$1" claim="$2"
58
- sed -e "s|__APP__|mysql|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$MYSQL_IMAGE|g" \
59
- -e "s|__PORT__|$MYSQL_PORT|g" -e "s|__MEMOIRE__|$MYSQL_MEMOIRE|g" \
60
- -e "s|__TAILLE__|$MYSQL_TAILLE|g" -e "s|__CLAIM__|$claim|g" \
61
- "$ICI/manifeste.yaml" | kubectl --context devzone -n "$ns" apply -f - >/dev/null
61
+ chart_install mysql "$ns" "image=$MYSQL_IMAGE" "port=$MYSQL_PORT" \
62
+ "memory=$MYSQL_MEMOIRE" "size=$MYSQL_TAILLE" "claim=$claim"
62
63
  }
63
64
 
64
65
  # (Ré)installe MySQL sur le claim demandé, données du PVC gardées (#440)
@@ -74,7 +75,7 @@ mysql_installer_claim() {
74
75
  namespace_isoler "$ns" >/dev/null
75
76
  mysql_secret
76
77
  k delete statefulset mysql --ignore-not-found >/dev/null 2>&1 || true
77
- mysql_appliquer_manifeste "$ns" "$claim"
78
+ mysql_appliquer_chart "$ns" "$claim" || return 1
78
79
  if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
79
80
  echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $ns describe pod mysql-0" >&2
80
81
  return 1