devzone 7.1.0 → 7.1.1

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 (53) hide show
  1. package/.devcontainer/Dockerfile +1 -8
  2. package/.devcontainer/catalog/app.sh +5 -12
  3. package/.devcontainer/cluster.sh +1 -11
  4. package/.devcontainer/devcontainer.json +1 -11
  5. package/.devcontainer/devzone +17 -9
  6. package/.devcontainer/devzone-cluster.sh +1 -1
  7. package/.devcontainer/devzone-modules.sh +7 -2
  8. package/.devcontainer/devzone-repair.sh +9 -19
  9. package/.devcontainer/devzone-services.sh +21 -20
  10. package/.devcontainer/devzone-status.sh +4 -12
  11. package/.devcontainer/help.sh +3 -4
  12. package/.devcontainer/isolation.sh +1 -1
  13. package/.devcontainer/kube-account.sh +12 -173
  14. package/.devcontainer/metrics-server.sh +1 -1
  15. package/.devcontainer/packages.sh +2 -2
  16. package/.devcontainer/ports-json.sh +0 -4
  17. package/.devcontainer/ports.sh +6 -102
  18. package/.devcontainer/state-json.sh +4 -14
  19. package/.devcontainer/versions.env +2 -2
  20. package/.devcontainer/workspace-init.sh +1 -2
  21. package/Makefile +4 -4
  22. package/README.md +13 -20
  23. package/bin/SHA256SUMS +6 -6
  24. package/bin/devzone-darwin-amd64 +0 -0
  25. package/bin/devzone-darwin-arm64 +0 -0
  26. package/bin/devzone-linux-amd64 +0 -0
  27. package/bin/devzone-linux-arm64 +0 -0
  28. package/bin/devzone-windows-amd64.exe +0 -0
  29. package/bin/devzone-windows-arm64.exe +0 -0
  30. package/manage/devzone +4 -4
  31. package/package.json +1 -1
  32. package/.devcontainer/argocd/argocd.sh +0 -222
  33. package/.devcontainer/argocd/catalog-argocd.sh +0 -119
  34. package/.devcontainer/argocd/services-hook.sh +0 -181
  35. package/.devcontainer/catalog/mysql/install.sh +0 -87
  36. package/.devcontainer/catalog/mysql/mysql.sh +0 -262
  37. package/.devcontainer/catalog/mysql/volume.sh +0 -71
  38. package/.devcontainer/git-identity.sh +0 -28
  39. package/.devcontainer/gitlab/argocd.sh +0 -54
  40. package/.devcontainer/gitlab/chart.sh +0 -39
  41. package/.devcontainer/gitlab/gitlab.sh +0 -168
  42. package/.devcontainer/gitlab/installation.sh +0 -193
  43. package/.devcontainer/gitlab/secrets.sh +0 -95
  44. package/.devcontainer/gitlab/seed.sh +0 -204
  45. package/.devcontainer/gitlab/test-gitlab-restes.sh +0 -16
  46. package/.devcontainer/gitlab/test-gitlab.sh +0 -489
  47. package/.devcontainer/kind-wrapper.sh +0 -45
  48. package/.devcontainer/kube-config.sh +0 -78
  49. package/.devcontainer/kube-reachable.sh +0 -64
  50. package/.devcontainer/ports-auto.sh +0 -247
  51. package/.devcontainer/post-create.sh +0 -91
  52. package/.devcontainer/postgres/postgres.sh +0 -309
  53. package/.devcontainer/startup.sh +0 -65
@@ -1,247 +0,0 @@
1
- #!/usr/bin/env bash
2
- HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
3
- # shellcheck source=ports.sh
4
- # shellcheck disable=SC1091
5
- . "$HERE/ports.sh"
6
- PORTS_AUTO_DIR="${DEVZONE_PORTS_AUTO_DIR:-/tmp/devzone-ports-auto}"
7
- BASE="$PORTS_AUTO_DIR/${INSTANCE:-devzone}"
8
- BRIDGES="$BASE/bridges"
9
- # State file names on disk (lock, busy, active, current): the watcher and the tests use them (#774)
10
- LOCK="$BASE/lock"; BUSY="$BASE/busy"; ACTIVE="$BASE/active"
11
- PENDING="$BASE/pending"; CURRENT="$BASE/current"
12
- JSON_APP_BUSY=$'occup\303\251 sur le poste' # JSON value, contract (see ports.sh)
13
- mkdir -p "$BASE" "$BRIDGES"
14
-
15
- # Automatic watcher state: off as soon as ports_auto= is off (« non » kept as a stored value)
16
- auto_enabled() { local v; v="$(grep -E '^ports_auto=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"; case "$v" in off|false|0|non|no) echo off ;; *) echo on ;; esac; }
17
- # List of the ports excluded by the user (excluded_ports=, comma-separated)
18
- excluded_read() { grep -E '^excluded_ports=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true; }
19
- # Writes a key=value line in the state, like write_ports does for ports=
20
- write_key() { state_write "$1" "${2:-}" || { echo "devzone : port : state not saved : $ETAT" >&2; return 1; }; }
21
- # A port is excluded when it is listed in excluded_ports=.
22
- port_excluded() { case ",$(excluded_read)," in *",$1,"*) return 0 ;; esac; return 1; }
23
- # Name of the automatic relay of a port: devzone-<instance>-auto-<port>.
24
- auto_relay_name() { echo "devzone-$INSTANCE-auto-$1"; }
25
- # Is the automatic relay of <port> already alive on the host's Docker?
26
- auto_relay_active() { local name; name="$(auto_relay_name "$1")"; command -v docker >/dev/null 2>&1 || return 1; [ -n "$(docker ps --filter "name=^$name$" --format '{{.Names}}' 2>/dev/null | grep -Fx "$name" || true)" ]; }
27
- # Delay after a port disappears before removing its bridge and relay.
28
- disappearance_delay() { local v; for v in DEVZONE_PORTS_AUTO_DISAPPEARANCE_DELAY DEVZONE_PORTS_AUTO_DELAY DEVZONE_PORTS_AUTO_LATE PORTS_AUTO_DELAI PORTS_AUTO_RETARD; do [ -n "${!v:-}" ] && { echo "${!v}"; return 0; }; done; echo 10; }
29
-
30
- # Guard: the loop and demarrer never run under bats,
31
- # and outside the container only if the real context is set.
32
- guard_watcher() {
33
- if [ -n "${BATS_TEST_TMPDIR:-}" ]; then
34
- echo "devzone : port : automatic watcher refused under bats (tests)" >&2
35
- return 2
36
- fi
37
- [ "${DEVZONE_PORTS_AUTO_REAL:-}" = yes ] && return 0
38
- echo "devzone : port : automatic watcher refused here: run devzone repair instead" >&2
39
- return 2
40
- }
41
-
42
- # Launches the automatic relay; on failure, a message and code 1 (busy port marked).
43
- launch_auto() {
44
- local port="$1" network="$2" ip="$3" name output
45
- name="$(auto_relay_name "$port")"
46
- if output="$(docker run -d --restart unless-stopped --name "$name" --label "devzone.instance=$INSTANCE" --label "devzone.port=$port" --label "devzone.auto=true" --network "$network" -p "127.0.0.1:$port:$port" "$SOCAT_IMAGE" "tcp-listen:$port,fork,reuseaddr" "tcp-connect:$ip:$port" 2>&1)"; then return 0; fi
47
- case "$output" in *"port is already allocated"*|*"address already in use"*) echo "devzone : port : port already in use on the workstation : $port" >&2 ;; *) echo "devzone : port : relay on port $port failed : $output" >&2 ;; esac
48
- return 1
49
- }
50
- # Starts the internal bridge: socat on the container IP, toward the 127.0.0.1 of the port.
51
- start_bridge() { local port="$1" ip="$2"; local pidfile="$BRIDGES/$port.pid"; if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile" 2>/dev/null)" 2>/dev/null; then return 0; fi; socat "TCP-LISTEN:$port,bind=$ip,fork,reuseaddr" "TCP:127.0.0.1:$port" >/dev/null 2>&1 & echo "$!" >"$pidfile"; }
52
- # Stops the internal bridge (pid in $BRIDGES).
53
- stop_bridge() { local port="$1"; local pidfile="$BRIDGES/$port.pid"; local pid; if [ -f "$pidfile" ]; then pid="$(cat "$pidfile" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi; wait "$pid" 2>/dev/null || true; rm -f "$pidfile"; fi; }
54
- # Removes the automatic relay and its bridge.
55
- close_auto() { local port="$1"; docker rm -f "$(auto_relay_name "$port")" >/dev/null 2>&1 || true; stop_bridge "$port"; }
56
-
57
- # Removes all the automatic relays and their bridges, then empties the states.
58
- clean_auto_all() {
59
- local port; [ -f "$ACTIVE" ] && while IFS= read -r port; do [ -n "$port" ] && close_auto "$port"; done <"$ACTIVE"
60
- [ -f "$BUSY" ] && while IFS= read -r port; do [ -n "$port" ] && stop_bridge "$port"; done <"$BUSY"
61
- : >"$ACTIVE" 2>/dev/null || true; : >"$BUSY" 2>/dev/null || true; : >"$PENDING" 2>/dev/null || true; rm -f "$BRIDGES"/*.pid 2>/dev/null || true
62
- }
63
- # Removes the automatic relays of a previous session.
64
- clean_previous() { docker ps -a --filter "name=devzone-$INSTANCE-auto-" --format '{{.Names}}' 2>/dev/null | while IFS= read -r name; do case "$name" in devzone-"$INSTANCE"-auto-*) docker rm -f "$name" >/dev/null 2>&1 || true ;; esac; done; rm -f "$BRIDGES"/*.pid 2>/dev/null || true; }
65
-
66
- # Exclusive lock (mkdir) with a pid: a single watcher instance.
67
- lock_take() {
68
- local start now age pid
69
- start="$(date +%s)"
70
- while true; do
71
- if mkdir "$LOCK" 2>/dev/null; then echo "$$" >"$LOCK/pid"; return 0; fi
72
- now="$(date +%s)"; age=""; [ -d "$LOCK" ] && age="$(stat -c %Y "$LOCK" 2>/dev/null || stat -f %m "$LOCK" 2>/dev/null || true)"
73
- pid="$(cat "$LOCK/pid" 2>/dev/null || true)"
74
- if [ -n "$age" ] && [ "$(( now - age ))" -gt 30 ]; then rm -rf "$LOCK"; continue; fi
75
- if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$LOCK"; continue; fi
76
- [ "$(( now - start ))" -ge 5 ] && return 1
77
- sleep 1
78
- done
79
- }
80
-
81
- # Marks the lock as alive: recent date and pid of the holder up to date,
82
- # otherwise another instance takes the lock as stale.
83
- lock_refresh() { touch "$LOCK" 2>/dev/null || true; echo "$$" >"$LOCK/pid" 2>/dev/null || true; }
84
-
85
- # One watcher pass: relays the listening ports, removes the vanished ones.
86
- auto_pass() {
87
- local port now delay output
88
- # State restored or rebuilt: nothing for 60 s (#417, step 4)
89
- state_recovery_wait && return 0
90
- if [ "$(auto_enabled)" = off ]; then
91
- # Never uninstall on an unconfirmed state (#417, step 4)
92
- state_recovery_pending || clean_auto_all
93
- return 0
94
- fi
95
- if ! network_ip; then echo "devzone : ports-auto : devzone container not found" >&2; return 1; fi
96
- : >"$CURRENT"
97
- ss -ltnH 2>/dev/null | awk '{ if (NF >= 4) print $4; else if (NF >= 1) print $1 }' | while IFS= read -r listen; do
98
- [ -n "$listen" ] || continue
99
- p="${listen##*:}"; a="${listen%:*}"; a="${a#[}"; a="${a%]}"
100
- case "$p" in ''|*[!0-9]*) continue ;; esac
101
- [ "$a" = "127.0.0.11" ] && continue
102
- [ "$p" -lt 1024 ] 2>/dev/null && continue
103
- case "$p" in 5432|8929|2224) continue ;; esac
104
- case ",$(read_ports)," in *",$p,"*) continue ;; esac
105
- port_excluded "$p" && continue
106
- [ "$a" = "$IP" ] && continue
107
- printf '%s %s\n' "$a" "$p" >>"$CURRENT"
108
- done
109
- awk '{print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/actuels"
110
- awk '$1=="0.0.0.0" || $1=="::" || $1=="*" || $1==":::" {print $2}' "$CURRENT" 2>/dev/null | sort -n -u >"$BASE/allif"
111
- : >"$BASE/managed"
112
- [ -f "$ACTIVE" ] && cat "$ACTIVE" >>"$BASE/managed"
113
- for f in "$BRIDGES"/*.pid; do [ -e "$f" ] || continue; basename "${f%.pid}" >>"$BASE/managed"; done
114
- [ -f "$BUSY" ] && cat "$BUSY" >>"$BASE/managed"
115
- sort -n -u "$BASE/managed" -o "$BASE/managed" 2>/dev/null || true
116
-
117
- now="$(date +%s)"; delay="$(disappearance_delay)"
118
- while IFS= read -r port; do
119
- [ -n "$port" ] || continue
120
- grep -qxF "$port" "$BUSY" 2>/dev/null && continue
121
- grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
122
- grep -qxF "$port" "$BASE/allif" || start_bridge "$port" "$IP"
123
- # shellcheck disable=SC2153
124
- if output="$(launch_auto "$port" "$NETWORK" "$IP" 2>&1)"; then
125
- grep -qxF "$port" "$ACTIVE" 2>/dev/null || echo "$port" >>"$ACTIVE"
126
- else
127
- printf '%s\n' "$output" >&2
128
- grep -qxF "$port" "$BASE/allif" || stop_bridge "$port"
129
- case "$output" in *"already in use"*|*"already allocated"*) echo "$port" >>"$BUSY" ;; esac
130
- fi
131
- done <"$BASE/actuels"
132
-
133
- while IFS= read -r port; do
134
- [ -n "$port" ] || continue
135
- grep -qxF "$port" "$BASE/actuels" 2>/dev/null && continue
136
- if grep -qxF "$port" "$BUSY" 2>/dev/null; then
137
- grep -vxF "$port" "$BUSY" >"$BUSY.tmp" 2>/dev/null || true; mv "$BUSY.tmp" "$BUSY" 2>/dev/null || true
138
- stop_bridge "$port"; continue
139
- fi
140
- if grep -q "^$port " "$PENDING" 2>/dev/null; then
141
- old="$(grep "^$port " "$PENDING" | head -1 | cut -d' ' -f2)"
142
- # Nothing is removed on an unconfirmed restored state (#417)
143
- if state_recovery_pending; then continue; fi
144
- if [ -n "$old" ] && [ "$(( now - old ))" -ge "$delay" ]; then
145
- close_auto "$port"
146
- grep -v "^$port " "$PENDING" >"$PENDING.tmp" 2>/dev/null || true; mv "$PENDING.tmp" "$PENDING" 2>/dev/null || true
147
- grep -vxF "$port" "$ACTIVE" >"$ACTIVE.tmp" 2>/dev/null || true; mv "$ACTIVE.tmp" "$ACTIVE" 2>/dev/null || true
148
- fi
149
- else
150
- echo "$port $now" >>"$PENDING"
151
- fi
152
- done <"$BASE/managed"
153
-
154
- while IFS= read -r port; do
155
- [ -n "$port" ] || continue
156
- grep -v "^$port " "$PENDING" >"$PENDING.tmp" 2>/dev/null || true; mv "$PENDING.tmp" "$PENDING" 2>/dev/null || true
157
- done <"$BASE/actuels"
158
- }
159
-
160
- # Stops the watcher and cleans its relays.
161
- stop_watcher() { local pid; pid="$(cat "$LOCK/pid" 2>/dev/null || true)"; if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi; clean_auto_all; rm -rf "$LOCK"; }
162
-
163
- # Loop: one pass every DEVZONE_PORTS_AUTO_STEP seconds.
164
- auto_loop() {
165
- if ! lock_take; then return 0; fi
166
- clean_previous
167
- trap 'clean_auto_all; rm -rf "$LOCK"' EXIT INT TERM
168
- while true; do
169
- # State restored or rebuilt: nothing for 60 s (#417, step 4)
170
- if state_recovery_wait; then
171
- lock_refresh
172
- sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
173
- continue
174
- fi
175
- # State folder gone: the container has left, the watcher stops.
176
- if [ ! -f "$ETAT" ]; then clean_auto_all; break; fi
177
- lock_refresh
178
- if [ "$(auto_enabled)" = off ]; then
179
- # Never uninstall on an unconfirmed state (#417)
180
- state_recovery_pending || clean_auto_all
181
- break
182
- fi
183
- auto_pass || true
184
- sleep "${DEVZONE_PORTS_AUTO_STEP:-2}"
185
- done
186
- }
187
-
188
- # Excludes a port from the automatic list (writes excluded_ports=).
189
- auto_exclude() { validate_port "${1:-}"; local current; current="$(excluded_read)"; case ",$current," in *",$1,"*) echo "port $1 already excluded"; return 0 ;; esac; write_key excluded_ports "$(sort_ports "$current,$1")"; echo "✔ port $1 excluded"; }
190
- # Puts a port back in the automatic list (removes it from excluded_ports=).
191
- auto_include() { validate_port "${1:-}"; local current rest p; current="$(excluded_read)"; rest=""; for p in $(printf '%s' "$current" | tr ',' ' '); do [ "$p" = "$1" ] || rest="$rest${rest:+,}$p"; done; write_key excluded_ports "$(sort_ports "$rest")"; echo "✔ port $1 included"; }
192
-
193
- # Lists the automatic relays alive (or busy on the workstation).
194
- auto_list() {
195
- local port mark app
196
- if [ -f "$ACTIVE" ]; then
197
- while IFS= read -r port; do
198
- [ -n "$port" ] || continue
199
- if grep -qxF "$port" "$BUSY" 2>/dev/null; then printf ' %-5s %s auto\n' "$port" "busy on the workstation"; continue; fi
200
- if auto_relay_active "$port"; then mark="● active"; else mark="○ stopped"; fi
201
- if app_responds "$port"; then app="$APP_RESPONDS"; else app="$APP_NONE"; fi
202
- printf ' %-5s %s auto %s\n' "$port" "$mark" "$app"
203
- done <"$ACTIVE"
204
- fi
205
- if [ -f "$BUSY" ]; then
206
- while IFS= read -r port; do
207
- [ -n "$port" ] || continue
208
- grep -qxF "$port" "$ACTIVE" 2>/dev/null && continue
209
- printf ' %-5s %s auto\n' "$port" "busy on the workstation"
210
- done <"$BUSY"
211
- fi
212
- }
213
-
214
- # Machine output (jq) of the automatic relays.
215
- auto_list_json() {
216
- local port active app json='[]' ports=""
217
- [ -f "$ACTIVE" ] && ports="$(cat "$ACTIVE")"
218
- [ -f "$BUSY" ] && ports="$ports"$'\n'"$(cat "$BUSY")"
219
- ports="$(printf '%s\n' "$ports" | awk 'NF' | sort -n -u)"
220
- while IFS= read -r port; do
221
- [ -n "$port" ] || continue
222
- if grep -qxF "$port" "$BUSY" 2>/dev/null; then
223
- json="$(jq -c --argjson port "$port" --arg busy "$JSON_APP_BUSY" '. + [{port:$port,active:false,application:$busy,auto:true}]' <<<"$json")"; continue
224
- fi
225
- if auto_relay_active "$port"; then active=true; else active=false; fi
226
- if app_responds "$port"; then app="$JSON_APP_RESPONDS"; else app="$JSON_APP_NONE"; fi
227
- json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" '. + [{port:$port,active:$active,application:$app,auto:true}]' <<<"$json")"
228
- done <<<"$ports"
229
- printf '%s\n' "$json"
230
- }
231
-
232
- if [ "${BASH_SOURCE[0]}" = "$0" ]; then
233
- case "${1:-}" in
234
- ''|boucle|loop) if ! guard_watcher; then exit 2; fi; auto_loop ;;
235
- tour|one|un-tour) auto_pass ;;
236
- demarrer|start|lancer) if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then echo "ports: Kubernetes workspace, ports go through devzone workspace ports"; exit 0; fi; if ! guard_watcher; then exit 2; fi; if kill -0 "$(cat "$LOCK/pid" 2>/dev/null)" 2>/dev/null; then echo "already running"; else DEVZONE_PORTS_AUTO_REAL=yes bash "$0" boucle >/dev/null 2>&1 & echo "started"; fi ;;
237
- arreter|stop) stop_watcher; echo "stopped" ;;
238
- nettoyer|clean) clean_auto_all ;;
239
- auto) case "${2:-}" in on) write_key ports_auto on; echo "✔ automatic ports enabled" ;; off) write_key ports_auto off; stop_watcher; echo "✔ automatic ports disabled" ;; *) echo "devzone : port : auto on|off" >&2; exit 2 ;; esac ;;
240
- exclude|exclure) auto_exclude "${2:-}" ;;
241
- include|inclure) auto_include "${2:-}" ;;
242
- list_auto) auto_list ;;
243
- list_json_auto) auto_list_json ;;
244
- -h|--help|aide) sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//' ;;
245
- *) echo "devzone : ports-auto : unknown command : ${1:-}" >&2; exit 2 ;;
246
- esac
247
- fi
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Steps that cannot be in the image (Dockerfile):
3
- # - volumes mounted at startup only
4
- # - npm provided by the node feature, added after the Dockerfile
5
- set -euo pipefail
6
- # Never a question: the devcontainer CLI runs this step under a terminal, output
7
- # sent to .devzone.log by make, so invisible; a question (repowarden install
8
- # proposes « repowarden bots » in a GitHub repository whose gh is administrator)
9
- # would wait forever. Empty input: each tool switches to non-interactive mode
10
- # (bots: « later, repowarden bots »)
11
- exec </dev/null
12
-
13
- # Named volumes created as root → give back to the vscode user
14
- # (and ~/.config, created by Docker to mount ~/.config/opencode)
15
- sudo chown -R vscode:vscode /home/vscode/.m2 /home/vscode/.gradle /home/vscode/.local /home/vscode/.claude \
16
- /home/vscode/.config/opencode /home/vscode/.config/gh /home/vscode/.config/git \
17
- /home/vscode/.config/devzone /home/vscode/.local/state/oc-lancer
18
- sudo chown vscode:vscode /home/vscode/.config
19
-
20
- # Git: the container's repositories declared safe (their owner may differ from
21
- # the user running git: volumes, Docker Desktop, tools run separately), and
22
- # GitHub access by the gh token, kept in its volume (https, even for the
23
- # git@github.com: remotes, without an ssh key to copy)
24
- # Machine settings in the container's ~/.gitconfig (recreated at each rebuild):
25
- # without this file, git config --global (and repowarden install) would write
26
- # into ~/.config/git/config, the identity volume, where they would pile up from
27
- # one rebuild to the next
28
- touch "$HOME/.gitconfig"
29
- # Volume touched by a previous version: only these settings are removed from it,
30
- # the identity and any other setting are kept
31
- volume="$HOME/.config/git/config"
32
- if [ -f "$volume" ]; then
33
- remove() { git config --file "$volume" --unset-all "$@" 2>/dev/null || true; }
34
- remove safe.directory '^/workspaces/devzone'
35
- remove credential.https://github.com.helper
36
- remove url.https://github.com/.insteadOf
37
- remove core.hooksPath 'repowarden'
38
- remove alias.cc 'repowarden'
39
- remove repowarden.lang
40
- fi
41
- git config --global --add safe.directory /workspaces/devzone
42
- git config --global --add safe.directory '/workspaces/devzone/workspace/*'
43
- git config --global --replace-all credential.https://github.com.helper ''
44
- git config --global --add credential.https://github.com.helper '!gh auth git-credential'
45
- git config --global url.https://github.com/.insteadOf git@github.com:
46
-
47
- # repowarden, pinned version (it installs global git hooks); update
48
- # .devcontainer/versions.env, then Rebuild Container
49
- echo "devzone : installing repowarden…"
50
- # shellcheck source=SCRIPTDIR/versions.env
51
- . "$(dirname "${BASH_SOURCE[0]}")/versions.env"
52
- npm install -g "repowarden@$REPOWARDEN_VERSION"
53
- repowarden install --global --lang fr
54
-
55
- # Optional modules (AI assistants, Kubernetes): devzone command, state kept in
56
- # the instance folder ($RACINE/.devzone.modules); installs what is enabled. A
57
- # failing module does not stop the creation: the container stays usable and the
58
- # state (devzone, at each startup) shows it as « in failure »
59
- sudo ln -sf /workspaces/devzone/.devcontainer/devzone /usr/local/bin/devzone
60
- # Access to the workstation cluster (hote.config) before the modules that depend
61
- # on it (#370); a failure does not stop the creation, the startup runs it again
62
- bash /workspaces/devzone/.devcontainer/kube-config.sh || echo "devzone : kube configuration incomplete, retry: devzone start" >&2
63
- # Former names (state key ia=) renamed before the first read of the state (#774)
64
- bash /workspaces/devzone/.devcontainer/rename-legacy-files.sh || echo "devzone : legacy names not renamed, retry: devzone repair" >&2
65
- devzone apply || echo "devzone : modules incomplete (details above), retry: devzone apply" >&2
66
- # Guarded system packages (#351): reinstalled at each creation; a failure does not stop the creation
67
- devzone packages apply || echo "devzone : packages failed, retry: devzone packages" >&2
68
-
69
- # Kubernetes prompt of the shell (#337): prefixes PS1, only once. The check also
70
- # accepts the block written before the rename to kube-prompt.sh (invite-kube.sh)
71
- if grep -qE 'invite-kube\.sh|devzone_invite_kube' "$HOME/.bashrc" 2>/dev/null; then
72
- sed -i -e 's#/\.devcontainer/invite-kube\.sh#/.devcontainer/kube-prompt.sh#' \
73
- -e 's#devzone_invite_kube#devzone_kube_prompt#' "$HOME/.bashrc"
74
- fi
75
- if ! grep -qE 'kube-prompt.sh|invite-kube.sh' "$HOME/.bashrc" 2>/dev/null; then
76
- cat >>"$HOME/.bashrc" <<'PROMPT'
77
- # >>> devzone invite >>>
78
- # shellcheck source=/dev/null
79
- . /workspaces/devzone/.devcontainer/kube-prompt.sh
80
- PS1='$(devzone_kube_prompt) '"$PS1"
81
- # <<< devzone invite <<<
82
- PROMPT
83
- fi
84
-
85
- # What remains to be done (git identity, GitHub, modules): devzone summary,
86
- # displayed at each startup (startup.sh)
87
-
88
- recap="java $(java -version 2>&1 | head -1 | cut -d'"' -f2), node $(node -v), python $(python3 --version | cut -d' ' -f2), repowarden $(repowarden --version)"
89
- ! command -v claude >/dev/null || recap+=", claude $(claude --version | cut -d' ' -f1)"
90
- ! command -v opencode >/dev/null || recap+=", opencode $(opencode --version)"
91
- echo "devzone up : $recap"
@@ -1,309 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Module postgres (#280): shared PostgreSQL in the devzone cluster (cluster.sh),
3
- # one database and one user per project.
4
- # postgres.sh install | uninstall | status | relay-start | relay-stop
5
- # postgres.sh create <project> [--new-password] database, role, workspace/.postgres/<project>.env
6
- # postgres.sh list databases and owners
7
- # postgres.sh psql [<project>] console in the pod
8
- # postgres.sh delete <project> [--yes] database, role and .env file
9
- # Secrets in workspace/.postgres/ (600, ignored by git), never displayed.
10
- set -euo pipefail
11
-
12
- ICI="$(cd "$(dirname "$0")" && pwd)"
13
- RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
14
- # shellcheck disable=SC2034 # read by cluster.sh (sourced library)
15
- ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
16
- # shellcheck source=SCRIPTDIR/../cluster.sh
17
- . "$ICI/../cluster.sh"
18
- # shellcheck source=SCRIPTDIR/../password.sh
19
- # shellcheck disable=SC1091
20
- . "$ICI/../password.sh"
21
- # shellcheck source=SCRIPTDIR/../chart-direct.sh
22
- # shellcheck disable=SC1091
23
- . "$ICI/../chart-direct.sh"
24
- # Network isolation: namespace_isolate, which provides the NetworkPolicies
25
- # shellcheck source=SCRIPTDIR/../isolation.sh
26
- # shellcheck disable=SC1091
27
- . "$ICI/../isolation.sh"
28
-
29
- NS=devzone-postgres
30
- SECRETS="$RACINE/workspace/.postgres"
31
- # Container port where the relay makes PostgreSQL reachable
32
- POSTGRES_PORT="${POSTGRES_PORT:-5432}"
33
- POSTGRES_ATTENTE="${POSTGRES_ATTENTE:-300}"
34
- POSTGRES_TAILLE="${POSTGRES_TAILLE:-5Gi}"
35
-
36
- refuse() { echo "devzone : postgres : $*" >&2; exit 2; }
37
-
38
- # Grouped credentials view: a failure never blocks the operation
39
- regenerate_credentials() {
40
- password_regenerate ||
41
- echo "devzone : postgres : grouped credentials not updated (devzone passwords)" >&2
42
- }
43
-
44
- # Module context: the devzone cluster; without a choice nothing is
45
- # installed (devzone enable postgres sets it)
46
- module_context() {
47
- local c
48
- c="$(cluster_saved)"
49
- [ -n "$c" ] || refuse "no cluster chosen: devzone enable postgres"
50
- echo "$c"
51
- }
52
-
53
- k() {
54
- kubectl --context devzone -n "$NS" "$@"
55
- }
56
-
57
- # Namespace present in the services cluster: reading namespaces is
58
- # reserved to the administrator (#430)
59
- is_installed() {
60
- account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1
61
- }
62
-
63
- # psql as superuser in the pod: local connection (socket), no password;
64
- # the SQL script goes through stdin, never as a visible argument
65
- psql_admin() {
66
- k exec -i postgres-0 -c postgres -- psql -v ON_ERROR_STOP=1 -X -q -U postgres "$@"
67
- }
68
-
69
- # Project name = role name and database name: simple SQL identifier, never
70
- # to escape, and not a reserved name
71
- validate_project() {
72
- local p="${1:-}"
73
- [ -n "$p" ] || refuse "project name missing"
74
- [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "invalid project name: $p (lowercase, digits, _; starts with a letter)"
75
- case "$p" in
76
- postgres | template0 | template1) refuse "reserved name: $p" ;;
77
- esac
78
- }
79
-
80
- new_password() {
81
- openssl rand -hex 24
82
- }
83
-
84
- # Superuser password: the one in the secret if it already exists in the
85
- # cluster (never regenerated: the database keeps its own), otherwise the local
86
- # file, otherwise a new one
87
- admin_secret() {
88
- local file="$SECRETS/admin-password" pw
89
- mkdir -p "$SECRETS"
90
- chmod 700 "$SECRETS"
91
- if k get secret postgres-admin >/dev/null 2>&1; then
92
- pw="$(k get secret postgres-admin -o jsonpath='{.data.password}' | base64 -d)"
93
- (umask 077 && printf '%s' "$pw" >"$file")
94
- return 0
95
- fi
96
- if [ ! -s "$file" ]; then
97
- (umask 077 && new_password | tr -d '\n' >"$file")
98
- fi
99
- k create secret generic postgres-admin --from-file=password="$file" >/dev/null
100
- }
101
-
102
- do_install() {
103
- CTX="$(module_context)"
104
- cluster_prepare "$CTX"
105
- # On a new machine, the devzone context must point to the chosen cluster
106
- # before any resource is created (#396); otherwise, everything stops: message and code
107
- if ! devzone_context_set "$CTX"; then
108
- echo "devzone : postgres : cannot set the devzone context on $CTX" >&2
109
- return 1
110
- fi
111
- echo "▶ PostgreSQL on cluster $CTX (namespace $NS)…"
112
- # Namespace created and labeled by the administrator (#430): the limited
113
- # account may not create objects outside the devzone-* namespaces
114
- account_admin "$CTX" create namespace "$NS" --dry-run=client -o yaml |
115
- account_admin "$CTX" apply -f - >/dev/null
116
- account_admin "$CTX" label namespace "$NS" "$CLUSTER_LABEL" --overwrite >/dev/null
117
- # Limited account allowed in the namespace: RoleBinding to edit
118
- account_allow "$CTX" "$NS"
119
- admin_secret
120
- chart_install postgres "$NS" "size=$POSTGRES_TAILLE" || return 1
121
- echo "▶ Waiting for PostgreSQL (timeout ${POSTGRES_ATTENTE}s)…"
122
- if ! k rollout status statefulset/postgres --timeout="${POSTGRES_ATTENTE}s" >/dev/null; then
123
- echo "devzone : postgres : not ready after ${POSTGRES_ATTENTE}s: kubectl --context $CTX -n $NS describe pod postgres-0" >&2
124
- return 1
125
- fi
126
- relay_stop postgres
127
- relay_start postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
128
- echo "✔ PostgreSQL ready: 127.0.0.1:$POSTGRES_PORT in the container"
129
- echo " Database for a project: devzone postgres create <project>"
130
- regenerate_credentials
131
- }
132
-
133
- do_uninstall() {
134
- CTX="$(cluster_saved)"
135
- relay_stop postgres
136
- # Uninstall on a new machine: the devzone context is reset to the chosen
137
- # cluster (otherwise it points to the old one); without it, only the
138
- # local cleanup takes place
139
- if [ -n "$CTX" ]; then
140
- devzone_context_set "$CTX" ||
141
- echo "devzone : postgres : devzone context not set on $CTX; local cleanup only" >&2
142
- fi
143
- if [ -n "$CTX" ] && is_installed; then
144
- echo "▶ Deleting PostgreSQL and all its databases on ${CTX}…"
145
- # RoleBinding removed, then namespace deleted by the administrator (#430)
146
- account_remove "$CTX" "$NS" >/dev/null 2>&1 || true
147
- account_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
148
- cluster_release "$CTX"
149
- fi
150
- rm -rf "$SECRETS"
151
- echo "✔ PostgreSQL uninstalled."
152
- regenerate_credentials
153
- }
154
-
155
- count_databases() {
156
- psql_admin -At -c "SELECT count(*) FROM pg_database WHERE datname NOT IN ('postgres','template0','template1')" 2>/dev/null || echo "?"
157
- }
158
-
159
- do_status() {
160
- CTX="$(cluster_saved)"
161
- if [ -z "$CTX" ] || ! is_installed; then
162
- echo "disabled"
163
- return 0
164
- fi
165
- if [ "$(k get statefulset postgres -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
166
- echo "failed on $CTX: devzone apply"
167
- elif ! relay_active postgres; then
168
- echo "ready on $CTX, relay stopped: devzone apply"
169
- else
170
- echo "ready on $CTX: 127.0.0.1:$POSTGRES_PORT, $(count_databases) database(s)"
171
- fi
172
- }
173
-
174
- do_create() {
175
- local project="${1:-}" renew="" file pw arg
176
- validate_project "$project"
177
- for arg in "${@:2}"; do
178
- case "$arg" in
179
- --new-password) renew=1 ;;
180
- *) refuse "unknown argument: $arg" ;;
181
- esac
182
- done
183
- CTX="$(module_context)"
184
- is_installed || refuse "module disabled: devzone enable postgres"
185
- file="$SECRETS/$project.env"
186
- # Kept password: an application already configured keeps working
187
- pw="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null || true)"
188
- if [ -z "$pw" ] || [ -n "$renew" ]; then
189
- pw="$(new_password)"
190
- fi
191
- # REVOKE ... FROM PUBLIC: a project does not connect to another project's database
192
- psql_admin <<SQL
193
- SELECT 'CREATE ROLE $project LOGIN' WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$project')\gexec
194
- ALTER ROLE $project PASSWORD '$pw';
195
- SELECT 'CREATE DATABASE $project OWNER $project' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$project')\gexec
196
- REVOKE CONNECT ON DATABASE $project FROM PUBLIC;
197
- GRANT CONNECT ON DATABASE $project TO $project;
198
- SQL
199
- mkdir -p "$SECRETS"
200
- chmod 700 "$SECRETS"
201
- (
202
- umask 077
203
- cat >"$file" <<ENV
204
- DB_HOST=127.0.0.1
205
- DB_PORT=$POSTGRES_PORT
206
- DB_NAME=$project
207
- DB_USER=$project
208
- DB_PASSWORD=$pw
209
- DB_URL=jdbc:postgresql://127.0.0.1:$POSTGRES_PORT/$project
210
- ENV
211
- )
212
- echo "✔ database $project ready; credentials: $file"
213
- regenerate_credentials
214
- }
215
-
216
- do_list() {
217
- CTX="$(module_context)"
218
- is_installed || refuse "module disabled: devzone enable postgres"
219
- psql_admin -At -F ' ' -c "SELECT datname, pg_get_userbyid(datdba) FROM pg_database WHERE datname NOT IN ('postgres','template0','template1') ORDER BY 1" |
220
- awk 'BEGIN { n = 0 } { printf " %-30s owner %s\n", $1, $2; n++ } END { if (n == 0) print " (no database: devzone postgres create <project>)" }'
221
- }
222
-
223
- do_psql() {
224
- local project="${1:-}" tty=()
225
- CTX="$(module_context)"
226
- is_installed || refuse "module disabled: devzone enable postgres"
227
- [ -t 0 ] && tty=(-t)
228
- if [ -n "$project" ]; then
229
- validate_project "$project"
230
- k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U "$project" -d "$project"
231
- else
232
- k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U postgres
233
- fi
234
- }
235
-
236
- do_delete() {
237
- local project="${1:-}" yes="" arg answer
238
- validate_project "$project"
239
- for arg in "${@:2}"; do
240
- case "$arg" in
241
- --yes) yes=1 ;;
242
- *) refuse "unknown argument: $arg" ;;
243
- esac
244
- done
245
- CTX="$(module_context)"
246
- is_installed || refuse "module disabled: devzone enable postgres"
247
- if [ -z "$yes" ]; then
248
- cluster_interactive || refuse "cannot confirm without a terminal: devzone postgres delete $project --yes"
249
- printf 'Delete database %s and all its data? [y/N] ' "$project" >&2
250
- read -r answer || answer=""
251
- case "$answer" in
252
- y | Y | yes) ;;
253
- *) echo "Abandon: nothing was deleted."; return 0 ;;
254
- esac
255
- fi
256
- psql_admin <<SQL
257
- DROP DATABASE IF EXISTS $project WITH (FORCE);
258
- DROP ROLE IF EXISTS $project;
259
- SQL
260
- rm -f "$SECRETS/$project.env"
261
- echo "✔ database $project deleted"
262
- regenerate_credentials
263
- }
264
-
265
- do_relay_start() {
266
- CTX="$(cluster_saved)"
267
- if [ -n "$CTX" ] && is_installed; then
268
- relay_start postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
269
- fi
270
- }
271
-
272
- do_authorize() {
273
- local ns="${1:-}"
274
- [ -n "$ns" ] || { echo "devzone postgres: namespace missing" >&2; return 2; }
275
- namespace_isolate "$ns"
276
- echo "devzone postgres: access allowed from $ns to the PostgreSQL service"
277
- }
278
-
279
- do_forbid() {
280
- local ns="${1:-}" patch out
281
- [ -n "$ns" ] || { echo "devzone postgres: namespace missing" >&2; return 2; }
282
- # JSON built by jq, never assembled by hand (invalid JSON was silently
283
- # rejected); a failed patch is displayed and returns a code (#396)
284
- patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
285
- if ! out="$(kubectl --context devzone -n "$NS" patch networkpolicy devzone-meme-namespace \
286
- -p "$patch" 2>&1)"; then
287
- echo "devzone : postgres : cannot remove the access rule of $ns: $out" >&2
288
- return 1
289
- fi
290
- echo "devzone postgres: access forbidden from $ns to the PostgreSQL service"
291
- }
292
-
293
- case "${1:-}" in
294
- install) do_install ;;
295
- uninstall) do_uninstall ;;
296
- status) do_status ;;
297
- create) do_create "${@:2}" ;;
298
- list) do_list ;;
299
- psql) do_psql "${@:2}" ;;
300
- delete) do_delete "${@:2}" ;;
301
- relay-start) do_relay_start ;;
302
- relay-stop) relay_stop postgres ;;
303
- authorize) do_authorize "${@:2}" ;;
304
- forbid) do_forbid "${@:2}" ;;
305
- *)
306
- echo "devzone postgres: create <project> [--new-password] | list | psql [<project>] | delete <project> [--yes]" >&2
307
- exit 1
308
- ;;
309
- esac