devzone 0.36.7 → 0.38.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 (44) hide show
  1. package/.devcontainer/.dockerignore +1 -1
  2. package/.devcontainer/argocd/application.sh +69 -0
  3. package/.devcontainer/argocd/apps.sh +262 -0
  4. package/.devcontainer/argocd/argocd.sh +52 -8
  5. package/.devcontainer/argocd/catalogue-argocd.sh +114 -0
  6. package/.devcontainer/argocd/conf.sh +141 -0
  7. package/.devcontainer/argocd/gitops.sh +214 -0
  8. package/.devcontainer/argocd/services.sh +138 -0
  9. package/.devcontainer/catalogue/app.sh +58 -17
  10. package/.devcontainer/catalogue/mysql/installer.sh +31 -0
  11. package/.devcontainer/catalogue/mysql/mysql.sh +12 -0
  12. package/.devcontainer/devzone +2 -1
  13. package/.devcontainer/password.sh +8 -0
  14. package/README.md +2 -2
  15. package/charts/devzone-argocd/Chart.lock +6 -0
  16. package/charts/devzone-argocd/Chart.yaml +13 -0
  17. package/charts/devzone-argocd/values.yaml +28 -0
  18. package/charts/devzone-mysql/Chart.yaml +6 -0
  19. package/charts/devzone-mysql/templates/service.yaml +15 -0
  20. package/charts/devzone-mysql/templates/statefulset.yaml +55 -0
  21. package/charts/devzone-mysql/values.yaml +19 -0
  22. package/charts/devzone-postgres/Chart.yaml +6 -0
  23. package/charts/devzone-postgres/templates/service.yaml +15 -0
  24. package/charts/devzone-postgres/templates/statefulset.yaml +56 -0
  25. package/charts/devzone-postgres/values.yaml +11 -0
  26. package/manage/devzone +4 -1
  27. package/manage/scripts/argocd-services-svc.sh +110 -0
  28. package/manage/scripts/argocd-services.sh +179 -0
  29. package/manage/scripts/argocd-workspace.sh +221 -0
  30. package/manage/scripts/ci-dns.sh +10 -10
  31. package/manage/scripts/desinstaller.sh +137 -135
  32. package/manage/scripts/docker.sh +26 -22
  33. package/manage/scripts/lancer.sh +103 -103
  34. package/manage/scripts/migrer-retour.sh +37 -34
  35. package/manage/scripts/migrer.sh +154 -138
  36. package/manage/scripts/ports-workspace.sh +94 -82
  37. package/manage/scripts/poste.sh +48 -49
  38. package/manage/scripts/services-workspace.sh +22 -5
  39. package/manage/scripts/versions.sh +88 -88
  40. package/manage/scripts/workspace-aliases.sh +47 -0
  41. package/manage/scripts/workspace-wait.sh +27 -24
  42. package/manage/workspace.sh +134 -105
  43. package/package.json +1 -1
  44. package/.devcontainer/argocd/values.yaml +0 -21
@@ -19,6 +19,10 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
19
19
  # shellcheck source=SCRIPTDIR/installer.sh
20
20
  # shellcheck disable=SC1091
21
21
  . "$ICI/installer.sh"
22
+ # Le module argocd actif : MySQL installé par une Application (#538)
23
+ # shellcheck source=SCRIPTDIR/../../argocd/catalogue-argocd.sh
24
+ # shellcheck disable=SC1091
25
+ . "$ICI/../../argocd/catalogue-argocd.sh"
22
26
  NS=devzone-mysql
23
27
  SECRETS="$RACINE/workspace/.mysql"
24
28
  MYSQL_PORT="${MYSQL_PORT:-3306}"
@@ -28,6 +32,8 @@ MYSQL_TAILLE="${MYSQL_TAILLE:-5Gi}"
28
32
  MYSQL_ATTENTE="${MYSQL_ATTENTE:-300}"
29
33
  # Refus standard avec message et code 2
30
34
  refuse() { echo "devzone : catalogue mysql : $*" >&2; exit 2; }
35
+ # Secret mysql-admin du hook services.sh : le même que l'installation directe
36
+ services_secret_mysql() { mysql_secret; }
31
37
  # Régénère la vue .password (échec non bloquant)
