devzone 0.37.0 → 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 (36) hide show
  1. package/.devcontainer/.dockerignore +1 -1
  2. package/.devcontainer/argocd/argocd.sh +6 -7
  3. package/.devcontainer/argocd/catalogue-argocd.sh +114 -0
  4. package/.devcontainer/argocd/services.sh +138 -0
  5. package/.devcontainer/catalogue/app.sh +58 -17
  6. package/.devcontainer/catalogue/mysql/installer.sh +31 -0
  7. package/.devcontainer/catalogue/mysql/mysql.sh +12 -0
  8. package/.devcontainer/devzone +1 -1
  9. package/.devcontainer/password.sh +8 -0
  10. package/README.md +1 -1
  11. package/charts/devzone-argocd/Chart.lock +6 -0
  12. package/charts/devzone-argocd/Chart.yaml +13 -0
  13. package/charts/devzone-argocd/values.yaml +28 -0
  14. package/charts/devzone-mysql/Chart.yaml +6 -0
  15. package/charts/devzone-mysql/templates/service.yaml +15 -0
  16. package/charts/devzone-mysql/templates/statefulset.yaml +55 -0
  17. package/charts/devzone-mysql/values.yaml +19 -0
  18. package/manage/devzone +2 -1
  19. package/manage/scripts/argocd-services-svc.sh +110 -0
  20. package/manage/scripts/argocd-services.sh +21 -85
  21. package/manage/scripts/argocd-workspace.sh +8 -6
  22. package/manage/scripts/ci-dns.sh +10 -10
  23. package/manage/scripts/desinstaller.sh +137 -135
  24. package/manage/scripts/docker.sh +26 -22
  25. package/manage/scripts/lancer.sh +103 -103
  26. package/manage/scripts/migrer-retour.sh +37 -34
  27. package/manage/scripts/migrer.sh +154 -138
  28. package/manage/scripts/ports-workspace.sh +87 -82
  29. package/manage/scripts/poste.sh +48 -49
  30. package/manage/scripts/services-workspace.sh +15 -10
  31. package/manage/scripts/versions.sh +88 -88
  32. package/manage/scripts/workspace-aliases.sh +47 -0
  33. package/manage/scripts/workspace-wait.sh +26 -23
  34. package/manage/workspace.sh +124 -111
  35. package/package.json +1 -1
  36. package/.devcontainer/argocd/values.yaml +0 -25
