devzone 7.4.0 → 7.5.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 (48) hide show
  1. package/.devcontainer/devzone +18 -63
  2. package/.devcontainer/devzone-modules.sh +8 -3
  3. package/.devcontainer/devzone-repair.sh +7 -7
  4. package/.devcontainer/devzone-services.sh +21 -21
  5. package/.devcontainer/devzone-status.sh +12 -9
  6. package/.devcontainer/help.sh +5 -1
  7. package/.devcontainer/versions.env +8 -0
  8. package/.devcontainer/workspace-init.sh +8 -9
  9. package/.gitattributes +8 -0
  10. package/README.md +2 -2
  11. package/bin/SHA256SUMS +6 -6
  12. package/bin/devzone-darwin-amd64 +0 -0
  13. package/bin/devzone-darwin-arm64 +0 -0
  14. package/bin/devzone-linux-amd64 +0 -0
  15. package/bin/devzone-linux-arm64 +0 -0
  16. package/bin/devzone-windows-amd64.exe +0 -0
  17. package/bin/devzone-windows-arm64.exe +0 -0
  18. package/charts/devzone-mysql/values.yaml +1 -1
  19. package/charts/devzone-postgres/values.yaml +1 -1
  20. package/manage/devzone +6 -3
  21. package/manage/scripts/create-mode.sh +3 -3
  22. package/manage/scripts/uninstall.sh +4 -5
  23. package/manage/scripts/workspace/argocd-workspace.sh +2 -2
  24. package/manage/workspace.sh +1 -1
  25. package/package.json +1 -1
  26. package/.devcontainer/ai/host-check.sh +0 -173
  27. package/.devcontainer/ai/host-models.sh +0 -200
  28. package/.devcontainer/catalog/app.sh +0 -202
  29. package/.devcontainer/catalog/catalog-watcher.sh +0 -127
  30. package/.devcontainer/catalog.sh +0 -208
  31. package/.devcontainer/chart-direct.sh +0 -49
  32. package/.devcontainer/cluster.sh +0 -388
  33. package/.devcontainer/clusters.sh +0 -86
  34. package/.devcontainer/devzone-ai-guard.sh +0 -98
  35. package/.devcontainer/devzone-ai.sh +0 -201
  36. package/.devcontainer/devzone-cluster.sh +0 -209
  37. package/.devcontainer/devzone-skill.sh +0 -97
  38. package/.devcontainer/isolation.sh +0 -65
  39. package/.devcontainer/kube-account.sh +0 -107
  40. package/.devcontainer/kube-prompt.sh +0 -42
  41. package/.devcontainer/memory.sh +0 -113
  42. package/.devcontainer/metrics-server.sh +0 -100
  43. package/.devcontainer/packages.sh +0 -228
  44. package/.devcontainer/password.sh +0 -148
  45. package/.devcontainer/ports-json.sh +0 -31
  46. package/.devcontainer/ports.sh +0 -132
  47. package/manage/scripts/create-cluster.sh +0 -107
  48. package/manage/scripts/docker.sh +0 -43
