devzone 0.42.1 → 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 (32) hide show
  1. package/.devcontainer/Dockerfile +1 -1
  2. package/.devcontainer/argocd/catalogue-argocd.sh +4 -0
  3. package/.devcontainer/argocd/gitops-gitlab.sh +127 -0
  4. package/.devcontainer/argocd/gitops.sh +12 -2
  5. package/.devcontainer/argocd/services-hook.sh +181 -0
  6. package/.devcontainer/catalogue/app.sh +7 -8
  7. package/.devcontainer/catalogue/mysql/installer.sh +9 -8
  8. package/.devcontainer/catalogue/mysql/mysql.sh +1 -1
  9. package/.devcontainer/catalogue.sh +1 -1
  10. package/.devcontainer/chart-direct.sh +49 -0
  11. package/.devcontainer/devzone +8 -4
  12. package/.devcontainer/gitlab/argocd.sh +54 -0
  13. package/.devcontainer/gitlab/chart.sh +39 -0
  14. package/.devcontainer/gitlab/gitlab.sh +11 -168
  15. package/.devcontainer/gitlab/installation.sh +25 -38
  16. package/.devcontainer/gitlab/seed.sh +204 -0
  17. package/.devcontainer/postgres/postgres.sh +4 -2
  18. package/.devcontainer/services-admin.sh +12 -2
  19. package/.devcontainer/versions.env +1 -1
  20. package/README.md +55 -23
  21. package/charts/devzone-gitlab/Chart.lock +9 -0
  22. package/charts/devzone-gitlab/Chart.yaml +15 -0
  23. package/charts/devzone-gitlab/values.yaml +94 -0
  24. package/charts/devzone-mysql/values.yaml +3 -3
  25. package/charts/devzone-postgres/values.yaml +2 -2
  26. package/manage/scripts/check-charts.sh +67 -19
  27. package/manage/scripts/services-workspace.sh +10 -1
  28. package/package.json +1 -1
  29. package/.devcontainer/catalogue/mysql/manifeste.yaml +0 -81
  30. package/.devcontainer/gitlab/runner-values.yaml +0 -27
  31. package/.devcontainer/gitlab/values.yaml +0 -83
  32. 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 \
@@ -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
@@ -66,7 +69,7 @@ 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)"
@@ -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"
@@ -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
@@ -111,7 +111,7 @@ installer() {
111
111
  else
112
112
  mysql_secret
113
113
  claim="$(mysql_claim_choisir "$NS")" || return 2
114
- mysql_appliquer_manifeste "$NS" "$claim"
114
+ mysql_appliquer_chart "$NS" "$claim" || return 1
115
115
  if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
116
116
  echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $NS describe pod mysql-0" >&2
117
117
  return 1
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # Catalogue d'applications (#414) : une application préconfigurée par dossier
3
- # .devcontainer/catalogue/<app>/ (app.conf, manifeste.yaml), installée dans le
3
+ # .devcontainer/catalogue/<app>/ (app.conf ; le chart charts/devzone-<app>, #559), installée dans le
4
4
  # cluster des services de devzone sous son namespace de app.conf ; l'état
5
5
  # voulu est la ligne <app>=on|off de .devzone.modules.
6
6
  # catalogue.sh sync | apply | list | resume | json | remove <app>
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env bash
2
+ # Helm-direct installation of a devzone service (#559, step 7): the chart
3
+ # charts/devzone-<svc> of the code tree is the only definition, installed with
4
+ # helm on the devzone context as the release <svc> in <ns>. Objects already
5
+ # there (kubectl apply of an earlier version, or left by Argo CD when its module
6
+ # went away) are adopted first: the annotations and the label helm requires, so
7
+ # that the release takes them over without recreating them.
8
+ # chart_install <svc> <ns> [key=value ...] adoption, then helm upgrade --install
9
+ # bash 3.2 (macOS).
10
+
11
+ # The charts are code: read from the code tree (this file is in .devcontainer/),
12
+ # whatever the devzone folder (RACINE, the state) is
13
+ CHART_CODE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14
+
15
+ # Adopts the objects of the rendered chart that already exist in <ns>: helm
16
+ # refuses an object it does not own, so the release annotations and the
17
+ # managed-by label are written on them (no object is recreated)
18
+ chart_adopt() {
19
+ local svc="$1" ns="$2" rendu="$3" objets o
20
+ objets="$(kubectl --context devzone -n "$ns" get -f "$rendu" -o name --ignore-not-found 2>/dev/null || true)"
21
+ for o in $objets; do
22
+ kubectl --context devzone -n "$ns" annotate "$o" \
23
+ "meta.helm.sh/release-name=$svc" "meta.helm.sh/release-namespace=$ns" --overwrite >/dev/null
24
+ kubectl --context devzone -n "$ns" label "$o" app.kubernetes.io/managed-by=Helm --overwrite >/dev/null
25
+ done
26
+ }
27
+
28
+ # Installs or upgrades the release <svc> from charts/devzone-<svc>; the
29
+ # key=value arguments become --set options (image, port, memory, size, claim)
30
+ chart_install() {
31
+ local svc="$1" ns="$2" chart rendu arg
32
+ local -a sets
33
+ shift 2
34
+ chart="$CHART_CODE/charts/devzone-$svc"
35
+ if [ ! -f "$chart/Chart.yaml" ]; then
36
+ echo "✖ $svc : chart charts/devzone-$svc missing (manage/docs/reference.md#charts-de-devzone)" >&2
37
+ return 2
38
+ fi
39
+ sets=()
40
+ for arg in "$@"; do sets+=(--set "$arg"); done
41
+ rendu="$(mktemp)"
42
+ if ! helm template "$svc" "$chart" -n "$ns" ${sets[@]+"${sets[@]}"} >"$rendu"; then
43
+ rm -f "$rendu"
44
+ return 1
45
+ fi
46
+ chart_adopt "$svc" "$ns" "$rendu"
47
+ rm -f "$rendu"
48
+ helm --kube-context devzone upgrade --install "$svc" "$chart" -n "$ns" ${sets[@]+"${sets[@]}"} >/dev/null
49
+ }
@@ -421,8 +421,10 @@ appliquer_ia() {
421
421
  rm -f "$(fichier_echec ia)"
422
422
  # Garde-fou repowarden : retiré à la désactivation (symétrique de
423
423
  # l'activation). repowarden le fait lui-même s'il est présent ; sinon
424
- # retrait par jq de la seule entrée PreToolUse qui appelle
425
- # « repowarden garde », le reste de settings.json intact.
424
+ # retrait par jq des seules entrées PreToolUse qui appellent le garde-fou,
425
+ # le reste de settings.json intact. Le garde-fou s'appelle « repowarden
426
+ # guard » depuis repowarden 4.17.3 ; « repowarden garde » est son ancien
427
+ # nom, toujours alias côté repowarden et reconnu ici.
426
428
  if command -v repowarden >/dev/null 2>&1; then
427
429
  repowarden agents retirer --global >/dev/null 2>&1 || true
428
430
  elif [ -f "$HOME/.claude/settings.json" ]; then
@@ -432,10 +434,10 @@ appliquer_ia() {
432
434
  .hooks.PreToolUse = [
433
435
  .hooks.PreToolUse[] |
434
436
  if (.hooks // null) != null then
435
- .hooks = [ .hooks[] | select(((.command // "") | contains("repowarden garde")) | not) ] |
437
+ .hooks = [ .hooks[] | select(((.command // "") | (contains("repowarden garde") or contains("repowarden guard"))) | not) ] |
436
438
  select((.hooks | length) > 0)
437
439
  else
438
- select(((.command // "") | contains("repowarden garde")) | not)
440
+ select(((.command // "") | (contains("repowarden garde") or contains("repowarden guard"))) | not)
439
441
  end
440
442
  ] |
441
443
  if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
@@ -1373,6 +1375,8 @@ changer() {
1373
1375
  confirmer_suppression "$m" "${@:3}" || return 0
1374
1376
  fi
1375
1377
  ecrire "$m" "$1"
1378
+ # Services held by Argo CD (#559): 0 done, 3 helm direct as before, else failed
1379
+ if DEVZONE_ETAT="$ETAT" bash "$ICI/argocd/services-hook.sh" "$m" "$1"; then return 0; elif [ $? -ne 3 ]; then return 1; fi
1376
1380
  "appliquer_$m" "$1" "${@:3}"
1377
1381
  }
1378
1382
 
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env bash
2
+ # GitLab held by Argo CD (#538): with the module argocd on and installed, the
3
+ # installation is the Application devzone-gitlab on the wrapper chart
4
+ # charts/devzone-gitlab at the revision, instead of a helm pass (chart.sh).
5
+ # The Rails secret is re-applied before it (installation.sh), the seed runs
6
+ # once GitLab answers (seed.sh); the runner token goes to the Secret
7
+ # gitlab-runner-secret written by the seed, out of Git.
8
+ # Sourced by installation.sh (through gitlab.sh). bash 3.2 (macOS).
9
+ # gitlab_argocd_active module argocd on, chart present, revision
10
+ # gitlab_release_adopter helm release of before Argo CD: its release
11
+ # secrets removed, the objects are adopted
12
+ # gitlab_application_apply the Application devzone-gitlab
13
+ # gitlab_application_retirer the Application removed (namespace kept)
14
+
15
+ # The catalogue side of Argo CD (module on, chart, revision, Application)
16
+ # shellcheck source=SCRIPTDIR/../argocd/catalogue-argocd.sh
17
+ # shellcheck disable=SC1091
18
+ . "$ICI/../argocd/catalogue-argocd.sh"
19
+
20
+ # The module argocd is on, the namespace devzone-argocd is installed, the chart
21
+ # is in the repository and the revision is known: a development clone (version
22
+ # 0.0.0) keeps the helm-direct path, like the catalogue applications
23
+ gitlab_argocd_active() {
24
+ catalogue_argocd_active gitlab
25
+ }
26
+
27
+ # Argo CD takes over the objects of a helm release gitlab: the release secrets
28
+ # (sh.helm.release.v1.gitlab.*) go, so that helm no longer owns the objects
29
+ gitlab_release_adopter() {
30
+ kubectl --context devzone -n "$GITLAB_NS" delete secret \
31
+ -l owner=helm,name=gitlab --ignore-not-found >/dev/null 2>&1 || true
32
+ }
33
+
34
+ # The Application on charts/devzone-gitlab at the revision, in the namespace of
35
+ # the instance; the internal URL of the webservice follows that namespace
36
+ # (chart value not templated, passed as a helm parameter, as in chart.sh)
37
+ gitlab_application_apply() {
38
+ catalogue_argocd_load
39
+ chart_require gitlab || return $?
40
+ echo "▶ Application devzone-gitlab (Argo CD, charts/devzone-gitlab at $(argocd_revision))…"
41
+ gitops_apply_application devzone-gitlab service "$GITLAB_NS" \
42
+ "$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-gitlab" \
43
+ "gitlab-runner.gitlabUrl=http://gitlab-webservice-default.$GITLAB_NS.svc:8181" || return 1
44
+ # Argo CD reads Git every 3 min: an immediate refresh of the Application
45
+ kubectl --context devzone -n devzone-argocd annotate application.argoproj.io \
46
+ devzone-gitlab argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
47
+ }
48
+
49
+ # The Application removed when GitLab is uninstalled: its resources leave with
50
+ # it; nothing to do when the module argocd is off or the Application is absent
51
+ gitlab_application_retirer() {
52
+ catalogue_argocd_application_exists gitlab || return 0
53
+ catalogue_argocd_delete gitlab
54
+ }