devzone 1.1.0 → 3.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 (118) hide show
  1. package/.devcontainer/Dockerfile +4 -4
  2. package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
  3. package/.devcontainer/agent-local.sh +2 -2
  4. package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
  5. package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
  6. package/.devcontainer/agent-pod-manifest.sh +4 -4
  7. package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
  8. package/.devcontainer/agent-session.sh +3 -3
  9. package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
  10. package/.devcontainer/agent-workspace.sh +1 -1
  11. package/.devcontainer/agent.sh +14 -14
  12. package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
  13. package/.devcontainer/{ia → ai}/host-models.sh +2 -2
  14. package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
  15. package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
  16. package/.devcontainer/argocd/argocd.sh +94 -93
  17. package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
  18. package/.devcontainer/argocd/services-hook.sh +8 -8
  19. package/.devcontainer/argocd/services.sh +1 -1
  20. package/.devcontainer/catalog/app.sh +209 -0
  21. package/.devcontainer/catalog/catalog-watcher.sh +130 -0
  22. package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
  23. package/.devcontainer/catalog/mysql/install.sh +87 -0
  24. package/.devcontainer/catalog/mysql/mysql.sh +262 -0
  25. package/.devcontainer/catalog/mysql/volume.sh +71 -0
  26. package/.devcontainer/catalog.sh +231 -0
  27. package/.devcontainer/chart-direct.sh +1 -1
  28. package/.devcontainer/cluster.sh +222 -224
  29. package/.devcontainer/clusters.sh +41 -41
  30. package/.devcontainer/devcontainer.json +1 -1
  31. package/.devcontainer/devzone +103 -1506
  32. package/.devcontainer/devzone-ai-guard.sh +76 -0
  33. package/.devcontainer/devzone-ai.sh +201 -0
  34. package/.devcontainer/devzone-cluster.sh +210 -0
  35. package/.devcontainer/devzone-modules.sh +126 -0
  36. package/.devcontainer/devzone-platform.sh +189 -0
  37. package/.devcontainer/devzone-repair.sh +94 -0
  38. package/.devcontainer/devzone-services.sh +241 -0
  39. package/.devcontainer/devzone-skill.sh +97 -0
  40. package/.devcontainer/devzone-status.sh +140 -0
  41. package/.devcontainer/devzone-version.sh +78 -0
  42. package/.devcontainer/git-identity.sh +28 -0
  43. package/.devcontainer/gitlab/argocd.sh +2 -2
  44. package/.devcontainer/gitlab/chart.sh +2 -2
  45. package/.devcontainer/gitlab/gitlab.sh +83 -84
  46. package/.devcontainer/gitlab/installation.sh +111 -111
  47. package/.devcontainer/gitlab/secrets.sh +47 -47
  48. package/.devcontainer/gitlab/seed.sh +77 -77
  49. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  50. package/.devcontainer/help.sh +1 -1
  51. package/.devcontainer/isolation.sh +65 -0
  52. package/.devcontainer/kind-wrapper.sh +45 -0
  53. package/.devcontainer/kube-account.sh +199 -0
  54. package/.devcontainer/kube-config.sh +45 -46
  55. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  56. package/.devcontainer/kube-reachable.sh +64 -0
  57. package/.devcontainer/{memoire.sh → memory.sh} +1 -1
  58. package/.devcontainer/metrics-server.sh +2 -2
  59. package/.devcontainer/opencode.jsonc +2 -2
  60. package/.devcontainer/packages.sh +228 -0
  61. package/.devcontainer/password.sh +1 -1
  62. package/.devcontainer/ports-auto.sh +152 -153
  63. package/.devcontainer/ports-json.sh +16 -15
  64. package/.devcontainer/ports.sh +127 -123
  65. package/.devcontainer/post-create.sh +52 -52
  66. package/.devcontainer/postgres/postgres.sh +176 -176
  67. package/.devcontainer/rename-legacy-files.sh +103 -0
  68. package/.devcontainer/services-admin.sh +5 -5
  69. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  70. package/.devcontainer/startup.sh +65 -0
  71. package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
  72. package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
  73. package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
  74. package/.devcontainer/{etat.sh → state.sh} +4 -4
  75. package/.devcontainer/workspace-init.sh +17 -3
  76. package/Makefile +8 -8
  77. package/README.md +195 -194
  78. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  79. package/manage/devzone +8 -10
  80. package/manage/scripts/argocd-workspace.sh +1 -1
  81. package/manage/scripts/check-go-layout.sh +40 -0
  82. package/manage/scripts/check-names.sh +61 -0
  83. package/manage/scripts/create-cluster.sh +1 -1
  84. package/manage/scripts/create-mode.sh +2 -2
  85. package/manage/scripts/devzone-create.sh +5 -5
  86. package/manage/scripts/devzone-manifest.sh +3 -3
  87. package/manage/scripts/devzone-update.sh +12 -8
  88. package/manage/scripts/docker-workstation.sh +2 -2
  89. package/manage/scripts/docker.sh +2 -2
  90. package/manage/scripts/{lancer.sh → launch.sh} +10 -51
  91. package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
  92. package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
  93. package/manage/scripts/ports-apps.sh +1 -1
  94. package/manage/scripts/ports-workspace.sh +7 -7
  95. package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
  96. package/manage/scripts/workspace-egress.sh +2 -2
  97. package/manage/scripts/workspace-update.sh +5 -2
  98. package/manage/scripts/workspace-wait.sh +2 -2
  99. package/manage/workspace.sh +4 -4
  100. package/package.json +1 -1
  101. package/.devcontainer/catalogue/app.sh +0 -211
  102. package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
  103. package/.devcontainer/catalogue/mysql/installer.sh +0 -87
  104. package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
  105. package/.devcontainer/catalogue/mysql/volume.sh +0 -71
  106. package/.devcontainer/catalogue.sh +0 -231
  107. package/.devcontainer/demarrage.sh +0 -66
  108. package/.devcontainer/docker-relais.sh +0 -149
  109. package/.devcontainer/docker-sans-hote.sh +0 -12
  110. package/.devcontainer/git-identite.sh +0 -28
  111. package/.devcontainer/isolement.sh +0 -65
  112. package/.devcontainer/kind-enveloppe.sh +0 -45
  113. package/.devcontainer/kube-compte.sh +0 -200
  114. package/.devcontainer/kube-joignable.sh +0 -64
  115. package/.devcontainer/paquets.sh +0 -227
  116. /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
  117. /package/.devcontainer/{ia → ai}/host-check.message +0 -0
  118. /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # devzone, platform: GitHub or GitLab.
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
+ # ---- Platform: GitHub (default) or GitLab (#240) ----
9
+ # Choice kept in the state file (platform=, gitlab_url=), per instance; the
10
+ # configuration of a service only exists while it is chosen (#242): glab and the
11
+ # URL disappear when going back to github.
12
+
13
+ # Current platform: github when there is no line (default)
14
+ platform_read() {
15
+ local v
16
+ v="$(grep -E '^platform=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2 || true)"
17
+ [ "$v" = gitlab ] && echo gitlab || echo github
18
+ }
19
+
20
+ # URL of the GitLab instance, nothing if missing
21
+ gitlab_url_read() {
22
+ grep -E '^gitlab_url=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true
23
+ }
24
+
25
+ # Host of a URL, without its protocol (glab --hostname)
26
+ host_of() {
27
+ echo "$1" | sed -E 's#^[a-z]+://##; s#/$##'
28
+ }
29
+
30
+ # Removes glab and its configuration (back to github)
31
+ remove_glab() {
32
+ rm -f "$GLAB"
33
+ rm -rf "$HOME/.config/glab-cli"
34
+ }
35
+
36
+ # State line for the platform: github by default, or the GitLab instance with
37
+ # its connected glab on the login command otherwise
38
+ platform_line() {
39
+ local url host
40
+ if [ "$(platform_read)" = gitlab ]; then
41
+ url="$(gitlab_url_read)"
42
+ host="$(host_of "$url")"
43
+ if [ -x "$GLAB" ] && "$GLAB" auth status --hostname "$host" >/dev/null 2>&1; then
44
+ printf ' ✔ platform gitlab: %s, glab connected\n' "$url"
45
+ else
46
+ printf ' ⚠ platform gitlab: %s, glab not connected: glab auth login --hostname %s\n' "$url" "$host"
47
+ fi
48
+ else
49
+ echo " ✔ platform github"
50
+ fi
51
+ }
52
+
53
+ # Simple display of the platform (devzone platform)
54
+ platform_summary() {
55
+ local url host
56
+ if [ "$(platform_read)" = gitlab ]; then
57
+ url="$(gitlab_url_read)"
58
+ host="$(host_of "$url")"
59
+ if [ -x "$GLAB" ] && "$GLAB" auth status --hostname "$host" >/dev/null 2>&1; then
60
+ echo "devzone : gitlab platform: $url, glab connected"
61
+ else
62
+ echo "devzone : gitlab platform: $url, glab not connected: glab auth login --hostname $host"
63
+ fi
64
+ else
65
+ echo "devzone : github platform (default)"
66
+ fi
67
+ }
68
+
69
+ # Installs glab (official release, SHA-256 sum checked), nothing if it is
70
+ # already there; the binary ends in ~/.local/bin (remove_glab removes it)
71
+ install_glab() {
72
+ local arch="" sum archive folder glab_tmp
73
+ if [ -x "$GLAB" ] && "$GLAB" --version >/dev/null 2>&1; then
74
+ return 0
75
+ fi
76
+ case "$(uname -m)" in
77
+ arm64 | aarch64) arch=arm64 sum="$GLAB_SOMME_ARM64" ;;
78
+ *) arch=amd64 sum="$GLAB_SOMME_AMD64" ;;
79
+ esac
80
+ echo "devzone : downloading glab $GLAB_VERSION (SHA-256 checked)…"
81
+ archive="$(mktemp)"
82
+ if ! curl -fsSL -o "$archive" "https://gitlab.com/gitlab-org/cli/-/releases/$GLAB_VERSION/downloads/glab_${GLAB_VERSION#v}_linux_${arch}.tar.gz"; then
83
+ rm -f "$archive"
84
+ echo "devzone : glab download failed (official gitlab.com release); retry: devzone platform gitlab --url URL" >&2
85
+ return 1
86
+ fi
87
+ if [ "$(sha256sum "$archive" | cut -d' ' -f1)" != "$sum" ]; then
88
+ rm -f "$archive"
89
+ echo "devzone : glab SHA-256 sum unexpected, aborting; archive refused" >&2
90
+ return 1
91
+ fi
92
+ folder="$(mktemp -d)"
93
+ glab_tmp="$folder/bin/glab"
94
+ if ! tar -xzf "$archive" -C "$folder" || [ ! -f "$glab_tmp" ]; then
95
+ glab_tmp="$folder/glab"
96
+ fi
97
+ if [ ! -f "$glab_tmp" ]; then
98
+ rm -rf "$folder" "$archive"
99
+ echo "devzone : glab binary missing from the archive, aborting" >&2
100
+ return 1
101
+ fi
102
+ mkdir -p "$HOME/.local/bin"
103
+ mv "$glab_tmp" "$GLAB"
104
+ chmod +x "$GLAB"
105
+ rm -rf "$folder" "$archive"
106
+ }
107
+
108
+ # Login to the GitLab instance: instance of the gitlab module -> root token of
109
+ # the module (http protocol, never shown); another instance -> interactive, a
110
+ # browser asking for the login code. Checks: exit code of the auth login, then
111
+ # auth status --hostname; without that check, not "connected".
112
+ connect_glab() {
113
+ local host="$1" url="$2" token
114
+ if [ "$url" = "$GITLAB_URL_MODULE" ]; then
115
+ if [ ! -f "$RACINE/workspace/.gitlab/root-token" ]; then
116
+ echo "devzone : root token of the gitlab module not found ($RACINE/workspace/.gitlab/root-token): devzone enable gitlab, or by hand: glab auth login --hostname $host" >&2
117
+ return 1
118
+ fi
119
+ token="$(cat "$RACINE/workspace/.gitlab/root-token")"
120
+ if ! "$GLAB" auth login --hostname "$host" --api-protocol http --git-protocol http --token "$token"; then
121
+ echo "devzone : cannot connect to the gitlab instance: devzone enable gitlab, or by hand: glab auth login --hostname $host" >&2
122
+ return 1
123
+ fi
124
+ elif ! "$GLAB" auth login --hostname "$host"; then
125
+ echo "devzone : cannot connect to the gitlab instance: glab auth login --hostname $host" >&2
126
+ return 1
127
+ fi
128
+ if ! "$GLAB" auth status --hostname "$host" >/dev/null 2>&1; then
129
+ echo "devzone : cannot verify the connection: glab auth status --hostname $host" >&2
130
+ return 1
131
+ fi
132
+ }
133
+
134
+ # Changes the platform: github (default, current behaviour) or gitlab
135
+ change_platform() {
136
+ local target="${1:-}" url="" expect="" arg host
137
+ case "$target" in
138
+ github)
139
+ # Removes the credential setting of the last gitlab host, if there is one
140
+ if [ -n "$(gitlab_url_read)" ]; then
141
+ git config --global --unset-all "credential.$(gitlab_url_read).helper" 2>/dev/null || true
142
+ fi
143
+ remove_glab
144
+ remove_key platform
145
+ remove_key gitlab_url
146
+ echo "devzone : github platform (default): gh checks; glab and its configuration removed if they were installed"
147
+ ;;
148
+ gitlab)
149
+ for arg in "${@:2}"; do
150
+ if [ -n "$expect" ]; then url="$arg"; expect=""; continue; fi
151
+ case "$arg" in
152
+ --url) expect=1 ;;
153
+ *) echo "devzone : unknown argument: $arg (devzone platform gitlab --url URL)" >&2; return 1 ;;
154
+ esac
155
+ done
156
+ if [ -n "$expect" ]; then
157
+ echo "devzone : --url expects a URL" >&2
158
+ return 1
159
+ fi
160
+ if [ -z "$url" ]; then
161
+ if [ "$(value_of gitlab)" = on ]; then
162
+ url="$GITLAB_URL_MODULE"
163
+ else
164
+ echo "devzone : missing URL: devzone platform gitlab --url URL (or an active gitlab module for the local instance)" >&2
165
+ return 1
166
+ fi
167
+ fi
168
+ host="$(host_of "$url")"
169
+ if ! install_glab; then
170
+ return 1
171
+ fi
172
+ if ! connect_glab "$host" "$url"; then
173
+ echo "devzone : reconnect needed: glab auth login --hostname $host" >&2
174
+ return 1
175
+ fi
176
+ if ! git config --global "credential.$url.helper" "!$GLAB auth git-credential"; then
177
+ echo "devzone : cannot set the git credential" >&2
178
+ return 1
179
+ fi
180
+ write_value platform gitlab
181
+ write_value gitlab_url "$url"
182
+ echo "devzone : gitlab platform: $url, glab connected"
183
+ ;;
184
+ *)
185
+ echo "devzone : unknown platform: ${target:-(none)}; choices: github (default) or gitlab [--url URL]" >&2
186
+ return 1
187
+ ;;
188
+ esac
189
+ }
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # devzone, repair of the workstation.
4
+ # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
+ # functions only, shared variables are defined in devzone.
6
+
7
+ # Lines "package pinned installed" of the outdated tools; fails if the versions.sh
8
+ # script is missing or cannot answer (the state then omits the line)
9
+ outdated_tools() {
10
+ [ -f "$VERSIONS" ] || return 1
11
+ bash "$VERSIONS" --installees 2>/dev/null
12
+ }
13
+
14
+ # Sets repowarden back to the pinned version if it differs, like post-create.sh
15
+ # (it installs the global git hooks)
16
+ apply_repowarden() {
17
+ local line pinned installed package=repowarden
18
+ [ -f "$VERSIONS" ] || return 0
19
+ line="$(bash "$VERSIONS" --installees 2>/dev/null | awk '$1 == "repowarden"' || true)"
20
+ [ -n "$line" ] || return 0
21
+ read -r _ pinned installed <<<"$line"
22
+ echo "devzone : installing repowarden ${pinned}…"
23
+ npm install -g "$package@$pinned" >/dev/null
24
+ repowarden install --global --lang fr
25
+ echo "devzone : repowarden $installed → $pinned"
26
+ }
27
+
28
+ # Paths of the worktrees of the devzone repository and of the workspace
29
+ # repositories absent here: created on the other side (host), a git worktree
30
+ # prune would break them. Read-only: nothing is deleted or repaired.
31
+ missing_worktrees() {
32
+ local repo line path
33
+ {
34
+ [ -e "$RACINE/.git" ] && echo "$RACINE"
35
+ find "$RACINE/workspace" -mindepth 2 -maxdepth 3 -name .git -type d 2>/dev/null | sed 's|/\.git$||'
36
+ } | while IFS= read -r repo; do
37
+ { git -C "$repo" worktree list --porcelain 2>/dev/null || true; } | while IFS= read -r line; do
38
+ case "$line" in
39
+ "worktree "*)
40
+ path="${line#worktree }"
41
+ [ -d "$path" ] || echo "$path"
42
+ ;;
43
+ esac
44
+ done
45
+ done || true
46
+ }
47
+
48
+ # Repair (#341): resumes the startup.sh sequence without the git identity nor
49
+ # the clusters. Each item is really repaired; ✔ or ✖ with the reason.
50
+ repair_item() {
51
+ local name="$1" output code reason
52
+ shift
53
+ if output="$("$@" 2>&1)"; then
54
+ echo "✔ $name"
55
+ else
56
+ code=$?
57
+ reason="$(printf '%s\n' "$output" | sed '/^[[:space:]]*$/d' | tail -1)"
58
+ [ -n "$reason" ] || reason="failed (code $code)"
59
+ echo "✖ $name : $reason"
60
+ repair_failed=1
61
+ fi
62
+ }
63
+
64
+ # Application repairs (#341): active services, ports and credentials; a failure
65
+ # does not stop the following ones.
66
+ repair_workstation() {
67
+ repair_failed=0
68
+ # Limited Kubernetes account token (#430): 24 h, renewed here; without the
69
+ # kubernetes module and without a services cluster, nothing to do
70
+ if [ "$(value_of kubernetes)" = on ] || [ -n "$(cluster_saved)" ]; then
71
+ repair_item "kubernetes account" bash "$ICI/kube-account.sh" jeton
72
+ fi
73
+ if [ "$(value_of gitlab)" = on ]; then
74
+ repair_item "gitlab name" bash "$ICI/gitlab/gitlab.sh" hote-poser
75
+ repair_item "gitlab relay" bash "$ICI/gitlab/gitlab.sh" relay-start
76
+ fi
77
+ if [ "$(value_of postgres)" = on ]; then
78
+ repair_item "postgres relay" bash "$ICI/postgres/postgres.sh" relay-start
79
+ fi
80
+ if [ "$(value_of argocd)" = on ]; then
81
+ repair_item "argocd relay" bash "$ICI/argocd/argocd.sh" relay-start
82
+ fi
83
+ if [ "$(value_of mysql)" = on ]; then
84
+ repair_item "mysql relay" bash "$ICI/catalog/mysql/mysql.sh" relay-start
85
+ fi
86
+ repair_item "ports relay" bash "$ICI/ports.sh" restart
87
+ # Kubernetes workspace (#517): no automatic port watcher
88
+ if ! in_pod; then
89
+ repair_item "ports auto watcher" env DEVZONE_PORTS_AUTO_REAL=yes bash "$ICI/ports-auto.sh" demarrer
90
+ fi
91
+ repair_item "catalog watcher" env DEVZONE_CATALOG_REAL=yes bash "$ICI/catalog/catalog-watcher.sh" demarrer
92
+ repair_item "credentials" bash "$ICI/password.sh" regenerer
93
+ return "$repair_failed"
94
+ }
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # devzone, services of the cluster and their apply functions.
4
+ # Sourced by .devcontainer/devzone (split of the 1 600 lines file, #722):
5
+ # functions only, shared variables are defined in devzone.
6
+
7
+ # Runs a long command, writing "still running" every DEVZONE_PROGRESS s on
8
+ # stderr: a silent installation looks blocked (#195)
9
+ with_progress() {
10
+ local step="${DEVZONE_PROGRESS:-30}" elapsed=0 pid code=0
11
+ "$@" &
12
+ pid=$!
13
+ while kill -0 "$pid" 2>/dev/null; do
14
+ sleep 1
15
+ elapsed=$((elapsed + 1))
16
+ if [ $((elapsed % step)) -eq 0 ] && kill -0 "$pid" 2>/dev/null; then
17
+ echo "devzone : … still running (${elapsed} s)" >&2
18
+ fi
19
+ done
20
+ wait "$pid" || code=$?
21
+ return "$code"
22
+ }
23
+
24
+ # File that marks an active module in failure (content: where to look); next to
25
+ # the state, in its volume: the state shows it at each startup
26
+ failure_marker_file() {
27
+ echo "$ETAT-failed-$1"
28
+ }
29
+
30
+ # Services in the Kubernetes workspace pod (#528): gitlab, postgres and argocd
31
+ # live in the cluster, installed from the workstation (devzone workspace
32
+ # services). The pod has no kubeconfig and a limited account (#430): their
33
+ # presence is the cluster DNS (like #515), never an installer failure marker.
34
+ in_pod() {
35
+ [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]
36
+ }
37
+
38
+ service_module() {
39
+ case "$1" in
40
+ gitlab | postgres | argocd) return 0 ;;
41
+ esac
42
+ return 1
43
+ }
44
+
45
+ # DNS name of the service of a module: <service>.<namespace>.svc
46
+ service_dns() {
47
+ case "$1" in
48
+ gitlab) echo "gitlab-webservice-default.devzone-gitlab${INSTANCE_SUFFIX}.svc" ;;
49
+ postgres) echo "postgres.devzone-postgres.svc" ;;
50
+ argocd) echo "argocd-server.devzone-argocd.svc" ;;
51
+ esac
52
+ }
53
+
54
+ service_present() {
55
+ getent hosts "$(service_dns "$1")" >/dev/null 2>&1
56
+ }
57
+
58
+ # Status line of a service module in the pod: present → active; absent → the
59
+ # workstation command that installs it
60
+ service_pod_line() {
61
+ local m="$1"
62
+ if service_present "$m"; then
63
+ printf ' ✔ module %-10s active: %s (%s)\n' "$m" "$(description "$m")" "$(service_dns "$m")"
64
+ elif [ "$(value_of "$m")" = on ]; then
65
+ printf ' ⚠ module %-10s not in the cluster: on the workstation, devzone workspace services enable %s\n' "$m" "$m"
66
+ else
67
+ printf ' ○ module %-10s optional, %s: on the workstation, devzone workspace services enable %s\n' "$m" "$(description "$m")" "$m"
68
+ fi
69
+ }
70
+
71
+ # devzone apply of a service module: in the Kubernetes workspace pod nothing
72
+ # is installed (the workstation does it, #528) and the failure marker of an
73
+ # earlier start is cleared; elsewhere, the installer of the module
74
+ apply_service() {
75
+ if in_pod; then
76
+ rm -f "$(failure_marker_file "$1")"
77
+ echo "devzone: $1 is installed from the workstation (devzone workspace services enable $1): nothing to do in the pod"
78
+ return 0
79
+ fi
80
+ "apply_$1" on
81
+ }
82
+
83
+ apply_kubernetes() {
84
+ if [ "$1" = on ]; then
85
+ bash "$ICI/kube-config.sh"
86
+ else
87
+ rm -f "$HOME/.kube/hote.config"
88
+ # metrics-server removed from the clusters where devzone installed it
89
+ # (devzone=installe marker set by metrics-server.sh); via its subcommand
90
+ bash "$ICI/metrics-server.sh" retirer || true
91
+ echo "devzone : kubernetes disabled"
92
+ fi
93
+ }
94
+
95
+ apply_gitlab() {
96
+ local current_state
97
+ if [ "$1" = on ]; then
98
+ # Skip if the state is ready and the runner online; otherwise install resumes
99
+ current_state="$(bash "$ICI/gitlab/gitlab.sh" status)"
100
+ if [[ "$current_state" == *"ready"* && "$current_state" == *"runner online"* ]]; then
101
+ echo "devzone : gitlab already active, nothing to do."
102
+ # /etc/hosts regenerated by Docker: gitlab.localhost is set again here too
103
+ bash "$ICI/gitlab/gitlab.sh" hote-poser
104
+ # Failure of an old run cleared: gitlab is ready (#366)
105
+ rm -f "$(failure_marker_file gitlab)"
106
+ else
107
+ echo "devzone : activating gitlab via its installer…"
108
+ if ! bash "$ICI/gitlab/gitlab.sh" install; then
109
+ echo "gitlab" > "$(failure_marker_file gitlab)"
110
+ return 1
111
+ fi
112
+ rm -f "$(failure_marker_file gitlab)"
113
+ fi
114
+ else
115
+ # Disable gitlab only if its namespace still exists
116
+ if bash "$ICI/gitlab/gitlab.sh" installe; then
117
+ echo "devzone : deactivating gitlab…"
118
+ if [ -n "${DELETE_DATA:-}" ]; then
119
+ bash "$ICI/gitlab/gitlab.sh" uninstall --yes
120
+ else
121
+ bash "$ICI/gitlab/gitlab.sh" uninstall
122
+ fi
123
+ else
124
+ echo "devzone : gitlab already deactivated (no devzone-gitlab namespace)."
125
+ fi
126
+ fi
127
+ }
128
+
129
+ # Shared PostgreSQL (#280): installed on the devzone cluster, chosen at the
130
+ # first activation (--context, terminal menu, dedicated kind otherwise)
131
+ apply_postgres() {
132
+ local wanted="" confirm_ctx="" expect="" arg ctx actual current_state
133
+ if [ "$1" = on ]; then
134
+ for arg in "${@:2}"; do
135
+ if [ -n "$expect" ]; then
136
+ case "$expect" in
137
+ context) wanted="$arg" ;;
138
+ confirm) confirm_ctx="$arg" ;;
139
+ esac
140
+ expect=""
141
+ continue
142
+ fi
143
+ case "$arg" in
144
+ --context) expect=context ;;
145
+ --confirm) expect=confirm ;;
146
+ *) echo "devzone : unknown argument: $arg (devzone enable postgres --context CTX [--confirm CTX])" >&2; write_value postgres off; return 2 ;;
147
+ esac
148
+ done
149
+ if [ -n "$expect" ]; then
150
+ echo "devzone : $expect expects a context" >&2
151
+ write_value postgres off
152
+ return 2
153
+ fi
154
+ actual="$(cluster_saved)"
155
+ if [ -n "$wanted" ] && [ -n "$actual" ] && [ "$wanted" != "$actual" ]; then
156
+ echo "devzone : devzone services are on $actual; to change: devzone cluster $wanted" >&2
157
+ write_value postgres off
158
+ return 2
159
+ fi
160
+ if [ -n "$confirm_ctx" ]; then
161
+ ctx="$(cluster_choose "$wanted" --confirm "$confirm_ctx")" || { write_value postgres off; return 2; }
162
+ else
163
+ ctx="$(cluster_choose "$wanted")" || { write_value postgres off; return 2; }
164
+ fi
165
+ # Choice kept before the installation: a resume targets the same cluster
166
+ cluster_save "$ctx"
167
+ current_state="$(bash "$ICI/postgres/postgres.sh" status)"
168
+ # "relay stopped" first: this line also starts with "ready on"
169
+ if [[ "$current_state" == *"relay stopped"* ]]; then
170
+ bash "$ICI/postgres/postgres.sh" relay-start
171
+ echo "devzone : postgres : relay restarted"
172
+ elif [[ "$current_state" == "ready on"* ]]; then
173
+ echo "devzone : postgres already active, nothing to do."
174
+ elif ! bash "$ICI/postgres/postgres.sh" install; then
175
+ echo "postgres" >"$(failure_marker_file postgres)"
176
+ return 1
177
+ fi
178
+ rm -f "$(failure_marker_file postgres)"
179
+ else
180
+ bash "$ICI/postgres/postgres.sh" uninstall
181
+ rm -f "$(failure_marker_file postgres)"
182
+ fi
183
+ }
184
+
185
+ # Argo CD (#411): installed in the services cluster, access through the relay
186
+ # 127.0.0.1:8443; a failure is marked in the state and resumed by devzone apply
187
+ apply_argocd() {
188
+ local current_state
189
+ if [ "$1" = on ]; then
190
+ current_state="$(bash "$ICI/argocd/argocd.sh" status)"
191
+ # "relay stopped" first: this line also starts with "ready"
192
+ if [[ "$current_state" == *"relay stopped"* ]]; then
193
+ bash "$ICI/argocd/argocd.sh" relay-start
194
+ echo "devzone : argocd : relay restarted"
195
+ elif [[ "$current_state" == "ready"* ]]; then
196
+ echo "devzone : argocd already active, nothing to do."
197
+ elif ! bash "$ICI/argocd/argocd.sh" install; then
198
+ echo "argocd" >"$(failure_marker_file argocd)"
199
+ return 1
200
+ fi
201
+ rm -f "$(failure_marker_file argocd)"
202
+ else
203
+ bash "$ICI/argocd/argocd.sh" uninstall
204
+ rm -f "$(failure_marker_file argocd)"
205
+ fi
206
+ }
207
+
208
+ # Catalog MySQL (#414): same logic as postgres (relay restarted if stopped),
209
+ # installation delegated to mysql.sh
210
+ apply_mysql() {
211
+ local current_state ctx
212
+ if [ "$1" = on ]; then
213
+ ctx="$(cluster_saved)"
214
+ if [ -z "$ctx" ]; then
215
+ echo "devzone : mysql: no cluster chosen: devzone enable mysql" >&2
216
+ write_value mysql off
217
+ echo mysql >"$(failure_marker_file mysql)"
218
+ return 2
219
+ fi
220
+ current_state="$(bash "$ICI/catalog/mysql/mysql.sh" status)"
221
+ # "relay stopped" first: this line also starts with "ready on"
222
+ if [[ "$current_state" == *"relay stopped"* ]]; then
223
+ bash "$ICI/catalog/mysql/mysql.sh" relay-start
224
+ echo "devzone : mysql: relay restarted"
225
+ elif [[ "$current_state" == "ready on"* ]]; then
226
+ echo "devzone : mysql already active, nothing to do."
227
+ elif ! bash "$ICI/catalog/mysql/mysql.sh" install; then
228
+ echo mysql >"$(failure_marker_file mysql)"
229
+ return 1
230
+ fi
231
+ rm -f "$(failure_marker_file mysql)"
232
+ else
233
+ # Removal without deleting the data: volume kept (#441); the databases
234
+ # only leave with a yes (confirm_removal)
235
+ bash "$ICI/catalog.sh" remove mysql
236
+ if [ -n "${DELETE_DATA:-}" ]; then
237
+ bash "$ICI/catalog/mysql/mysql.sh" delete-data --yes
238
+ fi
239
+ rm -f "$(failure_marker_file mysql)"
240
+ fi
241
+ }
@@ -0,0 +1,97 @@
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 ia -->'
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
+ }