devzone 7.5.5 → 7.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,234 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Full devzone uninstall, run on the host:
3
- # make desinstaller everything, after confirmation
4
- # make desinstaller KEEP=logins everything except logins (gh, git,
5
- # Claude Code, opencode, modules)
6
- # Removes: container, image, kind clusters of the instance and containers
7
- # labeled devzone.instance on the host Docker (#291), former internal Docker
8
- # volume (installs before #291), devzone-* volumes, metrics-server installed by
9
- # devzone on host local clusters, namespace of devzone services (postgres
10
- # module) on the chosen host cluster. Never touches: workspace/ (your projects),
11
- # the base image, a metrics-server not installed by devzone.
12
- # Without a terminal: CONFIRM=yes.
13
- set -euo pipefail
14
-
15
- # devzone folder: two levels above the script (manage/scripts/), so the command
16
- # works when run from any folder
17
- HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
18
- STATE="$HERE/.devzone.state"
19
- KEEP="${KEEP:-${GARDER:-}}"
20
- LOGINS=(gh git claude opencode-config opencode-data config)
21
- LOCAL_CTX='^(kind-.*|docker-desktop|rancher-desktop|orbstack|minikube)$'
22
-
23
- case "$KEEP" in "" | logins | connexions) ;; *)
24
- echo "KEEP: unknown value: $KEEP (only value: logins)" >&2
25
- exit 1
26
- ;;
27
- esac
28
-
29
- # Host engine first: without it every call would show its raw error. The check
30
- # is the Go program's (#884), found through DEVZONE_HOST_BIN, exported by manage/devzone
31
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" host-check "${DEVZONE_COMMAND:-make desinstaller}" || exit 1
32
-
33
- # .argocd.conf of the devzone folder: the GitOps repository is never removed
34
- # with the devzone, only its designation can be changed later
35
- # shellcheck disable=SC2034 # read by conf.sh
36
- ARGOCD_CONF="$HERE/.argocd.conf"
37
- # shellcheck source=SCRIPTDIR/../.devcontainer/argocd/conf.sh
38
- # shellcheck disable=SC1091
39
- . "$HERE/.devcontainer/argocd/conf.sh"
40
-
41
- # Instance name: an instance name may contain a dash (my-devzone),
42
- # so DEVZONE_VOLUMES is never split
43
- DEVZONE_INSTANCE="${DEVZONE_VOLUMES:-devzone}"
44
- INSTANCE_SUFFIX=""
45
- if [ "$DEVZONE_INSTANCE" != "devzone" ]; then
46
- INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
47
- fi
48
-
49
- # Run INSIDE the container, docker talks to host Docker (#291): volumes, images
50
- # and containers seen are those of the workstation, and the host instance name
51
- # (DEVZONE_VOLUMES) is unknown here. Touching Docker from the container could
52
- # remove another instance's resources (or the default instance): only the
53
- # Kubernetes part is handled.
54
- # DEVZONE_IN_CONTAINER=yes|no forces the mode (tests, which run inside a container)
55
- case "${DEVZONE_IN_CONTAINER:-}" in
56
- yes) INSIDE_CONTAINER=true ;;
57
- no) INSIDE_CONTAINER=false ;;
58
- *) INSIDE_CONTAINER=false; [ ! -f /.dockerenv ] || INSIDE_CONTAINER=true ;;
59
- esac
60
-
61
- # --- Inventory ---------------------------------------------------------------
62
- echo "▶ Inventory (folder $HERE)"
63
- containers=() images=() dind=() volumes=() kept=()
64
- kind_containers="" labeled_containers=""
65
- if [ "$INSIDE_CONTAINER" = true ]; then
66
- echo "ℹ Inside the container: only metrics-server and devzone services are handled."
67
- echo " Container, image, volumes and kind clusters: make desinstaller on your machine."
68
- else
69
- # Label set with the path as opened (VS Code, make): logical or physical path
70
- # depending on symlinks; both are searched
71
- ids="$(for path in "$HERE" "$(cd "$HERE" && pwd -P)"; do docker ps -aq --filter "label=devcontainer.local_folder=$path" 2>/dev/null || true; done | sort -u)"
72
- for id in ${ids}; do
73
- containers+=("$id")
74
- images+=("$(docker inspect "$id" --format '{{.Config.Image}}')")
75
- v="$(docker inspect "$id" --format '{{range .Mounts}}{{if eq .Destination "/var/lib/docker"}}{{.Name}}{{end}}{{end}}')"
76
- [ -z "$v" ] || dind+=("$v")
77
- done
78
- # Container already removed: image and internal Docker noted then
79
- if [ "${#containers[@]}" -eq 0 ] && [ -f "$STATE" ]; then
80
- # Read only, never executed
81
- IMAGE="$(sed -n 's/^IMAGE=//p' "$STATE")"
82
- DIND="$(sed -n 's/^DIND=//p' "$STATE")"
83
- [ -z "${IMAGE:-}" ] || ! docker image inspect "$IMAGE" >/dev/null 2>&1 || images+=("$IMAGE")
84
- [ -z "${DIND:-}" ] || ! docker volume inspect "$DIND" >/dev/null 2>&1 || dind+=("$DIND")
85
- fi
86
-
87
- # Containers of the instance kind clusters on host Docker: a kind cluster is
88
- # nothing more than containers carrying this label
89
- kind_containers_devzone="$(docker ps -aq --filter "label=io.x-k8s.kind.cluster=devzone${INSTANCE_SUFFIX}" 2>/dev/null | sort -u)"
90
- kind_containers_gitlab="$(docker ps -aq --filter "label=io.x-k8s.kind.cluster=gitlab${INSTANCE_SUFFIX}" 2>/dev/null | sort -u)"
91
- kind_containers="${kind_containers_devzone} ${kind_containers_gitlab}"
92
- kind_containers="${kind_containers# }"
93
- kind_containers="${kind_containers% }"
94
-
95
- # Containers carrying label devzone.instance=<instance>
96
- labeled_containers="$(docker ps -aq --filter "label=devzone.instance=$DEVZONE_INSTANCE" 2>/dev/null | sort -u)"
97
-
98
- # Volumes: exact names from devcontainer.json (including DEVZONE_VOLUMES prefix)
99
- config="$(npx -y @devcontainers/cli read-configuration --workspace-folder "$HERE" 2>/dev/null)" || {
100
- echo "✖ cannot read .devcontainer/devcontainer.json (npx @devcontainers/cli)" >&2
101
- exit 1
102
- }
103
- # shellcheck disable=SC2016 # ${m.source}: JavaScript template, not shell
104
- for name in $(node -e '
105
- const c = JSON.parse(require("fs").readFileSync(0, "utf8")).configuration;
106
- for (const m of c.mounts || []) {
107
- const s = typeof m === "string" ? m : `source=${m.source},type=${m.type}`;
108
- if (/type=volume/.test(s)) { const r = /source=([^,]+)/.exec(s); if (r) console.log(r[1]); }
109
- }' <<<"$config"); do
110
- docker volume inspect "$name" >/dev/null 2>&1 || continue
111
- keep=false
112
- if [ "$KEEP" = logins ] || [ "$KEEP" = connexions ]; then
113
- for c in "${LOGINS[@]}"; do [[ "$name" == *-"$c" ]] && keep=true; done
114
- fi
115
- if [ "$keep" = true ]; then kept+=("$name"); else volumes+=("$name"); fi
116
- done
117
- fi
118
-
119
- # metrics-server installed by devzone (label devzone=installed), on reachable
120
- # host local clusters; never another one
121
- metrics=() foreign=()
122
- if command -v kubectl >/dev/null 2>&1; then
123
- for ctx in $(kubectl config get-contexts -o name 2>/dev/null | grep -E "$LOCAL_CTX" || true); do
124
- k=(kubectl --context "$ctx" --request-timeout=5s)
125
- "${k[@]}" get --raw /readyz >/dev/null 2>&1 || continue
126
- mark="$("${k[@]}" -n kube-system get deployment metrics-server -o jsonpath='{.metadata.labels.devzone}' 2>/dev/null)" || continue
127
- if [ "$mark" = installe ] || [ "$mark" = installed ]; then metrics+=("$ctx"); else foreign+=("$ctx"); fi
128
- done
129
- fi
130
-
131
- # devzone services (postgres module, #280) on a host cluster: the namespace it
132
- # created (label managed-by=devzone). On the dedicated kind, they go with that
133
- # cluster (removed below). Read only, never executed.
134
- services=()
135
- CLUSTER="$(sed -n 's/^cluster=//p' "$HERE/.devzone.modules" 2>/dev/null | tail -1 || true)"
136
- if [ -n "$CLUSTER" ] && [[ "$CLUSTER" != kind-* ]] && command -v kubectl >/dev/null 2>&1; then
137
- for ns in $(kubectl --context "$CLUSTER" --request-timeout=5s get namespaces -l app.kubernetes.io/managed-by=devzone -o name 2>/dev/null || true); do
138
- services+=("${ns#namespace/}")
139
- done
140
- fi
141
-
142
- # --- Confirmation ------------------------------------------------------------
143
- show_list() { if [ "$#" -eq 0 ]; then echo " (none)"; else printf ' %s\n' "$@"; fi; }
144
- echo "To remove:"
145
- echo " container(s):"; show_list ${containers[@]+"${containers[@]}"}
146
- echo " image(s):"; show_list ${images[@]+"${images[@]}"}
147
- echo " former internal Docker (installs before #291):"; show_list ${dind[@]+"${dind[@]}"}
148
- echo " volumes:"; show_list ${volumes[@]+"${volumes[@]}"}
149
- echo " metrics-server installed by devzone on:"; show_list ${metrics[@]+"${metrics[@]}"}
150
- echo " devzone services (including postgres databases) on ${CLUSTER:-no cluster}:"; show_list ${services[@]+"${services[@]}"}
151
- echo " kind clusters of the instance on host Docker:"
152
- # shellcheck disable=SC2086
153
- show_list ${kind_containers}
154
- echo " containers labeled devzone.instance=$DEVZONE_INSTANCE:"
155
- # shellcheck disable=SC2086
156
- show_list ${labeled_containers}
157
- [ "${#kept[@]}" -eq 0 ] || { echo "Kept (KEEP=logins):"; printf ' %s\n' "${kept[@]}"; }
158
- if [ "$INSIDE_CONTAINER" = false ] && [ "${#containers[@]}" -eq 0 ] && [ ! -f "$STATE" ] && [ "${#images[@]}" -eq 0 ]; then
159
- echo "ℹ No container and no image trace: if an older removal left them,"
160
- echo " find them with: docker images 'vsc-$(basename "$HERE")-*' ; docker volume ls -q -f name=dind-var-lib-docker"
161
- fi
162
-
163
- nb_ck=0; for _ in ${kind_containers}; do nb_ck=$((nb_ck + 1)); done
164
- nb_ce=0; for _ in ${labeled_containers}; do nb_ce=$((nb_ce + 1)); done
165
- total=$((${#containers[@]} + ${#images[@]} + ${#dind[@]} + ${#volumes[@]} + ${#metrics[@]} + ${#services[@]} + nb_ck + nb_ce))
166
- if [ "$total" -eq 0 ]; then
167
- echo "✔ Nothing to remove."
168
- else
169
- CONFIRM_VALUE="${CONFIRM:-${CONFIRMER:-}}"
170
- if [ "$CONFIRM_VALUE" != yes ]; then
171
- if [ ! -t 0 ]; then
172
- echo "✖ Cannot confirm without a terminal: CONFIRM=yes make desinstaller" >&2
173
- exit 1
174
- fi
175
- read -r -p "Permanently remove? Type yes: " answer
176
- case "$answer" in
177
- yes) ;;
178
- *) echo "Canceled: nothing was removed."; exit 0 ;;
179
- esac
180
- fi
181
-
182
- # --- Removal -------------------------------------------------------------
183
- for id in ${containers[@]+"${containers[@]}"}; do docker rm -f "$id" >/dev/null && echo "✔ container removed: $id"; done
184
- for i in ${images[@]+"${images[@]}"}; do docker rmi "$i" >/dev/null && echo "✔ image removed: $i"; done
185
- for v in ${dind[@]+"${dind[@]}"} ${volumes[@]+"${volumes[@]}"}; do docker volume rm "$v" >/dev/null && echo "✔ volume removed: $v"; done
186
- if [ "${#metrics[@]}" -gt 0 ]; then
187
- version="$(sed -n 's/^METRICS_SERVER_VERSION=//p' "$HERE/.devcontainer/versions.env" | head -1)"
188
- manifest="https://github.com/kubernetes-sigs/metrics-server/releases/download/${version}/components.yaml"
189
- for ctx in "${metrics[@]}"; do
190
- kubectl --context "$ctx" delete -f "$manifest" --ignore-not-found >/dev/null &&
191
- echo "✔ metrics-server removed: $ctx"
192
- done
193
- fi
194
- for ns in ${services[@]+"${services[@]}"}; do
195
- kubectl --context "$CLUSTER" delete namespace "$ns" --wait=true >/dev/null &&
196
- echo "✔ namespace removed: $ns ($CLUSTER)"
197
- done
198
- for id in ${kind_containers}; do
199
- docker rm -f "$id" >/dev/null 2>&1 && echo "✔ kind cluster container removed: $id"
200
- done
201
- # kind Docker network: removed only if no container uses it anymore
202
- kind_network=""
203
- [ "$INSIDE_CONTAINER" = true ] || kind_network="$(docker network inspect kind 2>/dev/null || true)"
204
- if [ -n "$kind_network" ] && printf '%s\n' "$kind_network" | grep -q '"Containers": {}'; then
205
- if docker network rm kind >/dev/null 2>&1; then
206
- echo "✔ kind Docker network removed"
207
- fi
208
- fi
209
- for id in ${labeled_containers}; do
210
- docker rm -f "$id" >/dev/null 2>&1 && echo "✔ labeled container removed: $id"
211
- done
212
- fi
213
- rm -f "$HERE/.devzone.log" "$STATE"
214
-
215
- # Instance module state (one "module=on|off" line): removed, modules return to
216
- # their default values on next start
217
- rm -f "$HERE/.devzone.modules"
218
-
219
- # --- What remains ------------------------------------------------------------
220
- echo
221
- echo "Not touched (remove yourself if you want):"
222
- echo " workspace/: your projects"
223
- for ctx in ${foreign[@]+"${foreign[@]}"}; do
224
- echo " metrics-server on $ctx: not installed by devzone (kubectl --context $ctx -n kube-system delete deployment metrics-server)"
225
- done
226
- command -v kubectl >/dev/null 2>&1 || echo " metrics-server: kubectl not on host, host clusters not checked"
227
- echo " base image mcr.microsoft.com/devcontainers/base (shared): docker rmi mcr.microsoft.com/devcontainers/base:ubuntu-24.04"
228
- echo " devcontainer CLI npx cache: ~/.npm/_npx"
229
- echo " \"GitHub CLI\" authorization on your account: GitHub → Settings → Applications"
230
- ARGOCD_REPO="$(conf_get argocd repo)"
231
- if [ -n "$ARGOCD_REPO" ] && [ "$ARGOCD_REPO" != none ]; then
232
- echo " GitOps repository not removed: $ARGOCD_REPO (delete it yourself if you want to)"
233
- fi
234
- echo " this folder: $HERE"