devzone 2.0.0 → 4.0.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 (100) hide show
  1. package/.devcontainer/agent-errors.sh +6 -6
  2. package/.devcontainer/agent-pod-manifest.sh +4 -4
  3. package/.devcontainer/agent-session.sh +2 -2
  4. package/.devcontainer/agent-state-json.sh +2 -2
  5. package/.devcontainer/agent-workspace.sh +1 -1
  6. package/.devcontainer/agent.sh +7 -7
  7. package/.devcontainer/ai/host-models.sh +2 -2
  8. package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
  9. package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
  10. package/.devcontainer/argocd/argocd.sh +90 -89
  11. package/.devcontainer/argocd/catalog-argocd.sh +2 -2
  12. package/.devcontainer/argocd/services-hook.sh +3 -3
  13. package/.devcontainer/argocd/services.sh +1 -1
  14. package/.devcontainer/catalog/app.sh +114 -116
  15. package/.devcontainer/catalog/catalog-watcher.sh +62 -62
  16. package/.devcontainer/catalog/mysql/app.conf +1 -1
  17. package/.devcontainer/catalog/mysql/install.sh +40 -40
  18. package/.devcontainer/catalog/mysql/mysql.sh +141 -141
  19. package/.devcontainer/catalog/mysql/volume.sh +39 -39
  20. package/.devcontainer/catalog.sh +112 -112
  21. package/.devcontainer/chart-direct.sh +1 -1
  22. package/.devcontainer/cluster.sh +216 -218
  23. package/.devcontainer/clusters.sh +41 -41
  24. package/.devcontainer/command-aliases.sh +17 -8
  25. package/.devcontainer/devzone +93 -1496
  26. package/.devcontainer/devzone-ai-guard.sh +76 -0
  27. package/.devcontainer/devzone-ai.sh +201 -0
  28. package/.devcontainer/devzone-cluster.sh +210 -0
  29. package/.devcontainer/devzone-modules.sh +126 -0
  30. package/.devcontainer/devzone-platform.sh +189 -0
  31. package/.devcontainer/devzone-repair.sh +94 -0
  32. package/.devcontainer/devzone-services.sh +241 -0
  33. package/.devcontainer/devzone-skill.sh +97 -0
  34. package/.devcontainer/devzone-status.sh +140 -0
  35. package/.devcontainer/devzone-version.sh +78 -0
  36. package/.devcontainer/git-identity.sh +28 -0
  37. package/.devcontainer/gitlab/chart.sh +2 -2
  38. package/.devcontainer/gitlab/gitlab.sh +81 -82
  39. package/.devcontainer/gitlab/installation.sh +109 -109
  40. package/.devcontainer/gitlab/secrets.sh +47 -47
  41. package/.devcontainer/gitlab/seed.sh +77 -77
  42. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  43. package/.devcontainer/help.sh +1 -1
  44. package/.devcontainer/isolation.sh +30 -30
  45. package/.devcontainer/kind-wrapper.sh +17 -17
  46. package/.devcontainer/kube-account.sh +112 -113
  47. package/.devcontainer/kube-config.sh +45 -46
  48. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  49. package/.devcontainer/kube-reachable.sh +40 -40
  50. package/.devcontainer/memory.sh +1 -1
  51. package/.devcontainer/metrics-server.sh +2 -2
  52. package/.devcontainer/opencode.jsonc +2 -2
  53. package/.devcontainer/packages.sh +136 -135
  54. package/.devcontainer/password.sh +1 -1
  55. package/.devcontainer/ports-auto.sh +152 -153
  56. package/.devcontainer/ports-json.sh +16 -15
  57. package/.devcontainer/ports.sh +126 -122
  58. package/.devcontainer/post-create.sh +52 -52
  59. package/.devcontainer/postgres/postgres.sh +174 -174
  60. package/.devcontainer/rename-legacy-files.sh +103 -0
  61. package/.devcontainer/services-admin.sh +3 -3
  62. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  63. package/.devcontainer/startup.sh +48 -49
  64. package/.devcontainer/state-gitops.sh +1 -1
  65. package/.devcontainer/state-json.sh +36 -62
  66. package/.devcontainer/state.sh +2 -2
  67. package/.devcontainer/workspace-init.sh +16 -2
  68. package/Makefile +1 -1
  69. package/README.md +191 -195
  70. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  71. package/manage/devzone +7 -11
  72. package/manage/scripts/argocd-workspace.sh +1 -1
  73. package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
  74. package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
  75. package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
  76. package/manage/scripts/{check-names.sh → ci/check-names.sh} +7 -6
  77. package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
  78. package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
  79. package/manage/scripts/create-cluster.sh +1 -1
  80. package/manage/scripts/create-mode.sh +11 -18
  81. package/manage/scripts/devzone-create.sh +7 -35
  82. package/manage/scripts/devzone-manifest.sh +1 -1
  83. package/manage/scripts/devzone-update.sh +12 -8
  84. package/manage/scripts/launch.sh +7 -48
  85. package/manage/scripts/ports-apps.sh +1 -1
  86. package/manage/scripts/ports-workspace.sh +7 -7
  87. package/manage/scripts/poste.sh +6 -7
  88. package/manage/scripts/uninstall.sh +8 -8
  89. package/manage/scripts/workspace-egress.sh +2 -2
  90. package/manage/scripts/workspace-update.sh +5 -2
  91. package/manage/scripts/workspace-wait.sh +2 -2
  92. package/manage/workspace.sh +2 -12
  93. package/package.json +1 -1
  94. package/.devcontainer/docker-relay.sh +0 -149
  95. package/.devcontainer/docker-without-host.sh +0 -12
  96. package/.devcontainer/git-identite.sh +0 -28
  97. package/manage/scripts/docker-workstation.sh +0 -73
  98. package/manage/scripts/migrate-revert.sh +0 -60
  99. package/manage/scripts/migrate.sh +0 -243
  100. /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
