devzone 0.42.1 → 0.44.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 (47) hide show
  1. package/.devcontainer/Dockerfile +1 -1
  2. package/.devcontainer/agent-local.sh +45 -0
  3. package/.devcontainer/agent-workspace.sh +2 -2
  4. package/.devcontainer/agent.sh +10 -10
  5. package/.devcontainer/argocd/catalogue-argocd.sh +4 -0
  6. package/.devcontainer/argocd/gitops-gitlab.sh +127 -0
  7. package/.devcontainer/argocd/gitops.sh +12 -2
  8. package/.devcontainer/argocd/services-hook.sh +211 -0
  9. package/.devcontainer/catalogue/app.sh +7 -8
  10. package/.devcontainer/catalogue/mysql/installer.sh +9 -8
  11. package/.devcontainer/catalogue/mysql/mysql.sh +2 -2
  12. package/.devcontainer/catalogue.sh +1 -1
  13. package/.devcontainer/chart-direct.sh +49 -0
  14. package/.devcontainer/devzone +22 -16
  15. package/.devcontainer/etat-json.sh +3 -3
  16. package/.devcontainer/gitlab/argocd.sh +54 -0
  17. package/.devcontainer/gitlab/chart.sh +39 -0
  18. package/.devcontainer/gitlab/gitlab.sh +11 -168
  19. package/.devcontainer/gitlab/installation.sh +25 -38
  20. package/.devcontainer/gitlab/seed.sh +204 -0
  21. package/.devcontainer/help.sh +2 -0
  22. package/.devcontainer/llm/llm.sh +250 -0
  23. package/.devcontainer/llm/opencode.sh +56 -0
  24. package/.devcontainer/llm/presets.sh +43 -0
  25. package/.devcontainer/postgres/postgres.sh +5 -3
  26. package/.devcontainer/services-admin.sh +19 -6
  27. package/.devcontainer/versions.env +1 -1
  28. package/README.md +57 -23
  29. package/charts/devzone-gitlab/Chart.lock +9 -0
  30. package/charts/devzone-gitlab/Chart.yaml +15 -0
  31. package/charts/devzone-gitlab/values.yaml +94 -0
  32. package/charts/devzone-llm/Chart.yaml +6 -0
  33. package/charts/devzone-llm/templates/deployment.yaml +97 -0
  34. package/charts/devzone-llm/templates/pvc.yaml +19 -0
  35. package/charts/devzone-llm/templates/service.yaml +18 -0
  36. package/charts/devzone-llm/values.yaml +46 -0
  37. package/charts/devzone-mysql/values.yaml +3 -3
  38. package/charts/devzone-postgres/values.yaml +2 -2
  39. package/manage/devzone +1 -1
  40. package/manage/scripts/check-charts.sh +67 -19
  41. package/manage/scripts/check-utf8-vars.sh +67 -0
  42. package/manage/scripts/services-workspace.sh +16 -6
  43. package/package.json +1 -1
  44. package/.devcontainer/catalogue/mysql/manifeste.yaml +0 -81
  45. package/.devcontainer/gitlab/runner-values.yaml +0 -27
  46. package/.devcontainer/gitlab/values.yaml +0 -83
  47. package/.devcontainer/postgres/postgres.yaml +0 -84
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env bash
2
+ # Seed of the GitLab of devzone (#396, #538): the data a fresh instance needs,
3
+ # group devzone, demo project, dev user, runner. Sourced by gitlab.sh. The
4
+ # installer starts the relays and waits for GitLab before the seed; the seed
5
+ # command (devzone gitlab seed, run in the pod by services-admin.sh when Argo
6
+ # CD holds the chart) does it itself (gitlab_seed_commande).
7
+ # gitlab_attendre_pret waits for the readiness of GitLab (GITLAB_ATTENTE)
8
+ # gitlab_seed group, project, user, runner token and its Secret
9
+ # gitlab_seed_commande devzone gitlab seed: relays, readiness, seed
10
+
11
+ # ---- Helper : attendre que GitLab soit prêt ----
12
+ gitlab_attendre_pret() {
13
+ local debut
14
+ debut=$(date +%s)
15
+ echo "▶ Attente de GitLab prêt (timeout ${GITLAB_ATTENTE}s)…"
16
+ while [ $(( $(date +%s) - debut )) -lt "$GITLAB_ATTENTE" ]; do
17
+ if curl -sf http://gitlab.localhost:8929/-/readiness >/dev/null 2>&1 || curl -sf http://gitlab.localhost:8929/users/sign_in >/dev/null 2>&1; then
18
+ echo "▶ GitLab prêt."
19
+ return 0
20
+ fi
21
+ sleep 5
22
+ done
23
+ echo "devzone : timeout attente GitLab." >&2
24
+ return 1
25
+ }
26
+
27
+ # ---- seed : peupler GitLab de données de base ----
28
+ gitlab_seed() {
29
+ echo "▶ Seed de GitLab…"
30
+
31
+ mkdir -p "$GITLAB_SECRETS_DIR"
32
+
33
+ # Mot de passe root lu dans le secret gitlab-gitlab-initial-root-password
34
+ local mot_de_passe
35
+ mot_de_passe="$(kubectl --context devzone get secret -n "$GITLAB_NS" gitlab-gitlab-initial-root-password -o jsonpath='{.data.password}' 2>/dev/null | base64 -d 2>/dev/null || true)"
36
+ if [ -z "$mot_de_passe" ]; then
37
+ echo "devzone : seed GitLab : secret root (gitlab-gitlab-initial-root-password) introuvable, arrêt du seed." >&2
38
+ return 1
39
+ fi
40
+ printf '%s' "$mot_de_passe" > "$GITLAB_SECRETS_DIR/root-password"
41
+ chmod 600 "$GITLAB_SECRETS_DIR/root-password"
42
+
43
+ # Token d'accès root créé par kubectl exec dans le pod toolbox avec gitlab-rails runner
44
+ local toolbox_pod root_token
45
+ toolbox_pod="$(kubectl --context devzone get pod -n "$GITLAB_NS" -l app=toolbox -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
46
+ if [ -z "$toolbox_pod" ]; then
47
+ echo "devzone : seed GitLab : pod toolbox (label app=toolbox) introuvable, arrêt du seed." >&2
48
+ return 1
49
+ fi
50
+ root_token="$(kubectl --context devzone exec -n "$GITLAB_NS" "$toolbox_pod" -- gitlab-rails runner 'puts User.find_by_username("root").personal_access_tokens.create(name: "devzone", scopes: ["api", "write_repository"], expires_at: 30.days.from_now).token' 2>/dev/null | tail -n 1 || true)"
51
+ if [ -z "$root_token" ]; then
52
+ echo "devzone : seed GitLab : création du jeton root (gitlab-rails runner) échouée, arrêt du seed." >&2
53
+ return 1
54
+ fi
55
+ printf '%s' "$root_token" > "$GITLAB_SECRETS_DIR/root-token"
56
+ chmod 600 "$GITLAB_SECRETS_DIR/root-token"
57
+
58
+ # Via l'API curl avec le token (jamais affiché en clair)
59
+ local token groupe_id
60
+ token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
61
+
62
+ # Groupe devzone (testé avant création)
63
+ if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" >/dev/null 2>&1; then
64
+ if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/groups" --data "name=devzone&path=devzone&visibility=private" >/dev/null 2>&1; then
65
+ echo "devzone : seed GitLab : création du groupe devzone échouée, arrêt du seed." >&2
66
+ return 1
67
+ fi
68
+ fi
69
+ groupe_id="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" | jq -r '.id // empty')"
70
+ if [ -z "$groupe_id" ]; then
71
+ echo "devzone : seed GitLab : lecture de l'identifiant numérique du groupe devzone échouée, arrêt du seed." >&2
72
+ return 1
73
+ fi
74
+
75
+ # Projet devzone/demo (testé avant création, namespace_id = ID numérique du groupe)
76
+ if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo" >/dev/null 2>&1; then
77
+ if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/projects" --data "name=demo&namespace_id=$groupe_id" >/dev/null 2>&1; then
78
+ echo "devzone : seed GitLab : création du projet devzone/demo échouée, arrêt du seed." >&2
79
+ return 1
80
+ fi
81
+ fi
82
+
83
+ # Utilisateur dev (testé avant création, mot de passe généré aléatoirement) :
84
+ # un dev-password existant n'est réutilisé que si l'utilisateur dev existe
85
+ # encore (vérifié via l'API) ; sinon il est recréé avec un utilisateur nouveau.
86
+ local users_json devpass
87
+ users_json="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/users?username=dev")"
88
+ if [ "$(jq length <<<"$users_json")" -eq 0 ]; then
89
+ devpass="$(openssl rand -base64 18 | tr -d '\n')"
90
+ if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/users" --data "email=dev@gitlab.localhost&username=dev&name=dev&skip_confirmation=true" --data-urlencode "password=$devpass" >/dev/null 2>&1; then
91
+ echo "devzone : seed GitLab : création de l'utilisateur dev échouée, arrêt du seed." >&2
92
+ return 1
93
+ fi
94
+ printf '%s' "$devpass" > "$GITLAB_SECRETS_DIR/dev-password"
95
+ chmod 600 "$GITLAB_SECRETS_DIR/dev-password"
96
+ fi
97
+
98
+ # Token de runner : vérifié via POST /api/v4/runners/verify ; un jeton valide
99
+ # est gardé, un jeton refusé (403/404) est recréé, GitLab injoignable arrête le seed.
100
+ local rt_jeton rt_code rt_token
101
+ if [ -f "$GITLAB_SECRETS_DIR/runner-token" ]; then
102
+ rt_jeton="$(cat "$GITLAB_SECRETS_DIR/runner-token")"
103
+ rt_code="$(curl -s -o /dev/null -w '%{http_code}' --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/runners/verify" --data "token=${rt_jeton}" || true)"
104
+ if [ "$rt_code" = "200" ]; then
105
+ echo "✔ Jeton de runner valide : gardé."
106
+ elif [ "$rt_code" = "403" ] || [ "$rt_code" = "404" ]; then
107
+ echo "devzone : jeton de runner d'une installation précédente refusé : recréé."
108
+ rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
109
+ if [ -z "$rt_token" ]; then
110
+ echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
111
+ return 1
112
+ fi
113
+ printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
114
+ chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
115
+ else
116
+ echo "devzone : seed GitLab : vérification du jeton de runner impossible (code ${rt_code}), arrêt du seed." >&2
117
+ return 1
118
+ fi
119
+ else
120
+ rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
121
+ if [ -z "$rt_token" ]; then
122
+ echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
123
+ return 1
124
+ fi
125
+ printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
126
+ chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
127
+ fi
128
+
129
+ # Secret of the runner of the chart (runners.secret, #538): created apart, out
130
+ # of Git; the token is read from its file, never on a command line
131
+ if ! kubectl --context devzone -n "$GITLAB_NS" create secret generic gitlab-runner-secret \
132
+ --from-file=runner-token="$GITLAB_SECRETS_DIR/runner-token" \
133
+ --from-literal=runner-registration-token= \
134
+ --dry-run=client -o yaml |
135
+ kubectl --context devzone -n "$GITLAB_NS" apply -f - >/dev/null 2>&1; then
136
+ echo "devzone : seed GitLab : secret gitlab-runner-secret non créé, arrêt du seed." >&2
137
+ return 1
138
+ fi
139
+ # A runner already running may hold the previous token: restarted on the
140
+ # one just written (no runner yet: nothing to restart)
141
+ kubectl --context devzone -n "$GITLAB_NS" rollout restart deployment \
142
+ --selector=app=gitlab-gitlab-runner >/dev/null 2>&1 || true
143
+
144
+ # Push du contenu de demo/ dans devzone/demo (dépôt git temporaire, remote http avec le jeton dans l'URL, jamais affiché ; branche main)
145
+ # Le push utilise le jeton root (write_repository) : le jeton de runner ne peut pas pousser.
146
+ local push_token=""
147
+ push_token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
148
+ if [ -z "$push_token" ]; then
149
+ echo "devzone : seed GitLab : jeton root introuvable, arrêt du seed." >&2
150
+ return 1
151
+ fi
152
+ # Déjà poussé (installation relancée) : rien à refaire
153
+ if curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
154
+ echo "✔ Seed GitLab terminé (projet demo déjà poussé)."
155
+ regenerer_identifiants
156
+ return 0
157
+ fi
158
+ if [ -d "$ICI/demo" ]; then
159
+ local tmpdir
160
+ tmpdir="$(mktemp -d)"
161
+ cp -r "$ICI/demo/." "$tmpdir/"
162
+ if (
163
+ cd "$tmpdir"
164
+ # Dépôt jetable du script : les hooks git globaux (repowarden) n'ont
165
+ # rien à vérifier ici et refuseraient le commit
166
+ export GIT_CONFIG_PARAMETERS="'core.hooksPath=/dev/null'"
167
+ git init -q -b main
168
+ git add -A
169
+ git -c user.email=dev@gitlab.localhost -c user.name=dev commit -q -m "chore: projet de démonstration"
170
+ # gitlab.localhost n'est pas toujours résolu par git : adresse
171
+ # locale, et l'hôte attendu par l'ingress passé en en-tête
172
+ git remote add origin "http://oauth2:${push_token}@127.0.0.1:8929/devzone/demo.git"
173
+ git -c http.extraHeader="Host: gitlab.localhost" push -q -u origin main >/dev/null 2>&1
174
+ ); then
175
+ # Vérifie le push : la branche main existe bien sur le projet
176
+ if ! curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
177
+ echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git réussi mais branche main absente, arrêt du seed." >&2
178
+ rm -rf "$tmpdir"
179
+ return 1
180
+ fi
181
+ else
182
+ echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git échoué, arrêt du seed." >&2
183
+ rm -rf "$tmpdir"
184
+ return 1
185
+ fi
186
+ rm -rf "$tmpdir"
187
+ fi
188
+
189
+ echo "✔ Seed GitLab terminé."
190
+ regenerer_identifiants
191
+ }
192
+
193
+ # devzone gitlab seed: the seed alone, when Argo CD holds the chart (the
194
+ # workstation runs it in the pod, services-admin.sh seed gitlab). The API and
195
+ # the push go through the relays: they start, GitLab is awaited, then the seed.
196
+ # The Rails secret of the pod is mirrored when it is not kept yet.
197
+ gitlab_seed_commande() {
198
+ gitlab_relais_lancer || return 1
199
+ gitlab_attendre_pret || return 1
200
+ gitlab_seed || return 1
201
+ if [ ! -f "$GITLAB_RAILS_FICHIER" ]; then
202
+ gitlab_secrets_copier
203
+ fi
204
+ }
@@ -26,6 +26,8 @@ devzone_aide() {
26
26
  devzone enable postgres [--context CTX] [--confirm CTX] shared PostgreSQL, cluster of choice
27
27
  devzone postgres create <project> database and user of a project (also: list, psql, delete)
28
28
  devzone mysql create <project> database and user of a MySQL project (also: list, delete)
29
+ devzone enable llm [--preset light] local code model (llama.cpp), devzone llm status
30
+ devzone llm status | delete-data [--yes] model and reachability | namespace and model removed
29
31
  devzone gitlab migrate [--yes] GitLab in the services cluster, then the old kind cluster deleted
30
32
  devzone gitlab new-password [root|dev] random password (root or dev) regenerated
31
33
  devzone enable argocd Argo CD in the services cluster, access https://127.0.0.1:8443
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/env bash
2
+ # Module llm (#586): local code model (llama.cpp llama-server, CPU) in the
3
+ # cluster of the services, namespace devzone-llm, chart charts/devzone-llm.
4
+ # llm.sh install [--preset default|light] [--context CTX]
5
+ # llm.sh uninstall release removed, the volume llm-models is kept
6
+ # llm.sh status | relay-start | relay-stop | policy (ingress from devzone-workspace)
7
+ # llm.sh preset [--preset P] preset stored for the next install (Argo CD path)
8
+ # llm.sh apply on|off [...] what `devzone enable|disable llm` runs
9
+ # llm.sh delete-data [--yes] namespace and volume removed (the model is downloaded again)
10
+ # First start = model download: LLM_ATTENTE (seconds, default 1800) is the wait.
11
+ # The relay LLM_PORT (default 8089) reaches the service. The opencode provider is
12
+ # opencode.sh. bash 3.2 (macOS).
13
+ set -euo pipefail
14
+
15
+ ICI="$(cd "$(dirname "$0")" && pwd)"
16
+ RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$ICI")")}"
17
+ # shellcheck disable=SC2034 # read by cluster.sh (sourced library)
18
+ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
19
+ # shellcheck source=SCRIPTDIR/../cluster.sh
20
+ # shellcheck disable=SC1091
21
+ . "$ICI/../cluster.sh"
22
+ # shellcheck source=SCRIPTDIR/../chart-direct.sh
23
+ # shellcheck disable=SC1091
24
+ . "$ICI/../chart-direct.sh"
25
+ # shellcheck source=SCRIPTDIR/../isolement.sh
26
+ # shellcheck disable=SC1091
27
+ . "$ICI/../isolement.sh"
28
+ # shellcheck source=SCRIPTDIR/presets.sh
29
+ # shellcheck disable=SC1091
30
+ . "$ICI/presets.sh"
31
+
32
+ NS=devzone-llm
33
+ STATE_DIR="$RACINE/workspace/.llm"
34
+ LLM_PORT="${LLM_PORT:-8089}"
35
+ LLM_ATTENTE="${LLM_ATTENTE:-1800}"
36
+ LLM_SIZE="${LLM_SIZE:-8Gi}"
37
+
38
+ refuse() { echo "devzone: llm: $*" >&2; exit 2; }
39
+
40
+ k() { kubectl --context devzone -n "$NS" "$@"; }
41
+
42
+ installed() { compte_admin "$(compte_ctx)" get namespace "$NS" >/dev/null 2>&1; }
43
+
44
+ # Preset stored by the last install, "default" without one
45
+ preset_read() {
46
+ local p
47
+ p="$(cat "$STATE_DIR/preset" 2>/dev/null || true)"
48
+ llm_preset_name "$p" 2>/dev/null || echo default
49
+ }
50
+
51
+ # --preset P and --context C of the arguments: PRESET and WANTED_CTX are set
52
+ parse_args() {
53
+ local want="" arg
54
+ PRESET=""
55
+ WANTED_CTX=""
56
+ for arg in "$@"; do
57
+ if [ -n "$want" ]; then
58
+ case "$want" in
59
+ preset) PRESET="$arg" ;;
60
+ context) WANTED_CTX="$arg" ;;
61
+ esac
62
+ want=""
63
+ continue
64
+ fi
65
+ case "$arg" in
66
+ --preset) want=preset ;;
67
+ --context) want=context ;;
68
+ *) refuse "unknown argument: $arg (devzone enable llm [--preset light] [--context CTX])" ;;
69
+ esac
70
+ done
71
+ [ -z "$want" ] || refuse "--$want needs a value"
72
+ if [ -n "$PRESET" ]; then
73
+ PRESET="$(llm_preset_name "$PRESET")" || refuse "unknown preset (default or light)"
74
+ fi
75
+ }
76
+
77
+ # Stores the preset: the explicit one, else the one already stored
78
+ preset_store() {
79
+ parse_args "$@"
80
+ [ -n "$PRESET" ] || PRESET="$(preset_read)"
81
+ mkdir -p "$STATE_DIR"
82
+ printf '%s\n' "$PRESET" >"$STATE_DIR/preset"
83
+ }
84
+
85
+ # Ingress from the workspace namespace (the pod of the workspace reaches
86
+ # llm:8080), next to the same-namespace rule of namespace_isoler
87
+ policy() {
88
+ kubectl --context devzone -n "$NS" apply -f - >/dev/null <<YAML
89
+ apiVersion: networking.k8s.io/v1
90
+ kind: NetworkPolicy
91
+ metadata:
92
+ name: devzone-llm-workspace
93
+ labels:
94
+ app.kubernetes.io/managed-by: devzone
95
+ spec:
96
+ podSelector: {}
97
+ ingress:
98
+ - from:
99
+ - namespaceSelector:
100
+ matchLabels:
101
+ kubernetes.io/metadata.name: devzone-workspace
102
+ YAML
103
+ }
104
+
105
+ # Waits for the deployment, a progress line each minute (the model is
106
+ # downloaded on the first start)
107
+ wait_ready() {
108
+ local waited=0 step=60
109
+ echo "▶ Waiting for the model (first start: download, several minutes; timeout ${LLM_ATTENTE}s, LLM_ATTENTE)…"
110
+ while [ "$waited" -lt "$LLM_ATTENTE" ]; do
111
+ if k rollout status deployment/llm --timeout="${step}s" >/dev/null 2>&1; then
112
+ return 0
113
+ fi
114
+ waited=$((waited + step))
115
+ echo " … ${waited}s/${LLM_ATTENTE}s: model not ready yet"
116
+ done
117
+ echo "devzone: llm: not ready after ${LLM_ATTENTE}s: kubectl --context devzone -n $NS logs deploy/llm -c fetch-model" >&2
118
+ return 1
119
+ }
120
+
121
+ install() {
122
+ local ctx sets
123
+ local -a args
124
+ preset_store "$@"
125
+ ctx="$(cluster_lu)"
126
+ if [ -z "$ctx" ]; then
127
+ ctx="$(cluster_choisir "$WANTED_CTX")" || return 2
128
+ cluster_ecrire "$ctx"
129
+ fi
130
+ cluster_preparer "$ctx"
131
+ contexte_devzone_poser "$ctx" || { echo "devzone: llm: cannot set the devzone context on $ctx" >&2; return 1; }
132
+ echo "▶ Local model on the cluster $ctx (namespace $NS, preset $(preset_read))…"
133
+ compte_namespace "$ctx" "$NS"
134
+ namespace_isoler "$NS" >/dev/null
135
+ policy
136
+ sets="$(llm_preset_sets "$(preset_read)") size=$LLM_SIZE"
137
+ read -r -a args <<<"$sets"
138
+ chart_install llm "$NS" "${args[@]}" || return 1
139
+ wait_ready || return 1
140
+ relais_arreter llm
141
+ relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
142
+ bash "$ICI/opencode.sh" set
143
+ echo "✔ Local model ready: http://llm.$NS.svc.cluster.local:8080/v1 (127.0.0.1:$LLM_PORT here)"
144
+ }
145
+
146
+ # The release leaves, the volume (model) and the namespace stay
147
+ uninstall() {
148
+ local ctx
149
+ ctx="$(cluster_lu)"
150
+ relais_arreter llm
151
+ bash "$ICI/opencode.sh" unset
152
+ if [ -n "$ctx" ] && installed; then
153
+ contexte_devzone_poser "$ctx" || true
154
+ helm --kube-context devzone uninstall llm -n "$NS" >/dev/null 2>&1 || true
155
+ echo "✔ llm removed from $ctx; volume llm-models kept (devzone llm delete-data removes it)"
156
+ fi
157
+ }
158
+
159
+ delete_data() {
160
+ local ctx yes="" answer
161
+ ctx="$(cluster_lu)"
162
+ [ "${1:-}" != --yes ] || yes=1
163
+ installed || { echo "devzone: llm: nothing to delete"; return 0; }
164
+ if [ -z "$yes" ]; then
165
+ cluster_interactif || refuse "no terminal: devzone llm delete-data --yes"
166
+ printf 'Delete the namespace %s and the downloaded model? [y/N] ' "$NS" >&2
167
+ read -r answer || answer=""
168
+ case "$answer" in y | Y | yes | o | O | oui) ;; *) echo "Aborted: nothing deleted."; return 0 ;; esac
169
+ fi
170
+ uninstall
171
+ compte_retirer "$ctx" "$NS" >/dev/null 2>&1 || true
172
+ compte_admin "$ctx" delete namespace "$NS" --wait=true >/dev/null
173
+ cluster_liberer "$ctx"
174
+ echo "✔ namespace $NS and model volume deleted"
175
+ }
176
+
177
+ status() {
178
+ local ctx mem
179
+ ctx="$(cluster_lu)"
180
+ if [ -z "$ctx" ] || ! installed; then
181
+ echo "disabled"
182
+ return 0
183
+ fi
184
+ if [ "$(k get deployment llm -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
185
+ echo "not ready on $ctx: starting (first download) or failed, devzone apply"
186
+ return 0
187
+ fi
188
+ mem="$(k get deployment llm -o jsonpath='{.spec.template.spec.containers[0].resources.limits.memory}' 2>/dev/null || true)"
189
+ if relais_actif llm; then
190
+ echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, reachable 127.0.0.1:$LLM_PORT"
191
+ else
192
+ echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, relay stopped: devzone apply"
193
+ fi
194
+ }
195
+
196
+ relay_start() {
197
+ local ctx
198
+ ctx="$(cluster_lu)"
199
+ if [ -n "$ctx" ] && installed; then
200
+ relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
201
+ fi
202
+ }
203
+
204
+ # Writes llm=off in the state file (bad argument, no cluster)
205
+ state_off() {
206
+ [ -f "$ETAT" ] || return 0
207
+ grep -v '^llm=' "$ETAT" >"$ETAT.tmp" || true
208
+ echo "llm=off" >>"$ETAT.tmp"
209
+ mv "$ETAT.tmp" "$ETAT"
210
+ }
211
+
212
+ # What `devzone enable|disable llm` runs: on installs (or restarts the relay),
213
+ # off removes the release; a failure leaves a marker read by devzone status
214
+ apply() {
215
+ local action="${1:-}" current marker="$ETAT-echec-llm"
216
+ shift || true
217
+ if [ "$action" = on ]; then
218
+ current="$(status)"
219
+ if [[ "$current" == *"relay stopped"* ]]; then
220
+ relay_start
221
+ echo "devzone: llm: relay restarted"
222
+ elif [[ "$current" == "ready on"* ]]; then
223
+ bash "$ICI/opencode.sh" set && echo "devzone: llm already active, nothing to do."
224
+ elif ! bash "${BASH_SOURCE[0]}" install "$@"; then
225
+ state_off
226
+ echo llm >"$marker"
227
+ return 1
228
+ fi
229
+ rm -f "$marker"
230
+ else
231
+ uninstall
232
+ rm -f "$marker"
233
+ fi
234
+ }
235
+
236
+ case "${1:-}" in
237
+ install) install "${@:2}" ;;
238
+ uninstall) uninstall ;;
239
+ status) status ;;
240
+ preset) preset_store "${@:2}" ;;
241
+ policy) policy ;;
242
+ apply) apply "${@:2}" ;;
243
+ delete-data) delete_data "${2:-}" ;;
244
+ relay-start) relay_start ;;
245
+ relay-stop) relais_arreter llm ;;
246
+ *)
247
+ echo "devzone llm: status | delete-data [--yes]" >&2
248
+ exit 1
249
+ ;;
250
+ esac
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bash
2
+ # opencode provider of the local model (#586), in a file apart managed by devzone:
3
+ # opencode.sh set provider devzone-llm (model local) put in the config
4
+ # opencode.sh unset provider removed (the rest of the file is kept)
5
+ # opencode.sh url base URL of the model seen from here
6
+ # File: ~/.config/opencode/config.json. opencode (1.19) reads it on its own, for
7
+ # the interactive session and for `opencode run`, with no environment variable,
8
+ # before opencode.json(c) (devzone enable ia) and OPENCODE_CONFIG_CONTENT (devzone
9
+ # agent), which keep the priority; providers merge, nothing of ia is replaced.
10
+ # URL: cluster DNS in the Kubernetes workspace pod, the relay of the container
11
+ # (127.0.0.1:LLM_PORT) elsewhere. bash 3.2 (macOS).
12
+ set -euo pipefail
13
+
14
+ FILE="$HOME/.config/opencode/config.json"
15
+
16
+ base_url() {
17
+ if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
18
+ echo "http://llm.devzone-llm.svc.cluster.local:8080/v1"
19
+ else
20
+ echo "http://127.0.0.1:${LLM_PORT:-8089}/v1"
21
+ fi
22
+ }
23
+
24
+ # jq program $1 applied to the file (or {}), written back atomically
25
+ rewrite() {
26
+ local current="{}" out
27
+ [ ! -f "$FILE" ] || current="$(cat "$FILE")"
28
+ mkdir -p "$(dirname "$FILE")"
29
+ out="$(printf '%s' "$current" | jq --arg url "$(base_url)" "$1")" || {
30
+ echo "devzone: llm: $FILE is not valid JSON: provider not touched" >&2
31
+ return 1
32
+ }
33
+ # Nothing left but the schema: the file was ours, it goes
34
+ if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ] && [ "$1" != "$SET" ]; then
35
+ rm -f "$FILE"
36
+ else
37
+ printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
38
+ fi
39
+ }
40
+
41
+ # shellcheck disable=SC2016 # jq programs, $url is a jq variable
42
+ SET='."$schema" = (."$schema" // "https://opencode.ai/config.json")
43
+ | .provider["devzone-llm"] = {npm: "@ai-sdk/openai-compatible", name: "devzone local model",
44
+ options: {baseURL: $url}, models: {local: {name: "Local code model"}}}'
45
+ # shellcheck disable=SC2016
46
+ UNSET='if .provider then del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
47
+
48
+ case "${1:-}" in
49
+ set) rewrite "$SET" ;;
50
+ unset) [ ! -f "$FILE" ] || rewrite "$UNSET" ;;
51
+ url) base_url ;;
52
+ *)
53
+ echo "usage: opencode.sh set|unset|url" >&2
54
+ exit 1
55
+ ;;
56
+ esac
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env bash
2
+ # Presets of the local model (#586), sourced by llm.sh and argocd/services-hook.sh.
3
+ # The values are the ones documented in charts/devzone-llm/values.yaml: the
4
+ # Hugging Face URL is pinned to a commit (resolve/<commit>) and the sha256 is
5
+ # the one of the file, checked by the init container of the chart.
6
+ # llm_preset_name <name> canonical preset (default | light), 1 when unknown
7
+ # llm_preset_sets <name> helm parameters key=value, space separated
8
+ # llm_preset_file <name> file name of the model of the preset
9
+ # bash 3.2 (macOS).
10
+
11
+ LLM_HF_7B="https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/13fb94bfda8c8cf22497dc57b78f391a9acb426a"
12
+ LLM_HF_3B="https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct-GGUF/resolve/f74adce6aa16316c625447af059dbebe4983757c"
13
+
14
+ llm_preset_name() {
15
+ case "${1:-}" in
16
+ "" | default | qwen2.5-coder-7b-instruct-q4_k_m) echo default ;;
17
+ light | qwen2.5-coder-3b-instruct-q4_k_m) echo light ;;
18
+ *) return 1 ;;
19
+ esac
20
+ }
21
+
22
+ llm_preset_file() {
23
+ case "$(llm_preset_name "${1:-}")" in
24
+ default) echo qwen2.5-coder-7b-instruct-q4_k_m.gguf ;;
25
+ light) echo qwen2.5-coder-3b-instruct-q4_k_m.gguf ;;
26
+ esac
27
+ }
28
+
29
+ llm_preset_sets() {
30
+ local name file
31
+ name="$(llm_preset_name "${1:-}")" || return 1
32
+ file="$(llm_preset_file "$name")"
33
+ case "$name" in
34
+ default)
35
+ printf 'model.url=%s/%s model.file=%s model.sha256=%s' "$LLM_HF_7B" "$file" "$file" \
36
+ 509287f78cb4d4cf6b3843734733b914b2c158e43e22a7f4bf5e963800894d3c
37
+ ;;
38
+ light)
39
+ printf 'model.url=%s/%s model.file=%s model.sha256=%s memory=3Gi resources.limits.memory=4Gi contextSize=16384' \
40
+ "$LLM_HF_3B" "$file" "$file" 724fb256bec1ff062b2f65e4569e871ad2e95ab2a3989723d1769c54294730b7
41
+ ;;
42
+ esac
43
+ }
@@ -18,6 +18,9 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
18
18
  # shellcheck source=SCRIPTDIR/../password.sh
