devzone 0.40.0 → 0.42.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 (30) hide show
  1. package/.devcontainer/agent-workspace.sh +22 -8
  2. package/.devcontainer/argocd/catalogue-argocd.sh +1 -0
  3. package/.devcontainer/argocd/services.sh +16 -0
  4. package/.devcontainer/catalogue/mysql/manifeste.yaml +4 -0
  5. package/.devcontainer/devzone +2 -0
  6. package/.devcontainer/postgres/postgres.yaml +4 -0
  7. package/.devcontainer/ticket.sh +101 -0
  8. package/README.md +1 -1
  9. package/charts/devzone-mysql/templates/service.yaml +2 -0
  10. package/charts/devzone-mysql/templates/statefulset.yaml +2 -0
  11. package/charts/devzone-postgres/templates/service.yaml +3 -1
  12. package/charts/devzone-postgres/templates/statefulset.yaml +5 -3
  13. package/charts/devzone-postgres/values.yaml +6 -1
  14. package/charts/devzone-workspace/Chart.yaml +1 -1
  15. package/charts/devzone-workspace/templates/networkpolicy.yaml +4 -0
  16. package/charts/devzone-workspace/templates/role.yaml +4 -0
  17. package/charts/devzone-workspace/templates/rolebinding.yaml +4 -0
  18. package/charts/devzone-workspace/templates/service.yaml +4 -0
  19. package/charts/devzone-workspace/templates/serviceaccount.yaml +4 -0
  20. package/charts/devzone-workspace/templates/statefulset.yaml +4 -0
  21. package/manage/devzone +2 -2
  22. package/manage/scripts/argocd-services-svc.sh +2 -0
  23. package/manage/scripts/argocd-services.sh +1 -0
  24. package/manage/scripts/argocd-workspace.sh +7 -1
  25. package/manage/scripts/check-charts.sh +158 -0
  26. package/manage/scripts/kube-ready.sh +54 -10
  27. package/manage/scripts/workspace-clone.sh +77 -0
  28. package/manage/scripts/workspace-copies.sh +74 -0
  29. package/manage/workspace.sh +14 -9
  30. package/package.json +1 -1
@@ -49,18 +49,31 @@ workspace_disponible() {
49
49
  }
50
50
 
51
51
  # Lance la consigne dans le pod, puis rapatrie son journal même en échec.