@@ -36,11 +36,11 @@ egress_params() {
36
36
 
37
37
  # Waits for the proxy after the redeploy. Argo CD creates its Deployment a few
38
38
  # seconds to a minute after the sync: the Deployment is looked up every
39
- # DEVZONE_EGRESS_PAS s (3 by default) up to DEVZONE_EGRESS_WAIT s (90 by
39
+ # DEVZONE_EGRESS_STEP s (3 by default) up to DEVZONE_EGRESS_WAIT s (90 by
40
40
  # default); then its rollout is awaited for DEVZONE_EGRESS_ROLLOUT s (120 by
41
41
  # default). Returns 1 when either is not reached.
42
42
  egress_wait_proxy() {
43
- local limit="${DEVZONE_EGRESS_WAIT:-90}" rollout="${DEVZONE_EGRESS_ROLLOUT:-120}" pas="${DEVZONE_EGRESS_PAS:-3}" attendu=0
43
+ local limit="${DEVZONE_EGRESS_WAIT:-90}" rollout="${DEVZONE_EGRESS_ROLLOUT:-120}" pas="${DEVZONE_EGRESS_STEP:-3}" attendu=0
44
44
  until ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy >/dev/null 2>&1; do
45
45
  if [ "$attendu" -ge "$limit" ]; then
46
46
  echo "⚠ the egress proxy was not created by Argo CD after $limit s: the setting is kept, check devzone workspace argocd status" >&2
@@ -87,15 +87,18 @@ update_workspace() {
87
87
  echo "✖ no terminal to confirm: run again with --yes (devzone workspace update --yes)" >&2
88
88
  return 1
89
89
  fi
90
- read -r -p "Update the workspace to v$version? [o/N] " answer || answer=""
90
+ read -r -p "Update the workspace to v$version? [y/N] " answer || answer=""
91
91
  case "$answer" in
92
- o | O | oui | y | Y | yes) ;;
92
+ y | Y | yes) ;;
93
93
  *)
94
94
  echo "✖ canceled, nothing changed" >&2
95
95
  return 1
96
96
  ;;
97
97
  esac
98
98
  fi
99
+ # Former French names renamed once the update is confirmed (#733); the
100
+ # script comes from the package, the devzone folder is the current one
101
+ DEVZONE_ROOT="$PWD" bash "$ROOT/.devcontainer/rename-legacy-files.sh" || true
99
102
  # Same path as workspace start, at the release: Argo CD revision and image tag
100
103
  export DEVZONE_ARGOCD_REVISION="v$version"
101
104
  workspace_deploy "$IMAGE_REPO" "$version" ""
@@ -6,8 +6,8 @@
6
6
  # Waits for the workspace pod; missing image or slow pod are reported clearly.
7
7
  wait_for_pod() {
8
8
  local image="$1" timeout step start state events arch target_revision pod_revision
9
- timeout="${DEVZONE_WORKSPACE_ATTENTE:-120}"
10
- step="${DEVZONE_WORKSPACE_PAS:-2}"
9
+ timeout="${DEVZONE_WORKSPACE_WAIT:-120}"
10
+ step="${DEVZONE_WORKSPACE_STEP:-2}"
11
11
  start="$SECONDS"
12
12
  while [ $((SECONDS - start)) -lt "$timeout" ]; do
13
13
  # Why: after helm upgrade the pod is still the old one; judge only the revision the StatefulSet is updating to, within the same wait bound.
@@ -175,10 +175,6 @@ copy_from() {
175
175
  . "$HERE/scripts/workspace-clone.sh"
176
176
  # shellcheck source=manage/scripts/workspace-copies.sh
177
177
  . "$HERE/scripts/workspace-copies.sh"
178
- # shellcheck source=manage/scripts/migrate.sh
179
- . "$HERE/scripts/migrate.sh"
180
- # shellcheck source=manage/scripts/migrate-revert.sh
181
- . "$HERE/scripts/migrate-revert.sh"
182
178
  # shellcheck source=manage/scripts/ports-workspace.sh
183
179
  . "$HERE/scripts/ports-workspace.sh"
184
180
  # shellcheck source=manage/scripts/services-workspace.sh
@@ -217,14 +213,11 @@ case "${1:-}" in
217
213
  copy-from) copy_from "${@:2}" ;;
218
214
  clone) workspace_clone "${@:2}" ;;
219
215
  ports) ports "${@:2}" ;;