19
19
  # shellcheck disable=SC1091
20
20
  . "$ICI/../password.sh"
21
+ # shellcheck source=SCRIPTDIR/../chart-direct.sh
22
+ # shellcheck disable=SC1091
23
+ . "$ICI/../chart-direct.sh"
21
24
  # Isolation réseau : namespace_isoler, d'où viennent les NetworkPolicies
22
25
  # shellcheck source=SCRIPTDIR/../isolement.sh
23
26
  # shellcheck disable=SC1091
@@ -126,8 +129,7 @@ installer() {
126
129
  # Compte limité autorisé dans le namespace : RoleBinding vers edit
127
130
  compte_autoriser "$CTX" "$NS"
128
131
  secret_admin
129
- sed "s/__TAILLE__/$POSTGRES_TAILLE/" "$ICI/postgres.yaml" |
130
- kubectl --context devzone apply -f - >/dev/null
132
+ chart_install postgres "$NS" "size=$POSTGRES_TAILLE" || return 1
131
133
  echo "▶ Attente de PostgreSQL (timeout ${POSTGRES_ATTENTE}s)…"
132
134
  if ! k rollout status statefulset/postgres --timeout="${POSTGRES_ATTENTE}s" >/dev/null; then
133
135
  echo "devzone : postgres : pas prêt après ${POSTGRES_ATTENTE}s : kubectl --context $CTX -n $NS describe pod postgres-0" >&2
@@ -151,7 +153,7 @@ desinstaller() {
151
153
  echo "devzone : postgres : contexte devzone non posé sur $CTX ; nettoyage local seulement" >&2
152
154
  fi
153
155
  if [ -n "$CTX" ] && installe; then
154
- echo "▶ Suppression de PostgreSQL et de toutes ses bases sur $CTX…"
156
+ echo "▶ Suppression de PostgreSQL et de toutes ses bases sur ${CTX}…"
155
157
  # RoleBinding retiré puis namespace supprimé par l'administrateur (#430)
156
158
  compte_retirer "$CTX" "$NS" >/dev/null 2>&1 || true
157
159
  compte_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Installs or removes a devzone service (gitlab, postgres, argocd) from inside
2
+ # Installs or removes a devzone service (gitlab, postgres, argocd, llm) from inside
3
3
  # the Kubernetes workspace pod, with a temporary administrator token (#528).
4
4
  # services-admin.sh enable|disable <service> [options of devzone enable]
5
+ # services-admin.sh seed gitlab data of gitlab seeded again, in the pod (#538)
5
6
  # Run by the workstation (manage/scripts/services-workspace.sh) through
6
7
  # kubectl exec -i: the token comes on stdin, is never printed and lives only
7
8
  # in a temporary kubeconfig removed at the end.
@@ -17,6 +18,9 @@
17
18
  set -euo pipefail
18
19
 
19
20
  HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21
+ # The devzone command beside this script, not the one of the PATH: the copy
22
+ # that runs the installers is the one of this folder (#591)
23
+ DEVZONE_CMD="$HERE/devzone"
20
24
  RACINE="${DEVZONE_RACINE:-$(dirname "$HERE")}"
21
25
  ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
22
26
  SA_DIR="${DEVZONE_SA_DIR:-/var/run/secrets/kubernetes.io/serviceaccount}"
@@ -39,12 +43,17 @@ service="${2:-}"
39
43
  case "$action" in
40
44
  enable | activer) action=enable ;;
41
45
  disable | desactiver) action=disable ;;