@@ -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
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() {
@@ -462,7 +463,7 @@ creer() {
462
463
  # Docker d'abord : le dossier reste prêt, à lancer une fois Docker démarré
463
464
  # shellcheck source=SCRIPTDIR/scripts/docker.sh
464
465
  . "$PAQUET/manage/scripts/docker.sh"
465
- if ! docker_pret "cd $cible && make shell"; then
466
+ if ! docker_ready "cd $cible && make shell"; then
466
467
  echo " Le dossier est prêt : rien à refaire, sauf ce lancement." >&2
467
468
  exit 1
468
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
+
@@ -1,18 +1,26 @@
1
1
  #!/usr/bin/env bash
2
2
  # Deployments held by Argo CD in the Kubernetes workspace (#516), sourced by
3
3
  # manage/workspace.sh after argocd-workspace.sh: the workspace itself, the
4
- # postgres service, the argocd services switch and devzone workspace argocd.
4
+ # services of the [services] section (services.sh), the argocd services
5
+ # switch and devzone workspace argocd.
5
6
  # workspace_deploy <repository> <tag> <with-image> start: Application, else helm direct
6
7
  # workspace_undeploy stop: Application, else helm uninstall
7
8
  # argocd_toggle enable|disable devzone workspace services … argocd
8
- # postgres_argocd enable|disable [--yes] postgres as an Application
9
+ # services_secret_postgres postgres secret created apart
10
+ # postgres_argocd enable|disable [--yes] postgres: [services] written, then reconciled
9
11
  # argocd_cmd status | init | apply | app add|list|remove devzone workspace argocd …
10
12
  # Secrets stay out of Git: created here, only referenced by the charts.
11
13
  # bash 3.2 (macOS).
12
14
 
13
15
  WORKSPACE_APP="devzone-workspace"
14
- POSTGRES_APP="devzone-postgres"
16
+ # shellcheck disable=SC2034 # read by argocd-services-svc.sh
15
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"
16
24
 
17
25
  # The only option of a removal: --yes (--oui still accepted); prints 1 or 0
18
26
  yes_flag() {
@@ -27,20 +35,6 @@ yes_flag() {
27
35
  echo "$found"
28
36
  }
29
37
 
30
- # [y/N] in a terminal; without one, --yes is required
31
- confirm_removal() {
32
- local answer=""
33
- [ "${2:-0}" = 1 ] && return 0
34
- if [ ! -t 0 ]; then
35
- echo "✖ no terminal: confirmation impossible, run again with --yes" >&2
36
- return 1
37
- fi
38
- read -r -p "$1 [y/N] " answer || true
39
- case "$answer" in y | Y | yes | YES | o | O | oui) return 0 ;; esac
40
- echo "✖ cancelled, nothing changed" >&2
41
- return 1
42
- }
43
-
44
38
  # shellcheck disable=SC2034 # read by apps.sh
45
39
  APPS_CMD="devzone workspace argocd app"
46
40
  # shellcheck disable=SC2034 # read by apps.sh
@@ -61,6 +55,9 @@ ARGOCD_CONF="$PWD/.argocd.conf"
61
55
  # shellcheck source=../../.devcontainer/argocd/apps.sh
62
56
  # shellcheck disable=SC1091
63
57
  . "$RACINE/.devcontainer/argocd/apps.sh"
58
+ # shellcheck source=../../.devcontainer/argocd/services.sh
59
+ # shellcheck disable=SC1091
60
+ . "$RACINE/.devcontainer/argocd/services.sh"
64
61
  argocd_kubectl() { ak "$@"; }
65
62
 
66
63
  # workspace start and argocd apply: the declarations of .argocd.conf held
@@ -69,6 +66,9 @@ argocd_reconcile() {
69
66
  gitops_init || return 1
70
67
  gitops_root || return 1
71
68
  apps_reconcile
69
+ if argocd_holds_charts; then
70
+ services_reconcile
71
+ fi
72
72
  }
73
73
 
74
74
  # Root token of the devzone GitLab for app add: the file of the workstation,
@@ -144,74 +144,10 @@ argocd_toggle() {
144
144
  esac
145
145
  }
146
146
 
147
- # Namespace of the service: labelled, isolated like the other devzone-*
148
- postgres_namespace_prepare() {
149
- ak create namespace "$POSTGRES_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
150
- ak label namespace "$POSTGRES_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
151
- ak -n "$POSTGRES_NS" apply -f - >/dev/null <<EOF
152
- apiVersion: networking.k8s.io/v1
153
- kind: NetworkPolicy
154
- metadata:
155
- name: devzone-meme-namespace
156
- labels:
157
- app.kubernetes.io/managed-by: devzone
158
- spec:
159
- podSelector: {}
160
- ingress:
161
- - from:
162
- - podSelector: {}
163
- EOF
164
- }
165
-
166
- # Superuser secret postgres-admin, created apart: an existing secret is kept
167
- # and mirrored; otherwise a password generated on the workstation. Mirror
168
- # workspace/.postgres/admin-password (600) and .password; never printed
169
- postgres_secret_ensure() {
170
- local dir="$PWD/workspace/.postgres" file password
171
- file="$dir/admin-password"
172
- mkdir -p "$dir"
173
- chmod 700 "$dir"
174
- password="$(ak -n "$POSTGRES_NS" get secret postgres-admin \
175
- -o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
176
- if [ -n "$password" ]; then
177
- (umask 077 && printf '%s' "$password" >"$file")
178
- else
179
- if [ ! -s "$file" ]; then
180
- (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
181
- fi
182
- ak -n "$POSTGRES_NS" create secret generic postgres-admin --from-file=password="$file" >/dev/null
183
- fi
184
- chmod 600 "$file"
185
- argocd_passwords_refresh
186
- }
187
-
188
- postgres_argocd() {
189
- local action="$1" yes
190
- shift
191
- case "$action" in
192
- enable)
193
- if [ "$#" -ne 0 ]; then
194
- echo "✖ postgres through Argo CD takes no option (got: $*)" >&2
195
- return 1
196
- fi
197
- echo "▶ postgres as an Argo CD Application (charts/devzone-postgres at $(argocd_revision))…"
198
- postgres_namespace_prepare
199
- postgres_secret_ensure
200
- argocd_apply_application "$POSTGRES_APP" service "$POSTGRES_NS" \
201
- "$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-postgres
202
- echo "✔ Application $POSTGRES_APP declared; status: devzone workspace argocd status; local access: devzone workspace ports"
203
- ;;
204
- disable)
205
- yes="$(yes_flag "services disable postgres [--yes]" "$@")" || return 1
206
- confirm_removal "Remove PostgreSQL and ALL its databases (Application and namespace $POSTGRES_NS)?" "$yes" || return 1
207
- argocd_delete_application "$POSTGRES_APP"
208
- ak delete namespace "$POSTGRES_NS" --wait=true --ignore-not-found >/dev/null
209
- rm -rf "$PWD/workspace/.postgres"
210
- argocd_passwords_refresh
211
- echo "✔ postgres removed: Application, namespace $POSTGRES_NS and databases"
212
- ;;
213
- esac
214
- }
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"
215
151
 
216
152
  # devzone workspace argocd status | app …
217
153
  argocd_cmd() {
@@ -21,7 +21,8 @@ ARGOCD_WAIT="${ARGOCD_ATTENTE:-600}"
21
21
  ARGOCD_MIN_MEMORY_KI=1048576
22
22
  DEVZONE_REPO_URL="${DEVZONE_REPO_URL:-https://github.com/SimBienvenueHoulBoumi/devzone.git}"
23
23
 
24
- argocd_values() { printf '%s/.devcontainer/argocd/values.yaml' "$RACINE"; }
24
+ # Wrapper chart installed by the workstation and by the container (#538)
25
+ argocd_chart() { printf '%s/charts/devzone-argocd' "$RACINE"; }
25
26
  argocd_generator() { printf '%s/.devcontainer/argocd/application.sh' "$RACINE"; }
26
27
  argocd_secrets_dir() { printf '%s/workspace/.argocd' "$PWD"; }
27
28
 
@@ -140,12 +141,13 @@ argocd_install() {
140
141
  echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
141
142
  ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
142
143
  ak label namespace "$ARGOCD_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
143
- helm repo add argo https://argoproj.github.io/argo-helm >/dev/null 2>&1 || true
144
- helm repo update >/dev/null 2>&1 || true
144
+ # Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
145
+ # first, then installed from the local chart (#538)
146
+ helm dependency build "$(argocd_chart)" >/dev/null
145
147
  # shellcheck disable=SC2046
146
- helm $(drapeau_helm) upgrade --install argocd argo/argo-cd \
147
- --version "$ARGOCD_CHART_VERSION" --namespace "$ARGOCD_NS" \
148
- -f "$(argocd_values)" --timeout "${ARGOCD_WAIT}s" --wait || return 1
148
+ helm $(drapeau_helm) upgrade --install argocd "$(argocd_chart)" \
149
+ --namespace "$ARGOCD_NS" \
150
+ --timeout "${ARGOCD_WAIT}s" --wait || return 1
149
151
  argocd_save_admin_password
150
152
  echo "✔ Argo CD ready: https://localhost:$ARGOCD_LOCAL_PORT once devzone workspace ports runs; user admin, password in .password"
151
153
  }
@@ -1,22 +1,22 @@
1
1
  #!/usr/bin/env bash
2
- # DNS publics pour le Docker d'un runner GitHub Actions (#468) : le DNS des
3
- # runners ubuntu échoue parfois à résoudre archive.ubuntu.com pendant la
4
- # construction du conteneur. Ajoute 1.1.1.1 et 8.8.8.8 à daemon.json (les clés
5
- # existantes sont gardées), redémarre Docker et attend qu'il réponde.
6
- # Garde-fou : refuse hors CI, jamais lancé sur un poste.
2
+ # Public DNS for Docker on a GitHub Actions runner (#468): runner ubuntu DNS
3
+ # sometimes fails to resolve archive.ubuntu.com while building the container.
4
+ # Adds 1.1.1.1 and 8.8.8.8 to daemon.json (existing keys are kept), restarts
5
+ # Docker and waits until it responds.
6
+ # Guard: refuses outside CI, never run on a workstation.
7
7
  set -euo pipefail
8
8
 
9
9
  if [ "${CI:-}" != true ] || [ "${GITHUB_ACTIONS:-}" != true ]; then
10
- echo "ci-dns.sh : réservé à GitHub Actions (CI et GITHUB_ACTIONS doivent valoir true)" >&2
10
+ echo "ci-dns.sh: reserved for GitHub Actions (CI and GITHUB_ACTIONS must be true)" >&2
11
11
  exit 1
12
12
  fi
13
13
 
14
- # Chemin surchargeable pour les tests
14
+ # Overridable path for tests
15
15
  daemon="${DEVZONE_CI_DOCKER_DAEMON:-/etc/docker/daemon.json}"
16
16
  tmp="$(mktemp)"
17
17
  trap 'rm -f "$tmp"' EXIT
18
18
 
19
- # Fusion avec le fichier existant, ou création s'il n'existe pas
19
+ # Merge with existing file, or create it if missing
20
20
  if [ -s "$daemon" ]; then
21
21
  jq '. + {"dns": ["1.1.1.1", "8.8.8.8"]}' "$daemon" >"$tmp"
22
22
  else
@@ -27,12 +27,12 @@ sudo cp "$tmp" "$daemon"
27
27
 
28
28
  sudo systemctl restart docker
29
29
 
30
- # Attente de Docker : 20 secondes au plus
30
+ # Wait for Docker: at most 20 seconds
31
31
  for _ in $(seq 1 20); do
32
32
  if docker info >/dev/null 2>&1; then
33
33
  exit 0
34
34
  fi
35
35
  sleep 1
36
36
  done
37
- echo "ci-dns.sh : Docker ne répond pas après 20 s" >&2
37
+ echo "ci-dns.sh: Docker did not respond after 20 s" >&2
38
38
  exit 1