devzone 0.40.0 → 0.41.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.
- package/.devcontainer/agent-workspace.sh +22 -8
- package/.devcontainer/devzone +2 -0
- package/.devcontainer/ticket.sh +101 -0
- package/README.md +1 -1
- package/manage/devzone +2 -2
- package/manage/scripts/workspace-clone.sh +77 -0
- package/manage/scripts/workspace-copies.sh +74 -0
- package/manage/workspace.sh +10 -8
- 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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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,
|
|
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"' _ "
|
|
63
|
-
journal="$(journal_de "$
|
|
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]
|
package/.devcontainer/devzone
CHANGED
|
@@ -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
|
;;
|
|
@@ -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
|
|
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 ;;
|
|
@@ -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
|
+
}
|
package/manage/workspace.sh
CHANGED
|
@@ -86,6 +86,7 @@ start_workspace() {
|
|
|
86
86
|
# Projects of .argocd.conf held too (#516)
|
|
87
87
|
argocd_reconcile || true
|
|
88
88
|
wait_for_pod "$image" || return 1
|
|
89
|
+
workspace_agents_guard || true
|
|
89
90
|
ports_start silence
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -113,12 +114,6 @@ stop_workspace() {
|
|
|
113
114
|
workspace_undeploy
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
# Shows workspace pod status.
|
|
117
|
-
status_workspace() {
|
|
118
|
-
# shellcheck disable=SC2046
|
|
119
|
-
kubectl $(kubectl_flag) get pods --namespace devzone-workspace
|
|
120
|
-
}
|
|
121
|
-
|
|
122
117
|
# Opens a shell in the workspace container.
|
|
123
118
|
shell_workspace() {
|
|
124
119
|
# shellcheck disable=SC2046
|
|
@@ -153,6 +148,7 @@ copy_to() {
|
|
|
153
148
|
exit 1
|
|
154
149
|
fi
|
|
155
150
|
folder="$(cd "$folder" && pwd)"
|
|
151
|
+
copy_guard "$folder" || exit 1
|
|
156
152
|
# shellcheck disable=SC2046
|
|
157
153
|
kubectl $(kubectl_flag) cp "$folder" "$POD:$PROJECTS_DIR/$(basename "$folder")" \
|
|
158
154
|
--namespace "$NAMESPACE" -c workspace
|
|
@@ -178,6 +174,10 @@ copy_from() {
|
|
|
178
174
|
. "$HERE/scripts/workspace-aliases.sh"
|
|
179
175
|
# shellcheck source=manage/scripts/workspace-wait.sh
|
|
180
176
|
. "$HERE/scripts/workspace-wait.sh"
|
|
177
|
+
# shellcheck source=manage/scripts/workspace-clone.sh
|
|
178
|
+
. "$HERE/scripts/workspace-clone.sh"
|
|
179
|
+
# shellcheck source=manage/scripts/workspace-copies.sh
|
|
180
|
+
. "$HERE/scripts/workspace-copies.sh"
|
|
181
181
|
# shellcheck source=manage/scripts/migrer.sh
|
|
182
182
|
. "$HERE/scripts/migrer.sh"
|
|
183
183
|
# shellcheck source=manage/scripts/migrer-retour.sh
|
|
@@ -220,6 +220,7 @@ case "${1:-}" in
|
|
|
220
220
|
vscode) vscode_workspace ;;
|
|
221
221
|
copy-to) copy_to "${@:2}" ;;
|
|
222
222
|
copy-from) copy_from "${@:2}" ;;
|
|
223
|
+
clone) workspace_clone "${@:2}" ;;
|
|
223
224
|
ports) ports "${@:2}" ;;
|
|
224
225
|
migrate) migrate_workspace "${@:2}" ;;
|
|
225
226
|
revert) revert_workspace "${@:2}" ;;
|
|
@@ -227,8 +228,9 @@ case "${1:-}" in
|
|
|
227
228
|
services) services "${@:2}" ;;
|
|
228
229
|
argocd) argocd_cmd "${@:2}" ;;
|
|
229
230
|
'' | -h | --help | aide)
|
|
230
|
-
echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|ports|services|argocd|migrate|revert|clean-docker"
|
|
231
|
+
echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker"
|
|
231
232
|
echo " start [--image repository:tag] install workspace (image for devzone version by default)"
|
|
233
|
+
echo " clone <url> [<name>] git clone into the pod projects folder (gh credentials, identity, repowarden hooks)"
|
|
232
234
|
echo " ports [start|stop|status] applications and services from pod on workstation localhost"
|
|
233
235
|
echo " services enable|disable <service> [options] | status"
|
|
234
236
|
echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
|
|
@@ -239,7 +241,7 @@ case "${1:-}" in
|
|
|
239
241
|
echo " clean-docker remove devzone-* Docker volumes, after confirmation [y/N] (--yes)"
|
|
240
242
|
;;
|
|
241
243
|
*)
|
|
242
|
-
echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|ports|services|argocd|migrate|revert|clean-docker)" >&2
|
|
244
|
+
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
245
|
exit 1
|
|
244
246
|
;;
|
|
245
247
|
esac
|