220
- migrate) migrate_workspace "${@:2}" ;;
221
- revert) revert_workspace "${@:2}" ;;
222
- clean-docker) clean_docker "${@:2}" ;;
223
216
  services) services "${@:2}" ;;
224
217
  argocd) argocd_cmd "${@:2}" ;;
225
218
  egress) egress_workspace "${@:2}" ;;
226
219
  '' | -h | --help | help)
227
- echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update|egress"
220
+ echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|update|egress"
228
221
  echo " start [--image repository:tag] install workspace (image for devzone version by default)"
229
222
  echo " update [--version X.Y.Z] [--yes] move to the latest stable release (or X.Y.Z); the pod is recreated"
230
223
  echo " clone <url> [<name>] git clone into the pod projects folder (gh credentials, identity, repowarden hooks)"
@@ -233,13 +226,10 @@ case "${1:-}" in
233
226
  echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
234
227
  echo " argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>"
235
228
  echo " Argo CD of the workspace: .argocd.conf, GitOps repository, your projects as Applications"
236
- echo " migrate [--yes] copy Docker workstation to Kubernetes workspace (nothing is deleted)"
237
- echo " revert [--bring-back] back to Docker workstation (deprecated, will be removed); --bring-back: copy pod projects first"
238
- echo " clean-docker remove devzone-* Docker volumes, after confirmation [y/N] (--yes)"
239
229
  echo " egress observation|strict|off|status|allow <domain>|deny <domain> egress proxy of the agent sessions (--pod)"
240
230
  ;;
241
231
  *)
242
- echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update)" >&2
232
+ echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|update)" >&2
243
233
  exit 1
244
234
  ;;
245
235
  esac
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Relais du socket Docker (#293), lancé en premier par startup.sh.
3
- #
4
- # Pourquoi : la feature docker-outside-of-docker relaie le socket de l'hôte
5
- # par « socat UNIX-LISTEN:/var/run/docker.sock,… UNIX-CONNECT:… » sans
6
- # option -t (seulement sous Docker Desktop, socket au gid 0 ; sous Linux elle
7
- # passe par un groupe, sans socat). Dès que le client ferme son côté (un
8
- # « docker exec » sans entrée standard), socat coupe la connexion 0,5 s plus
9
- # tard : la sortie est tronquée et docker exec renvoie quand même 0. kind lance
10
- # kubeadm init ainsi, et le croit réussi au bout de 0,5 s (cluster kind et
11
- # module gitlab impossibles depuis devzone). Le même socat avec -t 86400 laisse
12
- # passer la réponse du démon jusqu'à ce qu'il ferme lui-même.
13
- #
14
- # Ce que fait le script : relais de la feature sans -t → remplacé par le même
15
- # avec -t 86400 (fichier PID de la feature mis à jour, docker-init.sh ne le
16
- # relance donc pas) ; puis contrôle qu'un docker exec long va au bout. Sans
17
- # relais socat (Linux), seul le contrôle est fait. Idempotent.
18
- #
19
- # Sûr par construction : chemins et commandes réglables (tests : tout sous un
20
- # dossier temporaire), et refus de toucher au vrai socket sans
21
- # DEVZONE_RELAIS_REEL=oui, que seuls startup.sh et devzone repair posent.
22
- # Code : 0 contrôle réussi, 1 contrôle en échec (marque écrite pour le
23
- # récapitulatif devzone), 2 refus de la garde. Compatible bash 3.2.
24
- set -euo pipefail
25
-
26
- SOCKET="${DEVZONE_RELAIS_SOCKET:-/var/run/docker.sock}"
27
- SOURCE="${DEVZONE_RELAIS_SOURCE:-/var/run/docker-host.sock}"
28
- # Fichiers de la feature (/usr/local/share/docker-init.sh : SOCAT_PID, SOCAT_LOG)
29
- PID_FICHIER="${DEVZONE_RELAIS_PID:-/tmp/vscr-docker-from-docker.pid}"
30
- JOURNAL="${DEVZONE_RELAIS_LOG:-/tmp/vscr-docker-from-docker.log}"
31
- UTILISATEUR="${DEVZONE_RELAIS_UTILISATEUR:-vscode}"
32
- DOCKER="${DEVZONE_RELAIS_DOCKER:-docker}"
33
- # Marque d'échec lue par le récapitulatif (.devcontainer/devzone) : propre au
34
- # conteneur, effacée à chaque redémarrage avec /tmp
35
- MARQUE="${DEVZONE_RELAIS_MARQUE:-/tmp/devzone-relais-docker.echec}"
36
- ATTENTE="${DEVZONE_RELAIS_ATTENTE:-10}"
37
- # Le relais de la feature tourne en root : sudo sauf si on est déjà root
38
- if [ -n "${DEVZONE_RELAIS_SUDO+x}" ]; then
39
- SUDO="$DEVZONE_RELAIS_SUDO"
40
- elif [ "$(id -u)" = 0 ]; then
41
- SUDO=""
42
- else
43
- SUDO=sudo
44
- fi
45
-
46
- if [ -n "${BATS_TEST_TMPDIR:-}" ] && [ "$SOCKET" = /var/run/docker.sock ]; then
47
- echo "docker-relais : refus sous bats (tests)" >&2
48
- exit 2
49
- fi
50
-
51
- if [ "$SOCKET" = /var/run/docker.sock ] && [ "${DEVZONE_RELAIS_REEL:-}" != oui ]; then
52
- echo "docker-relais : refus de toucher au vrai socket ($SOCKET) : lancer plutôt devzone repair" >&2
53
- exit 2
54
- fi
55
-
56
- # Sans socket (option docker-hote=off, #432) : rien à relayer ni à contrôler.
57
- # Sortie 0 pour ne pas gêner le démarrage ; docker renvoie au workspace.
58
- if [ ! -e "$SOCKET" ]; then
59
- rm -f "$MARQUE" 2>/dev/null || true
60
- echo "docker-relais : pas de socket Docker de l'hôte (option docker-hote=off)"
61
- exit 0
62
- fi
63
-
64
- # $SUDO vide : commande lancée par env, jamais en commande intégrée (kill est
65
- # un builtin de bash : env passe par le PATH, comme sudo ; les tests y mettent
66
- # leurs faux outils)
67
- en_root() {
68
- if [ -n "$SUDO" ]; then
69
- "$SUDO" "$@"
70
- else
71
- env "$@"
72
- fi
73
- }
74
-
75
- echec() {
76
- echo "docker-relais : $1" >&2
77
- printf '%s\n' "$1" >"$MARQUE" 2>/dev/null || true
78
- exit 1
79
- }
80
-
81
- # « <pid> <a_t> » du socat qui écoute sur $SOCKET (a_t : 1 s'il a -t), rien
82
- # sinon. Seul le processus socat lui-même compte (pas un « sudo socat » parent),
83
- # et seulement s'il écoute sur ce socket-là.
84
- relais_trouve() {
85
- local pid args
86
- while read -r pid args; do
87
- case "$args" in
88
- "socat "*) ;;
89
- *) continue ;;
90
- esac
91
- case "$args" in
92
- *"UNIX-LISTEN:$SOCKET,"* | *"UNIX-LISTEN:$SOCKET "* | *"UNIX-LISTEN:$SOCKET") ;;
93
- *) continue ;;
94
- esac
95
- case " $args " in
96
- *" -t "*) echo "$pid 1" ;;
97
- *) echo "$pid 0" ;;
98
- esac
99
- return 0
100
- done < <(ps -eo pid=,args=)
101
- }
102
-
103
- remplacer() {
104
- local ancien="$1" nouveau i
105
- en_root kill "$ancien" 2>/dev/null || true
106
- i=0
107
- while [ "$i" -lt 20 ] && en_root kill -0 "$ancien" 2>/dev/null; do
108
- sleep 0.1
109
- i=$((i + 1))
110
- done
111
- en_root rm -f "$SOCKET"
112
- # setsid -f : socat détaché, il survit à la fin du démarrage ; -lf : son
113
- # journal (fichier de root) est ouvert par socat lui-même
114
- en_root setsid -f socat -t 86400 -lf "$JOURNAL" \
115
- "UNIX-LISTEN:$SOCKET,fork,mode=660,user=$UTILISATEUR,backlog=128" \
116
- "UNIX-CONNECT:$SOURCE" </dev/null >/dev/null 2>&1 ||
117
- echec "relais non relancé (socat -t 86400)"
118
- # PID du nouveau socat dans le fichier de la feature : docker-init.sh le
119
- # voit vivant et ne relance pas l'ancien relais
120
- i=0
121
- nouveau=""
122
- while [ "$i" -lt 20 ]; do
123
- nouveau="$(relais_trouve || true)"
124
- [ -n "$nouveau" ] && break
125
- sleep 0.1
126
- i=$((i + 1))
127
- done
128
- [ -n "$nouveau" ] || echec "relais relancé introuvable (ps)"
129
- printf '%s\n' "${nouveau%% *}" | en_root tee "$PID_FICHIER" >/dev/null
130
- echo "✔ relais Docker : socat -t 86400 (docker exec longs non coupés)"
131
- }
132
-
133
- trouve="$(relais_trouve || true)"
134
- if [ -n "$trouve" ] && [ "${trouve##* }" = 0 ]; then
135
- remplacer "${trouve%% *}"
136
- fi
137
-
138
- i=0
139
- until "$DOCKER" version >/dev/null 2>&1; do
140
- i=$((i + 1))
141
- [ "$i" -lt "$ATTENTE" ] || echec "le socket $SOCKET ne répond pas"
142
- sleep 1
143
- done
144
-
145
- # Contrôle : 1 s dépasse les 0,5 s de socat sans -t ; « ok » prouve que la
146
- # sortie d'un docker exec sans entrée standard arrive en entier
147
- sortie="$("$DOCKER" exec "$(hostname)" sh -c 'sleep 1; echo ok' </dev/null 2>&1 || true)"
148
- [ "$sortie" = ok ] || echec "docker exec long coupé (sortie : ${sortie:-vide})"
149
- rm -f "$MARQUE" 2>/dev/null || true
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Docker du poste non partagé (option docker-hote=off, #432). post-create.sh
3
- # installe ce script comme commande docker quand la feature
4
- # docker-outside-of-docker est absente : au lieu d'un « command not found »,
5
- # un message clair renvoie au workspace Kubernetes.
6
- cat >&2 <<'MESSAGE'
7
- ✖ Docker du poste non partagé (option docker-hote=off) : docker n'est pas disponible ici.
8
- Pour lancer des conteneurs, utilise le workspace Kubernetes : devzone workspace
9
- (docker et Testcontainers y parlent à kubedock, les images sont construites par BuildKit).
10
- Pour partager le socket Docker de l'hôte : devzone enable docker-hote, puis make rebuild sur le poste.
11
- MESSAGE
12
- exit 1
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Identité git, à chaque démarrage tant qu'elle manque : déduite du compte gh
3
- # (propre à chaque utilisateur, connexion gardée dans son volume) et écrite dans
4
- # ~/.config/git/config (volume devzone-git, survit aux rebuilds).
5
- # Une identité déjà définie (à la main, ou recopiée par VS Code dans
6
- # ~/.gitconfig) n'est jamais remplacée. Email noreply de GitHub : les commits
7
- # sont rattachés au compte sans exposer l'email personnel.
8
- set -euo pipefail
9
-
10
- CONFIG="$HOME/.config/git/config"
11
- nom_git="$(git config --get user.name || true)"
12
- email_git="$(git config --get user.email || true)"
13
-
14
- [ -n "$nom_git" ] && [ -n "$email_git" ] && exit 0
15
-
16
- # Sans gh : rien à déduire ; le récapitulatif de devzone le signale
17
- gh auth status >/dev/null 2>&1 || exit 0
18
-
19
- id="" login="" nom=""
20
- IFS=$'\t' read -r id login nom < <(gh api user --jq '[.id, .login, (.name // "")] | @tsv' 2>/dev/null || true)
21
- if [ -z "$id" ] || [ -z "$login" ]; then
22
- echo "git-identite : compte GitHub illisible (réseau ?) ; relancer : bash .devcontainer/git-identite.sh"
23
- exit 0
24
- fi
25
-
26
- [ -n "$nom_git" ] || git config --file "$CONFIG" user.name "${nom:-$login}"
27
- [ -n "$email_git" ] || git config --file "$CONFIG" user.email "${id}+${login}@users.noreply.github.com"
28
- echo "git-identite : $(git config --get user.name) <$(git config --get user.email)>"
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Docker workstation put to sleep when the Kubernetes workspace takes over (#517).
3
- # Sourced by migrate.sh (stop) and migrate-revert.sh (start). Containers of the
4
- # workstation folder (label devcontainer.local_folder) and the automatic port
5
- # relays of this instance (labels devzone.auto=true, devzone.instance) are
6
- # stopped, never removed. Without Docker,
7
- # only a warning: the migration does not fail for that.
8
-
9
- # Docker answers on the workstation (command present and daemon running).
10
- docker_workstation_ready() {
11
- command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1
12
- }
13
-
14
- # Ids, one per line, of the containers of folder $1 and of the automatic relays
15
- # of this instance (DEVZONE_VOLUMES, default devzone, as in uninstall.sh): the
16
- # relays of another devzone on the same machine are not touched.
17
- # $2 is "running" (docker ps) or "exited" (stopped containers, docker ps -a).
18
- docker_workstation_ids() {
19
- local folder="$1" etat="$2" instance="${DEVZONE_VOLUMES:-devzone}"
20
- if [ "$etat" = exited ]; then
21
- {
22
- docker ps -aq --filter "label=devcontainer.local_folder=$folder" --filter status=exited
23
- docker ps -aq --filter "label=devzone.auto=true" --filter "label=devzone.instance=$instance" --filter status=exited
24
- } 2>/dev/null | sort -u || true
25
- else
26
- {
27
- docker ps -q --filter "label=devcontainer.local_folder=$folder"
28
- docker ps -q --filter "label=devzone.auto=true" --filter "label=devzone.instance=$instance"
29
- } 2>/dev/null | sort -u || true
30
- fi
31
- }
32
-
33
- # Stops the running containers of folder $1 and the automatic relays (docker stop).
34
- docker_workstation_stop() {
35
- local ids
36
- if ! docker_workstation_ready; then
37
- echo " ⚠ Docker workstation: Docker does not respond, nothing stopped" >&2
38
- return 0
39
- fi
40
- ids="$(docker_workstation_ids "$1" running)"
41
- if [ -z "$ids" ]; then
42
- echo " – Docker workstation: no running container"
43
- return 0
44
- fi
45
- # shellcheck disable=SC2086
46
- if docker stop $ids >/dev/null 2>&1; then
47
- echo " ✔ Docker workstation stopped (kept: devzone workspace revert restarts it)"
48
- else
49
- echo " ⚠ Docker workstation: some containers could not be stopped" >&2
50
- fi
51
- return 0
52
- }
53
-
54
- # Starts again the stopped containers of folder $1 and the automatic relays (docker start).
55
- docker_workstation_start() {
56
- local ids
57
- if ! docker_workstation_ready; then
58
- echo " ⚠ Docker workstation: Docker does not respond, nothing started" >&2
59
- return 0
60
- fi
61
- ids="$(docker_workstation_ids "$1" exited)"
62
- if [ -z "$ids" ]; then
63
- echo " – Docker workstation: no stopped container to start"
64
- return 0
65
- fi
66
- # shellcheck disable=SC2086
67
- if docker start $ids >/dev/null 2>&1; then
68
- echo " ✔ Docker workstation started again"
69
- else
70
- echo " ⚠ Docker workstation: some containers could not be started" >&2
71
- fi
72
- return 0
73
- }
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Rollback from Kubernetes workspace to Docker workstation (#403): devzone workspace
3
- # revert [--bring-back]. Sourced by manage/workspace.sh after migrate.sh (uses
4
- # copy_from, record_workspace, fail and kc). With --bring-back, the workstation
5
- # version of a project is moved to .devzone.sauvegarde/<date>/ before being replaced.
6
-
7
- # Backup folder for this run (relative to devzone), same convention as
8
- # devzone update: .devzone.sauvegarde/<YYYYMMDD-HHMMSS>, -n suffix if taken.
9
- backup_folder() {
10
- local base folder n=1
11
- base=".devzone.sauvegarde/$(date +%Y%m%d-%H%M%S)"
12
- folder="$base"
13
- while [ -e "$folder" ]; do
14
- n=$((n + 1))
15
- folder="$base-$n"
16
- done
17
- printf '%s' "$folder"
18
- }
19
-
20
- # Brings project $1 back from the pod; its workstation version ($2: backup folder)
21
- # is moved first. If the move fails, nothing is overwritten.
22
- bring_back_project() {
23
- local p="$1" backup="$2"
24
- if [ -e "workspace/$p" ]; then
25
- if ! mkdir -p "$backup/workspace" || ! mv "workspace/$p" "$backup/workspace/$p"; then
26
- fail "backup of workspace/$p failed: nothing was overwritten"
27
- return 1
28
- fi
29
- echo "project $p: workstation version saved in $backup/"
30
- fi
31
- copy_from "$PWD/workspace/$p" || {
32
- fail "bring-back of $p failed (workstation version: $backup/workspace/$p)"
33
- return 1
34
- }
35
- }
36
-
37
- # devzone workspace revert [--bring-back]: workspace=docker; --bring-back copies projects from the pod first.
38
- revert_workspace() {
39
- local bring_back p list backup
40
- bring_back="$(read_flag --bring-back "revert [--bring-back]" "$@")" || return 1
41
- # Deprecated with the Docker workstation (#671, #682): still works, but it will be removed.
42
- echo "⚠ devzone workspace revert is deprecated: the Docker workstation will be removed (two minor versions and 30 days at least after this release). devzone workspace migrate stays." >&2
43
- if [ "$bring_back" = 1 ]; then
44
- echo "▶ bring-back: projects from pod to ./workspace (workstation version is saved first)"
45
- list="$(kc exec "$POD" -c workspace -- ls -1 "$PROJECTS_DIR")" || { fail "cannot read project list from pod"; return 1; }
46
- mkdir -p workspace
47
- backup="$(backup_folder)"
48
- while IFS= read -r p; do
49
- [ -n "$p" ] || continue
50
- echo " … $p"
51
- bring_back_project "$p" "$backup" || return 1
52
- done <<<"$list"
53
- fi
54
- record_workspace docker || { fail "cannot write .devzone.modules"; return 1; }
55
- docker_workstation_start "$PWD"
56
- echo "✔ workspace=docker: Docker workstation and its volumes are intact. Start it again: make shell"
57
- }
58
-
59
- # compatibility alias, removed with lot 4 (#509)
60
- revenir() { revert_workspace "$@"; }
@@ -1,243 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Migration from Docker workstation to Kubernetes workspace, and rollback (#403).
3
- # Sourced by manage/workspace.sh: uses POD, NAMESPACE, PROJECTS_DIR,
4
- # kubectl_flag, copy_to and copy_from. Nothing is ever deleted except by
5
- # clean-docker, after confirmation. Run from the devzone workstation folder.
6
-
7
- # Docker workstation sleep on migrate (stop here, start in migrate-revert.sh).
8
- # shellcheck source=manage/scripts/docker-workstation.sh
9
- . "$(dirname "${BASH_SOURCE[0]}")/docker-workstation.sh"
10
-
11
- # vscode home in the pod and image used to copy Docker volumes.
12
- POD_HOME="/home/vscode"
13
- COPY_IMAGE="${DEVZONE_IMAGE_COPIE:-busybox:1.36}"
14
- # Docker workstation volumes: devzone-<x>, or $DEVZONE_VOLUMES-<x> (functional tests).
15
- DOCKER_VOLUMES=(gh git claude opencode-config opencode-data agent config m2 gradle pnpm)
16
- # Folder size measurement ($1): "file count bytes".
17
- # shellcheck disable=SC2016
18
- MEASURE='n=$(find "$1" -type f | wc -l | tr -d " "); o=$(find "$1" -type f -exec wc -c {} + 2>/dev/null | awk '\''$2!="total"{s+=$1} END{print s+0}'\''); echo "$n $o"'
19
-
20
- # Workstation kubectl, devzone context if it exists, workspace namespace.
21
- kc() {
22
- local flag
23
- flag="$(kubectl_flag)"
24
- # shellcheck disable=SC2086
25
- kubectl $flag --namespace "$NAMESPACE" "$@"
26
- }
27
-
28
- # Clear error on stderr (exit code 1 returned by caller).
29
- fail() {
30
- echo "✖ $*" >&2
31
- }
32
-
33
- # Reads the single accepted flag ($1) from following args ($3…): prints 1 if
34
- # present, 0 otherwise; any other flag: error with usage ($2), exit code 1.
35
- read_flag() {
36
- local flag="$1" usage="$2" a found=0
37
- shift 2
38
- for a in "$@"; do
39
- if [ "$a" = "$flag" ]; then found=1; continue; fi
40
- fail "unknown option: $a (devzone workspace $usage)"
41
- return 1
42
- done
43
- echo "$found"
44
- }
45
-
46
- # State volume path (relative to vscode home) for a devzone-<x> Docker volume;
47
- # empty if the chart mounts none (persistence.state.paths).
48
- state_path() {
49
- case "$1" in
50
- gh) echo .config/gh ;;
51
- git) echo .config/git ;;
52
- claude) echo .claude ;;
53
- opencode-config) echo .config/opencode ;;
54
- opencode-data) echo .local/share/opencode ;;
55
- agent) echo .local/state/oc-lancer ;;
56
- m2) echo .m2 ;;
57
- gradle) echo .gradle ;;
58
- pnpm) echo .local/share/pnpm ;;
59
- esac
60
- }
61
-
62
- # Docker volume name for <x>.
63
- docker_volume() {
64
- printf '%s-%s' "${DEVZONE_VOLUMES:-devzone}" "$1"
65
- }
66
-
67
- # Asks [y/N] ($1: question, $2: 1 if --yes). Without terminal and without --yes: refuse.
68
- confirm() {
69
- local reply=""
70
- [ "${2:-0}" = 1 ] && return 0
71
- if [ ! -t 0 ]; then
72
- echo "✖ no terminal: cannot confirm, run again with --yes" >&2
73
- return 1
74
- fi
75
- read -r -p "$1 [y/N] " reply || true
76
- case "$reply" in y | Y | yes | YES | Yes | o | O | oui | OUI | Oui) return 0 ;; esac
77
- echo "✖ canceled, nothing changed" >&2
78
- return 1
79
- }
80
-
81
- # Compares workstation folder ($1) with pod folder ($2): same files, same size.
82
- verify_copy() {
83
- local local_state pod_state
84
- local_state="$(sh -c "$MEASURE" _ "$1")"
85
- pod_state="$(kc exec "$POD" -c workspace -- sh -c "$MEASURE" _ "$2")" || pod_state="unreadable"
86
- if [ "$local_state" != "$pod_state" ]; then
87
- fail "different copy for $2: workstation \"$local_state\", pod \"$pod_state\" (files bytes)"
88
- return 1
89
- fi
90
- echo " ✔ $2: ${local_state% *} file(s), ${local_state#* } byte(s)"
91
- }
92
-
93
- # Step 1: cluster reachable, pod started, enough space for projects.
94
- step_checks() {
95
- local phase needed free
96
- echo "▶ [1/5] checks: cluster, workspace, space"
97
- kc get --raw /readyz >/dev/null 2>&1 || {
98
- fail "unreachable cluster: check kubectl context (kubectl config get-contexts)"
99
- return 1
100
- }
101
- if ! command -v docker >/dev/null 2>&1 || ! docker info >/dev/null 2>&1; then
102
- fail "Docker does not respond: devzone-* workstation volumes must be readable"
103
- return 1
104
- fi
105
- phase="$(kc get pod "$POD" -o 'jsonpath={.status.phase}' 2>/dev/null || true)"
106
- [ "$phase" = "Running" ] || { fail "workspace not started (pod $POD: ${phase:-missing}): devzone workspace start"; return 1; }
107
- needed=0
108
- [ -d workspace ] && needed="$(du -sk workspace | cut -f1)"
109
- free="$(kc exec "$POD" -c workspace -- df -Pk "$PROJECTS_DIR" | awk 'NR==2{print $4}')" || free=0
110
- if [ "${free:-0}" -lt "$needed" ]; then
111
- fail "not enough space on $PROJECTS_DIR: ${free:-0} KB free, $needed KB of projects"
112
- return 1
113
- fi
114
- echo " ✔ cluster reachable, pod $POD ready, $free KB free for $needed KB of projects"
115
- }
116
-
117
- # Step 2: each project in ./workspace copied to the pod, then verified.
118
- step_projects() {
119
- local d name
120
- echo "▶ [2/5] projects: ./workspace/<project> to $PROJECTS_DIR (.git included)"
121
- for d in workspace/*/; do
122
- [ -d "$d" ] || continue
123
- name="$(basename "$d")"
124
- echo " … $name"
125
- (copy_to "$d") || { fail "project $name copy failed"; return 1; }
126
- verify_copy "$d" "$PROJECTS_DIR/$name" || return 1
127
- done
128
- }
129
-
130
- # Copies Docker volume <x> ($1) to $2 under pod home, through a read-only container.
131
- copy_volume() {
132
- local v target="$POD_HOME/$2" tmp status=0
133
- v="$(docker_volume "$1")"
134
- tmp="$(mktemp -d)"
135
- if ! docker run --rm -v "$v:/src:ro" "$COPY_IMAGE" tar cf - -C /src . | tar xf - -C "$tmp"; then
136
- fail "volume $v read failed"
137
- status=1
138
- elif ! kc cp "$tmp/." "$POD:$target" -c workspace; then
139
- fail "volume $v copy to $target failed"
140
- status=1
141
- else
142
- verify_copy "$tmp" "$target" || status=1
143
- fi
144
- rm -rf "$tmp"
145
- return "$status"
146
- }
147
-
148
- # Step 3: identities and caches, Docker volumes to state volume paths.
149
- step_identities() {
150
- local x path v
151
- echo "▶ [3/5] identities and caches: Docker volumes to state volume"
152
- for x in "${DOCKER_VOLUMES[@]}"; do
153
- path="$(state_path "$x")"
154
- v="$(docker_volume "$x")"
155
- if [ -z "$path" ]; then
156
- echo " – $v: no path in chart, skipped"
157
- elif ! docker volume inspect "$v" >/dev/null 2>&1; then
158
- echo " – $v: missing, ignored"
159
- else
160
- echo " … $v → $POD_HOME/$path"
161
- copy_volume "$x" "$path" || return 1
162
- fi
163
- done
164
- }
165
-
166
- # Step 4: workstation .devzone.modules and .devzone.paquets copied to the pod.
167
- step_state() {
168
- local f
169
- echo "▶ [4/5] state: .devzone.modules and .devzone.paquets to $PROJECTS_DIR"
170
- for f in .devzone.modules .devzone.paquets; do
171
- if [ ! -f "$f" ]; then
172
- echo " – $f: missing on workstation, skipped"
173
- continue
174
- fi
175
- if ! kc cp "$PWD/$f" "$POD:$PROJECTS_DIR/$f" -c workspace \
176
- || ! kc exec "$POD" -c workspace -- test -f "$PROJECTS_DIR/$f"; then
177
- fail "failed to copy $f or missing from pod"
178
- return 1
179
- fi
180
- echo " ✔ $f"
181
- done
182
- }
183
-
184
- # Writes workspace=$1 in workstation .devzone.modules (line replaced, rest kept).
185
- record_workspace() {
186
- local f=".devzone.modules" tmp
187
- tmp="$f.tmp.$$"
188
- {
189
- if [ -f "$f" ]; then grep -v '^workspace=' "$f" || true; fi
190
- echo "workspace=$1"
191
- } >"$tmp" && mv "$tmp" "$f"
192
- }
193
-
194
- # Step 5: switch, workspace=kubernetes recorded on workstation; nothing is deleted.
195
- # The Docker workstation containers and port relays are stopped, not removed (#517).
196
- step_switch() {
197
- echo "▶ [5/5] switch: workspace=kubernetes in .devzone.modules"
198
- record_workspace kubernetes || { fail "cannot write .devzone.modules"; return 1; }
199
- docker_workstation_stop "$PWD"
200
- echo " ✔ done; Docker workstation and its volumes are intact (rollback: devzone workspace revert)"
201
- }
202
-
203
- # devzone workspace migrate [--yes]: the five steps, stop at first error.
204
- migrate_workspace() {
205
- local yes
206
- yes="$(read_flag --yes "migrate [--yes]" "$@")" || return 1
207
- confirm "Migrate this Docker workstation to the Kubernetes workspace (copy, nothing is deleted)?" "$yes" || return 1
208
- step_checks || return 1
209
- step_projects || return 1
210
- step_identities || return 1
211
- step_state || return 1
212
- step_switch || return 1
213
- echo "✔ migration complete"
214
- }
215
-
216
- # devzone workspace clean-docker [--yes]: removes devzone-* Docker volumes, after confirmation.
217
- clean_docker() {
218
- local yes x v present=()
219
- yes="$(read_flag --yes "clean-docker [--yes]" "$@")" || return 1
220
- for x in "${DOCKER_VOLUMES[@]}"; do
221
- v="$(docker_volume "$x")"
222
- ! docker volume inspect "$v" >/dev/null 2>&1 || present+=("$v")
223
- done
224
- if [ "${#present[@]}" -eq 0 ]; then
225
- echo "No devzone Docker volume to remove."
226
- return 0
227
- fi
228
- echo "Docker volumes to remove (irreversible, \"revert\" will not find them again):"
229
- printf ' %s\n' "${present[@]}"
230
- confirm "Remove these ${#present[@]} volume(s)?" "$yes" || return 1
231
- for v in "${present[@]}"; do
232
- docker volume rm "$v" >/dev/null || { fail "failed to remove $v"; return 1; }
233
- echo " ✔ $v removed"
234
- done
235
- }
236
-
237
- # compatibility aliases, removed with lot 4 (#509)
238
- lire_option() { read_flag "$@"; }
239
- confirmer() { confirm "$@"; }
240
- noter_workspace() { record_workspace "$@"; }
241
- migrer() { migrate_workspace "$@"; }
242
- nettoyer_docker() { clean_docker "$@"; }
243
- echec() { fail "$@"; }