@@ -1,201 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # devzone, ai module: opencode config, assistants install, apply.
4
- # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
- # functions only, shared variables are defined in devzone.
6
-
7
- # Marker of the default configuration: first line of opencode.jsonc. The former
8
- # wording (French, before #722) is still recognised. Byte escapes keep the accent
9
- # out of the source (English code check).
10
- OPENCODE_MARKER='// devzone : default opencode configuration'
11
-
12
- # True if the file carries the default-configuration marker
13
- opencode_marked() { grep -qF -e "$OPENCODE_MARKER" "$1"; }
14
-
15
- # Default opencode configuration (versioned model): written at first use,
16
- # updated while it keeps the devzone marker, customised otherwise. The marker
17
- # text is written in opencode.jsonc: it is kept as is.
18
- opencode_config() {
19
- local model="$ICI/opencode.jsonc" target
20
- if [ -f "$HOME/.config/opencode/opencode.jsonc" ]; then
21
- target="$HOME/.config/opencode/opencode.jsonc"
22
- elif [ -f "$HOME/.config/opencode/opencode.json" ]; then
23
- target="$HOME/.config/opencode/opencode.json"
24
- else
25
- target="$HOME/.config/opencode/opencode.jsonc"
26
- fi
27
- mkdir -p "$(dirname "$target")"
28
- if [ ! -f "$target" ]; then
29
- cp "$model" "$target"
30
- echo "opencode : default configuration written"
31
- elif opencode_marked "$target"; then
32
- if ! cmp -s "$model" "$target"; then
33
- cp "$model" "$target"
34
- echo "opencode : default configuration updated"
35
- fi
36
- elif only_schema_key "$target"; then
37
- cp "$model" "$target"
38
- echo "opencode : default configuration updated"
39
- else
40
- echo "opencode : custom configuration, kept"
41
- fi
42
- }
43
-
44
- # Removes the opencode configuration written by devzone if it still carries its
45
- # marker and was not changed; a custom configuration (no marker, or changed) is
46
- # kept. Symmetrical with opencode_config.
47
- remove_opencode_config() {
48
- local model target
49
- model="$ICI/opencode.jsonc"
50
- if [ -f "$HOME/.config/opencode/opencode.jsonc" ]; then
51
- target="$HOME/.config/opencode/opencode.jsonc"
52
- elif [ -f "$HOME/.config/opencode/opencode.json" ]; then
53
- target="$HOME/.config/opencode/opencode.json"
54
- else
55
- return 0
56
- fi
57
- if opencode_marked "$target" && cmp -s "$model" "$target"; then
58
- rm -f "$target"
59
- echo "opencode : default configuration removed"
60
- else
61
- echo "opencode : custom configuration, kept"
62
- fi
63
- }
64
-
65
- # Log of the last npm run (its path is to give on failure), or its folder;
66
- # timestamped names: the last one in glob order is the most recent
67
- last_npm_log() {
68
- local log="" f
69
- for f in "$HOME"/.npm/_logs/*-debug-0.log; do
70
- if [ -f "$f" ]; then log="$f"; fi
71
- done
72
- echo "${log:-$HOME/.npm/_logs}"
73
- }
74
-
75
- # Installs each pinned AI assistant with its own npm command (3 tries each),
76
- # then checks its binary: npm silently drops a platform binary it failed to
77
- # download (#194), and one assistant failing must not block the other.
78
- install_ai() {
79
- local package binary attempt
80
- IA_FAILED=()
81
- for package in "${IA_PAQUETS[@]}"; do
82
- case "$package" in
83
- opencode-ai@*) binary=opencode ;;
84
- *) binary=claude ;;
85
- esac
86
- for attempt in 1 2 3; do
87
- if with_progress npm install -g --no-fund --no-audit --loglevel=error "$package" >/dev/null &&
88
- "$binary" --version >/dev/null 2>&1; then
89
- break
90
- fi
91
- if [ "$attempt" -lt 3 ]; then
92
- echo "devzone : installation of ${package%@*} incomplete, retrying ($((attempt + 1))/3)…" >&2
93
- else
94
- IA_FAILED+=("$package")
95
- fi
96
- done
97
- done
98
- [ "${#IA_FAILED[@]}" -eq 0 ]
99
- }
100
-
101
- apply_ai() {
102
- local log tmp detected
103
- if [ "$1" = on ]; then
104
- echo "devzone : installing Claude Code and opencode (a few minutes)…"
105
- if ! install_ai; then
106
- log="$(last_npm_log)"
107
- echo "npm log: $log" >"$(failure_marker_file ai)"
108
- echo "devzone : installation of ${IA_FAILED[*]} failed (npm install -g, 3 tries); npm log: $log; retry: devzone apply" >&2
109
- return 1
110
- fi
111
- rm -f "$(failure_marker_file ai)"
112
- echo "devzone : Claude Code and opencode installed"
113
- # repowarden guard (Claude Code PreToolUse hook, opencode plugin): the
114
- # agent is stopped before changing main/develop, committing without
115
- # repowarden cc, or bypassing the hooks. Global, in the ~/.claude and
116
- # ~/.config/opencode volumes: kept across rebuilds; rerun, nothing changes
117
- if command -v repowarden >/dev/null 2>&1 && repowarden agents init --global >/dev/null 2>&1; then
118
- echo "devzone : repowarden guard active for Claude Code and opencode"
119
- else
120
- echo "devzone : repowarden guard not connected (repowarden 4.10 or later required): repowarden agents init --global" >&2
121
- fi
122
- install_docker_guard
123
- opencode_config
124
- # Remove the provider of the removed llm module from old configs (#669).
125
- if [ -f "$HOME/.config/opencode/config.json" ] && command -v jq >/dev/null 2>&1; then
126
- tmp="$(mktemp)"
127
- if jq '
128
- if .provider then del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end
129
- ' "$HOME/.config/opencode/config.json" >"$tmp" 2>/dev/null; then
130
- if [ "$(cat "$tmp")" = "{}" ] || [ "$(jq -c 'del(."$schema") | length' "$tmp" 2>/dev/null)" = 0 ]; then
131
- rm -f "$tmp" "$HOME/.config/opencode/config.json"
132
- else
133
- mv "$tmp" "$HOME/.config/opencode/config.json"
134
- fi
135
- else
136
- rm -f "$tmp"
137
- fi
138
- fi
139
- # opencode provider of the host models (Ollama), live detection:
140
- # silent and without effect if Ollama does not answer.
141
- set_provider || true
142
- # Reports the state of the detection (success in both cases).
143
- detected="$(modeles 2>/dev/null || true)"
144
- if [ -n "$detected" ]; then
145
- printf "devzone : %s model(s) of the host (Ollama) connected\n" "$(printf '%s\n' "$detected" | grep -c .)"
146
- else
147
- printf "devzone : no Ollama model detected on %s (host models not connected)\n" "$URL"
148
- fi
149
- # devzone skill: installed if missing, updated if unchanged, kept if customised.
150
- install_devzone_skill
151
- echo "devzone : ai active: claude (then /login), opencode auth login"
152
- else
153
- npm uninstall -g "${IA_NOMS[@]}" >/dev/null 2>&1 || true
154
- rm -f "$(failure_marker_file ai)"
155
- # repowarden guard: removed on disable (symmetrical with the enable).
156
- # repowarden does it itself when present; otherwise removal by jq of only
157
- # the PreToolUse entries calling the guard, the rest of settings.json
158
- # intact. The guard is called " repowarden guard " since repowarden
159
- # 4.17.3; " repowarden garde " is its old name, still an alias on the
160
- # repowarden side and recognised here.
161
- if command -v repowarden >/dev/null 2>&1; then
162
- repowarden agents retirer --global >/dev/null 2>&1 || true
163
- elif [ -f "$HOME/.claude/settings.json" ]; then
164
- tmp="$(mktemp)"
165
- if jq '
166
- if (.hooks.PreToolUse // null) != null then
167
- .hooks.PreToolUse = [
168
- .hooks.PreToolUse[] |
169
- if (.hooks // null) != null then
170
- .hooks = [ .hooks[] | select(((.command // "") | (contains("repowarden garde") or contains("repowarden guard"))) | not) ] |
171
- select((.hooks | length) > 0)
172
- else
173
- select(((.command // "") | (contains("repowarden garde") or contains("repowarden guard"))) | not)
174
- end
175
- ] |
176
- if (.hooks.PreToolUse | length) == 0 then del(.hooks.PreToolUse) else . end |
177
- if ((.hooks // {}) | keys | length) == 0 then del(.hooks) else . end
178
- else . end
179
- ' "$HOME/.claude/settings.json" >"$tmp" 2>/dev/null; then
180
- mv "$tmp" "$HOME/.claude/settings.json"
181
- else
182
- rm -f "$tmp"
183
- fi
184
- fi
185
- # opencode plugin of the guard (also removed by repowarden above)
186
- rm -f "$HOME/.config/opencode/plugins/repowarden-garde.js" \
187
- "$HOME/.config/opencode/plugins/repowarden-garde-v2.js"
188
- # docker guard: only its entries and its plugins are removed.
189
- remove_docker_guard
190
- # opencode configuration: removed only if it carries the devzone marker
191
- # and was not changed; customised -> kept.
192
- remove_opencode_config
193
- # Removes the opencode provider of the host models, keeps the rest of the file.
194
- unset_provider || true
195
- # devzone skill: removed only if unchanged; customised -> kept.
196
- remove_devzone_skill
197
- # devzone agent state: kept in the shared volume (disabling it in one
198
- # devzone does not remove the state of the others).
199
- echo "devzone : ai disabled (logins and devzone agent state kept in their volumes; workspace/.agents/ logs kept)"
200
- fi
201
- }
@@ -1,209 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # devzone, working cluster: change, use.
4
- # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
- # functions only, shared variables are defined in devzone.
6
-
7
- # All the databases disappear: confirmation in the terminal (without a terminal,
8
- # the command is explicit); a yes or --yes sets DELETE_DATA, read by
9
- # apply_mysql to run delete-data (#441); only --yes reaches this function.
10
- confirm_removal() {
11
- local app="$1" answer arg
12
- DELETE_DATA=""
13
- [ "$(value_of "$app")" = on ] || return 0
14
- for arg in "${@:2}"; do
15
- case "$arg" in --yes) DELETE_DATA=1 ;; esac
16
- done
17
- [ -z "$DELETE_DATA" ] || return 0
18
- cluster_interactive || return 0
19
- # mysql: the question is about the namespace (volume and databases stay);
20
- # postgres: everything goes, the refusal cancels; gitlab: the Rails secret
21
- # stays, its deletion only happens on a full uninstall on purpose
22
- if [ "$app" = mysql ]; then
23
- printf 'Disabling mysql removes the server; the volume and databases stay. Also delete the devzone-mysql namespace and its volumes? [y/N] ' >&2
24
- elif [ "$app" = gitlab ]; then
25
- printf 'Disabling gitlab keeps the Rails secret (browser sessions stay valid at reinstall). Also delete the Rails secret? [y/N] ' >&2
26
- else
27
- printf 'Disabling %s deletes all its databases. Continue? [y/N] ' "$app" >&2
28
- fi
29
- read -r answer || answer=""
30
- case "$answer" in
31
- y | Y | yes) DELETE_DATA=1; return 0 ;;
32
- esac
33
- # refusal: mysql and gitlab still disable (data kept), postgres cancels
34
- case "$app" in
35
- mysql | gitlab) return 0 ;;
36
- *) echo "Aborted: nothing was deleted."; return 1 ;;
37
- esac
38
- }
39
-
40
- # devzone cluster [CTX] [--yes]: shows the services cluster, or moves the
41
- # services to it (uninstalled from the old one, installed on the new one: data
42
- # not migrated, hence the confirmation)
43
- change_cluster() {
44
- local wanted="" yes="" confirm_ctx="" expect="" arg current new answer ctx_old ctx_new NS
45
- NS=devzone-postgres
46
- for arg in "$@"; do
47
- if [ -n "$expect" ]; then
48
- confirm_ctx="$arg"
49
- expect=""
50
- continue
51
- fi
52
- case "$arg" in
53
- --yes) yes=1 ;;
54
- --confirm) expect=1 ;;
55
- -*) echo "devzone : unknown argument: $arg (devzone cluster [CTX] [--yes] [--confirm CTX])" >&2; return 2 ;;
56
- *) wanted="$arg" ;;
57
- esac
58
- done
59
- if [ -n "$expect" ]; then
60
- echo "devzone : --confirm expects a context" >&2
61
- return 2
62
- fi
63
- current="$(cluster_saved)"
64
- if [ -z "$wanted" ]; then
65
- if [ -z "$current" ]; then
66
- echo "devzone : no cluster chosen (set when a module is enabled: devzone enable postgres)"
67
- elif cluster_is_dedicated "$current"; then
68
- echo "devzone : cluster $current (dedicated kind, in the container)"
69
- else
70
- echo "devzone : cluster $current (host cluster)"
71
- fi
72
- echo " possible: $(cluster_candidates | tr '\n' ' ')"
73
- return 0
74
- fi
75
- if [ -n "$confirm_ctx" ]; then
76
- new="$(cluster_choose "$wanted" --confirm "$confirm_ctx")" || return 2
77
- else
78
- new="$(cluster_choose "$wanted")" || return 2
79
- fi
80
- if [ "$new" = "$current" ]; then
81
- echo "devzone : already on $new, nothing to do."
82
- return 0
83
- fi
84
- ctx_old="$current"
85
- ctx_new="$new"
86
- if [ "$(value_of postgres)" = on ]; then
87
- if [ -z "$yes" ]; then
88
- if ! cluster_interactive; then
89
- echo "devzone : the postgres databases will be deleted from $ctx_old (not migrated): devzone cluster $ctx_new --yes" >&2
90
- return 1
91
- fi
92
- printf 'postgres will be reinstalled on %s, its databases deleted from %s (not migrated). Continue? [y/N] ' "$ctx_new" "$ctx_old" >&2
93
- read -r answer || answer=""
94
- case "$answer" in
95
- y | Y | yes) ;;
96
- *) echo "Aborted: nothing changed."; return 0 ;;
97
- esac
98
- fi
99
- # Removes PostgreSQL from the old cluster (explicit context);
100
- # namespace and RoleBinding by the administrator (#430)
101
- export KUBECONFIG="$HOME/.kube/config:$HOME/.kube/hote.config"
102
- account_remove "$ctx_old" "$NS" >/dev/null 2>&1 || true
103
- account_admin "$ctx_old" delete namespace "$NS" --wait=true >/dev/null 2>&1 || true
104
- cluster_release "$ctx_old"
105
- # The new cluster becomes the devzone context
106
- cluster_save "$ctx_new"
107
- # Sets the devzone context on the new cluster (cluster + user:
108
- # important command, failure shown and rendered #396)
109
- if ! devzone_context_set "$ctx_new"; then
110
- echo "devzone : cannot set the devzone context on $ctx_new" >&2
111
- return 1
112
- fi
113
- # Installs PostgreSQL on the new cluster (via --context devzone which now points to it)
114
- devzone postgres install
115
- else
116
- cluster_save "$ctx_new"
117
- # Sets the devzone context on the new cluster (cluster + user:
118
- # important command, failure shown and rendered #396)
119
- if ! devzone_context_set "$ctx_new"; then
120
- echo "devzone : cannot set the devzone context on $ctx_new" >&2
121
- return 1
122
- fi
123
- fi
124
- echo "devzone : services cluster: $ctx_new"
125
- }
126
-
127
- # Switches the user's working cluster (#341). Never touches the devzone services
128
- # cluster: no cluster_save, no cluster= line in the state.
129
- use_cluster() {
130
- local ctx="" confirm_ctx="" namespace="" answer arg current
131
- while [ "$#" -gt 0 ]; do
132
- arg="$1"
133
- shift
134
- case "$arg" in
135
- -n | --namespace)
136
- if [ "$#" -eq 0 ]; then
137
- echo "devzone : -n expects a namespace" >&2
138
- return 2
139
- fi
140
- namespace="$1"
141
- shift
142
- ;;
143
- --namespace=*) namespace="${arg#*=}" ;;
144
- --confirm)
145
- if [ "$#" -eq 0 ]; then
146
- echo "devzone : --confirm expects a context" >&2
147
- return 2
148
- fi
149
- confirm_ctx="$1"
150
- shift
151
- ;;
152
- --confirm=*) confirm_ctx="${arg#*=}" ;;
153
- -*)
154
- echo "devzone : unknown argument: $arg (devzone use CTX [-n NS] [--confirm CTX])" >&2
155
- return 2
156
- ;;
157
- *)
158
- if [ -n "$ctx" ]; then
159
- echo "devzone : unknown argument: $arg (devzone use CTX [-n NS] [--confirm CTX])" >&2
160
- return 2
161
- fi
162
- ctx="$arg"
163
- ;;
164
- esac
165
- done
166
- if [ -z "$ctx" ]; then
167
- if [ -z "$namespace" ]; then
168
- echo "devzone : missing context: devzone use CTX" >&2
169
- return 2
170
- fi
171
- current="$(kubectl config current-context 2>/dev/null || true)"
172
- if [ -z "$current" ]; then
173
- echo "devzone : no current context" >&2
174
- return 2
175
- fi
176
- ctx="$current"
177
- fi
178
- if ! kubectl config get-contexts -o name 2>/dev/null | grep -qxF -- "$ctx"; then
179
- echo "devzone : unknown context: $ctx (see kubectl config get-contexts)" >&2
180
- return 2
181
- fi
182
- current="$(kubectl config current-context 2>/dev/null || true)"
183
- if [ "$ctx" != "$current" ]; then
184
- if ! cluster_is_local "$ctx"; then
185
- if [ -n "$confirm_ctx" ]; then
186
- if [ "$confirm_ctx" != "$ctx" ]; then
187
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
188
- return 2
189
- fi
190
- elif cluster_interactive; then
191
- printf 'remote cluster: %s; type its name to confirm: ' "$ctx" >&2
192
- read -r answer || answer=""
193
- if [ "$answer" != "$ctx" ]; then
194
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
195
- return 2
196
- fi
197
- else
198
- echo "devzone : remote cluster refused: $ctx (--confirm $ctx)" >&2
199
- return 2
200
- fi
201
- fi
202
- kubectl config use-context "$ctx" >/dev/null
203
- fi
204
- if [ -n "$namespace" ]; then
205
- kubectl config set-context "$ctx" --namespace "$namespace" >/dev/null
206
- fi
207
- echo "working cluster: $ctx"
208
- [ -z "$namespace" ] || echo "namespace: $namespace"
209
- }
@@ -1,97 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # devzone, ai module: the devzone skill of the assistants.
4
- # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
- # functions only, shared variables are defined in devzone.
6
-
7
-
8
- # Skill marker: the file is installed if missing, updated while it carries the
9
- # marker and is unchanged, kept if customised (#161, opencode rule). The marker
10
- # text is the one written in SKILL.md: it is kept as is.
11
- SKILL_MARKER='<!-- devzone : skill set by devzone enable ai -->'
12
- # Fingerprint of the installed version, next to SKILL.md: it tells an unchanged
13
- # skill from a customised one that still carries the marker.
14
- SKILL_FINGERPRINT='.devzone-fingerprint'
15
-
16
- # True if the file carries the devzone marker
17
- has_skill_marker() { grep -qF -e "$SKILL_MARKER" "$1"; }
18
-
19
- # Folders of the devzone skill, in the volumes of Claude Code and opencode.
20
- skill_dirs() {
21
- echo "$HOME/.claude/skills/devzone"
22
- echo "$HOME/.config/opencode/skills/devzone"
23
- }
24
-
25
- # sha256 sum of a file (sha256sum on Linux, shasum on macOS).
26
- skill_checksum() {
27
- if command -v sha256sum >/dev/null 2>&1; then
28
- sha256sum "$1" | cut -d' ' -f1
29
- else
30
- shasum -a 256 "$1" | cut -d' ' -f1
31
- fi
32
- }
33
-
34
- # True if the target skill is still the installed one: recorded fingerprint,
35
- # or else content identical to the model.
36
- skill_unchanged() {
37
- local target="$1" fingerprint="$2" model="$3"
38
- if [ -n "$fingerprint" ]; then
39
- [ "$(skill_checksum "$target")" = "$fingerprint" ]
40
- else
41
- cmp -s "$model" "$target"
42
- fi
43
- }
44
-
45
- # Installs the devzone skill (versioned model): written if missing, updated
46
- # while it keeps the marker and the installed fingerprint, kept if customised.
47
- install_devzone_skill() {
48
- local model="$ICI/skills/devzone/SKILL.md" target d fingerprint
49
- for d in $(skill_dirs); do
50
- mkdir -p "$d"
51
- target="$d/SKILL.md"
52
- if [ ! -f "$target" ]; then
53
- cp "$model" "$target"
54
- skill_checksum "$target" >"$d/$SKILL_FINGERPRINT"
55
- echo "devzone : devzone skill installed in $d"
56
- continue
57
- fi
58
- fingerprint=""
59
- if [ -f "$d/$SKILL_FINGERPRINT" ]; then
60
- fingerprint="$(cat "$d/$SKILL_FINGERPRINT")"
61
- fi
62
- if has_skill_marker "$target" && skill_unchanged "$target" "$fingerprint" "$model"; then
63
- if ! cmp -s "$model" "$target"; then
64
- cp "$model" "$target"
65
- echo "devzone : devzone skill updated in $d"
66
- fi
67
- skill_checksum "$target" >"$d/$SKILL_FINGERPRINT"
68
- else
69
- echo "devzone : customised devzone skill in $d, kept"
70
- fi
71
- done
72
- }
73
-
74
- # Removes the devzone skill written by devzone if it still carries its marker
75
- # and was not changed; a customised skill is kept. Symmetrical with
76
- # install_devzone_skill.
77
- remove_devzone_skill() {
78
- local model target d fingerprint
79
- model="$ICI/skills/devzone/SKILL.md"
80
- for d in $(skill_dirs); do
81
- target="$d/SKILL.md"
82
- if [ ! -f "$target" ]; then
83
- rm -f "$d/$SKILL_FINGERPRINT"
84
- continue
85
- fi
86
- fingerprint=""
87
- if [ -f "$d/$SKILL_FINGERPRINT" ]; then
88
- fingerprint="$(cat "$d/$SKILL_FINGERPRINT")"
89
- fi
90
- if has_skill_marker "$target" && skill_unchanged "$target" "$fingerprint" "$model"; then
91
- rm -f "$target" "$d/$SKILL_FINGERPRINT"
92
- echo "devzone : devzone skill removed from $d"
93
- else
94
- echo "devzone : customised devzone skill in $d, kept"
95
- fi
96
- done
97
- }
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Network isolation and access authorization between devzone namespaces.
3
- # File <= 250 lines: functions namespace_isolate, allow, forbid.
4
- # These functions modify NetworkPolicies in the Kubernetes cluster.
5
- # Loaded by argocd.sh, catalog.sh, the mysql and postgres Go modules, gitlab.sh; shipped with the package.
6
-
7
- # Sets an isolating NetworkPolicy in a namespace.
8
- # Only the pods of the same namespace can reach the services.
9
- namespace_isolate() {
10
- local ns="${1:-}"
11
- [ -n "$ns" ] || { echo "devzone : namespace missing" >&2; return 2; }
12
-
13
- kubectl --context devzone -n "$ns" apply -f - <<EOF
14
- apiVersion: networking.k8s.io/v1
15
- kind: NetworkPolicy
16
- metadata:
17
- name: devzone-meme-namespace
18
- labels:
19
- app.kubernetes.io/managed-by: devzone
20
- spec:
21
- podSelector: {}
22
- ingress:
23
- - from:
24
- - podSelector: {}
25
- EOF
26
- }
27
-
28
- # Adds a namespaceSelector rule to the NetworkPolicy of the target namespace,
29
- # allowing access from outside this namespace.
30
- # Without this rule, an application in another namespace cannot reach the
31
- # devzone services (postgres, etc.).
32
- allow() {
33
- local target_ns="${1:-}" patch output
34
- [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
35
-
36
- kubectl --context devzone -n "$target_ns" get networkpolicy devzone-meme-namespace \
37
- -o yaml 2>/dev/null | kubectl --context devzone -n "$target_ns" apply -f - >/dev/null 2>&1 ||
38
- { echo "devzone : cannot apply the isolating NetworkPolicy in $target_ns" >&2; return 1; }
39
-
40
- patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
41
- "namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
42
- if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
43
- -p "$patch" 2>&1)"; then
44
- echo "devzone : cannot allow access to $target_ns : $output" >&2
45
- return 1
46
- fi
47
-
48
- echo "devzone : rule allowed to $target_ns"
49
- }
50
-
51
- # Removes the namespaceSelector rule from the NetworkPolicy,
52
- # blocking access again from the given namespace.
53
- forbid() {
54
- local target_ns="${1:-}" patch output
55
- [ -n "$target_ns" ] || { echo "devzone : target namespace missing" >&2; return 2; }
56
-
57
- patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
58
- if ! output="$(kubectl --context devzone -n "$target_ns" patch networkpolicy devzone-meme-namespace \
59
- -p "$patch" 2>&1)"; then
60
- echo "devzone : cannot forbid access to $target_ns : $output" >&2
61
- return 1
62
- fi
63
-
64
- echo "devzone : rule forbidden to $target_ns"
65
- }
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Limited Kubernetes account (#430): the devzone context (projects, relays,
3
- # agents) can only act in the devzone-* namespaces. The account is the
4
- # ServiceAccount devzone-agent of the devzone-system namespace, bound to the
5
- # edit ClusterRole (no RBAC, no quotas) in each devzone namespace by a
6
- # RoleBinding. The installers alone use the admin context (host context in
7
- # ~/.kube/hote.config, kind cluster in ~/.kube/config); the shells use
8
- # ~/.kube/config and the agents the limited ~/.kube/agent.config (devzone
9
- # context only, #844).
10
- # Library sourced by cluster.sh.
11
-
12
- ACCOUNT_NS=devzone-system
13
- ACCOUNT_SA=devzone-agent
14
- ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
15
-
16
- # kubeconfig file that holds the admin context ctx: hote.config if it lists it
17
- # (host clusters), otherwise ~/.kube/config (kind clusters of the container).
18
- account_admin_config() {
19
- local ctx="$1" host="${DEVZONE_KUBE_HOST:-$HOME/.kube/hote.config}"
20
- if [ -n "$ctx" ] && [ -f "$host" ]; then
21
- if KUBECONFIG="$host" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
22
- echo "$host"
23
- return 0
24
- fi
25
- fi
26
- echo "$ACCOUNT_CONFIG"
27
- }
28
-
29
- # kubectl on the admin context: explicit kubeconfig that holds this context,
30
- # never the combined KUBECONFIG (the admin never goes through the limited
31
- # account). Without a known context: the one kubectl uses.
32
- account_admin() {
33
- local ctx="$1" conf
34
- shift
35
- if [ -z "$ctx" ]; then
36
- ctx="$(kubectl config current-context 2>/dev/null || true)"
37
- fi
38
- conf="$(account_admin_config "$ctx")"
39
- if [ -n "$ctx" ]; then
40
- kubectl --kubeconfig="$conf" --context "$ctx" "$@"
41
- else
42
- kubectl --kubeconfig="$conf" "$@"
43
- fi
44
- }
45
-
46
- # helm on the admin context ctx: the charts create CRDs, ClusterRoles or
47
- # RoleBindings, beyond the limited account's rights (edit).
48
- # Usage: account_helm <ctx> <helm args…>
49
- account_helm() {
50
- local ctx="$1" conf
51
- shift
52
- if [ -z "$ctx" ]; then
53
- ctx="$(kubectl config current-context 2>/dev/null || true)"
54
- fi
55
- conf="$(account_admin_config "$ctx")"
56
- if [ -n "$ctx" ]; then
57
- helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
58
- else
59
- helm --kubeconfig "$conf" "$@"
60
- fi
61
- }
62
-
63
- # Admin context of an installation: the chosen services cluster (cluster_saved
64
- # of cluster.sh), otherwise the current kubectl context.
65
- account_context() {
66
- local ctx
67
- ctx="$(cluster_saved 2>/dev/null || true)"
68
- if [ -n "$ctx" ]; then
69
- echo "$ctx"
70
- return 0
71
- fi
72
- kubectl config current-context 2>/dev/null || true
73
- }
74
-
75
- # Allows the account in namespace ns: devzone-agent RoleBinding to the edit
76
- # ClusterRole (read, write, secrets, NetworkPolicies — no RBAC, no quotas), set
77
- # with the admin context after the namespace is created.
78
- # The account is set up first if missing: devzone-system namespace and
79
- # devzone-agent ServiceAccount, so an installation on a still blank cluster
80
- # makes the account usable at the next token renewal.
81
- account_allow() {
82
- local ctx="$1" ns="$2"
83
- account_admin "$ctx" create namespace "$ACCOUNT_NS" --dry-run=client -o yaml |
84
- account_admin "$ctx" apply -f - >/dev/null || return 1
85
- account_admin "$ctx" -n "$ACCOUNT_NS" create serviceaccount "$ACCOUNT_SA" \
86
- --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
87
- account_admin "$ctx" -n "$ns" create rolebinding "$ACCOUNT_SA" \
88
- --clusterrole=edit --serviceaccount="$ACCOUNT_NS:$ACCOUNT_SA" \
89
- --dry-run=client -o yaml | account_admin "$ctx" apply -f - >/dev/null || return 1
90
- }
91
-
92
- # Removes the account's permission in namespace ns (uninstall): RoleBinding
93
- # deleted with the admin context.
94
- account_remove() {
95
- local ctx="$1" ns="$2"
96
- account_admin "$ctx" -n "$ns" delete rolebinding "$ACCOUNT_SA" \
97
- --ignore-not-found >/dev/null || return 1
98
- }
99
-
100
- # Creates and labels namespace ns as administrator, then allows the account.
101
- account_namespace() {
102
- local ctx="$1" ns="$2"
103
- account_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
104
- account_admin "$ctx" apply -f - >/dev/null || return 1
105
- account_admin "$ctx" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null || return 1
106
- account_allow "$ctx" "$ns" || return 1
107
- }