42
- *) refuse "usage: services-admin.sh enable|disable gitlab|postgres|argocd [options]" ;;
46
+ seed) ;;
47
+ *) refuse "usage: services-admin.sh enable|disable|seed gitlab|postgres|argocd|llm [options]" ;;
43
48
  esac
44
49
  case "$service" in
45
- gitlab | postgres | argocd) ;;
46
- *) refuse "unknown service: ${service:-(none)} (gitlab, postgres, argocd)" ;;
50
+ gitlab | postgres | argocd | llm) ;;
51
+ *) refuse "unknown service: ${service:-(none)} (gitlab, postgres, argocd, llm)" ;;
47
52
  esac
53
+ # The seed of the data (group, demo project, dev user, runner) is gitlab's (#538)
54
+ if [ "$action" = seed ] && [ "$service" != gitlab ]; then
55
+ refuse "seed: only gitlab"
56
+ fi
48
57
  [ "${DEVZONE_WORKSPACE:-}" = kubernetes ] || refuse "only in the Kubernetes workspace pod"
49
58
  [ -f "$SA_DIR/ca.crt" ] || refuse "cluster CA not found: $SA_DIR/ca.crt"
50
59
  if [ -t 0 ]; then
@@ -62,7 +71,7 @@ cluster_before="$(grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f
62
71
  # cluster line of the state as before