52
+ # Un chemin /workspaces/projets/... absent du poste désigne un dossier du pod
53
+ # (clone ou worktree de devzone ticket, #558) : rien n'est copié.
52
54
  agent_workspace() {
53
- local dossier="$1" consigne="$2" nom journal code=0
55
+ local dossier="$1" consigne="$2" nom journal code=0 dans_pod=""
54
56
  local racine_pod=/home/vscode/.local/share/devzone
55
- [ -d "$dossier" ] || refuse "dossier introuvable : $dossier (cherché depuis $(pwd))"
56
- nom="$(basename "$(cd "$dossier" && pwd -P)")"
57
- if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "/workspaces/projets/$nom" 2>/dev/null; then
58
- refuse "projet $nom absent du workspace Kubernetes : devzone workspace copier-vers $dossier (sur la machine), ou --local"
57
+ case "$dossier" in
58
+ /workspaces/projets/*) [ -d "$dossier" ] || dans_pod="$dossier" ;;
59
+ esac
60
+ if [ -n "$dans_pod" ]; then
61
+ nom="$(basename "$dans_pod")"
62
+ if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$dans_pod" 2>/dev/null; then
63
+ refuse "dossier introuvable dans le pod : $dans_pod (devzone workspace clone, puis devzone ticket <n> dans le pod)"
64
+ fi
65
+ else
66
+ [ -d "$dossier" ] || refuse "dossier introuvable : $dossier (cherché depuis $(pwd))"
67
+ nom="$(basename "$(cd "$dossier" && pwd -P)")"
68
+ dans_pod="/workspaces/projets/$nom"
69
+ if ! agent_kc exec devzone-workspace-0 -c workspace -- test -d "$dans_pod" 2>/dev/null; then
70
+ refuse "projet $nom absent du workspace Kubernetes : devzone workspace copier-vers $dossier (sur la machine), ou --local"
71
+ fi
59
72
  fi
60
- echo "devzone agent : workspace Kubernetes (pod devzone-workspace-0, /workspaces/projets/$nom) ; --local pour le conteneur"
73
+ echo "devzone agent : workspace Kubernetes (pod devzone-workspace-0, $dans_pod) ; --local pour le conteneur"
61
74
  agent_kc cp "$consigne" "devzone-workspace-0:/tmp/devzone-agent-$nom.md" -c workspace
62
- agent_kc exec devzone-workspace-0 -c workspace -- env DEVZONE_RACINE="$racine_pod" bash -lc 'devzone agent "$1" "$2"' _ "/workspaces/projets/$nom" "/tmp/devzone-agent-$nom.md" || code=$?
63
- journal="$(journal_de "$dossier")"
75
+ agent_kc exec devzone-workspace-0 -c workspace -- env DEVZONE_RACINE="$racine_pod" bash -lc 'devzone agent "$1" "$2"' _ "$dans_pod" "/tmp/devzone-agent-$nom.md" || code=$?
76
+ journal="$(journal_de "$nom")"
64
77
  mkdir -p "$(dirname "$journal")"
65
78
  if ! agent_kc exec devzone-workspace-0 -c workspace -- cat "$racine_pod/workspace/.agents/$nom.log" >>"$journal"; then
66
79
  echo "=== journal du pod introuvable" >>"$journal"
@@ -73,6 +86,7 @@ agent_aide() {
73
86
  usage : devzone agent [--local] <dossier> <fichier-consigne>
74
87
  lance opencode sur la consigne, modèles gratuits en rotation
75
88
  workspace Kubernetes d'abord s'il tourne ; --local : ce conteneur
89
+ un chemin /workspaces/projets/... absent d'ici est un dossier du pod, sans copie
76
90
  devzone agent etat
77
91
  sessions connues et modèles écartés
78
92
  devzone agent liberer [<modèle>|--tous]
@@ -88,6 +88,7 @@ catalogue_argocd_active() {
88
88
  catalogue_argocd_apply() {
89
89
  local app="$1" ns="$2" image="$3" port="$4" memory="$5" size="$6" params extra="${7:-}"
90
90
  catalogue_argocd_load
91
+ chart_require "$app" || return $?
91
92
  params="image=$image port=$port memory=$memory size=$size"
92
93
  [ -n "$extra" ] && params="$params $extra"
93
94
  # shellcheck disable=SC2086
@@ -17,6 +17,7 @@
17
17
  # services_reconcile every service applied or released
18
18
  # services_state_of <svc> on | off | empty (not declared)
19
19
  # services_note <svc> on|off writes the [services] section
20
+ # chart_require <svc> chart charts/devzone-<svc> named devzone-<svc>, or code 2
20
21
  # Sourced after conf.sh and gitops.sh by the workstation
21
22
  # (manage/scripts/argocd-services.sh) and by the container (argocd.sh). The
22
23
  # includer defines argocd_kubectl, APPS_GENERATOR, ARGOCD_CONF and
@@ -35,6 +36,18 @@ services_app_of() { printf 'devzone-%s' "$1"; }
35
36
  # Used by services_namespace_prepare and services_application_apply.
36
37
  services_ns_of() { printf 'devzone-%s' "$1"; }
37
38
 
39
+ # The chart of a service, charts/devzone-<svc> of RACINE (the package), must
40
+ # exist and name itself devzone-<svc> in Chart.yaml. Otherwise a refusal, code
41
+ # 2, before anything is applied (#554)
42
+ chart_require() {
43
+ local svc="$1" chart="$RACINE/charts/devzone-$1"
44
+ if [ -f "$chart/Chart.yaml" ] && grep -qxF "name: devzone-$svc" "$chart/Chart.yaml"; then
45
+ return 0
46
+ fi
47
+ echo "✖ $svc : chart charts/devzone-$svc missing or misnamed (manage/docs/reference.md#charts-de-devzone)" >&2
48
+ return 2
49
+ }
50
+
38
51
  # State of a service: [services] of .argocd.conf first, then the line
39
52
  # <svc>=on|off of .devzone.modules (compatibility, #538); empty when neither
40
53
  # holds the service
@@ -92,6 +105,7 @@ EOF
92
105
  # repository at the revision; the parameters hook adds helm parameters
93
106
  services_application_apply() {
94
107
  local svc="$1" extra=""
108
+ chart_require "$svc" || return $?
95
109
  set -- "$(services_app_of "$svc")" service "$(services_ns_of "$svc")" \
96
110
  "$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-$svc"
97
111
  if command -v "services_chart_$svc" >/dev/null 2>&1; then
@@ -118,6 +132,8 @@ services_reconcile() {
118
132
  state="$(services_state_of "$svc")"
119
133
  case "$state" in
120
134
  on)
135
+ # Before the namespace and the secret: a misnamed chart applies nothing
136
+ chart_require "$svc" || { code=2; continue; }
121
137
  services_namespace_prepare "$svc" || code=1
122
138
  if command -v "services_secret_$svc" >/dev/null 2>&1; then
123
139
  "services_secret_$svc" || code=1
@@ -11,6 +11,8 @@ metadata:
11
11
  namespace: __NS__
12
12
  labels:
13
13
  app: __APP__
14
+ app.kubernetes.io/name: __APP__
15
+ app.kubernetes.io/part-of: devzone
14
16
  app.kubernetes.io/managed-by: devzone
15
17
  spec:
16
18
  selector:
@@ -27,6 +29,8 @@ metadata:
27
29
  namespace: __NS__
28
30
  labels:
29
31
  app: __APP__
32
+ app.kubernetes.io/name: __APP__
33
+ app.kubernetes.io/part-of: devzone
30
34
  app.kubernetes.io/managed-by: devzone
31
35
  spec:
32
36
  serviceName: __APP__
@@ -16,6 +16,7 @@
16
16
  # devzone test-bash32 lance les tests bats sous bash 3.2 (conteneur Docker)
17
17
  # devzone test-gitlab essai de bout en bout du module et de la plateforme GitLab
18
18
  # devzone agent <dossier> <fichier-consigne> dirige opencode sur une consigne
19
+ # devzone ticket <n> [--repo devzone|repowarden] worktree du ticket (ticket done <n> le retire)
19
20
  # devzone build <dossier> [--tag <nom>] construit une image dans le workspace Kubernetes (BuildKit)
20
21
  # devzone activer postgres [--contexte CTX] [--confirmer CTX] PostgreSQL partagé, cluster au choix
21
22
  # devzone postgres creer <projet> base et utilisateur d'un projet (aussi : liste, psql, supprimer)
@@ -1440,6 +1441,7 @@ case "${1:-}" in
1440
1441
  agent)
1441
1442
  bash "$ICI/agent.sh" "${@:2}"
1442
1443
  ;;
1444
+ ticket) bash "$ICI/ticket.sh" "${@:2}" ;;
1443
1445
  build)
1444
1446
  bash "$ICI/workspace-build.sh" "${@:2}"
1445
1447
  ;;
@@ -10,6 +10,8 @@ metadata:
10
10
  namespace: devzone-postgres
11
11
  labels:
12
12
  app: postgres
13
+ app.kubernetes.io/name: postgres
14
+ app.kubernetes.io/part-of: devzone
13
15
  app.kubernetes.io/managed-by: devzone
14
16
  spec:
15
17
  selector:
@@ -26,6 +28,8 @@ metadata:
26
28
  namespace: devzone-postgres
27
29
  labels:
28
30
  app: postgres
31
+ app.kubernetes.io/name: postgres
32
+ app.kubernetes.io/part-of: devzone
29
33
  app.kubernetes.io/managed-by: devzone
30
34
  spec:
31
35
  serviceName: postgres
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env bash
2
+ # Ticket worktrees (#558), in the Kubernetes workspace pod and in the tools
3
+ # container:
4
+ # devzone ticket <n> [--repo devzone|repowarden]
5
+ # devzone ticket done <n> [--repo devzone|repowarden]
6
+ # In the pod: clone /workspaces/projets/<repo>, worktree
7
+ # /workspaces/projets/<repo>-wt/<dz|rw>-<n>. In the tools container: clone
8
+ # /workspaces/devzone, worktree workspace/wt/dz-<n> (devzone only).
9
+ # DEVZONE_TICKET_PROJECTS and DEVZONE_TICKET_TOOLS move those roots (tests).
10
+ set -euo pipefail
11
+
12
+ PROJECTS="${DEVZONE_TICKET_PROJECTS:-/workspaces/projets}"
13
+ TOOLS="${DEVZONE_TICKET_TOOLS:-/workspaces/devzone}"
14
+
15
+ refuse() { echo "devzone ticket: $*" >&2; exit 2; }
16
+
17
+ usage() {
18
+ echo "usage: devzone ticket <n> [--repo devzone|repowarden]" >&2
19
+ echo " devzone ticket done <n> [--repo devzone|repowarden]" >&2
20
+ exit 1
21
+ }
22
+
23
+ # Sets CLONE, WT and BASE (worktree folder prefix) for the repo.
24
+ ticket_paths() {
25
+ local repo="$1" n="$2" prefix
26
+ case "$repo" in
27
+ devzone) prefix=dz ;;
28
+ repowarden) prefix=rw ;;
29
+ *) refuse "unknown repo: $repo (devzone or repowarden)" ;;
30
+ esac
31
+ if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
32
+ CLONE="$PROJECTS/$repo"
33
+ WT="$PROJECTS/$repo-wt/$prefix-$n"
34
+ else
35
+ [ "$repo" = devzone ] || refuse "repo $repo only in the Kubernetes workspace pod"
36
+ CLONE="$TOOLS"
37
+ WT="$TOOLS/workspace/wt/$prefix-$n"
38
+ fi
39
+ [ -e "$CLONE/.git" ] || refuse "no clone in $CLONE (from the workstation: devzone workspace clone <url>)"
40
+ }
41
+
42
+ ticket_start() {
43
+ local n="$1" repo="$2" branch
44
+ ticket_paths "$repo" "$n"
45
+ if [ -e "$WT" ]; then
46
+ echo "worktree already there: $WT"
47
+ echo "$WT"
48
+ return 0
49
+ fi
50
+ git -C "$CLONE" fetch --quiet origin
51
+ mkdir -p "$(dirname "$WT")"
52
+ git -C "$CLONE" worktree add --quiet --detach "$WT" origin/develop
53
+ # repowarden creates the ticket branch from develop and links it
54
+ if ! (cd "$WT" && repowarden ticket "$n"); then
55
+ git -C "$CLONE" worktree remove --force "$WT" || true
56
+ refuse "repowarden ticket $n failed, worktree removed"
57
+ fi
58
+ branch="$(git -C "$WT" branch --show-current)"
59
+ echo "ticket #$n: branch ${branch:-none}"
60
+ echo "$WT"
61
+ }
62
+
63
+ ticket_done() {
64
+ local n="$1" repo="$2" branch
65
+ ticket_paths "$repo" "$n"
66
+ [ -d "$WT" ] || refuse "no worktree for ticket $n: $WT"
67
+ if [ -n "$(git -C "$WT" status --porcelain)" ]; then
68
+ refuse "worktree $WT is not clean, commit or discard first"
69
+ fi
70
+ branch="$(git -C "$WT" branch --show-current)"
71
+ if [ -n "$branch" ] && git -C "$CLONE" ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then
72
+ refuse "branch $branch still exists on origin: merge the pull request first"
73
+ fi
74
+ git -C "$CLONE" worktree remove "$WT"
75
+ if [ -n "$branch" ]; then git -C "$CLONE" branch -D "$branch" >/dev/null; fi
76
+ echo "ticket #$n: worktree $WT and local branch ${branch:-none} removed"
77
+ }
78
+
79
+ main() {
80
+ local action=start n="" repo=devzone
81
+ [ "${1:-}" != "done" ] || { action="done"; shift; }
82
+ while [ $# -gt 0 ]; do
83
+ case "$1" in
84
+ --repo)
85
+ [ $# -ge 2 ] || usage
86
+ repo="$2"
87
+ shift 2
88
+ ;;
89
+ -*) usage ;;
90
+ *)
91
+ [ -z "$n" ] || usage
92
+ n="$1"
93
+ shift
94
+ ;;
95
+ esac
96
+ done
97
+ case "$n" in '' | *[!0-9]*) usage ;; esac
98
+ if [ "$action" = "done" ]; then ticket_done "$n" "$repo"; else ticket_start "$n" "$repo"; fi
99
+ }
100
+
101
+ main "$@"
package/README.md CHANGED
@@ -175,7 +175,7 @@ La liste vit dans `.devzone.paquets` à la racine du dossier devzone, hors du d
175
175
  | État | — | `make status` | — |
176
176
  | **Désinstaller** (tout ce que devzone a créé, après confirmation) | — | `make uninstall` | `npx devzone uninstall` |
177
177
 
178
- Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)). Argo CD y est installé d'office et tient les déploiements : interface sur https://localhost:8443 (mot de passe `admin` dans `.password`), dépôt GitOps `<login>/devzone-argocd` créé sur ton GitHub, projets déclarés dans `.argocd.conf` (`devzone workspace argocd app add <dépôt>`) ; voir [Argo CD dans le workspace Kubernetes](manage/docs/reference.md#argo-cd-dans-le-workspace-kubernetes).
178
+ Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)). Tu peux aussi y développer : `devzone workspace clone <url>` fait un clone de travail dans le pod, `devzone ticket <n>` y crée le worktree d'un ticket et `devzone agent` y lance opencode sans copie ([développer dans le pod](manage/docs/reference.md#développer-devzone-et-repowarden-dans-le-pod)). Argo CD y est installé d'office et tient les déploiements : interface sur https://localhost:8443 (mot de passe `admin` dans `.password`), dépôt GitOps `<login>/devzone-argocd` créé sur ton GitHub, projets déclarés dans `.argocd.conf` (`devzone workspace argocd app add <dépôt>`) ; voir [Argo CD dans le workspace Kubernetes](manage/docs/reference.md#argo-cd-dans-le-workspace-kubernetes).
179
179
 
180
180
  ### Mettre à jour devzone
181
181
 
@@ -5,6 +5,8 @@ metadata:
5
5
  namespace: {{ .Release.Namespace }}
6
6
  labels:
7
7
  app: {{ .Values.name }}
8
+ app.kubernetes.io/name: {{ .Values.name }}
9
+ app.kubernetes.io/part-of: devzone
8
10
  app.kubernetes.io/managed-by: devzone
9
11
  spec:
10
12
  selector:
@@ -5,6 +5,8 @@ metadata:
5
5
  namespace: {{ .Release.Namespace }}
6
6
  labels:
7
7
  app: {{ .Values.name }}
8
+ app.kubernetes.io/name: {{ .Values.name }}
9
+ app.kubernetes.io/part-of: devzone
8
10
  app.kubernetes.io/managed-by: devzone
9
11
  spec:
10
12
  serviceName: {{ .Values.name }}
@@ -5,11 +5,13 @@ metadata:
5
5
  namespace: {{ .Release.Namespace }}
6
6
  labels:
7
7
  app: postgres
8
+ app.kubernetes.io/name: postgres
9
+ app.kubernetes.io/part-of: devzone
8
10
  app.kubernetes.io/managed-by: devzone
9
11
  spec:
10
12
  selector:
11
13
  app: postgres
12
14
  ports:
13
15
  - name: postgres
14
- port: 5432
16
+ port: {{ .Values.port }}
15
17
  targetPort: 5432
@@ -5,6 +5,8 @@ metadata:
5
5
  namespace: {{ .Release.Namespace }}
6
6
  labels:
7
7
  app: postgres
8
+ app.kubernetes.io/name: postgres
9
+ app.kubernetes.io/part-of: devzone
8
10
  app.kubernetes.io/managed-by: devzone
9
11
  spec:
10
12
  serviceName: postgres
@@ -40,13 +42,13 @@ spec:
40
42
  resources:
41
43
  requests:
42
44
  cpu: {{ .Values.resources.requests.cpu }}
43
- memory: {{ .Values.resources.requests.memory }}
45
+ memory: {{ .Values.memory }}
44
46
  volumeMounts:
45
- - name: donnees
47
+ - name: {{ .Values.claim }}
46
48
  mountPath: /var/lib/postgresql/data
47
49
  volumeClaimTemplates:
48
50
  - metadata:
49
- name: donnees
51
+ name: {{ .Values.claim }}
50
52
  labels:
51
53
  app.kubernetes.io/managed-by: devzone
52
54
  spec:
@@ -3,9 +3,14 @@
3
3
  # secret postgres-admin (superuser password) is created apart by devzone,
4
4
  # never by the chart (#516: secrets out of Git).
5
5
  image: postgres:16.15-alpine
6
+ # Port of the Service (the container always listens on 5432)
7
+ port: 5432
8
+ # Memory request of the container
9
+ memory: 256Mi
10
+ # Name of the volume claim template mounted on the container
11
+ claim: donnees
6
12
  # Size of the data volume (POSTGRES_TAILLE of the helm-direct path)
7
13
  size: 5Gi
8
14
  resources:
9
15
  requests:
10
16
  cpu: 100m
11
- memory: 256Mi
@@ -1,6 +1,6 @@
1
1
  apiVersion: v2
2
2
  name: devzone-workspace
3
- description: devzone development workstation in Kubernetes.
3
+ description: devzone development workstation in Kubernetes, held by Argo CD (#516)
4
4
  type: application
5
5
  version: 0.1.0
6
6
  appVersion: "0.1.0"
@@ -4,6 +4,10 @@ kind: NetworkPolicy
4
4
  metadata:
5
5
  name: {{ include "devzone-workspace.fullname" . }}
6
6
  namespace: {{ .Release.Namespace }}
7
+ labels:
8
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
9
+ app.kubernetes.io/part-of: devzone
10
+ app.kubernetes.io/managed-by: devzone
7
11
  spec:
8
12
  podSelector: {}
9
13
  policyTypes:
@@ -3,6 +3,10 @@ kind: Role
3
3
  metadata:
4
4
  name: devzone-workspace
5
5
  namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
8
+ app.kubernetes.io/part-of: devzone
9
+ app.kubernetes.io/managed-by: devzone
6
10
  # Rights of kubedock (0.23.0, read in its sources), limited to the namespace:
7
11
  # pods (create and delete the test containers, list and follow them),
8
12
  # pods/log, pods/exec and pods/portforward (logs, commands, ports), services and
@@ -3,6 +3,10 @@ kind: RoleBinding
3
3
  metadata:
4
4
  name: devzone-workspace
5
5
  namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
8
+ app.kubernetes.io/part-of: devzone
9
+ app.kubernetes.io/managed-by: devzone
6
10
  subjects:
7
11
  - kind: ServiceAccount
8
12
  name: {{ include "devzone-workspace.serviceAccountName" . }}
@@ -3,6 +3,10 @@ kind: Service
3
3
  metadata:
4
4
  name: {{ include "devzone-workspace.fullname" . }}
5
5
  namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
8
+ app.kubernetes.io/part-of: devzone
9
+ app.kubernetes.io/managed-by: devzone
6
10
  spec:
7
11
  clusterIP: None
8
12
  selector:
@@ -4,4 +4,8 @@ kind: ServiceAccount
4
4
  metadata:
5
5
  name: {{ include "devzone-workspace.serviceAccountName" . }}
6
6
  namespace: {{ .Release.Namespace }}
7
+ labels:
8
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
9
+ app.kubernetes.io/part-of: devzone
10
+ app.kubernetes.io/managed-by: devzone
7
11
  {{- end -}}
@@ -3,6 +3,10 @@ kind: StatefulSet
3
3
  metadata:
4
4
  name: {{ include "devzone-workspace.fullname" . }}
5
5
  namespace: {{ .Release.Namespace }}
6
+ labels:
7
+ app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}
8
+ app.kubernetes.io/part-of: devzone
9
+ app.kubernetes.io/managed-by: devzone
6
10
  spec:
7
11
  serviceName: {{ include "devzone-workspace.fullname" . }}
8
12
  replicas: {{ .Values.replicaCount }}
package/manage/devzone CHANGED
@@ -433,7 +433,7 @@ devzone $(version) : environnement de développement conteneurisé
433
433
  devzone uninstall dans un dossier devzone : retire conteneur, image, volumes
434
434
  (à lancer avant npm uninstall -g devzone)
435
435
  devzone workspace start|stop|status|shell
436
- devzone workspace vscode|copy-to|copy-from|migrate|revert|clean-docker
436
+ devzone workspace vscode|copy-to|copy-from|clone|migrate|revert|clean-docker
437
437
  poste Kubernetes : pilote le chart devzone-workspace
438
438
  devzone workspace services enable|disable <service>|status
439
439
  services (gitlab, postgres, argocd) du workspace Kubernetes
@@ -583,7 +583,7 @@ commande_du_conteneur() {
583
583
  actif | activer | agent | appliquer | argocd | build | catalogue | cluster | clusters | \
584
584
  demarrer | desactiver | etat | gitlab | metrics | modules | mots-de-passe | \
585
585
  mysql | paquets | plateforme | port | postgres | reparer | test-bash32 | \
586
- test-gitlab | utiliser) return 0 ;;
586
+ test-gitlab | ticket | utiliser) return 0 ;;
587
587
  # English names of the container commands (#502)
588
588
  is-enabled | enable | disable | apply | catalog | start | status | \
589
589
  passwords | packages | platform | repair | use) return 0 ;;
@@ -81,6 +81,8 @@ services_argocd_toggle() {
81
81
  echo "✖ $svc through Argo CD takes no option (got: $*)" >&2
82
82
  return 1
83
83
  fi
84
+ # Before [services] is written: a refused chart leaves the state unchanged
85
+ chart_require "$svc" || return $?
84
86
  echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
85
87
  services_note "$svc" on
86
88
  services_reconcile
@@ -109,6 +109,7 @@ workspace_deploy() {
109
109
  params="image.tag=$tag"
110
110
  [ -z "$with_image" ] || params="$params image.repository=$repository"
111
111
  [ "$tag" != latest ] || params="$params image.pullPolicy=Always"
112
+ chart_require workspace || return $?
112
113
  # GitOps repository created or designated first, with its root Application
113
114
  gitops_init || return 1
114
115
  gitops_root || return 1
@@ -137,6 +137,7 @@ argocd_passwords_refresh() {
137
137
 
138
138
  # Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
139
139
  argocd_install() {
140
+ chart_require argocd || return 2
140
141
  argocd_memory_ok || return 2
141
142
  echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
142
143
  ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
@@ -153,10 +154,15 @@ argocd_install() {
153
154
  }
154
155
 
155
156
  # Installs it when wanted and missing (workspace start); a refusal (memory)
156
- # is told and the start goes on with helm direct
157
+ # is told and the start goes on with helm direct. A cluster that does not
158
+ # answer is not "helm direct": the start has already stopped on it (#565)
157
159
  argocd_ensure() {
158
160
  argocd_wanted || return 0
159
161
  argocd_installed && return 0
162
+ if ! kube_ready_reason >/dev/null; then
163
+ echo "⚠ Argo CD not checked: the cluster does not answer (devzone workspace services enable argocd once it does)" >&2
164
+ return 0
165
+ fi
160
166
  argocd_install || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
161
167
  return 0
162
168
  }
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env bash
2
+ # CI check of the convention of the devzone charts (#554), documented in the
3
+ # section "Charts de devzone" of manage/docs/reference.md. Each folder of
4
+ # charts/ is checked: its name, Chart.yaml, then its family, by its
5
+ # dependencies: a wrapper (Chart.lock, oci:// recommended) or a service
6
+ # (templates without a hard-coded namespace, Secret, Ingress or LoadBalancer,
7
+ # the three labels on each object; the common keys in values.yaml). Every
8
+ # charts/devzone-<x> named by the code must be a folder. helm lint and helm
9
+ # template run when helm is installed. A fault is printed as
10
+ # "✖ charts/<x> : <rule>" and the run exits 1; otherwise
11
+ # "✔ charts : N charts conformes". Tests: CHARTS_DIR, CHARTS_CODE_DIRS and
12
+ # CHARTS_NO_HELM=1. bash 3.2 (macOS).
13
+
14
+ set -u
15
+
16
+ ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
+ ROOT="$(cd "$ICI/../.." && pwd)"
18
+ CHARTS_DIR="${CHARTS_DIR:-$ROOT/charts}"
19
+ CHARTS_CODE_DIRS="${CHARTS_CODE_DIRS:-$ROOT/.devcontainer $ROOT/manage/scripts}"
20
+ # The workstation keeps its own values (per volume, not a shared service)
21
+ CHARTS_NO_COMMON="devzone-workspace"
22
+ COMMON_KEYS="image size memory port claim resources"
23
+ FAULTS=0
24
+ COUNT=0
25
+
26
+ fault() {
27
+ printf '✖ charts/%s : %s\n' "$1" "$2"
28
+ FAULTS=$((FAULTS + 1))
29
+ }
30
+
31
+ # Top-level key of Chart.yaml (file, key), quotes removed
32
+ chart_key() {
33
+ sed -n "s/^$2:[[:space:]]*//p" "$1" | head -1 |
34
+ sed -e 's/[[:space:]]*$//' -e 's/^"\(.*\)"$/\1/' -e "s/^'\(.*\)'\$/\1/"
35
+ }
36
+
37
+ # Chart.yaml: name equal to the folder, type, version (semver), appVersion and
38
+ # description not empty
39
+ charts_check_chart_yaml() {
40
+ local f="$1/Chart.yaml" name="$2" re='^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.+-]*)?$'
41
+ [ "$(chart_key "$f" name)" = "$name" ] || fault "$name" "Chart.yaml name must be \"$name\""
42
+ [ "$(chart_key "$f" type)" = application ] || fault "$name" "Chart.yaml type must be application"
43
+ [[ "$(chart_key "$f" version)" =~ $re ]] || fault "$name" "Chart.yaml version must be semver"
44
+ [ -n "$(chart_key "$f" appVersion)" ] || fault "$name" "Chart.yaml appVersion must not be empty"
45
+ [ -n "$(chart_key "$f" description)" ] || fault "$name" "Chart.yaml description must not be empty"
46
+ }
47
+
48
+ # Wrapper: Chart.lock committed; a repository outside oci:// is a warning
49
+ charts_check_wrapper() {
50
+ local dir="$1" name="$2"
51
+ [ -f "$dir/Chart.lock" ] || fault "$name" "wrapper without Chart.lock (commit it)"
52
+ if grep -E '^[[:space:]]*repository:' "$dir/Chart.yaml" | grep -qv 'oci://'; then
53
+ echo "⚠ charts/$name : a dependency repository is not oci:// (recommended)"
54
+ fi
55
+ }
56
+
57
+ # Service: objects (a kind: line) with the labels, no hard-coded namespace,
58
+ # no Secret, no Ingress, no LoadBalancer
59
+ charts_check_templates() {
60
+ local dir="$1" name="$2" f rel label
61
+ for f in "$dir"/templates/*.yaml; do
62
+ [ -f "$f" ] || continue
63
+ rel="templates/$(basename "$f")"
64
+ if grep -E '^[[:space:]]*namespace:' "$f" | grep -qv 'Release\.Namespace'; then
65
+ fault "$name" "$rel: namespace must be {{ .Release.Namespace }}, not hard-coded"
66
+ fi
67
+ grep -Eq '^kind:[[:space:]]*Secret' "$f" && fault "$name" "$rel: no Secret in a chart (created apart)"
68
+ grep -Eq '^kind:[[:space:]]*Ingress' "$f" && fault "$name" "$rel: no Ingress in a chart"
69
+ grep -Eq 'type:[[:space:]]*LoadBalancer' "$f" && fault "$name" "$rel: no LoadBalancer in a chart"
70
+ grep -Eq '^kind:' "$f" || continue
71
+ for label in 'app.kubernetes.io/name:' 'app.kubernetes.io/part-of: devzone' 'app.kubernetes.io/managed-by: devzone'; do
72
+ grep -Fq "$label" "$f" || fault "$name" "$rel: label $label missing"
73
+ done
74
+ done
75
+ }
76
+
77
+ # Service: the common keys of values.yaml (the workstation is exempt)
78
+ charts_check_values() {
79
+ local dir="$1" name="$2" key
80
+ case " $CHARTS_NO_COMMON " in *" $name "*) return 0 ;; esac
81
+ for key in $COMMON_KEYS; do
82
+ grep -Eq "^$key:" "$dir/values.yaml" || fault "$name" "values.yaml lacks the common key $key"
83
+ done
84
+ }
85
+
86
+ # helm lint and template, on a copy: the wrapper gets its dependency built
87
+ # first, with an empty DOCKER_CONFIG (anonymous pull)
88
+ charts_check_helm() {
89
+ local dir="$1" name="$2" tmp conf
90
+ [ "${CHARTS_NO_HELM:-0}" = 1 ] && return 0
91
+ command -v helm >/dev/null 2>&1 || return 0
92
+ tmp="$(mktemp -d)" || return 0
93
+ conf="$(mktemp -d)"
94
+ cp -R "$dir" "$tmp/$name"
95
+ if grep -q '^dependencies:' "$dir/Chart.yaml"; then
96
+ DOCKER_CONFIG="$conf" helm dependency build "$tmp/$name" >"$tmp/log" 2>&1 ||
97
+ fault "$name" "helm dependency build fails: $(tail -1 "$tmp/log")"
98
+ fi
99
+ helm lint --quiet "$tmp/$name" >"$tmp/log" 2>&1 || fault "$name" "helm lint fails: $(tail -1 "$tmp/log")"
100
+ DOCKER_CONFIG="$conf" helm template "$name" "$tmp/$name" >/dev/null 2>"$tmp/log" ||
101
+ fault "$name" "helm template fails: $(tail -1 "$tmp/log")"
102
+ rm -rf "$tmp" "$conf"
103
+ }
104
+
105
+ # One folder of charts/
106
+ charts_check_dir() {
107
+ local dir="$1" name re='^devzone-[a-z0-9-]+$'
108
+ name="$(basename "$dir")"
109
+ COUNT=$((COUNT + 1))
110
+ [[ "$name" =~ $re ]] || fault "$name" "folder name must match devzone-[a-z0-9-]+"
111
+ if [ ! -f "$dir/Chart.yaml" ]; then
112
+ fault "$name" "Chart.yaml missing"
113
+ return 0
114
+ fi
115
+ [ -f "$dir/values.yaml" ] || fault "$name" "values.yaml missing"
116
+ charts_check_chart_yaml "$dir" "$name"
117
+ if grep -q '^dependencies:' "$dir/Chart.yaml"; then
118
+ charts_check_wrapper "$dir" "$name"
119
+ else
120
+ charts_check_templates "$dir" "$name"
121
+ charts_check_values "$dir" "$name"
122
+ fi
123
+ charts_check_helm "$dir" "$name"
124
+ }
125
+
126
+ # Each charts/devzone-<x> named by the code must be a folder of CHARTS_DIR;
127
+ # $svc or $app (variables) are not names and do not match
128
+ charts_check_references() {
129
+ local dir hits hit file name
130
+ for dir in $CHARTS_CODE_DIRS; do
131
+ [ -d "$dir" ] || continue
132
+ hits="$(grep -rnoE 'charts/devzone-[a-z0-9-]+' "$dir" 2>/dev/null)" || hits=""
133
+ while IFS= read -r hit; do
134
+ [ -n "$hit" ] || continue
135
+ file="${hit%%:*}"
136
+ name="${hit##*charts/}"
137
+ if [ ! -d "$CHARTS_DIR/$name" ]; then
138
+ fault "$name" "named in $file but the folder is absent"
139
+ fi
140
+ done <<EOF
141
+ $hits
142
+ EOF
143
+ done
144
+ }
145
+
146
+ if [ ! -d "$CHARTS_DIR" ]; then
147
+ echo "✖ charts : folder not found: $CHARTS_DIR"
148
+ exit 1
149
+ fi
150
+ for dir in "$CHARTS_DIR"/*/; do
151
+ [ -d "$dir" ] || continue
152
+ charts_check_dir "${dir%/}"
153
+ done
154
+ charts_check_references
155
+ if [ "$FAULTS" -ne 0 ]; then
156
+ exit 1
157
+ fi
158
+ echo "✔ charts : $COUNT charts conformes"
@@ -1,31 +1,75 @@
1
1
  #!/usr/bin/env bash
2
- # Shared check of the Kubernetes cluster (#497), sourced by poste.sh (and by
3
- # create-mode.sh at creation). Sourced only: no code at file level.
4
- # Compatible with bash 3.2 (macOS) and Linux.
2
+ # Shared check of the Kubernetes cluster (#497, #565), sourced by poste.sh,
3
+ # create-mode.sh (creation) and workspace.sh (workspace start). Sourced only:
4
+ # no code at file level. Compatible with bash 3.2 (macOS) and Linux.
5
5
 
6
6
  # Returns 0 when kubectl and helm are present and the cluster answers within 5 s
7
7
  # (context devzone if declared, otherwise the current context). Otherwise
8
8
  # prints one short line on stdout (kubectl missing, helm missing, or
9
- # cluster <context> unreachable (<server>)) and returns 1.
9
+ # cluster <context> unreachable (<server>)) and returns 1. With --hint, prints
10
+ # the message for the user instead (#565, see kube_unreachable_hint).
10
11
  kube_ready_reason() {
11
- local context server
12
+ local context server hint=no
13
+ [ "${1:-}" = --hint ] && hint=yes
12
14
  command -v kubectl >/dev/null 2>&1 || {
13
- echo "kubectl missing"
15
+ kube_say "kubectl missing" "$hint"
14
16
  return 1
15
17
  }
16
18
  command -v helm >/dev/null 2>&1 || {
17
- echo "helm missing"
19
+ kube_say "helm missing" "$hint"
18
20
  return 1
19
21
  }
20
22
  if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
21
23
  kubectl cluster-info --request-timeout=5s --context devzone >/dev/null 2>&1 && return 0
22
24
  context=devzone
23
- server="$(kubectl config view --minify --context devzone -o 'jsonpath={.clusters[0].server}' 2>/dev/null || true)"
25
+ server="$(kubectl config view --minify --context devzone -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
24
26
  else
25
27
  kubectl cluster-info --request-timeout=5s >/dev/null 2>&1 && return 0
26
28
  context="$(kubectl config current-context 2>/dev/null || true)"
27
- server="$(kubectl config view --minify -o 'jsonpath={.clusters[0].server}' 2>/dev/null || true)"
29
+ server="$(kubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
30
+ fi
31
+ if [ "$hint" = yes ]; then
32
+ kube_unreachable_hint "${context:-none}" "${server:-unknown server}"
33
+ else
34
+ echo "cluster ${context:-none} unreachable (${server:-unknown server})"
28
35
  fi
29
- echo "cluster ${context:-none} unreachable (${server:-unknown server})"
30
36
  return 1
31
37
  }
38
+
39
+ # One reason line: as is, or as a ✖ line for the user (--hint).
40
+ kube_say() {
41
+ if [ "$2" = yes ]; then
42
+ echo "✖ $1"
43
+ else
44
+ echo "$1"
45
+ fi
46
+ }
47
+
48
+ # Cluster name of a context (empty when unknown).
49
+ kube_context_cluster() {
50
+ kubectl config view --minify --context "$1" -o 'jsonpath={.clusters[0].name}' 2>/dev/null || true
51
+ }
52
+
53
+ # Message of an unreachable cluster <context> at <server> (#565). The cluster of
54
+ # Docker Desktop (context docker-desktop, or a local server 127.0.0.1 or
55
+ # localhost of a cluster named docker-desktop) runs inside Docker Desktop: when
56
+ # docker info fails, the cause is Docker Desktop stopped; when Docker answers,
57
+ # Kubernetes is disabled in it. Any other context gets the generic message.
58
+ kube_unreachable_hint() {
59
+ local context="$1" server="$2" cluster host
60
+ cluster="$(kube_context_cluster "$context")"
61
+ host="${server#*://}"
62
+ host="${host%%[:/]*}"
63
+ if [ "$context" = docker-desktop ] ||
64
+ { [ "$cluster" = docker-desktop ] && { [ "$host" = 127.0.0.1 ] || [ "$host" = localhost ]; }; }; then
65
+ if ! docker info >/dev/null 2>&1; then
66
+ echo "✖ Docker Desktop is stopped: the Kubernetes cluster of this machine runs inside it. Start Docker Desktop, then: make shell"
67
+ echo " Tip: Settings → General → Start Docker Desktop when you sign in"
68
+ else
69
+ echo "✖ Kubernetes cluster $context unreachable ($server): enable Kubernetes in Docker Desktop (Settings → Kubernetes) or check kubectl config get-contexts"
70
+ fi
71
+ return 0
72
+ fi
73
+ echo "✖ Kubernetes cluster $context unreachable ($server)"
74
+ echo " Check the contexts: kubectl config get-contexts"
75
+ }
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env bash
2
+ # Working clones inside the pod (#558), sourced by manage/workspace.sh:
3
+ # devzone workspace clone <url> [<name>]
4
+ # git clone into $PROJECTS_DIR/<name> of the pod over HTTPS, credentials given
5
+ # by the gh git credential helper set up in the pod, git identity copied from
6
+ # the workstation, then "repowarden install" in the clone (hooks). bash 3.2.
7
+
8
+ # Script run in the pod: $1 clone folder, $2 url, $3 git name, $4 git email.
9
+ # Exit 3: the folder exists and is not a clone of this url.
10
+ workspace_clone_pod_script() {
11
+ cat <<'POD'
12
+ set -eu
13
+ dir="$1" url="$2" name="$3" email="$4"
14
+ norm() { local u="${1%/}"; echo "${u%.git}"; }
15
+ gh auth setup-git
16
+ if [ -d "$dir/.git" ]; then
17
+ remote="$(git -C "$dir" remote get-url origin 2>/dev/null || true)"
18
+ if [ "$(norm "$remote")" != "$(norm "$url")" ]; then
19
+ echo "✖ $dir already exists with another remote: ${remote:-none}" >&2
20
+ exit 3
21
+ fi
22
+ echo "$dir is already a clone of $url"
23
+ elif [ -e "$dir" ] && [ -n "$(ls -A "$dir" 2>/dev/null)" ]; then
24
+ echo "✖ $dir already exists and is not a git clone" >&2
25
+ exit 3
26
+ else
27
+ git clone "$url" "$dir"
28
+ fi
29
+ [ -z "$name" ] || git -C "$dir" config user.name "$name"
30
+ [ -z "$email" ] || git -C "$dir" config user.email "$email"
31
+ if command -v repowarden >/dev/null 2>&1; then
32
+ (cd "$dir" && repowarden install)
33
+ else
34
+ echo "⚠ repowarden missing in the pod: hooks not installed in $dir" >&2
35
+ fi
36
+ POD
37
+ }
38
+
39
+ # Folder name from a url: last path segment without .git.
40
+ workspace_clone_name() {
41
+ local u="${1%/}"
42
+ u="${u##*/}"
43
+ u="${u##*:}"
44
+ echo "${u%.git}"
45
+ }
46
+
47
+ workspace_clone() {
48
+ local url="${1:-}" name="${2:-}" git_name git_email
49
+ if [ -z "$url" ] || [ $# -gt 2 ]; then
50
+ echo "✖ usage: devzone workspace clone <url> [<name>]" >&2
51
+ return 1
52
+ fi
53
+ [ -n "$name" ] || name="$(workspace_clone_name "$url")"
54
+ case "$name" in
55
+ '' | . | .. | -* | */* | *[!A-Za-z0-9._-]*)
56
+ echo "✖ invalid folder name: ${name:-empty} (letters, digits, . _ - only)" >&2
57
+ return 1
58
+ ;;
59
+ esac
60
+ git_name="$(git config --get user.name 2>/dev/null || true)"
61
+ git_email="$(git config --get user.email 2>/dev/null || true)"
62
+ # shellcheck disable=SC2046
63
+ workspace_clone_pod_script | kubectl $(kubectl_flag) exec -i "$POD" \
64
+ --namespace "$NAMESPACE" -c workspace -- \
65
+ bash -s -- "$PROJECTS_DIR/$name" "$url" "$git_name" "$git_email"
66
+ }
67
+
68
+ # Guard of the agents in the pod (#558): when the ia module is on there,
69
+ # "repowarden agents init --global" is run (idempotent), so that an agent
70
+ # launched in the pod cannot edit develop. Never fails the workspace start.
71
+ workspace_agents_guard() {
72
+ # shellcheck disable=SC2046
73
+ if kubectl $(kubectl_flag) exec "$POD" --namespace "$NAMESPACE" -c workspace -- \
74
+ bash -lc 'devzone is-enabled ia && repowarden agents init --global' >/dev/null 2>&1; then
75
+ echo "✔ repowarden guard active for the agents of the pod"
76
+ fi
77
+ }
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env bash
2
+ # Stale copies in the pod (#558), sourced by manage/workspace.sh:
3
+ # status_workspace pod status, then the legacy copies still in the pod
4
+ # copy_guard copy-to never overwrites a pod clone of another remote
5
+ # Uses kubectl_flag, POD, NAMESPACE and PROJECTS_DIR from workspace.sh.
6
+
7
+ # Shows workspace pod status, then the legacy copies still in the pod.
8
+ status_workspace() {
9
+ # shellcheck disable=SC2046
10
+ kubectl $(kubectl_flag) get pods --namespace devzone-workspace
11
+ workspace_legacy_copies || true
12
+ }
13
+
14
+ # Script run in the pod: prints the legacy copies, one folder per line
15
+ # (repogarde, wt): their .git file points to a git folder missing from the pod.
16
+ workspace_legacy_pod_script() {
17
+ cat <<'POD'
18
+ broken() {
19
+ local g
20
+ [ -f "$1/.git" ] || return 1
21
+ g="$(sed -n 's/^gitdir: *//p' "$1/.git" | head -1)"
22
+ [ -n "$g" ] && [ ! -e "$g" ]
23
+ }
24
+ cd "$1" || exit 0
25
+ if broken repogarde; then echo repogarde; fi
26
+ for d in wt/*; do
27
+ if broken "$d"; then echo wt; break; fi
28
+ done
29
+ POD
30
+ }
31
+
32
+ # Legacy copies (repogarde/, wt/) are reported with the command to remove them;
33
+ # the removal itself is manual, after a backup.
34
+ workspace_legacy_copies() {
35
+ local found d dirs=""
36
+ # shellcheck disable=SC2046
37
+ found="$(workspace_legacy_pod_script | kubectl $(kubectl_flag) exec -i "$POD" \
38
+ --namespace "$NAMESPACE" -c workspace -- bash -s -- "$PROJECTS_DIR" 2>/dev/null)" || return 0
39
+ [ -n "$found" ] || return 0
40
+ for d in $found; do dirs="$dirs $PROJECTS_DIR/$d"; done
41
+ echo "⚠ legacy copies in the pod (their .git points outside the pod):$dirs"
42
+ echo " 1. save what you need: devzone workspace copy-from <folder>"
43
+ echo " 2. remove them from the pod shell (devzone workspace shell), one folder at a time:"
44
+ for d in $found; do echo " rm -rf $PROJECTS_DIR/$d"; done
45
+ }
46
+
47
+ # Script run in the pod: $1 pod folder, $2 remote of the workstation folder.
48
+ # Exit 3 (remote printed) when the pod folder is a clone of another remote.
49
+ workspace_copy_pod_script() {
50
+ cat <<'POD'
51
+ [ -e "$1/.git" ] || exit 0
52
+ r="$(git -C "$1" remote get-url origin 2>/dev/null || true)"
53
+ n() { local u="${1%/}"; echo "${u%.git}"; }
54
+ [ "$(n "$r")" = "$(n "$2")" ] && exit 0
55
+ echo "${r:-none}"
56
+ exit 3
57
+ POD
58
+ }
59
+
60
+ # copy-to never overwrites a pod clone of another repository.
61
+ copy_guard() {
62
+ local folder="$1" mine other code=0
63
+ mine="$(git -C "$folder" remote get-url origin 2>/dev/null || true)"
64
+ # shellcheck disable=SC2046
65
+ other="$(workspace_copy_pod_script | kubectl $(kubectl_flag) exec -i "$POD" \
66
+ --namespace "$NAMESPACE" -c workspace -- bash -s -- \
67
+ "$PROJECTS_DIR/$(basename "$folder")" "$mine" 2>/dev/null)" || code=$?
68
+ if [ "$code" -eq 3 ]; then
69
+ echo "✖ $PROJECTS_DIR/$(basename "$folder") in the pod is a git clone with another remote ($other, here: ${mine:-none}); not overwritten" >&2
70
+ echo " work in that clone (devzone workspace clone), or remove it first" >&2
71
+ return 1
72
+ fi
73
+ return 0
74
+ }
@@ -48,9 +48,10 @@ default_image_tag() {
48
48
  fi
49
49
  }
50
50
 
51
- # Installs or upgrades the workspace in the cluster.
51
+ # Installs or upgrades the workspace in the cluster; the cluster is checked first (#565): no Argo CD, helm or pod wait for a stopped one.
52
52
  start_workspace() {
53
53
  local repo tag image with_image="" args=()
54
+ kube_ready_reason --hint >&2 || return 1
54
55
  repo="$IMAGE_REPO"
55
56
  tag="$(default_image_tag)"
56
57
  while [ $# -gt 0 ]; do
@@ -86,6 +87,7 @@ start_workspace() {
86
87
  # Projects of .argocd.conf held too (#516)
87
88
  argocd_reconcile || true
88
89
  wait_for_pod "$image" || return 1
90
+ workspace_agents_guard || true
89
91
  ports_start silence
90
92
  }
91
93
 
@@ -113,12 +115,6 @@ stop_workspace() {
113
115
  workspace_undeploy
114
116
  }
115
117
 
116
- # Shows workspace pod status.
117
- status_workspace() {
118
- # shellcheck disable=SC2046
119
- kubectl $(kubectl_flag) get pods --namespace devzone-workspace
120
- }
121
-
122
118
  # Opens a shell in the workspace container.
123
119
  shell_workspace() {
124
120
  # shellcheck disable=SC2046
@@ -153,6 +149,7 @@ copy_to() {
153
149
  exit 1
154
150
  fi
155
151
  folder="$(cd "$folder" && pwd)"
152
+ copy_guard "$folder" || exit 1
156
153
  # shellcheck disable=SC2046
157
154
  kubectl $(kubectl_flag) cp "$folder" "$POD:$PROJECTS_DIR/$(basename "$folder")" \
158
155
  --namespace "$NAMESPACE" -c workspace
@@ -176,8 +173,14 @@ copy_from() {
176
173
  # French names of the command and compatibility aliases (lot 3, #508)
177
174
  # shellcheck source=manage/scripts/workspace-aliases.sh
178
175
  . "$HERE/scripts/workspace-aliases.sh"
176
+ # shellcheck source=manage/scripts/kube-ready.sh
177
+ . "$HERE/scripts/kube-ready.sh"
179
178
  # shellcheck source=manage/scripts/workspace-wait.sh
180
179
  . "$HERE/scripts/workspace-wait.sh"
180
+ # shellcheck source=manage/scripts/workspace-clone.sh
181
+ . "$HERE/scripts/workspace-clone.sh"
182
+ # shellcheck source=manage/scripts/workspace-copies.sh
183
+ . "$HERE/scripts/workspace-copies.sh"
181
184
  # shellcheck source=manage/scripts/migrer.sh
182
185
  . "$HERE/scripts/migrer.sh"
183
186
  # shellcheck source=manage/scripts/migrer-retour.sh
@@ -220,6 +223,7 @@ case "${1:-}" in
220
223
  vscode) vscode_workspace ;;
221
224
  copy-to) copy_to "${@:2}" ;;
222
225
  copy-from) copy_from "${@:2}" ;;
226
+ clone) workspace_clone "${@:2}" ;;
223
227
  ports) ports "${@:2}" ;;
224
228
  migrate) migrate_workspace "${@:2}" ;;
225
229
  revert) revert_workspace "${@:2}" ;;
@@ -227,8 +231,9 @@ case "${1:-}" in
227
231
  services) services "${@:2}" ;;
228
232
  argocd) argocd_cmd "${@:2}" ;;
229
233
  '' | -h | --help | aide)
230
- echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|ports|services|argocd|migrate|revert|clean-docker"
234
+ echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker"
231
235
  echo " start [--image repository:tag] install workspace (image for devzone version by default)"
236
+ echo " clone <url> [<name>] git clone into the pod projects folder (gh credentials, identity, repowarden hooks)"
232
237
  echo " ports [start|stop|status] applications and services from pod on workstation localhost"
233
238
  echo " services enable|disable <service> [options] | status"
234
239
  echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
@@ -239,7 +244,7 @@ case "${1:-}" in
239
244
  echo " clean-docker remove devzone-* Docker volumes, after confirmation [y/N] (--yes)"
240
245
  ;;
241
246
  *)
242
- echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|ports|services|argocd|migrate|revert|clean-docker)" >&2
247
+ echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker)" >&2
243
248
  exit 1
244
249
  ;;
245
250
  esac
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {