devzone 3.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.
- package/.devcontainer/command-aliases.sh +17 -8
- package/.devcontainer/devzone +1 -1
- package/README.md +7 -12
- package/manage/devzone +2 -4
- package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
- package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
- package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
- package/manage/scripts/{check-names.sh → ci/check-names.sh} +1 -1
- package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
- package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
- package/manage/scripts/create-mode.sh +9 -16
- package/manage/scripts/devzone-create.sh +5 -33
- package/manage/scripts/poste.sh +6 -7
- package/manage/workspace.sh +2 -12
- package/package.json +1 -1
- package/manage/scripts/docker-workstation.sh +0 -73
- package/manage/scripts/migrate-revert.sh +0 -60
- package/manage/scripts/migrate.sh +0 -237
- /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
|
@@ -36,9 +36,6 @@ renamed_command() {
|
|
|
36
36
|
desinstaller) echo uninstall ;;
|
|
37
37
|
copier-vers) echo copy-to ;;
|
|
38
38
|
copier-depuis) echo copy-from ;;
|
|
39
|
-
migrer) echo migrate ;;
|
|
40
|
-
revenir) echo revert ;;
|
|
41
|
-
nettoyer-docker) echo clean-docker ;;
|
|
42
39
|
*) return 1 ;;
|
|
43
40
|
esac
|
|
44
41
|
}
|
|
@@ -123,9 +120,6 @@ renamed_subcommand() {
|
|
|
123
120
|
etat) echo status ;;
|
|
124
121
|
copier-vers) echo copy-to ;;
|
|
125
122
|
copier-depuis) echo copy-from ;;
|
|
126
|
-
migrer) echo migrate ;;
|
|
127
|
-
revenir) echo revert ;;
|
|
128
|
-
nettoyer-docker) echo clean-docker ;;
|
|
129
123
|
aide) echo help ;;
|
|
130
124
|
*) return 1 ;;
|
|
131
125
|
esac
|
|
@@ -151,11 +145,17 @@ renamed_option() {
|
|
|
151
145
|
--oui) echo --yes ;;
|
|
152
146
|
--confirmer) echo --confirm ;;
|
|
153
147
|
--contexte) echo --context ;;
|
|
154
|
-
--rapatrier) echo --bring-back ;;
|
|
155
148
|
*) return 1 ;;
|
|
156
149
|
esac
|
|
157
150
|
}
|
|
158
151
|
|
|
152
|
+
# Names removed in 3.0 (#735): refused with the same exit code, with a notice
|
|
153
|
+
# that names no former feature and never creates a folder.
|
|
154
|
+
removed_notice() {
|
|
155
|
+
echo "✖ this command or option was removed in devzone 3.0 (see manage/docs/migrating-to-3.md)" >&2
|
|
156
|
+
return 1
|
|
157
|
+
}
|
|
158
|
+
|
|
159
159
|
# reject_renamed <command> <args...> : checks the command itself (top level),
|
|
160
160
|
# the first word of <args> that is not an option (subcommand), then every
|
|
161
161
|
# option. The first renamed name prints its message on stderr and returns 1;
|
|
@@ -163,10 +163,13 @@ renamed_option() {
|
|
|
163
163
|
reject_renamed() {
|
|
164
164
|
local command="${1:-}" word new
|
|
165
165
|
if [ "$#" -gt 0 ]; then shift; fi
|
|
166
|
+
case "$command" in
|
|
167
|
+
migrer | revenir | nettoyer-docker) removed_notice; return 1 ;;
|
|
168
|
+
esac
|
|
166
169
|
if new="$(renamed_command "$command")"; then
|
|
167
170
|
# these commands only exist under « devzone workspace »
|
|
168
171
|
case "$command" in
|
|
169
|
-
|
|
172
|
+
copier-vers | copier-depuis) new="workspace $new" ;;
|
|
170
173
|
esac
|
|
171
174
|
printf '✖ « %s » a été renommé : devzone %s\n' "$command" "$new" >&2
|
|
172
175
|
return 1
|
|
@@ -175,6 +178,11 @@ reject_renamed() {
|
|
|
175
178
|
case "$word" in
|
|
176
179
|
-*) continue ;;
|
|
177
180
|
esac
|
|
181
|
+
if [ "$command" = workspace ]; then
|
|
182
|
+
case "$word" in
|
|
183
|
+
migrer | revenir | nettoyer-docker) removed_notice; return 1 ;;
|
|
184
|
+
esac
|
|
185
|
+
fi
|
|
178
186
|
if new="$(renamed_subcommand "$command" "$word")"; then
|
|
179
187
|
printf '✖ « %s » a été renommé : devzone %s %s\n' "$word" "$command" "$new" >&2
|
|
180
188
|
return 1
|
|
@@ -183,6 +191,7 @@ reject_renamed() {
|
|
|
183
191
|
done
|
|
184
192
|
for word in "$@"; do
|
|
185
193
|
case "$word" in
|
|
194
|
+
--rapatrier) removed_notice; return 1 ;;
|
|
186
195
|
-*)
|
|
187
196
|
if new="$(renamed_option "$word")"; then
|
|
188
197
|
printf '✖ « %s » a été renommé : %s\n' "$word" "$new" >&2
|
package/.devcontainer/devzone
CHANGED
|
@@ -23,7 +23,7 @@ ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
|
23
23
|
# shellcheck source=SCRIPTDIR/help.sh
|
|
24
24
|
# shellcheck disable=SC1091
|
|
25
25
|
. "$ICI/help.sh"
|
|
26
|
-
VERSIONS="$ICI/../manage/scripts/versions.sh"
|
|
26
|
+
VERSIONS="$ICI/../manage/scripts/ci/versions.sh"
|
|
27
27
|
# devzone folder (/workspaces/devzone); DEVZONE_ROOT for the tests
|
|
28
28
|
RACINE="${DEVZONE_ROOT:-$(dirname "$ICI")}"
|
|
29
29
|
# Default state of the instance; DEVZONE_STATE takes precedence (tests, CI)
|
package/README.md
CHANGED
|
@@ -31,16 +31,13 @@ devzone avoids them: the same environment on every workstation, on your machine.
|
|
|
31
31
|
devzone prepares an Ubuntu environment with pinned tool versions, and runs it in one of these two places:
|
|
32
32
|
|
|
33
33
|
- **inside the Kubernetes cluster** of your machine, by default, as soon as a cluster answers at creation: the workstation is a pod `devzone-workspace-0` (namespace `devzone-workspace`);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
In both cases, nothing is hosted: everything runs on your machine. `workspace/` is kept across rebuilds, and the projects of a Kubernetes workstation stay in the pod's volume. The mode of each workstation is written in `.devzone.modules` (`workspace=kubernetes` or `workspace=docker`); the details are in the [reference](manage/docs/reference.md#kubernetes-workspace).
|
|
34
|
+
Nothing is hosted: everything runs on your machine. `workspace/` is kept across rebuilds, and the projects of the workstation stay in the pod's volume. The mode of each workstation is written in `.devzone.modules` (`workspace=kubernetes`); the details are in the [reference](manage/docs/reference.md#kubernetes-workspace).
|
|
37
35
|
|
|
38
36
|
## Quick start
|
|
39
37
|
|
|
40
38
|
### Prerequisites
|
|
41
39
|
|
|
42
40
|
- **Kubernetes (default mode)**: a Kubernetes 1.30 or newer cluster that answers, with `kubectl` and `helm` on the machine. On Mac and Windows, the simplest is the Docker Desktop cluster: *Settings → Kubernetes → Enable Kubernetes*. devzone itself does not need Docker in this mode, but the Docker Desktop cluster stops with Docker Desktop (if the cluster does not answer, see [Frequently asked questions](#frequently-asked-questions)). Details in the [Kubernetes workspace](manage/docs/reference.md#kubernetes-workspace).
|
|
43
|
-
- **Docker (deprecated)**: Docker Desktop (or Docker Engine on Linux). It serves the Docker workstation, which is no longer an automatic fallback: without a cluster, creation stops. It remains necessary to read the volumes to migrate (`devzone workspace migrate`, `devzone workspace revert` to go back).
|
|
44
41
|
- Node and npm (for `npx` or the global installation).
|
|
45
42
|
- `make` (needed for `make shell`; on Windows without `make`, see the table “Day to day”).
|
|
46
43
|
|
|
@@ -126,13 +123,13 @@ At creation, devzone needs a Kubernetes cluster that answers.
|
|
|
126
123
|
devzone mon-devzone
|
|
127
124
|
│
|
|
128
125
|
├─ cluster answers ─────▶ workspace in the cluster (Kubernetes)
|
|
129
|
-
│ make shell opens the pod
|
|
126
|
+
│ make shell opens the pod
|
|
130
127
|
│
|
|
131
128
|
└─ otherwise ───────────▶ nothing is created: devzone lists the ways
|
|
132
129
|
to get a cluster, then you rerun
|
|
133
130
|
```
|
|
134
131
|
|
|
135
|
-
Without a cluster, in a terminal, devzone offers to choose a remote cluster (a context of your kubeconfig, whose name you retype to confirm) or to create a minikube; without a terminal, it stops and shows commands to copy (it never runs them, and no cloud credential passes through it): a remote cluster (`aws eks update-kubeconfig`, `gcloud container clusters get-credentials`, `az aks get-credentials`, which declare it in your kubeconfig; make it the current kubectl context), or a local cluster (Docker Desktop: *Settings → Kubernetes → Enable Kubernetes*, or `minikube start -p devzone`).
|
|
132
|
+
Without a cluster, in a terminal, devzone offers to choose a remote cluster (a context of your kubeconfig, whose name you retype to confirm) or to create a minikube; without a terminal, it stops and shows commands to copy (it never runs them, and no cloud credential passes through it): a remote cluster (`aws eks update-kubeconfig`, `gcloud container clusters get-credentials`, `az aks get-credentials`, which declare it in your kubeconfig; make it the current kubectl context), or a local cluster (Docker Desktop: *Settings → Kubernetes → Enable Kubernetes*, or `minikube start -p devzone`). Details in [manage/docs/reference.md](manage/docs/reference.md#direct-creation-in-the-cluster).
|
|
136
133
|
|
|
137
134
|
### Check that everything works
|
|
138
135
|
|
|
@@ -200,7 +197,7 @@ The list lives in `.devzone.packages` at the root of the devzone folder, outside
|
|
|
200
197
|
| Status | — | `make status` | — |
|
|
201
198
|
| **Uninstall** (everything devzone created, after confirmation) | — | `make uninstall` | `npx devzone uninstall` |
|
|
202
199
|
|
|
203
|
-
In Kubernetes mode (workstation created while the cluster was answering
|
|
200
|
+
In Kubernetes mode (workstation created while the cluster was answering), the same table applies to the pod `devzone-workspace-0`: `make up`, `make shell` and `make stop` control it, and `make rebuild` is refused, because nothing needs rebuilding on the machine. The GitLab, PostgreSQL and Argo CD services are installed from the workstation: `devzone workspace services enable postgres` (see [the reference](manage/docs/reference.md#devzone-services-in-the-kubernetes-workspace)). You can also develop there: `devzone workspace clone <url>` makes a working clone in the pod, `devzone ticket <n>` creates the worktree of a ticket there and `devzone agent` launches opencode there without a copy ([developing in the pod](manage/docs/reference.md#developing-devzone-and-repowarden-in-the-pod)). Argo CD is installed by default there and keeps the deployments: interface at https://localhost:8443 (password `admin` in `.password`), GitOps repository `<login>/devzone-argocd` created on your GitHub, projects declared in `.argocd.conf` (`devzone workspace argocd app add <repo>`); see [Argo CD in the Kubernetes workspace](manage/docs/reference.md#argo-cd-in-the-kubernetes-workspace).
|
|
204
201
|
|
|
205
202
|
In the container, `devzone --version` shows the version of the workspace image, and `devzone --help` lists all the commands. Extract:
|
|
206
203
|
|
|
@@ -230,9 +227,7 @@ The command shows the folder's version and the package's, and does nothing if th
|
|
|
230
227
|
|
|
231
228
|
`workspace/`, `.devzone.modules`, `.devzone.packages`, `.password`, `.app`, `.devzone.log` and the Docker volumes are never touched.
|
|
232
229
|
|
|
233
|
-
The old names of files and folders (`.devzone.paquets`, `.devzone.sauvegarde`, `.devzone.ports-workspace`, `.devzone.etat`, `.devzone.catalogue-veilleur`) are renamed once only, with their contents, by `.devcontainer/rename-legacy-files.sh`: at container startup
|
|
234
|
-
|
|
235
|
-
The update never changes the workstation's mode; on a Docker workstation with Kubernetes reachable, it proposes `devzone workspace migrate`.
|
|
230
|
+
The old names of files and folders (`.devzone.paquets`, `.devzone.sauvegarde`, `.devzone.ports-workspace`, `.devzone.etat`, `.devzone.catalogue-veilleur`) are renamed once only, with their contents, by `.devcontainer/rename-legacy-files.sh`: at container startup and at update. A new name already present is never overwritten.
|
|
236
231
|
|
|
237
232
|
The Kubernetes workspace is updated separately: `devzone workspace update` moves it to the latest stable release (or `--version X.Y.Z`), image, charts and Argo CD at the same tag. **The pod `devzone-workspace-0` is recreated**: the VS Code windows attached to the pod are disconnected. The image is checked on ghcr.io before any write, and nothing changes if it does not exist yet. Details in the [reference](manage/docs/reference.md#updating-the-workspace).
|
|
238
233
|
|
|
@@ -240,7 +235,7 @@ In the container, the `devzone` summary reports a more recent published version
|
|
|
240
235
|
|
|
241
236
|
## Options
|
|
242
237
|
|
|
243
|
-
**Mode at creation**: `--kubernetes` (workspace in the cluster, refused without a cluster)
|
|
238
|
+
**Mode at creation**: `--kubernetes` (workspace in the cluster, refused without a cluster). Without an option, the cluster must answer, otherwise nothing is created (see [A cluster at creation](#a-cluster-at-creation)).
|
|
244
239
|
|
|
245
240
|
**`ia` module**: enables Claude Code and opencode (pinned versions), with the repowarden guard that stops them before they modify `main` or `develop` or commit without `repowarden cc` (see [manage/docs/reference.md](manage/docs/reference.md#ai-assistants-guard)). To enable it: `devzone enable ia`. They are uninstalled when the module is disabled, but your logins stay in their volumes. The module also sets up a guard that stops the `docker` commands of agents: devzone is Kubernetes first, only pods are containers (`kubectl`, or a disposable pod, instead).
|
|
246
241
|
|
|
@@ -391,7 +386,7 @@ Spring Boot listens on `0.0.0.0` by default: do not set `server.address` to `127
|
|
|
391
386
|
✖ Kubernetes not reachable: cluster <contexte> unreachable (<serveur>). Nothing created.
|
|
392
387
|
```
|
|
393
388
|
|
|
394
|
-
|
|
389
|
+
`devzone workspace start` (so `make up` and `make shell`) checks the cluster first and stops without changing anything. The message gives the cause:
|
|
395
390
|
|
|
396
391
|
- **Docker Desktop stopped**: `✖ Docker Desktop is stopped: the Kubernetes cluster of this machine runs inside it. Start Docker Desktop, then: make shell`. Start Docker Desktop, then `make shell`. To have it start at each login: *Settings → General → Start Docker Desktop when you sign in*.
|
|
397
392
|
- **Docker answers, not the cluster**: `✖ Kubernetes cluster <contexte> unreachable (<serveur>): enable Kubernetes in Docker Desktop (Settings → Kubernetes) or check kubectl config get-contexts`. Enable Kubernetes in Docker Desktop (*Settings → Kubernetes → Enable Kubernetes*).
|
package/manage/devzone
CHANGED
|
@@ -48,20 +48,18 @@ show_help() {
|
|
|
48
48
|
cat <<EOT
|
|
49
49
|
devzone $(version) : environnement de développement conteneurisé
|
|
50
50
|
|
|
51
|
-
devzone <dossier> [--gitops github|none|<url>] [--kubernetes
|
|
51
|
+
devzone <dossier> [--gitops github|none|<url>] [--kubernetes]
|
|
52
52
|
crée un devzone dans <dossier> puis le lance ;
|
|
53
53
|
GitOps repository for Argo CD: github, or a URL, or none
|
|
54
54
|
--kubernetes: workspace in the cluster (default when it answers;
|
|
55
55
|
fails with nothing created without one)
|
|
56
|
-
--docker: deprecated Docker workstation, no cluster check
|
|
57
|
-
(without a cluster nothing is created, no silent Docker)
|
|
58
56
|
devzone update [--yes] [--sans-reconstruire]
|
|
59
57
|
dans un dossier devzone : passe à la version du paquet
|
|
60
58
|
(sauvegarde les fichiers remplacés, propose make rebuild)
|
|
61
59
|
devzone uninstall dans un dossier devzone : retire conteneur, image, volumes
|
|
62
60
|
(à lancer avant npm uninstall -g devzone)
|
|
63
61
|
devzone workspace start|stop|status|shell|update
|
|
64
|
-
devzone workspace vscode|copy-to|copy-from|clone
|
|
62
|
+
devzone workspace vscode|copy-to|copy-from|clone
|
|
65
63
|
poste Kubernetes : pilote le chart devzone-workspace
|
|
66
64
|
devzone workspace services enable|disable <service>|status
|
|
67
65
|
services (gitlab, postgres, argocd) du workspace Kubernetes
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
set -u
|
|
17
17
|
|
|
18
18
|
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
|
-
ROOT="$(cd "$ICI
|
|
19
|
+
ROOT="$(cd "$ICI/../../.." && pwd)"
|
|
20
20
|
CHARTS_DIR="${CHARTS_DIR:-$ROOT/charts}"
|
|
21
21
|
CHARTS_CODE_DIRS="${CHARTS_CODE_DIRS:-$ROOT/.devcontainer $ROOT/manage/scripts}"
|
|
22
22
|
# The workstation keeps its own values (per volume, not a shared service)
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
set -u
|
|
11
11
|
|
|
12
12
|
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
13
|
-
ROOT="$(cd "$ICI
|
|
13
|
+
ROOT="$(cd "$ICI/../../.." && pwd)"
|
|
14
14
|
|
|
15
15
|
# French words that must not appear in a name. Split fragments, so this file
|
|
16
16
|
# does not match its own rules (the check-english convention).
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
set -u
|
|
12
12
|
|
|
13
13
|
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
-
ROOT="$(cd "$ICI
|
|
14
|
+
ROOT="$(cd "$ICI/../../.." && pwd)"
|
|
15
15
|
|
|
16
16
|
# Byte matching only. The class is every byte outside printable ASCII, minus
|
|
17
17
|
# the tab (a tab after a name is not a fault). Built from a printf so this
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
# Pinned container versions: compares repowarden (versions.env) and AI
|
|
3
3
|
# assistants (IA_… lines, devzone) to the latest npm version, or applies an
|
|
4
4
|
# upgrade.
|
|
5
|
-
# bash manage/scripts/versions.sh
|
|
5
|
+
# bash manage/scripts/ci/versions.sh
|
|
6
6
|
# one "package old new" line per outdated package, nothing otherwise
|
|
7
|
-
# bash manage/scripts/versions.sh --installed
|
|
7
|
+
# bash manage/scripts/ci/versions.sh --installed
|
|
8
8
|
# one "package pinned installed" line per installed tool behind its pin
|
|
9
|
-
# bash manage/scripts/versions.sh --apply <package> <version>
|
|
9
|
+
# bash manage/scripts/ci/versions.sh --apply <package> <version>
|
|
10
10
|
# replaces that pinned version in its file, nothing else
|
|
11
|
-
# bash manage/scripts/versions.sh --existing-ticket <package> <author>
|
|
11
|
+
# bash manage/scripts/ci/versions.sh --existing-ticket <package> <author>
|
|
12
12
|
# "number<TAB>title" of the open ticket by <author>, nothing otherwise
|
|
13
13
|
# Compatible with bash 3.2 (macOS).
|
|
14
14
|
set -euo pipefail
|
|
15
15
|
|
|
16
|
-
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")
|
|
16
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
|
17
17
|
VERSIONS_ENV="$HERE/.devcontainer/versions.env"
|
|
18
18
|
DEVZONE="$HERE/.devcontainer/devzone"
|
|
19
19
|
|
|
@@ -153,17 +153,17 @@ case "${1:-}" in
|
|
|
153
153
|
--installed | --installees) compare_installed ;;
|
|
154
154
|
--apply | --appliquer)
|
|
155
155
|
[ "$#" -eq 3 ] ||
|
|
156
|
-
{ echo "usage: bash manage/scripts/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2; exit 2; }
|
|
156
|
+
{ echo "usage: bash manage/scripts/ci/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2; exit 2; }
|
|
157
157
|
apply "$2" "$3"
|
|
158
158
|
;;
|
|
159
159
|
--existing-ticket | --ticket-existant)
|
|
160
160
|
[ "$#" -eq 3 ] ||
|
|
161
|
-
{ echo "usage: bash manage/scripts/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2; exit 2; }
|
|
161
|
+
{ echo "usage: bash manage/scripts/ci/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2; exit 2; }
|
|
162
162
|
existing_ticket "$2" "$3"
|
|
163
163
|
;;
|
|
164
164
|
-h | --help) sed -n '2,17p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//' ;;
|
|
165
165
|
*)
|
|
166
|
-
echo "usage: bash manage/scripts/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2
|
|
166
|
+
echo "usage: bash manage/scripts/ci/versions.sh [--installed | --apply <package> <version> | --existing-ticket <package> <author>]" >&2
|
|
167
167
|
exit 2
|
|
168
168
|
;;
|
|
169
169
|
esac
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
# cluster
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
2
|
+
# Workspace mode at creation (#497): a new devzone is a Kubernetes workspace,
|
|
3
|
+
# so the cluster must answer. Without a cluster there is no fallback (#671):
|
|
4
|
+
# creation stops and lists the ways to get a cluster. The Docker workstation is
|
|
5
|
+
# retired (#735). Sourced by manage/devzone (creer): create_mode_choose runs
|
|
6
|
+
# before any file is copied (so --kubernetes without a cluster creates
|
|
7
|
+
# nothing), create_mode_write once the folder exists.
|
|
8
8
|
# Sourced only: no code at file level. Compatible with bash 3.2 (macOS).
|
|
9
9
|
# shellcheck disable=SC2034 # CREATE_MODE is read by manage/devzone (creer)
|
|
10
10
|
# shellcheck source=manage/scripts/kube-ready.sh
|
|
@@ -34,21 +34,14 @@ create_mode_no_cluster() {
|
|
|
34
34
|
kubectl config use-context <context>
|
|
35
35
|
- a local cluster: Docker Desktop (Settings > Kubernetes > Enable Kubernetes), or minikube
|
|
36
36
|
minikube start -p devzone
|
|
37
|
-
--docker still creates the Docker workstation, deprecated: it will be removed
|
|
38
37
|
EOF
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
# Chooses the mode from the option (kubernetes
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
# workstation was not asked with --docker.
|
|
40
|
+
# Chooses the mode from the option (kubernetes or empty) and sets CREATE_MODE
|
|
41
|
+
# to kubernetes, with one line of notice. Returns 1, nothing set on disk, when
|
|
42
|
+
# the cluster does not answer.
|
|
45
43
|
create_mode_choose() {
|
|
46
44
|
local option="$1" reason
|
|
47
|
-
if [ "$option" = docker ]; then
|
|
48
|
-
CREATE_MODE=docker
|
|
49
|
-
echo "⚠ Docker workstation (--docker) is deprecated and will be removed: devzone workspace migrate moves it to the cluster"
|
|
50
|
-
return 0
|
|
51
|
-
fi
|
|
52
45
|
if reason="$(kube_ready_reason)"; then
|
|
53
46
|
CREATE_MODE=kubernetes
|
|
54
47
|
echo "✔ Kubernetes ready ($(kube_context)): workspace in the cluster"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Creation of a devzone (devzone <folder>): asks for the GitOps repository,
|
|
3
3
|
# copies the package, writes .argocd.conf and the manifest, then starts the
|
|
4
|
-
# workspace
|
|
4
|
+
# workspace in the cluster. Sourced by manage/devzone,
|
|
5
5
|
# which defines PAQUET, PACKAGE_ITEMS and version(); devzone-manifest.sh must
|
|
6
6
|
# be sourced first.
|
|
7
7
|
# shellcheck disable=SC2154 # PAQUET, PACKAGE_ITEMS: set by manage/devzone
|
|
@@ -32,14 +32,8 @@ create_workstation() {
|
|
|
32
32
|
case "$arg" in
|
|
33
33
|
--gitops) expect=gitops ;;
|
|
34
34
|
--gitops=*) gitops="${arg#--gitops=}" ;;
|
|
35
|
-
--kubernetes
|
|
36
|
-
|
|
37
|
-
echo "✖ --kubernetes and --docker: choose one" >&2
|
|
38
|
-
exit 1
|
|
39
|
-
fi
|
|
40
|
-
option="${arg#--}"
|
|
41
|
-
;;
|
|
42
|
-
*) echo "✖ option inconnue : $arg (devzone <dossier> [--gitops github|none|<url>] [--kubernetes|--docker])" >&2; exit 1 ;;
|
|
35
|
+
--kubernetes) option=kubernetes ;;
|
|
36
|
+
*) echo "✖ option inconnue : $arg (devzone <dossier> [--gitops github|none|<url>] [--kubernetes])" >&2; exit 1 ;;
|
|
43
37
|
esac
|
|
44
38
|
done
|
|
45
39
|
if [ -n "$expect" ]; then
|
|
@@ -111,28 +105,6 @@ create_workstation() {
|
|
|
111
105
|
target="$(cd "$target" && pwd)"
|
|
112
106
|
write_manifest "$target"
|
|
113
107
|
echo "✔ devzone $(version) créé dans $target"
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
if [ "$CREATE_MODE" = kubernetes ]; then
|
|
117
|
-
create_mode_start "$target" "$PAQUET/manage/workspace.sh"
|
|
118
|
-
return
|
|
119
|
-
fi
|
|
120
|
-
if [ -n "${DEVZONE_NO_START:-}" ]; then
|
|
121
|
-
echo "Pour le lancer : cd $target && make up"
|
|
122
|
-
return 0
|
|
123
|
-
fi
|
|
124
|
-
# Docker first: the folder stays ready, to start once Docker is running
|
|
125
|
-
# shellcheck source=SCRIPTDIR/docker.sh
|
|
126
|
-
. "$PAQUET/manage/scripts/docker.sh"
|
|
127
|
-
if ! docker_ready "cd $target && make shell"; then
|
|
128
|
-
echo " Le dossier est prêt : rien à refaire, sauf ce lancement." >&2
|
|
129
|
-
exit 1
|
|
130
|
-
fi
|
|
131
|
-
echo "▶ Lancement (quelques minutes la première fois)…"
|
|
132
|
-
if command -v make >/dev/null 2>&1; then
|
|
133
|
-
make -C "$target" up
|
|
134
|
-
else
|
|
135
|
-
bash "$target/manage/scripts/launch.sh" up "$target"
|
|
136
|
-
fi
|
|
137
|
-
echo "Ensuite : cd $target && make shell (ou ouvre le dossier dans VS Code : Reopen in Container)."
|
|
108
|
+
# The workspace goes to the cluster (kube check done by create_mode_choose)
|
|
109
|
+
create_mode_start "$target" "$PAQUET/manage/workspace.sh"
|
|
138
110
|
}
|
package/manage/scripts/poste.sh
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Why: make up|shell|stop|rebuild always
|
|
3
|
-
#
|
|
4
|
-
#
|
|
2
|
+
# Why: make up|shell|stop|rebuild always drove the Docker container, even
|
|
3
|
+
# once a folder was in Kubernetes mode (#472). The Docker workstation is retired
|
|
4
|
+
# (#735), but a folder still marked workspace=kubernetes in .devzone.modules
|
|
5
|
+
# must keep working. This script reads that mode: in Kubernetes it hands
|
|
5
6
|
# off to manage/workspace.sh (repo clone) or npx devzone@<version> workspace
|
|
6
7
|
# (folder created by npx devzone); in Docker it returns 3 and does nothing, so
|
|
7
8
|
# the Makefile keeps its original recipe. The advice target shows, after an
|
|
@@ -68,12 +69,10 @@ if [ -z "$folder" ]; then
|
|
|
68
69
|
exit 2
|
|
69
70
|
fi
|
|
70
71
|
|
|
71
|
-
# Advice after update: always exit 0,
|
|
72
|
+
# Advice after update: always exit 0, silent for a Docker folder (#735).
|
|
72
73
|
if [ "$target" = "advice" ] || [ "$target" = "conseil" ]; then
|
|
73
74
|
if [ "$(workspace_mode "$folder")" = kubernetes ]; then
|
|
74
75
|
echo "Kubernetes workspace: the new image is used on the next devzone workspace start (or make up)."
|
|
75
|
-
elif kube_ready_reason >/dev/null; then
|
|
76
|
-
echo "Kubernetes reachable: devzone workspace migrate moves this workstation to the cluster (nothing is deleted, rollback: devzone workspace revert)."
|
|
77
76
|
fi
|
|
78
77
|
exit 0
|
|
79
78
|
fi
|
|
@@ -86,7 +85,7 @@ case "$target" in
|
|
|
86
85
|
shell) workspace_cmd "$folder" start && workspace_cmd "$folder" shell ;;
|
|
87
86
|
stop) workspace_cmd "$folder" stop ;;
|
|
88
87
|
rebuild)
|
|
89
|
-
echo "✖ make rebuild: this workstation is in Kubernetes workspace mode (workspace=kubernetes in .devzone.modules), nothing to rebuild on the machine
|
|
88
|
+
echo "✖ make rebuild: this workstation is in Kubernetes workspace mode (workspace=kubernetes in .devzone.modules), nothing to rebuild on the machine" >&2
|
|
90
89
|
exit 1
|
|
91
90
|
;;
|
|
92
91
|
esac
|
package/manage/workspace.sh
CHANGED
|
@@ -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|
|
|
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|
|
|
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,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.backup/<date>/ before being replaced.
|
|
6
|
-
|
|
7
|
-
# Backup folder for this run (relative to devzone), same convention as
|
|
8
|
-
# devzone update: .devzone.backup/<YYYYMMDD-HHMMSS>, -n suffix if taken.
|
|
9
|
-
backup_folder() {
|
|
10
|
-
local base folder n=1
|
|
11
|
-
base=".devzone.backup/$(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,237 +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_COPY:-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) 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.packages copied to the pod.
|
|
167
|
-
step_state() {
|
|
168
|
-
local f
|
|
169
|
-
# Former French names renamed first (#733): the workstation folder may be old
|
|
170
|
-
DEVZONE_ROOT="$PWD" bash "$ROOT/.devcontainer/rename-legacy-files.sh" || true
|
|
171
|
-
echo "▶ [4/5] state: .devzone.modules and .devzone.packages to $PROJECTS_DIR"
|
|
172
|
-
for f in .devzone.modules .devzone.packages; do
|
|
173
|
-
if [ ! -f "$f" ]; then
|
|
174
|
-
echo " – $f: missing on workstation, skipped"
|
|
175
|
-
continue
|
|
176
|
-
fi
|
|
177
|
-
if ! kc cp "$PWD/$f" "$POD:$PROJECTS_DIR/$f" -c workspace \
|
|
178
|
-
|| ! kc exec "$POD" -c workspace -- test -f "$PROJECTS_DIR/$f"; then
|
|
179
|
-
fail "failed to copy $f or missing from pod"
|
|
180
|
-
return 1
|
|
181
|
-
fi
|
|
182
|
-
echo " ✔ $f"
|
|
183
|
-
done
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
# Writes workspace=$1 in workstation .devzone.modules (line replaced, rest kept).
|
|
187
|
-
record_workspace() {
|
|
188
|
-
local f=".devzone.modules" tmp
|
|
189
|
-
tmp="$f.tmp.$$"
|
|
190
|
-
{
|
|
191
|
-
if [ -f "$f" ]; then grep -v '^workspace=' "$f" || true; fi
|
|
192
|
-
echo "workspace=$1"
|
|
193
|
-
} >"$tmp" && mv "$tmp" "$f"
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
# Step 5: switch, workspace=kubernetes recorded on workstation; nothing is deleted.
|
|
197
|
-
# The Docker workstation containers and port relays are stopped, not removed (#517).
|
|
198
|
-
step_switch() {
|
|
199
|
-
echo "▶ [5/5] switch: workspace=kubernetes in .devzone.modules"
|
|
200
|
-
record_workspace kubernetes || { fail "cannot write .devzone.modules"; return 1; }
|
|
201
|
-
docker_workstation_stop "$PWD"
|
|
202
|
-
echo " ✔ done; Docker workstation and its volumes are intact (rollback: devzone workspace revert)"
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
# devzone workspace migrate [--yes]: the five steps, stop at first error.
|
|
206
|
-
migrate_workspace() {
|
|
207
|
-
local yes
|
|
208
|
-
yes="$(read_flag --yes "migrate [--yes]" "$@")" || return 1
|
|
209
|
-
confirm "Migrate this Docker workstation to the Kubernetes workspace (copy, nothing is deleted)?" "$yes" || return 1
|
|
210
|
-
step_checks || return 1
|
|
211
|
-
step_projects || return 1
|
|
212
|
-
step_identities || return 1
|
|
213
|
-
step_state || return 1
|
|
214
|
-
step_switch || return 1
|
|
215
|
-
echo "✔ migration complete"
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
# devzone workspace clean-docker [--yes]: removes devzone-* Docker volumes, after confirmation.
|
|
219
|
-
clean_docker() {
|
|
220
|
-
local yes x v present=()
|
|
221
|
-
yes="$(read_flag --yes "clean-docker [--yes]" "$@")" || return 1
|
|
222
|
-
for x in "${DOCKER_VOLUMES[@]}"; do
|
|
223
|
-
v="$(docker_volume "$x")"
|
|
224
|
-
! docker volume inspect "$v" >/dev/null 2>&1 || present+=("$v")
|
|
225
|
-
done
|
|
226
|
-
if [ "${#present[@]}" -eq 0 ]; then
|
|
227
|
-
echo "No devzone Docker volume to remove."
|
|
228
|
-
return 0
|
|
229
|
-
fi
|
|
230
|
-
echo "Docker volumes to remove (irreversible, \"revert\" will not find them again):"
|
|
231
|
-
printf ' %s\n' "${present[@]}"
|
|
232
|
-
confirm "Remove these ${#present[@]} volume(s)?" "$yes" || return 1
|
|
233
|
-
for v in "${present[@]}"; do
|
|
234
|
-
docker volume rm "$v" >/dev/null || { fail "failed to remove $v"; return 1; }
|
|
235
|
-
echo " ✔ $v removed"
|
|
236
|
-
done
|
|
237
|
-
}
|
|
File without changes
|