devzone 0.46.1 → 0.47.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/README.md +1 -1
- package/manage/scripts/ports-apps.sh +109 -0
- package/manage/scripts/ports-workspace.sh +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -361,7 +361,7 @@ L'utilisateur d'un projet possède **sa** base (il y crée tables, index, donné
|
|
|
361
361
|
|
|
362
362
|
## Voir mon application dans le navigateur
|
|
363
363
|
|
|
364
|
-
Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
|
|
364
|
+
Sur le poste Kubernetes, `devzone workspace start` lance un veilleur de ports : chaque port TCP ≥ 1024 qui écoute dans le pod est relayé sur `127.0.0.1` du poste, au même numéro, par `kubectl port-forward`. Un serveur lancé dans le pod (`npm run dev`, port 5173) répond donc sur `http://localhost:5173`, sans commande. Les services activés (PostgreSQL, MySQL, Argo CD) sont relayés aussi, sur leur port habituel. Les Services des applications déployées dans le cluster sont relayés de la même façon, chacun sur un port local (80 → 8080 ; un port déjà pris ailleurs devient un autre port) : `devzone workspace ports status` affiche leur URL `http://127.0.0.1:<port>`. Un Service peut être exclu avec l'annotation `devzone.io/relay: "false"`. Le veilleur se pilote avec `devzone workspace ports start|stop|status` ; détails dans la [référence](manage/docs/reference.md#applications-et-services-sur-localhost-du-poste).
|
|
365
365
|
|
|
366
366
|
Sur le poste Docker, une application lancée **dans** le conteneur (par exemple un Spring Boot avec `./gradlew bootRun` sur le port 8080) n'est pas joignable depuis le poste : le conteneur devzone ne publie aucun port. Dès qu'elle écoute dans le conteneur, le **veilleur de ports automatiques** (`.devcontainer/ports-auto.sh`) pose un relais `alpine/socat` (version figée) sur le Docker de l'hôte, de `127.0.0.1:<port>` du poste vers le port du conteneur : `http://localhost:<port>` **sans commande**. Le relais disparaît quand l'application s'arrête.
|
|
367
367
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Applications of the Kubernetes workspace relayed on workstation localhost (#611).
|
|
3
|
+
# Sourced by ports-workspace.sh, never run alone. One kubectl get svc -A per
|
|
4
|
+
# round: each TCP port of each Service gets a local port, kept stable in
|
|
5
|
+
# .devzone.ports-workspace/apps/<namespace>.<service>.<port> while the Service
|
|
6
|
+
# exists. Output lines: "portlocal|namespace|svc/name|remoteport", as pw_services.
|
|
7
|
+
|
|
8
|
+
PA_MAX=30
|
|
9
|
+
# Namespaces never relayed: system ones, and those of the devzone modules
|
|
10
|
+
# (relayed by pw_services, or without any interface).
|
|
11
|
+
PA_NS_SKIP=" kube-system kube-public kube-node-lease local-path-storage devzone-system devzone-workspace devzone-postgres devzone-mysql devzone-argocd devzone-gitlab devzone-llm "
|
|
12
|
+
|
|
13
|
+
# Services of the cluster, one "namespace|name|clusterIP|type|relay annotation|port/proto," line each.
|
|
14
|
+
pa_discover() {
|
|
15
|
+
pw_kubectl get svc -A -o 'jsonpath={range .items[*]}{.metadata.namespace}|{.metadata.name}|{.spec.clusterIP}|{.spec.type}|{.metadata.annotations.devzone\.io/relay}|{range .spec.ports[*]}{.port}/{.protocol},{end}{"\n"}{end}' 2>/dev/null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# Is the Service excluded? $1 namespace, $2 name, $3 clusterIP, $4 type, $5 relay annotation.
|
|
19
|
+
pa_excluded() {
|
|
20
|
+
case "$PA_NS_SKIP" in *" $1 "*) return 0 ;; esac
|
|
21
|
+
[ "$1/$2" != default/kubernetes ] || return 0
|
|
22
|
+
[ "$5" != false ] || return 0
|
|
23
|
+
case "$4" in ExternalName) return 0 ;; esac
|
|
24
|
+
case "$3" in '' | None) return 0 ;; esac
|
|
25
|
+
return 1
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Is local port $1 free for an application? Not in the list "$2" (" p p "), not taken on the workstation.
|
|
29
|
+
pa_free() {
|
|
30
|
+
case "$2" in *" $1 "*) return 1 ;; esac
|
|
31
|
+
! pw_taken "$1"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# First free local port for Service port $1, given the ports in use "$2": the port itself
|
|
35
|
+
# when >= 1024, else $1 + 8000 (80 -> 8080), then incrementing; past 65000, from 20000.
|
|
36
|
+
pa_new() {
|
|
37
|
+
local c=$(($1 + 8000)) i=0
|
|
38
|
+
if [ "$1" -ge 1024 ] && pa_free "$1" "$2"; then
|
|
39
|
+
echo "$1"
|
|
40
|
+
return 0
|
|
41
|
+
fi
|
|
42
|
+
[ "$c" -le 65000 ] || c=20000
|
|
43
|
+
while [ "$i" -lt 60000 ]; do
|
|
44
|
+
if pa_free "$c" "$2"; then
|
|
45
|
+
echo "$c"
|
|
46
|
+
return 0
|
|
47
|
+
fi
|
|
48
|
+
c=$((c + 1))
|
|
49
|
+
i=$((i + 1))
|
|
50
|
+
[ "$c" -le 65000 ] || c=20000
|
|
51
|
+
done
|
|
52
|
+
return 1
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# One round of applications, from the ports already wanted "$1" (services, pod).
|
|
56
|
+
# Prints the relay lines; writes apps/ (stable local port) and plafond/ (cap marker),
|
|
57
|
+
# removes the state of Services gone, warns once per port over the cap of PA_MAX.
|
|
58
|
+
pa_round() {
|
|
59
|
+
local d used excl ns name ip type annot ports pp port key stored loc n=0 seen="" f
|
|
60
|
+
d="$(pw_dir)"
|
|
61
|
+
mkdir -p "$d/apps" "$d/plafond"
|
|
62
|
+
excl="$(grep -E '^ports_exclus=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- | tr ',' ' ')"
|
|
63
|
+
used=" $1 $excl "
|
|
64
|
+
while IFS='|' read -r ns name ip type annot ports; do
|
|
65
|
+
[ -n "$ns" ] || continue
|
|
66
|
+
pa_excluded "$ns" "$name" "$ip" "$type" "$annot" && continue
|
|
67
|
+
for pp in ${ports//,/ }; do
|
|
68
|
+
case "$pp" in */TCP) ;; *) continue ;; esac
|
|
69
|
+
port="${pp%/*}"
|
|
70
|
+
case "$port" in '' | *[!0-9]*) continue ;; esac
|
|
71
|
+
key="$ns.$name.$port"
|
|
72
|
+
seen="$seen $key "
|
|
73
|
+
stored="$(cat "$d/apps/$key" 2>/dev/null || true)"
|
|
74
|
+
loc=""
|
|
75
|
+
case "$stored" in '' | *[!0-9]*) ;; *) case "$used" in *" $stored "*) ;; *) loc="$stored" ;; esac ;; esac
|
|
76
|
+
if [ -z "$loc" ]; then
|
|
77
|
+
loc="$(pa_new "$port" "$used")" || { echo "⚠ no free local port for $ns/$name:$port" >&2; continue; }
|
|
78
|
+
fi
|
|
79
|
+
used="$used $loc "
|
|
80
|
+
[ "$loc" = "$stored" ] || printf '%s' "$loc" >"$d/apps/$key"
|
|
81
|
+
if [ "$n" -lt "$PA_MAX" ]; then
|
|
82
|
+
n=$((n + 1))
|
|
83
|
+
rm -f "$d/plafond/$key"
|
|
84
|
+
echo "$loc|$ns|svc/$name|$port"
|
|
85
|
+
elif [ ! -e "$d/plafond/$key" ]; then
|
|
86
|
+
: >"$d/plafond/$key"
|
|
87
|
+
echo "⚠ cap of $PA_MAX application relays reached, $ns/$name:$port not relayed" >&2
|
|
88
|
+
fi
|
|
89
|
+
done
|
|
90
|
+
done <<<"$(pa_discover)"
|
|
91
|
+
for f in "$d"/apps/* "$d"/plafond/*; do
|
|
92
|
+
[ -e "$f" ] || continue
|
|
93
|
+
case "$seen" in *" $(basename "$f") "*) ;; *) rm -f "$f" ;; esac
|
|
94
|
+
done
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Status lines of relayed applications: local URL, then namespace/service:port.
|
|
98
|
+
pa_status() {
|
|
99
|
+
local d f key rest loc
|
|
100
|
+
d="$(pw_dir)"
|
|
101
|
+
for f in "$d"/apps/*; do
|
|
102
|
+
[ -e "$f" ] || continue
|
|
103
|
+
loc="$(cat "$f")"
|
|
104
|
+
pw_alive "$(cat "$d/relais/$loc" 2>/dev/null)" || continue
|
|
105
|
+
key="$(basename "$f")"
|
|
106
|
+
rest="${key#*.}"
|
|
107
|
+
echo " http://127.0.0.1:$loc ${key%%.*}/${rest%%.*}:${rest#*.}"
|
|
108
|
+
done
|
|
109
|
+
}
|
|
@@ -13,6 +13,9 @@ PW_NS="devzone-workspace"
|
|
|
13
13
|
PW_INTERNAL=" 2475 1234 "
|
|
14
14
|
# pgAdmin service port: read from the service, without it nothing is relayed.
|
|
15
15
|
PW_JSONPATH='jsonpath={.spec.ports[0].port}'
|
|
16
|
+
# Cluster Services relayed as applications (#611).
|
|
17
|
+
# shellcheck source=manage/scripts/ports-apps.sh
|
|
18
|
+
. "$(dirname "${BASH_SOURCE[0]}")/ports-apps.sh"
|
|
16
19
|
|
|
17
20
|
# Watcher state folder: lock, pid, relays, reported ports, log.
|
|
18
21
|
pw_dir() { printf '%s' "${DEVZONE_PORTS_WORKSPACE_DIR:-$PWD/.devzone.ports-workspace}"; }
|
|
@@ -125,6 +128,11 @@ pw_round() {
|
|
|
125
128
|
wanted="$wanted $p "
|
|
126
129
|
pw_relay "$p" "$PW_NS" "pod/$PW_POD"
|
|
127
130
|
done
|
|
131
|
+
while IFS='|' read -r p ns target remote; do
|
|
132
|
+
[ -n "$p" ] || continue
|
|
133
|
+
wanted="$wanted $p "
|
|
134
|
+
pw_relay "$p" "$ns" "$target" "$remote"
|
|
135
|
+
done <<<"$(pa_round "$wanted")"
|
|
128
136
|
for f in "$d"/relais/* "$d"/pris/*; do
|
|
129
137
|
[ -e "$f" ] || continue
|
|
130
138
|
l="$(basename "$f")"
|
|
@@ -197,6 +205,7 @@ ports_status() {
|
|
|
197
205
|
for f in "$d"/pris/*; do
|
|
198
206
|
if [ -e "$f" ]; then echo " ⚠ port $(basename "$f") already in use on the workstation, not relayed"; fi
|
|
199
207
|
done
|
|
208
|
+
pa_status
|
|
200
209
|
return 0
|
|
201
210
|
}
|
|
202
211
|
|