devzone 0.28.0 → 0.29.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.
- package/.devcontainer/catalogue/app.sh +146 -0
- package/.devcontainer/catalogue/catalogue-veilleur.sh +99 -0
- package/.devcontainer/catalogue/mysql/app.conf +11 -0
- package/.devcontainer/catalogue/mysql/manifeste.yaml +77 -0
- package/.devcontainer/catalogue/mysql/mysql.sh +250 -0
- package/.devcontainer/catalogue.sh +201 -0
- package/.devcontainer/demarrage.sh +10 -0
- package/.devcontainer/devzone +57 -3
- package/.devcontainer/etat-json.sh +16 -0
- package/.devcontainer/password.sh +31 -0
- package/.gitattributes +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Opérations d'installation du catalogue (#414) : sourcé par catalogue.sh.
|
|
3
|
+
|
|
4
|
+
ATTENTE="${DEVZONE_CATALOGUE_ATTENTE:-300}"
|
|
5
|
+
|
|
6
|
+
# Secret de l'application : mot de passe généré une fois, miroir local
|
|
7
|
+
# (workspace/.$app/admin-password, 600, jamais affiché). Reprise : le mot de
|
|
8
|
+
# passe déjà là (secret cluster ou root.env) est conservé, jamais régénéré.
|
|
9
|
+
app_secret() {
|
|
10
|
+
local app="$1" ns="$2" mdp fichier
|
|
11
|
+
fichier="$RACINE/workspace/.$app/admin-password"
|
|
12
|
+
mkdir -p "$(dirname "$fichier")"
|
|
13
|
+
chmod 700 "$(dirname "$fichier")"
|
|
14
|
+
if kubectl --context devzone -n "$ns" get secret "$app-admin" >/dev/null 2>&1; then
|
|
15
|
+
mdp="$(kubectl --context devzone -n "$ns" get secret "$app-admin" \
|
|
16
|
+
-o jsonpath='{.data.password}' | tr -d '\n')"
|
|
17
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
18
|
+
return 0
|
|
19
|
+
fi
|
|
20
|
+
mdp="$(sed -n 's/^\(MYSQL_\|\)PASSWORD=//p' "$RACINE/workspace/.$app/root.env" 2>/dev/null | tail -1 || true)"
|
|
21
|
+
if [ -z "$mdp" ] && [ -s "$fichier" ]; then mdp="$(cat "$fichier")"; fi
|
|
22
|
+
if [ -z "$mdp" ]; then
|
|
23
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$fichier")
|
|
24
|
+
elif [ ! -s "$fichier" ]; then
|
|
25
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
26
|
+
fi
|
|
27
|
+
kubectl --context devzone -n "$ns" create secret generic "$app-admin" \
|
|
28
|
+
--from-file=password="$fichier" >/dev/null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Vue regroupée des identifiants : un échec n'empêche jamais l'opération
|
|
32
|
+
regenerer_identifiants() {
|
|
33
|
+
password_regenerer ||
|
|
34
|
+
echo "devzone : catalogue : identifiants regroupés non mis à jour (devzone mots-de-passe)" >&2
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Installe une application : contexte devzone posé (#396), namespace créé et
|
|
38
|
+
# isolé (#396), secret généré, manifeste appliqué, attente prête, relais lancé
|
|
39
|
+
# vers 127.0.0.1:<port> du conteneur ; rend non nul en échec
|
|
40
|
+
app_installer() {
|
|
41
|
+
local app="$1" ns port image CTX man
|
|
42
|
+
ns="$(app_ns "$app")"
|
|
43
|
+
port="$(app_lire "$app" port)"
|
|
44
|
+
image="$(app_lire "$app" image)"
|
|
45
|
+
CTX="$(cluster_lu)"
|
|
46
|
+
[ -n "$CTX" ] || refuse "aucun cluster choisi : devzone activer $app"
|
|
47
|
+
if ! contexte_devzone_poser "$CTX"; then
|
|
48
|
+
echo "devzone : catalogue : impossible de poser le contexte devzone sur $CTX" >&2
|
|
49
|
+
return 1
|
|
50
|
+
fi
|
|
51
|
+
echo "▶ Application $app sur le cluster $CTX (namespace $ns)…"
|
|
52
|
+
kubectl --context devzone create namespace "$ns" --dry-run=client -o yaml |
|
|
53
|
+
kubectl --context devzone apply -f - >/dev/null
|
|
54
|
+
kubectl --context devzone label namespace "$ns" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null
|
|
55
|
+
namespace_isoler "$ns" >/dev/null
|
|
56
|
+
app_secret "$app" "$ns"
|
|
57
|
+
man="$(mktemp)"
|
|
58
|
+
sed -e "s|__APP__|$app|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$image|g" \
|
|
59
|
+
-e "s|__PORT__|$port|g" -e "s|__MEMOIRE__|$(app_lire "$app" memoire)|g" \
|
|
60
|
+
-e "s|__TAILLE__|$(app_lire "$app" taille)|g" \
|
|
61
|
+
"$(dossier_catalogue)/$app/manifeste.yaml" >"$man" &&
|
|
62
|
+
kubectl --context devzone -n "$ns" apply -f "$man" >/dev/null
|
|
63
|
+
rm -f "$man"
|
|
64
|
+
if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
|
|
65
|
+
--timeout="${ATTENTE}s" >/dev/null; then
|
|
66
|
+
echo "devzone : catalogue : $app pas prêt après ${ATTENTE}s" >&2
|
|
67
|
+
return 1
|
|
68
|
+
fi
|
|
69
|
+
relais_lancer "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
|
|
70
|
+
echo "✔ $app prêt : 127.0.0.1:$port dans le conteneur"
|
|
71
|
+
regenerer_identifiants
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Désinstalle une application : relais coupé, manifeste retiré, marque oubliée ;
|
|
75
|
+
# en terminal, confirmation avant de supprimer les données (PVC), sinon gardées
|
|
76
|
+
app_desinstaller() {
|
|
77
|
+
local app="$1" ns reponse
|
|
78
|
+
ns="$(app_ns "$app")"
|
|
79
|
+
relais_arreter "$app"
|
|
80
|
+
rm -f "$(fichier_echec "$app")"
|
|
81
|
+
kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
|
|
82
|
+
"secret/$app-admin" >/dev/null 2>&1 || true
|
|
83
|
+
if cluster_interactif; then
|
|
84
|
+
printf 'Supprimer les données de %s (namespace %s) ? [o/N] ' "$app" "$ns" >&2
|
|
85
|
+
read -r reponse || reponse=""
|
|
86
|
+
case "$reponse" in
|
|
87
|
+
o | O | oui)
|
|
88
|
+
kubectl --context devzone delete namespace "$ns" >/dev/null 2>&1 || true
|
|
89
|
+
rm -rf "$RACINE/workspace/.$app"
|
|
90
|
+
;;
|
|
91
|
+
*) echo "Données de $app gardées (namespace $ns) ; pour les supprimer : devzone desactiver $app" ;;
|
|
92
|
+
esac
|
|
93
|
+
else
|
|
94
|
+
echo "Sans terminal : données de $app gardées (namespace $ns) ; pour les supprimer, dans un terminal : devzone desactiver $app"
|
|
95
|
+
fi
|
|
96
|
+
echo "✔ $app retiré du cluster"
|
|
97
|
+
regenerer_identifiants
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Marque d'échec d'une tentative : dernière ligne du message gardée et montrée
|
|
101
|
+
app_echec() {
|
|
102
|
+
printf '%s\n' "$2" | tail -1 >"$(fichier_echec "$1")"
|
|
103
|
+
printf '%s\n' "$2" >&2
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# Comble l'écart entre le voulu et le réel : installe, retire, relance le
|
|
107
|
+
# relais permanent ; marque l'échec au premier problème puis passe à la suite
|
|
108
|
+
catalogue_appliquer() {
|
|
109
|
+
local app sortie code=0 port CTX ns
|
|
110
|
+
while IFS= read -r app; do
|
|
111
|
+
[ -n "$app" ] || continue
|
|
112
|
+
port="$(app_lire "$app" port)"
|
|
113
|
+
if [ "$(voulu "$app")" != on ] && presente "$app"; then
|
|
114
|
+
if ! sortie="$(app_desinstaller "$app" 2>&1)"; then
|
|
115
|
+
code=1; app_echec "$app" "$sortie"
|
|
116
|
+
else
|
|
117
|
+
printf '%s\n' "$sortie"
|
|
118
|
+
fi
|
|
119
|
+
elif [ "$(voulu "$app")" = on ] && presente "$app"; then
|
|
120
|
+
if ! app_prete "$app"; then
|
|
121
|
+
code=1
|
|
122
|
+
echo "devzone : catalogue : $app installé mais pas prêt : devzone appliquer" >&2
|
|
123
|
+
echo "pas prêt" >"$(fichier_echec "$app")"
|
|
124
|
+
else
|
|
125
|
+
rm -f "$(fichier_echec "$app")"
|
|
126
|
+
fi
|
|
127
|
+
# Relais permanent : relancé s'il est arrêté
|
|
128
|
+
CTX="$(cluster_lu)" || true
|
|
129
|
+
ns="$(app_ns "$app")"
|
|
130
|
+
if [ -n "$CTX" ]; then
|
|
131
|
+
if ! sortie="$(relais_lancer "$app" "$CTX" "$ns" "svc/$app" "$port:$port" 2>&1)"; then
|
|
132
|
+
code=1; app_echec "$app" "$sortie"
|
|
133
|
+
else
|
|
134
|
+
[ -n "$sortie" ] && printf '%s\n' "$sortie"
|
|
135
|
+
fi
|
|
136
|
+
fi
|
|
137
|
+
elif [ "$(voulu "$app")" = on ]; then
|
|
138
|
+
if ! sortie="$(app_installer "$app" 2>&1)"; then
|
|
139
|
+
code=1; app_echec "$app" "$sortie"
|
|
140
|
+
else
|
|
141
|
+
printf '%s\n' "$sortie"
|
|
142
|
+
fi
|
|
143
|
+
fi
|
|
144
|
+
done <<<"$(catalogue_apps)"
|
|
145
|
+
return "$code"
|
|
146
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Détection à chaud du catalogue (#414) : quand .devzone.modules change,
|
|
3
|
+
# catalogue.sh appliquer est lancé. Une seule instance (verrou, comme #394).
|
|
4
|
+
# catalogue-veilleur.sh demarrer | arreter | tour
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
+
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
9
|
+
ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
10
|
+
BASE="${DEVZONE_CATALOGUE_VEILLEUR_DIR:-$RACINE/.devzone.catalogue-veilleur}"
|
|
11
|
+
VERROU="$BASE/verrou"
|
|
12
|
+
DERNIER="$BASE/dernier"
|
|
13
|
+
|
|
14
|
+
refuse() { echo "devzone : catalogue-veilleur : $*" >&2; exit 2; }
|
|
15
|
+
|
|
16
|
+
# Garde-fou (#293) : jamais sous bats, seulement avec DEVZONE_CATALOGUE_REEL=oui
|
|
17
|
+
garde_veilleur() {
|
|
18
|
+
if [ "${DEVZONE_CATALOGUE_REEL:-}" != oui ]; then
|
|
19
|
+
echo "devzone : catalogue-veilleur : refusé ici (DEVZONE_CATALOGUE_REEL=oui)" >&2
|
|
20
|
+
return 2
|
|
21
|
+
fi
|
|
22
|
+
if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
|
|
23
|
+
echo "devzone : catalogue-veilleur : refusé sous bats (tests)" >&2
|
|
24
|
+
return 2
|
|
25
|
+
fi
|
|
26
|
+
return 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# Verrou exclusif (mkdir) avec pid ; une seule instance du veilleur
|
|
30
|
+
verrou_prendre() {
|
|
31
|
+
local debut now age pid
|
|
32
|
+
debut="$(date +%s)"
|
|
33
|
+
while true; do
|
|
34
|
+
if mkdir "$VERROU" 2>/dev/null; then echo "$$" >"$VERROU/pid"; return 0; fi
|
|
35
|
+
now="$(date +%s)"
|
|
36
|
+
age=""; [ -d "$VERROU" ] && age="$(stat -c %Y "$VERROU" 2>/dev/null || stat -f %m "$VERROU" 2>/dev/null || true)"
|
|
37
|
+
pid="$(cat "$VERROU/pid" 2>/dev/null || true)"
|
|
38
|
+
if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$VERROU"; continue; fi
|
|
39
|
+
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$VERROU"; continue; fi
|
|
40
|
+
[ "$(( now - debut ))" -ge 5 ] && return 1
|
|
41
|
+
sleep 1
|
|
42
|
+
done
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Marque le verrou vivant (date et pid à jour)
|
|
46
|
+
verrou_rafraichir() { touch "$VERROU" 2>/dev/null || true; echo "$$" >"$VERROU/pid" 2>/dev/null || true; }
|
|
47
|
+
|
|
48
|
+
# Un tour : si .devzone.modules a changé depuis le dernier tour, on applique
|
|
49
|
+
tour() {
|
|
50
|
+
local maintenant ancien
|
|
51
|
+
[ -f "$ETAT" ] || return 0
|
|
52
|
+
mkdir -p "$BASE"
|
|
53
|
+
maintenant="$(stat -c %Y "$ETAT" 2>/dev/null || stat -f %m "$ETAT" 2>/dev/null || true)"
|
|
54
|
+
[ -n "$maintenant" ] || return 0
|
|
55
|
+
ancien="$(cat "$DERNIER" 2>/dev/null || true)"
|
|
56
|
+
if [ "$maintenant" != "$ancien" ]; then
|
|
57
|
+
echo "$maintenant" >"$DERNIER"
|
|
58
|
+
echo "devzone : catalogue-veilleur : .devzone.modules modifié, application" >&2
|
|
59
|
+
bash "$ICI/../catalogue.sh" appliquer
|
|
60
|
+
fi
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Boucle : un tour toutes les 5 s, verrou rafraîchi à chaque tour
|
|
64
|
+
boucle() {
|
|
65
|
+
if ! verrou_prendre; then return 0; fi
|
|
66
|
+
trap 'rm -rf "$VERROU"' EXIT INT TERM
|
|
67
|
+
while true; do
|
|
68
|
+
[ -f "$ETAT" ] || { rm -rf "$VERROU"; break; }
|
|
69
|
+
verrou_rafraichir
|
|
70
|
+
tour || true
|
|
71
|
+
sleep 5
|
|
72
|
+
done
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# Arrête le veilleur et retire le verrou
|
|
76
|
+
arreter() {
|
|
77
|
+
local pid
|
|
78
|
+
pid="$(cat "$VERROU/pid" 2>/dev/null || true)"
|
|
79
|
+
if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi
|
|
80
|
+
rm -rf "$VERROU"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
case "${1:-}" in
|
|
84
|
+
demarrer | start | lancer)
|
|
85
|
+
if ! garde_veilleur; then exit 2; fi
|
|
86
|
+
if [ -f "$VERROU/pid" ] && kill -0 "$(cat "$VERROU/pid")" 2>/dev/null; then
|
|
87
|
+
echo "déjà lancé"
|
|
88
|
+
else
|
|
89
|
+
DEVZONE_CATALOGUE_REEL=oui bash "$0" boucle >/dev/null 2>&1 &
|
|
90
|
+
echo "lancé"
|
|
91
|
+
fi
|
|
92
|
+
;;
|
|
93
|
+
arreter | stop) arreter ; echo "arrêté" ;;
|
|
94
|
+
tour | un-tour) tour ;;
|
|
95
|
+
*)
|
|
96
|
+
echo "devzone : catalogue-veilleur : demarrer | arreter | tour" >&2
|
|
97
|
+
exit 2
|
|
98
|
+
;;
|
|
99
|
+
esac
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Application MySQL du catalogue (#414) : MySQL local de test pour les projets
|
|
2
|
+
# du workspace, installé dans le cluster des services de devzone.
|
|
3
|
+
# Mémoire et taille du volume : 1 Gi et 5Gi par défaut, modifiables ici.
|
|
4
|
+
nom=mysql
|
|
5
|
+
description=MySQL partagé, une base par projet
|
|
6
|
+
image=mysql:8.4
|
|
7
|
+
port=3306
|
|
8
|
+
memoire=1Gi
|
|
9
|
+
taille=5Gi
|
|
10
|
+
namespace=devzone-mysql
|
|
11
|
+
utilisateur_admin=root
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# namespace __NS__
|
|
2
|
+
# Application MySQL du catalogue (#414) : manifeste simple (pas de chart,
|
|
3
|
+
# kubectl apply suffit, comme postgres.yaml) appliqué par catalogue.sh avec
|
|
4
|
+
# les variables suivantes remplacées :
|
|
5
|
+
# __APP__ __NS__ __IMAGE__ __PORT__ __MEMOIRE__ __TAILLE__
|
|
6
|
+
# Secret __APP__-admin créé avant (mot de passe root, jamais écrit ici).
|
|
7
|
+
apiVersion: v1
|
|
8
|
+
kind: Service
|
|
9
|
+
metadata:
|
|
10
|
+
name: __APP__
|
|
11
|
+
namespace: __NS__
|
|
12
|
+
labels:
|
|
13
|
+
app: __APP__
|
|
14
|
+
app.kubernetes.io/managed-by: devzone
|
|
15
|
+
spec:
|
|
16
|
+
selector:
|
|
17
|
+
app: __APP__
|
|
18
|
+
ports:
|
|
19
|
+
- name: __APP__
|
|
20
|
+
port: __PORT__
|
|
21
|
+
targetPort: 3306
|
|
22
|
+
---
|
|
23
|
+
apiVersion: apps/v1
|
|
24
|
+
kind: StatefulSet
|
|
25
|
+
metadata:
|
|
26
|
+
name: __APP__
|
|
27
|
+
namespace: __NS__
|
|
28
|
+
labels:
|
|
29
|
+
app: __APP__
|
|
30
|
+
app.kubernetes.io/managed-by: devzone
|
|
31
|
+
spec:
|
|
32
|
+
serviceName: __APP__
|
|
33
|
+
replicas: 1
|
|
34
|
+
selector:
|
|
35
|
+
matchLabels:
|
|
36
|
+
app: __APP__
|
|
37
|
+
template:
|
|
38
|
+
metadata:
|
|
39
|
+
labels:
|
|
40
|
+
app: __APP__
|
|
41
|
+
app.kubernetes.io/managed-by: devzone
|
|
42
|
+
spec:
|
|
43
|
+
containers:
|
|
44
|
+
- name: __APP__
|
|
45
|
+
# Version figée : mettre à jour ici (même majeure : données gardées)
|
|
46
|
+
image: __IMAGE__
|
|
47
|
+
env:
|
|
48
|
+
- name: MYSQL_ROOT_PASSWORD
|
|
49
|
+
valueFrom:
|
|
50
|
+
secretKeyRef:
|
|
51
|
+
name: __APP__-admin
|
|
52
|
+
key: password
|
|
53
|
+
ports:
|
|
54
|
+
- containerPort: 3306
|
|
55
|
+
name: __APP__
|
|
56
|
+
readinessProbe:
|
|
57
|
+
exec:
|
|
58
|
+
command: ["/bin/sh", "-c", "mysql -uroot -p\"$MYSQL_ROOT_PASSWORD\" -e 'SELECT 1'"]
|
|
59
|
+
initialDelaySeconds: 10
|
|
60
|
+
periodSeconds: 5
|
|
61
|
+
resources:
|
|
62
|
+
requests:
|
|
63
|
+
cpu: 100m
|
|
64
|
+
memory: __MEMOIRE__
|
|
65
|
+
volumeMounts:
|
|
66
|
+
- name: donnees
|
|
67
|
+
mountPath: /var/lib/mysql
|
|
68
|
+
volumeClaimTemplates:
|
|
69
|
+
- metadata:
|
|
70
|
+
name: donnees
|
|
71
|
+
labels:
|
|
72
|
+
app.kubernetes.io/managed-by: devzone
|
|
73
|
+
spec:
|
|
74
|
+
accessModes: ["ReadWriteOnce"]
|
|
75
|
+
resources:
|
|
76
|
+
requests:
|
|
77
|
+
storage: __TAILLE__
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# MySQL du catalogue (#414) : creer, liste, supprimer, etat, relais, installer, desinstaller.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$(dirname "$ICI")")")}"
|
|
6
|
+
ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
7
|
+
# shellcheck source=SCRIPTDIR/../../cluster.sh
|
|
8
|
+
# shellcheck disable=SC1091
|
|
9
|
+
. "$ICI/../../cluster.sh"
|
|
10
|
+
# shellcheck source=SCRIPTDIR/../../password.sh
|
|
11
|
+
# shellcheck disable=SC1091
|
|
12
|
+
. "$ICI/../../password.sh"
|
|
13
|
+
# shellcheck source=SCRIPTDIR/../../isolement.sh
|
|
14
|
+
# shellcheck disable=SC1091
|
|
15
|
+
. "$ICI/../../isolement.sh"
|
|
16
|
+
NS=devzone-mysql
|
|
17
|
+
SECRETS="$RACINE/workspace/.mysql"
|
|
18
|
+
MYSQL_PORT="${MYSQL_PORT:-3306}"
|
|
19
|
+
MYSQL_IMAGE="${MYSQL_IMAGE:-mysql:8.4}"
|
|
20
|
+
MYSQL_MEMOIRE="${MYSQL_MEMOIRE:-1Gi}"
|
|
21
|
+
MYSQL_TAILLE="${MYSQL_TAILLE:-5Gi}"
|
|
22
|
+
MYSQL_ATTENTE="${MYSQL_ATTENTE:-300}"
|
|
23
|
+
# Refus standard avec message et code 2
|
|
24
|
+
refuse() { echo "devzone : catalogue mysql : $*" >&2; exit 2; }
|
|
25
|
+
# Régénère la vue .password (échec non bloquant)
|
|
26
|
+
regenerer_identifiants() {
|
|
27
|
+
password_regenerer ||
|
|
28
|
+
echo "devzone : catalogue mysql : identifiants regroupés non mis à jour (devzone mots-de-passe)" >&2
|
|
29
|
+
}
|
|
30
|
+
# Raccourci kubectl dans le namespace devzone-mysql
|
|
31
|
+
k() { kubectl --context devzone -n "$NS" "$@"; }
|
|
32
|
+
# Le namespace devzone-mysql existe-t-il ?
|
|
33
|
+
installe() { kubectl --context devzone get namespace "$NS" >/dev/null 2>&1; }
|
|
34
|
+
# Contexte du module : celui du cluster de devzone
|
|
35
|
+
contexte() {
|
|
36
|
+
local c
|
|
37
|
+
c="$(cluster_lu)"
|
|
38
|
+
[ -n "$c" ] || refuse "aucun cluster choisi : devzone activer mysql"
|
|
39
|
+
echo "$c"
|
|
40
|
+
}
|
|
41
|
+
# Marque d'échec du module (même schéma que fichier_echec de devzone)
|
|
42
|
+
fichier_echec() { echo "$ETAT-echec-mysql"; }
|
|
43
|
+
# Nom de projet : identifiant SQL simple, jamais à échapper, pas un nom réservé
|
|
44
|
+
valider_projet() {
|
|
45
|
+
local p="${1:-}"
|
|
46
|
+
[ -n "$p" ] || refuse "nom de projet manquant"
|
|
47
|
+
[[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "nom de projet invalide : $p (minuscules, chiffres, _ ; commence par une lettre)"
|
|
48
|
+
case "$p" in
|
|
49
|
+
mysql | information_schema | performance_schema | sys) refuse "nom réservé : $p" ;;
|
|
50
|
+
esac
|
|
51
|
+
}
|
|
52
|
+
# Mot de passe aléatoire pour un nouveau projet
|
|
53
|
+
mot_de_passe() { openssl rand -hex 24; }
|
|
54
|
+
# Mot de passe root : root.env d'une installation existante, sinon admin-password
|
|
55
|
+
root_password() {
|
|
56
|
+
local mdp
|
|
57
|
+
mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
58
|
+
[ -z "$mdp" ] && [ -f "$SECRETS/admin-password" ] && mdp="$(cat "$SECRETS/admin-password" 2>/dev/null || true)"
|
|
59
|
+
[ -n "$mdp" ] || refuse "mot de passe root MySQL introuvable (workspace/.mysql/root.env)"
|
|
60
|
+
echo "$mdp"
|
|
61
|
+
}
|
|
62
|
+
# mysql en superutilisateur dans le pod ; le mot de passe n'est jamais affiché
|
|
63
|
+
mysql_admin() { k exec -i mysql-0 -c mysql -- mysql -uroot -p"$(root_password)" "$@"; }
|
|
64
|
+
# Nombre de bases hors bases système
|
|
65
|
+
nombre_bases() {
|
|
66
|
+
local n
|
|
67
|
+
n="$(mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null | grep -vE '^(information_schema|mysql|performance_schema|sys)$' | grep -c . || true)"
|
|
68
|
+
echo "${n:-0}"
|
|
69
|
+
}
|
|
70
|
+
# Secret admin (mysql-admin) : root.env ou secret existant, jamais régénéré.
|
|
71
|
+
mysql_secret() {
|
|
72
|
+
local mdp fichier="$SECRETS/admin-password"
|
|
73
|
+
mkdir -p "$SECRETS"
|
|
74
|
+
chmod 700 "$SECRETS"
|
|
75
|
+
if k get secret mysql-admin >/dev/null 2>&1; then
|
|
76
|
+
mdp="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
|
|
77
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
78
|
+
return 0
|
|
79
|
+
fi
|
|
80
|
+
mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
81
|
+
if [ -z "$mdp" ] && [ -s "$fichier" ]; then mdp="$(cat "$fichier")"; fi
|
|
82
|
+
if [ -z "$mdp" ]; then
|
|
83
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$fichier")
|
|
84
|
+
k create secret generic mysql-admin --from-file=password="$fichier" >/dev/null
|
|
85
|
+
elif [ ! -s "$fichier" ]; then
|
|
86
|
+
(umask 077 && printf '%s' "$mdp" >"$fichier")
|
|
87
|
+
fi
|
|
88
|
+
}
|
|
89
|
+
installer() {
|
|
90
|
+
local CTX
|
|
91
|
+
CTX="$(contexte)"
|
|
92
|
+
if ! contexte_devzone_poser "$CTX"; then
|
|
93
|
+
echo "devzone : catalogue mysql : impossible de poser le contexte devzone sur $CTX" >&2
|
|
94
|
+
return 1
|
|
95
|
+
fi
|
|
96
|
+
echo "▶ MySQL sur le cluster $CTX (namespace $NS)…"
|
|
97
|
+
kubectl --context devzone create namespace "$NS" --dry-run=client -o yaml |
|
|
98
|
+
kubectl --context devzone apply -f - >/dev/null
|
|
99
|
+
kubectl --context devzone label namespace "$NS" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null
|
|
100
|
+
namespace_isoler "$NS" >/dev/null
|
|
101
|
+
if k get statefulset mysql >/dev/null 2>&1; then
|
|
102
|
+
echo "devzone : catalogue mysql : installation existante dans $NS, adoptée (volume et root.env gardés)"
|
|
103
|
+
else
|
|
104
|
+
mysql_secret
|
|
105
|
+
sed -e "s|__APP__|mysql|g" -e "s|__NS__|$NS|g" -e "s|__IMAGE__|$MYSQL_IMAGE|g" \
|
|
106
|
+
-e "s|__PORT__|$MYSQL_PORT|g" -e "s|__MEMOIRE__|$MYSQL_MEMOIRE|g" \
|
|
107
|
+
-e "s|__TAILLE__|$MYSQL_TAILLE|g" \
|
|
108
|
+
"$ICI/manifeste.yaml" | kubectl --context devzone -n "$NS" apply -f - >/dev/null
|
|
109
|
+
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
110
|
+
echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $NS describe pod mysql-0" >&2
|
|
111
|
+
return 1
|
|
112
|
+
fi
|
|
113
|
+
fi
|
|
114
|
+
mysql_secret
|
|
115
|
+
relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
116
|
+
echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
|
|
117
|
+
regenerer_identifiants
|
|
118
|
+
}
|
|
119
|
+
# Désinstalle MySQL : namespace supprimé, données de workspace/.mysql gardées
|
|
120
|
+
desinstaller() {
|
|
121
|
+
local CTX
|
|
122
|
+
CTX="$(cluster_lu)"
|
|
123
|
+
relais_arreter mysql
|
|
124
|
+
rm -f "$(fichier_echec)"
|
|
125
|
+
if [ -n "$CTX" ]; then
|
|
126
|
+
contexte_devzone_poser "$CTX" ||
|
|
127
|
+
echo "devzone : catalogue mysql : contexte devzone non posé sur $CTX ; nettoyage local seulement" >&2
|
|
128
|
+
fi
|
|
129
|
+
if [ -n "$CTX" ] && installe; then
|
|
130
|
+
echo "▶ Suppression de MySQL sur $CTX (données de workspace/.mysql gardées)…"
|
|
131
|
+
kubectl --context devzone delete namespace "$NS" --wait=true >/dev/null
|
|
132
|
+
fi
|
|
133
|
+
echo "✔ MySQL désinstallé ; données de workspace/.mysql gardées"
|
|
134
|
+
regenerer_identifiants
|
|
135
|
+
}
|
|
136
|
+
# État : désactivé, en échec, prêt, relais arrêté
|
|
137
|
+
etat() {
|
|
138
|
+
local CTX
|
|
139
|
+
CTX="$(cluster_lu)"
|
|
140
|
+
if [ -z "$CTX" ] || ! installe; then
|
|
141
|
+
echo "désactivé"
|
|
142
|
+
return 0
|
|
143
|
+
fi
|
|
144
|
+
if [ "$(k get statefulset mysql -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
|
|
145
|
+
echo "en échec sur $CTX : devzone appliquer"
|
|
146
|
+
return 0
|
|
147
|
+
fi
|
|
148
|
+
if ! relais_actif mysql; then
|
|
149
|
+
echo "prêt sur $CTX, relais arrêté : devzone appliquer"
|
|
150
|
+
return 0
|
|
151
|
+
fi
|
|
152
|
+
echo "prêt sur $CTX : 127.0.0.1:$MYSQL_PORT, $(nombre_bases) base(s)"
|
|
153
|
+
}
|
|
154
|
+
# Crée l'utilisateur et la base d'un projet ; .env en 600, mot de passe gardé
|
|
155
|
+
creer() {
|
|
156
|
+
local projet="${1:-}" nouveau="" fichier mdp arg
|
|
157
|
+
valider_projet "$projet"
|
|
158
|
+
for arg in "${@:2}"; do
|
|
159
|
+
case "$arg" in
|
|
160
|
+
--nouveau-mdp) nouveau=1 ;;
|
|
161
|
+
*) refuse "argument inconnu : $arg" ;;
|
|
162
|
+
esac
|
|
163
|
+
done
|
|
164
|
+
CTX="$(contexte)"
|
|
165
|
+
installe || refuse "module inactif : devzone activer mysql"
|
|
166
|
+
fichier="$SECRETS/$projet.env"
|
|
167
|
+
if [ -z "$nouveau" ] && [ -s "$fichier" ]; then
|
|
168
|
+
mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$fichier" 2>/dev/null | tail -1)"
|
|
169
|
+
else
|
|
170
|
+
mdp="$(mot_de_passe)"
|
|
171
|
+
fi
|
|
172
|
+
mysql_admin <<SQL
|
|
173
|
+
CREATE USER IF NOT EXISTS '$projet'@'%' IDENTIFIED BY '$mdp';
|
|
174
|
+
ALTER USER '$projet'@'%' IDENTIFIED BY '$mdp';
|
|
175
|
+
CREATE DATABASE IF NOT EXISTS $projet;
|
|
176
|
+
GRANT ALL ON $projet.* TO '$projet'@'%';
|
|
177
|
+
SQL
|
|
178
|
+
mkdir -p "$SECRETS"
|
|
179
|
+
chmod 700 "$SECRETS"
|
|
180
|
+
(
|
|
181
|
+
umask 077
|
|
182
|
+
cat >"$fichier" <<ENV
|
|
183
|
+
MYSQL_HOST=127.0.0.1
|
|
184
|
+
MYSQL_PORT=$MYSQL_PORT
|
|
185
|
+
MYSQL_USER=$projet
|
|
186
|
+
MYSQL_PASSWORD=$mdp
|
|
187
|
+
MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$projet
|
|
188
|
+
ENV
|
|
189
|
+
)
|
|
190
|
+
echo "✔ base $projet prête ; identifiants : $fichier"
|
|
191
|
+
regenerer_identifiants
|
|
192
|
+
}
|
|
193
|
+
# Liste les bases du serveur
|
|
194
|
+
liste() {
|
|
195
|
+
local CTX
|
|
196
|
+
CTX="$(contexte)"
|
|
197
|
+
installe || refuse "module inactif : devzone activer mysql"
|
|
198
|
+
mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null |
|
|
199
|
+
grep -vE '^(information_schema|mysql|performance_schema|sys)$' |
|
|
200
|
+
awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (aucune base : devzone mysql creer <projet>)" }'
|
|
201
|
+
}
|
|
202
|
+
# Supprime la base et l'utilisateur d'un projet (confirmation sans --oui)
|
|
203
|
+
supprimer() {
|
|
204
|
+
local projet="${1:-}" oui="" arg reponse
|
|
205
|
+
valider_projet "$projet"
|
|
206
|
+
for arg in "${@:2}"; do
|
|
207
|
+
case "$arg" in
|
|
208
|
+
--oui) oui=1 ;;
|
|
209
|
+
*) refuse "argument inconnu : $arg" ;;
|
|
210
|
+
esac
|
|
211
|
+
done
|
|
212
|
+
CTX="$(contexte)"
|
|
213
|
+
installe || refuse "module inactif : devzone activer mysql"
|
|
214
|
+
if [ -z "$oui" ]; then
|
|
215
|
+
cluster_interactif || refuse "confirmation impossible sans terminal : devzone mysql supprimer $projet --oui"
|
|
216
|
+
printf 'Supprimer la base %s et son utilisateur ? [o/N] ' "$projet" >&2
|
|
217
|
+
read -r reponse || reponse=""
|
|
218
|
+
case "$reponse" in
|
|
219
|
+
o | O | oui) ;;
|
|
220
|
+
*) echo "Abandon : rien n'a été supprimé."; return 0 ;;
|
|
221
|
+
esac
|
|
222
|
+
fi
|
|
223
|
+
mysql_admin <<SQL
|
|
224
|
+
DROP DATABASE IF EXISTS $projet;
|
|
225
|
+
DROP USER IF EXISTS '$projet'@'%';
|
|
226
|
+
SQL
|
|
227
|
+
rm -f "$SECRETS/$projet.env"
|
|
228
|
+
echo "✔ base $projet supprimée"
|
|
229
|
+
regenerer_identifiants
|
|
230
|
+
}
|
|
231
|
+
# Relance le relais 127.0.0.1:3306 si le namespace existe
|
|
232
|
+
relais() {
|
|
233
|
+
local CTX
|
|
234
|
+
CTX="$(cluster_lu)"
|
|
235
|
+
[ -n "$CTX" ] && installe && relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
236
|
+
}
|
|
237
|
+
case "${1:-}" in
|
|
238
|
+
installer) installer ;;
|
|
239
|
+
desinstaller) desinstaller ;;
|
|
240
|
+
etat) etat ;;
|
|
241
|
+
creer) creer "${@:2}" ;;
|
|
242
|
+
liste) liste ;;
|
|
243
|
+
supprimer) supprimer "${@:2}" ;;
|
|
244
|
+
relais-lancer) relais ;;
|
|
245
|
+
relais-arreter) relais_arreter mysql ;;
|
|
246
|
+
*)
|
|
247
|
+
echo "devzone : catalogue mysql : creer <projet> [--nouveau-mdp] | liste | supprimer <projet> [--oui]" >&2
|
|
248
|
+
exit 1
|
|
249
|
+
;;
|
|
250
|
+
esac
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Catalogue d'applications (#414) : une application préconfigurée par dossier
|
|
3
|
+
# .devcontainer/catalogue/<app>/ (app.conf, manifeste.yaml), installée dans le
|
|
4
|
+
# cluster des services de devzone sous son namespace de app.conf ; l'état
|
|
5
|
+
# voulu est la ligne <app>=on|off de .devzone.modules.
|
|
6
|
+
# catalogue.sh synchroniser | appliquer | lister | resume | json
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
10
|
+
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
11
|
+
ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
12
|
+
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
13
|
+
# shellcheck disable=SC1091
|
|
14
|
+
. "$ICI/cluster.sh"
|
|
15
|
+
# shellcheck source=SCRIPTDIR/password.sh
|
|
16
|
+
# shellcheck disable=SC1091
|
|
17
|
+
. "$ICI/password.sh"
|
|
18
|
+
# shellcheck source=SCRIPTDIR/isolement.sh
|
|
19
|
+
# shellcheck disable=SC1091
|
|
20
|
+
. "$ICI/isolement.sh"
|
|
21
|
+
# shellcheck source=SCRIPTDIR/catalogue/app.sh
|
|
22
|
+
# shellcheck disable=SC1091
|
|
23
|
+
. "$ICI/catalogue/app.sh"
|
|
24
|
+
|
|
25
|
+
refuse() { echo "devzone : catalogue : $*" >&2; exit 2; }
|
|
26
|
+
|
|
27
|
+
# Dossier du catalogue (surchargeable par les tests)
|
|
28
|
+
dossier_catalogue() { echo "${DEVZONE_CATALOGUE:-$ICI/catalogue}"; }
|
|
29
|
+
|
|
30
|
+
# Applications du catalogue : dossiers pourvus d'un app.conf, triés
|
|
31
|
+
catalogue_apps() {
|
|
32
|
+
local d
|
|
33
|
+
for d in "$(dossier_catalogue)"/*; do
|
|
34
|
+
[ -f "$d/app.conf" ] || continue
|
|
35
|
+
echo "${d##*/}"
|
|
36
|
+
done | LC_ALL=C sort
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Clé de app.conf (nom, description, image, port, mémoire, taille, namespace)
|
|
40
|
+
app_lire() {
|
|
41
|
+
grep -E "^$2=" "$(dossier_catalogue)/$1/app.conf" 2>/dev/null | tail -1 | cut -d= -f2- || true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Namespace de l'application : celui de app.conf (requis)
|
|
45
|
+
app_ns() {
|
|
46
|
+
local ns
|
|
47
|
+
ns="$(app_lire "$1" namespace)"
|
|
48
|
+
[ -n "$ns" ] || refuse "namespace manquant dans app.conf de $1"
|
|
49
|
+
echo "$ns"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Marque d'échec d'une application : même schéma que fichier_echec des modules
|
|
53
|
+
fichier_echec() { echo "$ETAT-echec-$1"; }
|
|
54
|
+
|
|
55
|
+
# État voulu : on si la ligne <app>=on existe, off par défaut
|
|
56
|
+
voulu() {
|
|
57
|
+
local v
|
|
58
|
+
v="$(grep -E "^$1=" "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
|
|
59
|
+
[ "$v" = on ] && echo on || echo off
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Application présente dans le cluster : namespace étiqueté et StatefulSet du
|
|
63
|
+
# nom de l'application ; sans cluster choisi ou absente : rien
|
|
64
|
+
presente() {
|
|
65
|
+
local ns
|
|
66
|
+
[ -n "$(cluster_lu)" ] || return 1
|
|
67
|
+
ns="$(app_ns "$1")"
|
|
68
|
+
kubectl --context devzone get namespace "$ns" >/dev/null 2>&1 &&
|
|
69
|
+
kubectl --context devzone -n "$ns" get statefulset "$1" >/dev/null 2>&1
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# Application prête : le StatefulSet compte une réplique prête
|
|
73
|
+
app_prete() {
|
|
74
|
+
local ns
|
|
75
|
+
ns="$(app_ns "$1")"
|
|
76
|
+
[ "$(kubectl --context devzone -n "$ns" get statefulset "$1" \
|
|
77
|
+
-o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" = 1 ]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Ajoute à l'état les lignes <app>=off des applications absentes (une fois
|
|
81
|
+
# chacune, jamais une ligne existante modifiée), précédées une fois du commentaire
|
|
82
|
+
catalogue_synchroniser() (
|
|
83
|
+
local app entete manque="" tmp
|
|
84
|
+
[ -f "$ETAT" ] || return 0
|
|
85
|
+
entete="# Applications du catalogue : passer à on pour installer (devzone catalogue)"
|
|
86
|
+
while IFS= read -r app; do
|
|
87
|
+
[ -n "$app" ] || continue
|
|
88
|
+
grep -qE "^${app}=" "$ETAT" 2>/dev/null && continue
|
|
89
|
+
manque="${manque}${manque:+$'\n'}${app}=off"
|
|
90
|
+
done <<<"$(catalogue_apps)"
|
|
91
|
+
[ -n "$manque" ] || return 0
|
|
92
|
+
mkdir -p "$(dirname "$ETAT")"
|
|
93
|
+
tmp="$(mktemp)"
|
|
94
|
+
{
|
|
95
|
+
cat "$ETAT"
|
|
96
|
+
grep -qF "$entete" "$ETAT" || echo "$entete"
|
|
97
|
+
echo "$manque"
|
|
98
|
+
} >"$tmp"
|
|
99
|
+
mv "$tmp" "$ETAT"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# État réel d'une application : disponible, attendue, installée, echec
|
|
103
|
+
app_etat() {
|
|
104
|
+
local app="$1"
|
|
105
|
+
if [ "$(voulu "$app")" != on ]; then
|
|
106
|
+
echo disponible
|
|
107
|
+
elif [ -f "$(fichier_echec "$app")" ]; then
|
|
108
|
+
echo echec
|
|
109
|
+
elif presente "$app"; then
|
|
110
|
+
echo installée
|
|
111
|
+
else
|
|
112
|
+
echo attendue
|
|
113
|
+
fi
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# devzone catalogue : nom, état (off, on installée, on en échec), description
|
|
117
|
+
catalogue_lister() {
|
|
118
|
+
local app etat etiquette
|
|
119
|
+
while IFS= read -r app; do
|
|
120
|
+
[ -n "$app" ] || continue
|
|
121
|
+
etat="$(app_etat "$app")"
|
|
122
|
+
case "$etat" in
|
|
123
|
+
disponible) etiquette='off disponible' ;;
|
|
124
|
+
installée) etiquette="on installée" ;;
|
|
125
|
+
echec) etiquette="on en échec" ;;
|
|
126
|
+
*) etiquette="on attendue" ;;
|
|
127
|
+
esac
|
|
128
|
+
printf ' %-12s %-14s %s\n' "$app" "$etiquette" "$(app_lire "$app" description)"
|
|
129
|
+
done <<<"$(catalogue_apps)"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Relais de l application installee : etat de son script, sinon pid du relais
|
|
133
|
+
app_relais_arrete() {
|
|
134
|
+
local app="$1" script etat
|
|
135
|
+
script="$ICI/catalogue/$app/$app.sh"
|
|
136
|
+
if [ -f "$script" ]; then
|
|
137
|
+
etat="$(bash "$script" etat 2>/dev/null || true)"
|
|
138
|
+
case "$etat" in *"relais arrêté"*) return 0 ;; esac
|
|
139
|
+
fi
|
|
140
|
+
! relais_actif "$app"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# Lignes Applications du récapitulatif de devzone : ○ disponible, ✔ installée
|
|
144
|
+
# (adresse du relais), ✖ en échec, ⚠ attendue
|
|
145
|
+
catalogue_resume() {
|
|
146
|
+
local app
|
|
147
|
+
while IFS= read -r app; do
|
|
148
|
+
[ -n "$app" ] || continue
|
|
149
|
+
case "$(app_etat "$app")" in
|
|
150
|
+
disponible) printf ' ○ application %-12s disponible, %s : devzone activer %s\n' \
|
|
151
|
+
"$app" "$(app_lire "$app" description)" "$app" ;;
|
|
152
|
+
installée)
|
|
153
|
+
if app_relais_arrete "$app"; then
|
|
154
|
+
printf ' ⚠ application %-12s installée, relais arrêté : devzone reparer\n' "$app"
|
|
155
|
+
else
|
|
156
|
+
printf ' ✔ application %-12s installée : 127.0.0.1:%s\n' \
|
|
157
|
+
"$app" "$(app_lire "$app" port)"
|
|
158
|
+
fi ;;
|
|
159
|
+
attendue) printf ' ⚠ application %-12s attendue : devzone appliquer\n' "$app" ;;
|
|
160
|
+
*) printf ' ✖ application %s en échec : %s : devzone appliquer\n' \
|
|
161
|
+
"$app" "$(head -1 "$(fichier_echec "$app")")" ;;
|
|
162
|
+
esac
|
|
163
|
+
done <<<"$(catalogue_apps)"
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Rubrique applications de devzone etat --json : mêmes champs que modules
|
|
167
|
+
catalogue_json() {
|
|
168
|
+
local app actif etat echec cmd json='[]'
|
|
169
|
+
while IFS= read -r app; do
|
|
170
|
+
[ -n "$app" ] || continue
|
|
171
|
+
actif=false
|
|
172
|
+
[ "$(voulu "$app")" = on ] && actif=true
|
|
173
|
+
etat="$(app_etat "$app")"
|
|
174
|
+
echec=""
|
|
175
|
+
cmd="devzone appliquer"
|
|
176
|
+
case "$etat" in
|
|
177
|
+
disponible) cmd="devzone activer $app" ;;
|
|
178
|
+
installée) cmd="devzone desactiver $app" ;;
|
|
179
|
+
echec) echec="$(head -1 "$(fichier_echec "$app")")" ;;
|
|
180
|
+
esac
|
|
181
|
+
json="$(jq -cn --argjson avant "$json" --arg nom "$app" --argjson actif "$actif" \
|
|
182
|
+
--arg description "$(app_lire "$app" description)" \
|
|
183
|
+
--arg etat "$etat" --arg port "$(app_lire "$app" port)" \
|
|
184
|
+
--arg echec "$echec" --arg commande "$cmd" \
|
|
185
|
+
'$avant + [{nom:$nom,actif:$actif,description:$description,port:$port,etat:$etat,echec:(if $echec=="" then null else $echec end),commande:(if $commande=="" then null else $commande end)}]')"
|
|
186
|
+
done <<<"$(catalogue_apps)"
|
|
187
|
+
printf '%s\n' "$json"
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case "${1:-}" in
|
|
191
|
+
synchroniser) catalogue_synchroniser ;;
|
|
192
|
+
appliquer) catalogue_appliquer ;;
|
|
193
|
+
lister) catalogue_lister ;;
|
|
194
|
+
resume) catalogue_resume ;;
|
|
195
|
+
json) catalogue_json ;;
|
|
196
|
+
-h | --help | aide) sed -n '2,6p' "$0" | sed 's/^# \{0,1\}//' ;;
|
|
197
|
+
*)
|
|
198
|
+
echo "devzone : catalogue : synchroniser | appliquer | lister | resume | json" >&2
|
|
199
|
+
exit 1
|
|
200
|
+
;;
|
|
201
|
+
esac
|
|
@@ -35,12 +35,22 @@ fi
|
|
|
35
35
|
if bash "$ICI/devzone" actif argocd; then
|
|
36
36
|
bash "$ICI/argocd/argocd.sh" relais-lancer || echo "démarrage : relais argocd non lancé (devzone reparer)"
|
|
37
37
|
fi
|
|
38
|
+
# Module mysql actif : le relais 127.0.0.1:3306, relancé comme celui de
|
|
39
|
+
# postgres après chaque démarrage
|
|
40
|
+
if bash "$ICI/devzone" actif mysql; then
|
|
41
|
+
bash "$ICI/catalogue/mysql/mysql.sh" relais-lancer || echo "démarrage : relais mysql non lancé (devzone reparer)"
|
|
42
|
+
fi
|
|
38
43
|
# Relais de ports vers le poste (#290) : l'IP du conteneur change à chaque
|
|
39
44
|
# démarrage, chaque relais de l'état est recréé ; un échec n'empêche rien
|
|
40
45
|
bash "$ICI/ports.sh" relancer || echo "démarrage : relais de ports non relancés (devzone reparer)"
|
|
41
46
|
# Veilleur de ports automatiques vers le poste (#394, garde #293) : une seule
|
|
42
47
|
# instance en arrière-plan, contexte réel posé pour cet appel seulement
|
|
43
48
|
DEVZONE_PORTS_AUTO_REEL=oui bash "$ICI/ports-auto.sh" demarrer >/dev/null 2>&1 || echo "démarrage : veilleur de ports auto non lancé (devzone reparer)"
|
|
49
|
+
# Catalogue d'applications : une ligne <app>=off par application absente,
|
|
50
|
+
# écrite une fois, jamais une ligne existante modifiée (#414)
|
|
51
|
+
bash "$ICI/catalogue.sh" synchroniser || echo "démarrage : catalogue non synchronisé (devzone reparer)"
|
|
52
|
+
# Veilleur du catalogue : réapplique à chaud dès que .devzone.modules change
|
|
53
|
+
DEVZONE_CATALOGUE_REEL=oui bash "$ICI/catalogue/catalogue-veilleur.sh" demarrer >/dev/null 2>&1 || echo "démarrage : veilleur catalogue non lancé (devzone reparer)"
|
|
44
54
|
|
|
45
55
|
# Vue regroupée des identifiants (#332), regénérée à chaque démarrage ; un
|
|
46
56
|
# échec n'empêche rien et le contenu n'est jamais affiché
|
package/.devcontainer/devzone
CHANGED
|
@@ -50,7 +50,7 @@ VERSIONS="$ICI/../manage/scripts/versions.sh"
|
|
|
50
50
|
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
51
51
|
# État par défaut de l'instance ; DEVZONE_ETAT garde la priorité (tests, CI)
|
|
52
52
|
ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
53
|
-
MODULES=(ia kubernetes gitlab postgres argocd)
|
|
53
|
+
MODULES=(ia kubernetes gitlab postgres argocd mysql)
|
|
54
54
|
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
55
55
|
# shellcheck disable=SC1091
|
|
56
56
|
. "$ICI/cluster.sh"
|
|
@@ -85,6 +85,7 @@ description() {
|
|
|
85
85
|
gitlab) echo "GitLab de test dans le cluster des services" ;;
|
|
86
86
|
postgres) echo "PostgreSQL partagé, une base par projet" ;;
|
|
87
87
|
argocd) echo "Argo CD, interface de déploiement du cluster des services" ;;
|
|
88
|
+
mysql) echo "MySQL partagé, une base par projet" ;;
|
|
88
89
|
esac
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -435,6 +436,36 @@ appliquer_argocd() {
|
|
|
435
436
|
fi
|
|
436
437
|
}
|
|
437
438
|
|
|
439
|
+
# MySQL du catalogue (#414) : même logique que postgres (relais relancé s'il
|
|
440
|
+
# est arrêté), installation déléguée à mysql.sh
|
|
441
|
+
appliquer_mysql() {
|
|
442
|
+
local etat_courant ctx
|
|
443
|
+
if [ "$1" = on ]; then
|
|
444
|
+
ctx="$(cluster_lu)"
|
|
445
|
+
if [ -z "$ctx" ]; then
|
|
446
|
+
echo "devzone : mysql : aucun cluster choisi : devzone activer mysql" >&2
|
|
447
|
+
ecrire mysql off
|
|
448
|
+
echo mysql >"$(fichier_echec mysql)"
|
|
449
|
+
return 2
|
|
450
|
+
fi
|
|
451
|
+
etat_courant="$(bash "$ICI/catalogue/mysql/mysql.sh" etat)"
|
|
452
|
+
# « relais arrêté » d'abord : cette ligne commence aussi par « prêt sur »
|
|
453
|
+
if [[ "$etat_courant" == *"relais arrêté"* ]]; then
|
|
454
|
+
bash "$ICI/catalogue/mysql/mysql.sh" relais-lancer
|
|
455
|
+
echo "devzone : mysql : relais relancé"
|
|
456
|
+
elif [[ "$etat_courant" == "prêt sur"* ]]; then
|
|
457
|
+
echo "devzone : mysql déjà actif, rien à faire."
|
|
458
|
+
elif ! bash "$ICI/catalogue/mysql/mysql.sh" installer; then
|
|
459
|
+
echo mysql >"$(fichier_echec mysql)"
|
|
460
|
+
return 1
|
|
461
|
+
fi
|
|
462
|
+
rm -f "$(fichier_echec mysql)"
|
|
463
|
+
else
|
|
464
|
+
bash "$ICI/catalogue/mysql/mysql.sh" desinstaller
|
|
465
|
+
rm -f "$(fichier_echec mysql)"
|
|
466
|
+
fi
|
|
467
|
+
}
|
|
468
|
+
|
|
438
469
|
# Toutes les bases disparaissent : confirmation en terminal (sans terminal, la
|
|
439
470
|
# commande est explicite)
|
|
440
471
|
confirmer_suppression_postgres() {
|
|
@@ -862,8 +893,12 @@ reparer() {
|
|
|
862
893
|
if [ "$(valeur argocd)" = on ]; then
|
|
863
894
|
reparer_element "relais argocd" bash "$ICI/argocd/argocd.sh" relais-lancer
|
|
864
895
|
fi
|
|
896
|
+
if [ "$(valeur mysql)" = on ]; then
|
|
897
|
+
reparer_element "relais mysql" bash "$ICI/catalogue/mysql/mysql.sh" relais-lancer
|
|
898
|
+
fi
|
|
865
899
|
reparer_element "relais de ports" bash "$ICI/ports.sh" relancer
|
|
866
900
|
reparer_element "veilleur ports auto" env DEVZONE_PORTS_AUTO_REEL=oui bash "$ICI/ports-auto.sh" demarrer
|
|
901
|
+
reparer_element "veilleur catalogue" env DEVZONE_CATALOGUE_REEL=oui bash "$ICI/catalogue/catalogue-veilleur.sh" demarrer
|
|
867
902
|
reparer_element "identifiants" bash "$ICI/password.sh" regenerer
|
|
868
903
|
return "$reparer_echec"
|
|
869
904
|
}
|
|
@@ -1014,12 +1049,18 @@ etat() {
|
|
|
1014
1049
|
printf ' ✔ module %-10s %s\n' "$m" "$(bash "$ICI/postgres/postgres.sh" etat)"
|
|
1015
1050
|
elif [ "$(valeur "$m")" = on ] && [ "$m" = argocd ]; then
|
|
1016
1051
|
printf ' ✔ module %-10s %s\n' "$m" "$(bash "$ICI/argocd/argocd.sh" etat)"
|
|
1052
|
+
elif [ "$(valeur "$m")" = on ] && [ "$m" = mysql ]; then
|
|
1053
|
+
printf ' ✔ module %-10s %s\n' "$m" "$(bash "$ICI/catalogue/mysql/mysql.sh" etat)"
|
|
1017
1054
|
elif [ "$(valeur "$m")" = on ]; then
|
|
1018
1055
|
printf ' ✔ module %-10s actif : %s\n' "$m" "$(description "$m")"
|
|
1019
1056
|
else
|
|
1020
1057
|
printf ' ○ module %-10s facultatif, %s : devzone activer %s\n' "$m" "$(description "$m")" "$m"
|
|
1021
1058
|
fi
|
|
1022
1059
|
done
|
|
1060
|
+
# Applications du catalogue (#414)
|
|
1061
|
+
if [ -d "$ICI/catalogue" ]; then
|
|
1062
|
+
bash "$ICI/catalogue.sh" resume
|
|
1063
|
+
fi
|
|
1023
1064
|
# Cluster de devzone distant : avertissement dans le récapitulatif
|
|
1024
1065
|
cluster_actuel="$(cluster_lu)"
|
|
1025
1066
|
if [ -n "$cluster_actuel" ] && ! cluster_est_local "$cluster_actuel"; then
|
|
@@ -1074,8 +1115,18 @@ etat() {
|
|
|
1074
1115
|
|
|
1075
1116
|
changer() {
|
|
1076
1117
|
local m="${2:-}"
|
|
1077
|
-
if [ -z "$m" ]
|
|
1078
|
-
echo "devzone : module inconnu :
|
|
1118
|
+
if [ -z "$m" ]; then
|
|
1119
|
+
echo "devzone : module inconnu : (aucun) ; modules : ${MODULES[*]}" >&2
|
|
1120
|
+
exit 1
|
|
1121
|
+
fi
|
|
1122
|
+
if ! connu "$m"; then
|
|
1123
|
+
# Une application du catalogue : on écrit la ligne, on applique
|
|
1124
|
+
if [ -f "$ICI/catalogue/$m/app.conf" ]; then
|
|
1125
|
+
ecrire "$m" "$1"
|
|
1126
|
+
bash "$ICI/catalogue.sh" appliquer
|
|
1127
|
+
return
|
|
1128
|
+
fi
|
|
1129
|
+
echo "devzone : module inconnu : $m ; modules : ${MODULES[*]}" >&2
|
|
1079
1130
|
exit 1
|
|
1080
1131
|
fi
|
|
1081
1132
|
if [ "$1" = off ] && [ "$m" = postgres ]; then
|
|
@@ -1100,6 +1151,7 @@ case "${1:-}" in
|
|
|
1100
1151
|
[ "$(valeur ia)" = off ] || appliquer_ia on
|
|
1101
1152
|
[ "$(valeur gitlab)" = off ] || appliquer_gitlab on
|
|
1102
1153
|
[ "$(valeur postgres)" = off ] || appliquer_postgres on
|
|
1154
|
+
[ "$(valeur mysql)" = off ] || appliquer_mysql on
|
|
1103
1155
|
[ "$(valeur argocd)" = off ] || appliquer_argocd on
|
|
1104
1156
|
;;
|
|
1105
1157
|
actif)
|
|
@@ -1118,7 +1170,9 @@ case "${1:-}" in
|
|
|
1118
1170
|
clusters) DEVZONE_ETAT="$ETAT" bash "$ICI/clusters.sh" "${@:2}" ;;
|
|
1119
1171
|
cluster) changer_cluster "${@:2}" ;;
|
|
1120
1172
|
postgres) DEVZONE_ETAT="$ETAT" bash "$ICI/postgres/postgres.sh" "${@:2}" ;;
|
|
1173
|
+
mysql) DEVZONE_ETAT="$ETAT" bash "$ICI/catalogue/mysql/mysql.sh" "${@:2}" ;;
|
|
1121
1174
|
gitlab) DEVZONE_ETAT="$ETAT" bash "$ICI/gitlab/gitlab.sh" "${@:2}" ;;
|
|
1175
|
+
catalogue) DEVZONE_ETAT="$ETAT" bash "$ICI/catalogue.sh" lister ;;
|
|
1122
1176
|
argocd) DEVZONE_ETAT="$ETAT" bash "$ICI/argocd/argocd.sh" "${@:2}" ;;
|
|
1123
1177
|
port) DEVZONE_ETAT="$ETAT" bash "$ICI/ports.sh" "${@:2}" ;;
|
|
1124
1178
|
paquets) bash "$ICI/paquets.sh" "${@:2}" ;;
|
|
@@ -33,6 +33,7 @@ etat_json() {
|
|
|
33
33
|
local travail_ctx="" travail_interne=false ctx_hote=""
|
|
34
34
|
local clusters_services_raw="" clusters_travail_raw="" clusters_commande=""
|
|
35
35
|
local ports_json='[]' ports_out
|
|
36
|
+
local applications_json='[]'
|
|
36
37
|
local identifiants_raw=""
|
|
37
38
|
local retards_out paquet figee installee count
|
|
38
39
|
local relais_marque paquets_marque paquets_noms n chemin wt_out
|
|
@@ -132,6 +133,13 @@ etat_json() {
|
|
|
132
133
|
etat_val=""
|
|
133
134
|
ajouter_erreur modules "argocd.sh etat indisponible"
|
|
134
135
|
fi
|
|
136
|
+
elif [ "$m" = mysql ]; then
|
|
137
|
+
if s="$(bash "$ICI/catalogue/mysql/mysql.sh" etat 2>/dev/null)"; then
|
|
138
|
+
etat_val="$s"
|
|
139
|
+
else
|
|
140
|
+
etat_val=""
|
|
141
|
+
ajouter_erreur modules "mysql.sh etat indisponible"
|
|
142
|
+
fi
|
|
135
143
|
else
|
|
136
144
|
etat_val="actif"
|
|
137
145
|
fi
|
|
@@ -181,6 +189,12 @@ etat_json() {
|
|
|
181
189
|
ajouter_erreur ports "ports.sh indisponible"
|
|
182
190
|
fi
|
|
183
191
|
|
|
192
|
+
applications_json="$(bash "$ICI/catalogue.sh" json 2>/dev/null || echo '[]')"
|
|
193
|
+
if ! printf '%s' "$applications_json" | jq -e . >/dev/null 2>&1; then
|
|
194
|
+
applications_json='[]'
|
|
195
|
+
ajouter_erreur modules "catalogue.sh json indisponible"
|
|
196
|
+
fi
|
|
197
|
+
|
|
184
198
|
if [ -f "$RACINE/.password" ]; then
|
|
185
199
|
identifiants_raw="$RACINE/.password"
|
|
186
200
|
fi
|
|
@@ -231,6 +245,7 @@ etat_json() {
|
|
|
231
245
|
--argjson travail_interne "$travail_interne" \
|
|
232
246
|
--arg clusters_commande "$clusters_commande" \
|
|
233
247
|
--argjson ports "$ports_json" \
|
|
248
|
+
--argjson applications "$applications_json" \
|
|
234
249
|
--arg identifiants "$identifiants_raw" \
|
|
235
250
|
--argjson alertes "$alertes_json" \
|
|
236
251
|
--argjson erreurs "$erreurs" \
|
|
@@ -243,6 +258,7 @@ etat_json() {
|
|
|
243
258
|
modules: $modules,
|
|
244
259
|
clusters: { services: (if $clusters_services=="" then null else $clusters_services end), services_distant: $services_distant, travail: (if $clusters_travail=="" then null else $clusters_travail end), travail_interne: $travail_interne, commande: (if $clusters_commande=="" then null else $clusters_commande end) },
|
|
245
260
|
ports: $ports,
|
|
261
|
+
applications: (if $applications=="" then null else $applications end),
|
|
246
262
|
identifiants: (if $identifiants=="" then null else $identifiants end),
|
|
247
263
|
alertes: $alertes,
|
|
248
264
|
erreurs: $erreurs
|
|
@@ -62,6 +62,37 @@ password_regenerer() (
|
|
|
62
62
|
adresse="127.0.0.1:5432/${adresse:-$nom}"
|
|
63
63
|
printf '%s\t%s\t%s\t%s\n' "$service" "$adresse" "$utilisateur" "$mdp" >>"$entrees"
|
|
64
64
|
done
|
|
65
|
+
# Chaque autre application du catalogue : workspace/.<app>/*.env, clés
|
|
66
|
+
# <APP>_HOST, <APP>_PORT, <APP>_USER, <APP>_PASSWORD (ou MYSQL_* pour mysql)
|
|
67
|
+
for repertoire in "$racine"/workspace/.*/; do
|
|
68
|
+
[ -d "$repertoire" ] || continue
|
|
69
|
+
app="${repertoire%/}"
|
|
70
|
+
app="${app##*/}"
|
|
71
|
+
case "$app" in . | .. | .gitlab | .postgres | .argocd) continue ;; esac
|
|
72
|
+
app="${app#.}"
|
|
73
|
+
appu="$(printf '%s' "$app" | tr '[:lower:]' '[:upper:]')"
|
|
74
|
+
for fichier in "$repertoire"*.env; do
|
|
75
|
+
[ -f "$fichier" ] || continue
|
|
76
|
+
base="${fichier##*/}"
|
|
77
|
+
base="${base%.env}"
|
|
78
|
+
utilisateur="$(sed -n "s/^${appu}_USER=//p" "$fichier" 2>/dev/null | tail -1 || true)"
|
|
79
|
+
[ -z "$utilisateur" ] && utilisateur="$(sed -n 's/^DB_USER=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
80
|
+
[ -z "$utilisateur" ] && utilisateur="$(sed -n 's/^MYSQL_USER=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
81
|
+
mdp="$(sed -n "s/^${appu}_PASSWORD=//p" "$fichier" 2>/dev/null | tail -1 || true)"
|
|
82
|
+
[ -z "$mdp" ] && mdp="$(sed -n 's/^DB_PASSWORD=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
83
|
+
[ -z "$mdp" ] && mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
84
|
+
[ -z "$utilisateur" ] || [ -z "$mdp" ] && continue
|
|
85
|
+
hote="$(sed -n "s/^${appu}_HOST=//p" "$fichier" 2>/dev/null | tail -1 || true)"
|
|
86
|
+
[ -z "$hote" ] && hote="$(sed -n 's/^DB_HOST=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
87
|
+
[ -z "$hote" ] && hote="$(sed -n 's/^MYSQL_HOST=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
88
|
+
[ -z "$hote" ] && hote=127.0.0.1
|
|
89
|
+
port="$(sed -n "s/^${appu}_PORT=//p" "$fichier" 2>/dev/null | tail -1 || true)"
|
|
90
|
+
[ -z "$port" ] && port="$(sed -n 's/^DB_PORT=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
91
|
+
[ -z "$port" ] && port="$(sed -n 's/^MYSQL_PORT=//p' "$fichier" 2>/dev/null | tail -1 || true)"
|
|
92
|
+
[ -z "$port" ] && port=3306
|
|
93
|
+
printf '%s\t%s\t%s\t%s\n' "$app:$base" "$hote:$port" "$utilisateur" "$mdp" >>"$entrees"
|
|
94
|
+
done
|
|
95
|
+
done
|
|
65
96
|
|
|
66
97
|
if [ ! -s "$entrees" ]; then
|
|
67
98
|
rm -f "$entrees" "$cible"
|
package/.gitattributes
CHANGED