32
38
  regenerer_identifiants() {
33
39
  password_regenerer ||
@@ -82,6 +88,10 @@ installer() {
82
88
  return 1
83
89
  fi
84
90
  echo "▶ MySQL sur le cluster $CTX (namespace $NS)…"
91
+ if catalogue_argocd_active mysql; then
92
+ mysql_installer_argocd "$CTX"
93
+ return
94
+ fi
85
95
  compte_namespace "$CTX" "$NS"
86
96
  namespace_isoler "$NS" >/dev/null
87
97
  if k get statefulset mysql >/dev/null 2>&1; then
@@ -123,6 +133,8 @@ supprimer_donnees() {
123
133
  [ -n "$CTX" ] || refuse "aucun cluster choisi : devzone activer mysql"
124
134
  installe || refuse "module inactif : devzone activer mysql"
125
135
  echo "▶ Suppression de MySQL et de ses volumes sur $CTX…"
136
+ # L'Application part d'abord (#538) : sinon Argo CD recrée le namespace
137
+ catalogue_argocd_delete mysql >/dev/null 2>&1 || true
126
138
  # RoleBinding retiré puis namespace supprimé par l'administrateur (#430)
127
139
  compte_retirer "$CTX" "$NS" >/dev/null 2>&1 || true
128
140
  compte_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
@@ -23,6 +23,7 @@
23
23
  # devzone gitlab nouveau-mdp [root|dev] mot de passe aléatoire (root ou dev) régénéré
24
24
  # devzone activer argocd Argo CD dans le cluster des services, accès https://127.0.0.1:8443
25
25
  # devzone argocd etat|relais-lancer|relais-arreter Argo CD (module argocd)
26
+ # devzone argocd app add <repo url> [path]|list|remove <N> projets déployés par Argo CD (#516)
26
27
  # devzone cluster [CTX] [--oui] [--confirmer CTX] cluster des services de devzone, ou en changer
27
28
  # devzone port [<n>|--fermer <n>] relais d'un port du conteneur vers le poste
28
29
  # devzone mots-de-passe régénère .password et affiche son chemin
@@ -68,7 +69,7 @@ fi
68
69
  # change pas : deux montées simultanées (workflow versions) se fusionnent sans
69
70
  # conflit, git n'en signalant qu'entre lignes voisines modifiées.
70
71
  # Claude Code
71
- IA_CLAUDE=@anthropic-ai/claude-code@2.1.322
72
+ IA_CLAUDE=@anthropic-ai/claude-code@2.1.325
72
73
  # opencode
73
74
  IA_OPENCODE=opencode-ai@1.19.5
74
75
  IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
@@ -18,6 +18,7 @@ password_regenerer() (
18
18
  local cible="$PASSWORD_CIBLE" racine="$PASSWORD_RACINE"
19
19
  local gl="$racine/workspace/.gitlab" pg="$racine/workspace/.postgres"
20
20
  local ar="$racine/workspace/.argocd"
21
+ local my="$racine/workspace/.mysql"
21
22
  local tab entrees tmp fichier nom service adresse utilisateur mdp
22
23
  tab="$(printf '\t')"
23
24
  entrees="$(mktemp "$racine/.password.entrees.XXXXXX")" || return 1
@@ -41,6 +42,13 @@ password_regenerer() (
41
42
  printf 'postgres\t%s\tpostgres\t%s\n' "127.0.0.1:5432" "$mdp" >>"$entrees"
42
43
  fi
43
44
  fi
45
+ # MySQL root du catalogue (helm direct ou Argo CD, #538) : miroir du poste
46
+ if [ -s "$my/admin-password" ]; then
47
+ mdp="$(cat "$my/admin-password")"
48
+ if [ -n "$mdp" ]; then
49
+ printf 'mysql\t%s\troot\t%s\n' "127.0.0.1:3306" "$mdp" >>"$entrees"
50
+ fi
51
+ fi
44
52
  if [ -s "$ar/admin.env" ]; then
45
53
  utilisateur="$(sed -n 's/^ARGOCD_USER=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
46
54
  mdp="$(sed -n 's/^ARGOCD_PASSWORD=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
package/README.md CHANGED
@@ -152,7 +152,7 @@ La liste vit dans .devzone.paquets a la racine du dossier devzone, hors du depot
152
152
  | État | — | `make status` | — |
153
153
  | **Désinstaller** (tout ce que devzone a créé, après confirmation) | — | `make desinstaller` | `npx devzone uninstall` |
154
154
 
155
- Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)).
155
+ Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)). Argo CD y est installé d'office et tient les déploiements : interface sur https://localhost:8443 (mot de passe `admin` dans `.password`), dépôt GitOps `<login>/devzone-argocd` créé sur ton GitHub, projets déclarés dans `.argocd.conf` (`devzone workspace argocd app add <dépôt>`) ; voir [Argo CD dans le workspace Kubernetes](manage/docs/reference.md#argo-cd-dans-le-workspace-kubernetes).
156
156
 
157
157
  ### Mettre à jour devzone
158
158
 
@@ -325,7 +325,7 @@ Spring Boot écoute sur `0.0.0.0` par défaut : ne fixe pas `server.address` à
325
325
  make desinstaller
326
326
  ```
327
327
 
328
- Cette commande supprime le conteneur, l'image `vsc-devzone-…`, les volumes `devzone-*`, les events du Docker de l'hôte et les clusters kind créés sur l'hôte, les namespaces `devzone-postgres` et les étiquettes `app.kubernetes.io/managed-by=devzone` sur les clusters de l'hôte, ainsi que les éventuels metrics-server installés par devzone. Les ressources sont filtrées par l'étiquette `devzone.instance` pour ne cibler que l'instance courante. Elle **ne touche jamais** à `workspace/` (tes projets). Pour garder tes connexions (GitHub, git, Claude Code, opencode et modules) : `make desinstaller GARDER=connexions`.
328
+ Cette commande supprime le conteneur, l'image `vsc-devzone-…`, les volumes `devzone-*`, les events du Docker de l'hôte et les clusters kind créés sur l'hôte, les namespaces `devzone-postgres` et les étiquettes `app.kubernetes.io/managed-by=devzone` sur les clusters de l'hôte, ainsi que les éventuels metrics-server installés par devzone. Les ressources sont filtrées par l'étiquette `devzone.instance` pour ne cibler que l'instance courante. Elle **ne touche jamais** à `workspace/` (tes projets). Pour garder tes connexions (GitHub, git, Claude Code, opencode et modules) : `make desinstaller KEEP=logins` (ancien `GARDER=connexions` accepté).
329
329
 
330
330
  Avec la commande installée globalement (`npm install -g devzone`), tu peux aussi lancer, dans le dossier du devzone :
331
331
 
@@ -0,0 +1,6 @@
1
+ dependencies:
2
+ - name: argo-cd
3
+ repository: oci://ghcr.io/argoproj/argo-helm
4
+ version: 10.14.0
5
+ digest: sha256:7d0625740caf57b26bbb56b2266f860e469111c09b9da38376a118b60b54a2a0
6
+ generated: "2026-11-14T00:24:00.563528835Z"
@@ -0,0 +1,13 @@
1
+ apiVersion: v2
2
+ name: devzone-argocd
3
+ description: Argo CD of devzone, minimal and pinned (#411, #538): a wrapper of the official chart argo-cd
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: "3.3.0"
7
+ dependencies:
8
+ # Version pinned (10.14.0): the Application and the helm-direct install both
9
+ # take this chart, and devzone-argocd manages itself once self-hosted (#538).
10
+ # Run `helm dependency build` before the installation.
11
+ - name: argo-cd
12
+ version: 10.14.0
13
+ repository: oci://ghcr.io/argoproj/argo-helm
@@ -0,0 +1,28 @@
1
+ # Values of the Argo CD of devzone (#411), once the content of
2
+ # .devcontainer/argocd/values.yaml, moved under the argo-cd key of the
3
+ # wrapper (#538). Argo CD minimal: one replica per component, without Dex nor
4
+ # notifications, server in ClusterIP (no Ingress, no LoadBalancer). The access
5
+ # goes through the kubectl port-forward relay of the container (8443:443).
6
+ argo-cd:
7
+ global:
8
+ domain: ""
9
+ # Aggregate ClusterRoles (#516): the Application resources join the edit role,
10
+ # so the limited devzone account (#430) manages the Applications of the
11
+ # projects in devzone-argocd (devzone argocd app ...)
12
+ createAggregateRoles: true
13
+ dex:
14
+ enabled: false
15
+ notifications:
16
+ enabled: false
17
+ server:
18
+ replicas: 1
19
+ service:
20
+ type: ClusterIP
21
+ ingress:
22
+ enabled: false
23
+ controller:
24
+ replicas: 1
25
+ repoServer:
26
+ replicas: 1
27
+ applicationSet:
28
+ replicas: 1
@@ -0,0 +1,6 @@
1
+ apiVersion: v2
2
+ name: devzone-mysql
3
+ description: Shared MySQL of devzone, one database per project (#414), deployed by Argo CD (#538)
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: "8.4"
@@ -0,0 +1,15 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: {{ .Values.name }}
5
+ namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app: {{ .Values.name }}
8
+ app.kubernetes.io/managed-by: devzone
9
+ spec:
10
+ selector:
11
+ app: {{ .Values.name }}
12
+ ports:
13
+ - name: {{ .Values.name }}
14
+ port: {{ .Values.port }}
15
+ targetPort: 3306
@@ -0,0 +1,55 @@
1
+ apiVersion: apps/v1
2
+ kind: StatefulSet
3
+ metadata:
4
+ name: {{ .Values.name }}
5
+ namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app: {{ .Values.name }}
8
+ app.kubernetes.io/managed-by: devzone
9
+ spec:
10
+ serviceName: {{ .Values.name }}
11
+ replicas: 1
12
+ selector:
13
+ matchLabels:
14
+ app: {{ .Values.name }}
15
+ template:
16
+ metadata:
17
+ labels:
18
+ app: {{ .Values.name }}
19
+ app.kubernetes.io/managed-by: devzone
20
+ spec:
21
+ containers:
22
+ - name: {{ .Values.name }}
23
+ # Pinned version: update it here (same major: data kept)
24
+ image: {{ .Values.image }}
25
+ env:
26
+ - name: MYSQL_ROOT_PASSWORD
27
+ valueFrom:
28
+ secretKeyRef:
29
+ name: {{ .Values.name }}-admin
30
+ key: password
31
+ ports:
32
+ - containerPort: 3306
33
+ name: {{ .Values.name }}
34
+ readinessProbe:
35
+ exec:
36
+ command: ["/bin/sh", "-c", "mysql -uroot -p\"$MYSQL_ROOT_PASSWORD\" -e 'SELECT 1'"]
37
+ initialDelaySeconds: 10
38
+ periodSeconds: 5
39
+ resources:
40
+ requests:
41
+ cpu: {{ .Values.resources.requests.cpu }}
42
+ memory: {{ .Values.memory }}
43
+ volumeMounts:
44
+ - name: {{ .Values.claim }}
45
+ mountPath: /var/lib/mysql
46
+ volumeClaimTemplates:
47
+ - metadata:
48
+ name: {{ .Values.claim }}
49
+ labels:
50
+ app.kubernetes.io/managed-by: devzone
51
+ spec:
52
+ accessModes: ["ReadWriteOnce"]
53
+ resources:
54
+ requests:
55
+ storage: {{ .Values.size }}
@@ -0,0 +1,19 @@
1
+ # Same objects as .devcontainer/catalogue/mysql/manifeste.yaml, the helm-direct
2
+ # path of the catalogue (#414): manage/test/chart-mysql.bats checks that both
3
+ # renderings agree. The secret <name>-admin (root password) is created apart by
4
+ # devzone, never by the chart (#538: secrets out of Git).
5
+ # Name of the application (Service, StatefulSet and secret ref): mysql of the
6
+ # catalogue by default.
7
+ name: mysql
8
+ image: mysql:8.4
9
+ # Port of the Service (the container always listens on 3306)
10
+ port: 3306
11
+ # Memory request (MYSQL_MEMOIRE of the catalogue)
12
+ memory: 1Gi
13
+ # Size of the data volume (MYSQL_TAILLE of the catalogue)
14
+ size: 5Gi
15
+ # Name of the volume claim template (chosen among the existing PVCs, #440)
16
+ claim: donnees
17
+ resources:
18
+ requests:
19
+ cpu: 100m
@@ -0,0 +1,6 @@
1
+ apiVersion: v2
2
+ name: devzone-postgres
3
+ description: Shared PostgreSQL of devzone, one database per project (#280), deployed by Argo CD (#516)
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: "16.15"
@@ -0,0 +1,15 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: postgres
5
+ namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app: postgres
8
+ app.kubernetes.io/managed-by: devzone
9
+ spec:
10
+ selector:
11
+ app: postgres
12
+ ports:
13
+ - name: postgres
14
+ port: 5432
15
+ targetPort: 5432
@@ -0,0 +1,56 @@
1
+ apiVersion: apps/v1
2
+ kind: StatefulSet
3
+ metadata:
4
+ name: postgres
5
+ namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app: postgres
8
+ app.kubernetes.io/managed-by: devzone
9
+ spec:
10
+ serviceName: postgres
11
+ replicas: 1
12
+ selector:
13
+ matchLabels:
14
+ app: postgres
15
+ template:
16
+ metadata:
17
+ labels:
18
+ app: postgres
19
+ app.kubernetes.io/managed-by: devzone
20
+ spec:
21
+ containers:
22
+ - name: postgres
23
+ image: {{ .Values.image }}
24
+ env:
25
+ - name: POSTGRES_PASSWORD
26
+ valueFrom:
27
+ secretKeyRef:
28
+ name: postgres-admin
29
+ key: password
30
+ - name: PGDATA
31
+ value: /var/lib/postgresql/data/pgdata
32
+ ports:
33
+ - containerPort: 5432
34
+ name: postgres
35
+ readinessProbe:
36
+ exec:
37
+ command: ["pg_isready", "-U", "postgres"]
38
+ initialDelaySeconds: 5
39
+ periodSeconds: 5
40
+ resources:
41
+ requests:
42
+ cpu: {{ .Values.resources.requests.cpu }}
43
+ memory: {{ .Values.resources.requests.memory }}
44
+ volumeMounts:
45
+ - name: donnees
46
+ mountPath: /var/lib/postgresql/data
47
+ volumeClaimTemplates:
48
+ - metadata:
49
+ name: donnees
50
+ labels:
51
+ app.kubernetes.io/managed-by: devzone
52
+ spec:
53
+ accessModes: ["ReadWriteOnce"]
54
+ resources:
55
+ requests:
56
+ storage: {{ .Values.size }}
@@ -0,0 +1,11 @@
1
+ # Same objects as .devcontainer/postgres/postgres.yaml, the helm-direct path:
2
+ # manage/test/chart-postgres.bats checks that both renderings agree. The
3
+ # secret postgres-admin (superuser password) is created apart by devzone,
4
+ # never by the chart (#516: secrets out of Git).
5
+ image: postgres:16.15-alpine
6
+ # Size of the data volume (POSTGRES_TAILLE of the helm-direct path)
7
+ size: 5Gi
8
+ resources:
9
+ requests:
10
+ cpu: 100m
11
+ memory: 256Mi
package/manage/devzone CHANGED
@@ -32,6 +32,7 @@ LIGNES_GITIGNORE=(
32
32
  '.password'
33
33
  '.devzone.sauvegarde/'
34
34
  '.devcontainer/sans-docker-hote/'
35
+ '.devcontainer/without-host-docker/'
35
36
  )
36
37
 
37
38
  version() {
@@ -431,6 +432,8 @@ devzone $(version) : environnement de développement conteneurisé
431
432
  poste Kubernetes : pilote le chart devzone-workspace
432
433
  devzone workspace services enable|disable <service>|status
433
434
  services (gitlab, postgres, argocd) du workspace Kubernetes
435
+ devzone workspace argocd status|init|apply|app add|list|remove
436
+ Argo CD du workspace : dépôt GitOps, .argocd.conf, projets
434
437
  (anciens noms français acceptés : mettre-a-jour, desinstaller, demarrer…)
435
438
  devzone --version
436
439
  EOF
@@ -460,7 +463,7 @@ creer() {
460
463
  # Docker d'abord : le dossier reste prêt, à lancer une fois Docker démarré
461
464
  # shellcheck source=SCRIPTDIR/scripts/docker.sh
462
465
  . "$PAQUET/manage/scripts/docker.sh"
463
- if ! docker_pret "cd $cible && make shell"; then
466
+ if ! docker_ready "cd $cible && make shell"; then
464
467
  echo " Le dossier est prêt : rien à refaire, sauf ce lancement." >&2
465
468
  exit 1
466
469
  fi
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env bash
2
+ # Service hooks of the workstation for services.sh (#538): secrets created
3
+ # apart (postgres-admin, mysql-admin, mirrored and never printed), Helm
4
+ # parameters of the mysql chart (existing volume claim), and the
5
+ # devzone workspace services enable|disable switch when Argo CD holds the
6
+ # charts. Sourced by manage/scripts/argocd-services.sh. bash 3.2 (macOS).
7
+
8
+ # Namespace of the service: labelled, isolated like the other devzone-*
9
+ # (services.sh: services_namespace_prepare)
10
+
11
+ # Superuser secret postgres-admin, created apart: an existing secret is kept
12
+ # and mirrored; otherwise a password generated on the workstation. Mirror
13
+ # workspace/.postgres/admin-password (600) and .password; never printed
14
+ services_secret_postgres() {
15
+ local dir="$PWD/workspace/.postgres" file password
16
+ file="$dir/admin-password"
17
+ mkdir -p "$dir"
18
+ chmod 700 "$dir"
19
+ password="$(ak -n "$POSTGRES_NS" get secret postgres-admin \
20
+ -o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
21
+ if [ -n "$password" ]; then
22
+ (umask 077 && printf '%s' "$password" >"$file")
23
+ else
24
+ if [ ! -s "$file" ]; then
25
+ (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
26
+ fi
27
+ ak -n "$POSTGRES_NS" create secret generic postgres-admin --from-file=password="$file" >/dev/null
28
+ fi
29
+ chmod 600 "$file"
30
+ argocd_passwords_refresh
31
+ }
32
+
33
+ # Superuser secret mysql-admin, created apart, the same way; the mirror
34
+ # workspace/.mysql/admin-password feeds the mysql entry of .password
35
+ services_secret_mysql() {
36
+ local dir="$PWD/workspace/.mysql" file password
37
+ file="$dir/admin-password"
38
+ mkdir -p "$dir"
39
+ chmod 700 "$dir"
40
+ password="$(ak -n "$MYSQL_NS" get secret mysql-admin \
41
+ -o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
42
+ if [ -n "$password" ]; then
43
+ (umask 077 && printf '%s' "$password" >"$file")
44
+ else
45
+ if [ ! -s "$file" ]; then
46
+ (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
47
+ fi
48
+ ak -n "$MYSQL_NS" create secret generic mysql-admin --from-file=password="$file" >/dev/null
49
+ fi
50
+ chmod 600 "$file"
51
+ argocd_passwords_refresh
52
+ }
53
+
54
+ # Values of the MySQL chart: image, port, memory and size (catalogue defaults),
55
+ # and the claim to mount chosen among the existing volumes (one PVC *-mysql-0:
56
+ # its prefix; none: the chart default donnees; several: refused)
57
+ services_chart_mysql() {
58
+ local liste claim=""
59
+ liste="$(ak -n "$MYSQL_NS" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
60
+ if [ -n "$liste" ]; then
61
+ if [ "$(printf '%s\n' "$liste" | grep -c .)" -gt 1 ]; then
62
+ echo "✖ several MySQL volumes in $MYSQL_NS: devzone mysql volume <name> picks the mounted one" >&2
63
+ return 2
64
+ fi
65
+ claim=" claim=${liste%-mysql-0}"
66
+ fi
67
+ printf 'image=mysql:8.4 port=3306 memory=1Gi size=5Gi%s' "$claim"
68
+ }
69
+
70
+ # devzone workspace services enable|disable postgres|mysql when Argo CD holds
71
+ # the charts: the [services] section written, then reconciled (services.sh).
72
+ # disable keeps the namespace, the volumes and the data; --yes is the explicit
73
+ # data removal (namespace deleted; the mirror workspace/.mysql stays, like
74
+ # supprimer-donnees of the module, the one of .postgres goes)
75
+ services_argocd_toggle() {
76
+ local svc="$1" action="$2" yes
77
+ shift 2
78
+ case "$action" in
79
+ enable)
80
+ if [ "$#" -ne 0 ]; then
81
+ echo "✖ $svc through Argo CD takes no option (got: $*)" >&2
82
+ return 1
83
+ fi
84
+ echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
85
+ services_note "$svc" on
86
+ services_reconcile
87
+ echo "✔ Application devzone-$svc declared ([services] $svc = on in $ARGOCD_CONF); status: devzone workspace argocd status; local access: devzone workspace ports"
88
+ ;;
89
+ disable)
90
+ yes="$(yes_flag "services disable $svc [--yes]" "$@")" || return 1
91
+ services_note "$svc" off
92
+ services_reconcile
93
+ if [ "$yes" = 1 ]; then
94
+ ak delete namespace "devzone-$svc" --wait=true --ignore-not-found >/dev/null
95
+ case "$svc" in
96
+ postgres) rm -rf "$PWD/workspace/.$svc" ;;
97
+ esac
98
+ argocd_passwords_refresh
99
+ echo "✔ $svc removed: Application, namespace devzone-$svc and data ([services] $svc = off)"
100
+ else
101
+ echo "✔ $svc stopped: Application removed, the namespace devzone-$svc, the volumes and the data stay (devzone workspace services disable $svc --yes to remove the data)"
102
+ fi
103
+ ;;
104
+ esac
105
+ }
106
+
107
+ # Toggles postgres on/off as an Argo CD Application (charts/devzone-postgres).
108
+ # Calls services_argocd_toggle to write the [services] section and reconcile.
109
+ postgres_argocd() { services_argocd_toggle postgres "$@"; }
110
+
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env bash
2
+ # Deployments held by Argo CD in the Kubernetes workspace (#516), sourced by
3
+ # manage/workspace.sh after argocd-workspace.sh: the workspace itself, the
4
+ # services of the [services] section (services.sh), the argocd services
5
+ # switch and devzone workspace argocd.
6
+ # workspace_deploy <repository> <tag> <with-image> start: Application, else helm direct
7
+ # workspace_undeploy stop: Application, else helm uninstall
8
+ # argocd_toggle enable|disable devzone workspace services … argocd
9
+ # services_secret_postgres postgres secret created apart
10
+ # postgres_argocd enable|disable [--yes] postgres: [services] written, then reconciled
11
+ # argocd_cmd status | init | apply | app add|list|remove devzone workspace argocd …
12
+ # Secrets stay out of Git: created here, only referenced by the charts.
13
+ # bash 3.2 (macOS).
14
+
15
+ WORKSPACE_APP="devzone-workspace"
16
+ # shellcheck disable=SC2034 # read by argocd-services-svc.sh
17
+ POSTGRES_NS="devzone-postgres"
18
+ # shellcheck disable=SC2034 # read by argocd-services-svc.sh
19
+ MYSQL_NS="devzone-mysql"
20
+ # Services held by Argo CD ([services] of .argocd.conf, services.sh); gitlab
21
+ # joins in its step (#538)
22
+ # shellcheck disable=SC2034 # read by services.sh
23
+ SERVICES_LIST="postgres mysql"
24
+
25
+ # The only option of a removal: --yes (--oui still accepted); prints 1 or 0
26
+ yes_flag() {
27
+ local usage="$1" arg found=0
28
+ shift
29
+ for arg in "$@"; do
30
+ case "$arg" in
31
+ --yes | --oui) found=1 ;;
32
+ *) echo "✖ unknown option: $arg (devzone workspace $usage)" >&2; return 1 ;;
33
+ esac
34
+ done
35
+ echo "$found"
36
+ }
37
+
38
+ # shellcheck disable=SC2034 # read by apps.sh
39
+ APPS_CMD="devzone workspace argocd app"
40
+ # shellcheck disable=SC2034 # read by apps.sh
41
+ APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
42
+ # shellcheck disable=SC2034 # read by gitops.sh
43
+ GITOPS_CMD="devzone workspace argocd init"
44
+ # .argocd.conf of the devzone folder of the workstation (conf.sh)
45
+ # shellcheck disable=SC2034 # read by conf.sh and apps.sh
46
+ ARGOCD_CONF_DIR="$PWD"
47
+ # shellcheck disable=SC2034
48
+ ARGOCD_CONF="$PWD/.argocd.conf"
49
+ # shellcheck source=../../.devcontainer/argocd/conf.sh
50
+ # shellcheck disable=SC1091
51
+ . "$RACINE/.devcontainer/argocd/conf.sh"
52
+ # shellcheck source=../../.devcontainer/argocd/gitops.sh
53
+ # shellcheck disable=SC1091
54
+ . "$RACINE/.devcontainer/argocd/gitops.sh"
55
+ # shellcheck source=../../.devcontainer/argocd/apps.sh
56
+ # shellcheck disable=SC1091
57
+ . "$RACINE/.devcontainer/argocd/apps.sh"
58
+ # shellcheck source=../../.devcontainer/argocd/services.sh
59
+ # shellcheck disable=SC1091
60
+ . "$RACINE/.devcontainer/argocd/services.sh"
61
+ argocd_kubectl() { ak "$@"; }
62
+
63
+ # workspace start and argocd apply: the declarations of .argocd.conf held
64
+ argocd_reconcile() {
65
+ argocd_installed || return 0
66
+ gitops_init || return 1
67
+ gitops_root || return 1
68
+ apps_reconcile
69
+ if argocd_holds_charts; then
70
+ services_reconcile
71
+ fi
72
+ }
73
+
74
+ # Root token of the devzone GitLab for app add: the file of the workstation,
75
+ # else the one of the pod (the module was installed there, #528); never printed
76
+ apps_gitlab_token() {
77
+ if [ -s "$PWD/workspace/.gitlab/root-token" ]; then
78
+ cat "$PWD/workspace/.gitlab/root-token"
79
+ else
80
+ ak -n "$NAMESPACE" exec "$POD" -c workspace -- cat "$DOSSIER_PROJETS/workspace/.gitlab/root-token" 2>/dev/null || true
81
+ fi
82
+ }
83
+
84
+ # Argo CD holds the devzone charts only with a Git revision (release tag or
85
+ # DEVZONE_ARGOCD_REVISION): a development clone stays on helm direct
86
+ argocd_holds_charts() {
87
+ argocd_active && [ -n "$(argocd_revision)" ]
88
+ }
89
+
90
+ argocd_clone_notice() {
91
+ if argocd_active && [ -z "$(argocd_revision)" ]; then
92
+ echo "ℹ development clone (version 0.0.0): helm direct; DEVZONE_ARGOCD_REVISION=<branch> to go through Argo CD"
93
+ fi
94
+ }
95
+
96
+ # Release secrets of a release deployed with helm before: deleted, so that
97
+ # Argo CD adopts the live resources without any helm uninstall (no downtime)
98
+ helm_release_forget() {
99
+ ak -n "$2" delete secret -l "owner=helm,name=$1" --ignore-not-found >/dev/null 2>&1 || true
100
+ }
101
+
102
+ workspace_deploy() {
103
+ local repository="$1" tag="$2" with_image="$3" params
104
+ if ! argocd_holds_charts; then
105
+ argocd_clone_notice
106
+ workspace_helm_deploy "$repository" "$tag" "$with_image"
107
+ return
108
+ fi
109
+ params="image.tag=$tag"
110
+ [ -z "$with_image" ] || params="$params image.repository=$repository"
111
+ [ "$tag" != latest ] || params="$params image.pullPolicy=Always"
112
+ # GitOps repository created or designated first, with its root Application
113
+ gitops_init || return 1
114
+ gitops_root || return 1
115
+ echo "▶ Application $WORKSPACE_APP (Argo CD, charts/devzone-workspace at $(argocd_revision))…"
116
+ helm_release_forget devzone-workspace devzone-workspace
117
+ # shellcheck disable=SC2086
118
+ argocd_apply_application "$WORKSPACE_APP" workspace devzone-workspace \
119
+ "$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-workspace $params
120
+ }
121
+
122
+ workspace_undeploy() {
123
+ if argocd_installed && argocd_application_exists "$WORKSPACE_APP"; then
124
+ echo "▶ Application $WORKSPACE_APP deleted (Argo CD removes the pod, the volumes stay)…"
125
+ argocd_delete_application "$WORKSPACE_APP"
126
+ else
127
+ # shellcheck disable=SC2046
128
+ helm $(drapeau_helm) uninstall devzone-workspace --namespace devzone-workspace
129
+ fi
130
+ }
131
+
132
+ # devzone workspace services enable|disable argocd: the workstation installs
133
+ # or removes it itself; the state line follows what succeeded
134
+ argocd_toggle() {
135
+ local action="$1"
136
+ shift
137
+ if [ "$#" -ne 0 ]; then
138
+ echo "✖ services $action argocd takes no option (got: $*)" >&2
139
+ return 1
140
+ fi
141
+ case "$action" in
142
+ enable) argocd_install && state_note argocd on && gitops_init && gitops_root ;;
143
+ disable) argocd_uninstall && state_note argocd off ;;
144
+ esac
145
+ }
146
+
147
+ # Service hooks (secrets, mysql chart parameters, services switch)
148
+ # shellcheck source=argocd-services-svc.sh
149
+ # shellcheck disable=SC1091
150
+ . "$(dirname "${BASH_SOURCE[0]}")/argocd-services-svc.sh"
151
+
152
+ # devzone workspace argocd status | app …
153
+ argocd_cmd() {
154
+ case "${1:-status}" in
155
+ status | etat) argocd_status ;;
156
+ init)
157
+ gitops_init "${@:2}" || return $?
158
+ if argocd_installed; then gitops_root; fi
159
+ ;;
160
+ apply)
161
+ if ! argocd_installed; then
162
+ echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
163
+ return 1
164
+ fi
165
+ argocd_reconcile
166
+ ;;
167
+ app)
168
+ if ! argocd_installed; then
169
+ echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
170
+ return 1
171
+ fi
172
+ argocd_app "${@:2}"
173
+ ;;
174
+ *)
175
+ echo "✖ devzone workspace argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>" >&2
176
+ return 1
177
+ ;;
178
+ esac
179
+ }