63
72
  cleanup() {
64
73
  rm -f "$kubeconfig"
65
- devzone "$service" relay-stop >/dev/null 2>&1 || true
74
+ "$DEVZONE_CMD" "$service" relay-stop >/dev/null 2>&1 || true
66
75
  if [ -n "$cluster_before" ]; then
67
76
  etat_ecrire cluster "$cluster_before" || true
68
77
  else
@@ -102,4 +111,8 @@ export DEVZONE_KUBE_CONFIG="$kubeconfig"
102
111
  export DEVZONE_SERVICES_ADMIN=1
103
112
  etat_ecrire cluster "$ADMIN_CONTEXT" || refuse "cannot write the state: $ETAT"
104
113
  echo "devzone services: $action $service in the cluster of the pod (temporary administrator)"
105
- devzone "$action" "$service" "${@:3}"
114
+ case "$action" in
115
+ # The seed is a module command: devzone gitlab seed (#538)
116
+ seed) "$DEVZONE_CMD" gitlab seed "${@:3}" ;;
117
+ *) "$DEVZONE_CMD" "$action" "$service" "${@:3}" ;;
118
+ esac
@@ -1,5 +1,5 @@
1
1
  # Single source for the repowarden version used by post-create.sh and workspace-init.sh.
2
- REPOWARDEN_VERSION=4.17.2
2
+ REPOWARDEN_VERSION=4.17.4
3
3
 
4
4
  # BuildKit client version installed in the workspace image (#514). Must match
5
5
  # buildkit.image in charts/devzone-workspace/values.yaml.