devzone 7.0.1 → 7.0.3
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/ai/docker-guard.sh +56 -3
- package/.devcontainer/ai/kube-guard.message +1 -0
- package/.devcontainer/devzone +14 -3
- package/.devcontainer/devzone-ai-guard.sh +26 -4
- package/.devcontainer/devzone-status.sh +8 -0
- package/.devcontainer/kube-account.sh +85 -16
- package/.devcontainer/state-json.sh +9 -0
- package/.devcontainer/versions.env +1 -1
- package/README.md +2 -1
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/manage/scripts/workspace/argocd-services.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +4 -4
- package/manage/scripts/workspace/services-workspace.sh +8 -8
- package/manage/scripts/workspace/workspace-clone.sh +0 -65
- package/manage/scripts/workspace/workspace-copies.sh +0 -30
- package/manage/workspace.sh +6 -58
- package/package.json +1 -1
- package/.devcontainer/ticket.sh +0 -101
- package/manage/scripts/workspace/workspace-aliases.sh +0 -21
|
@@ -4,19 +4,24 @@
|
|
|
4
4
|
# stderr when a shell command runs docker/docker-compose as the command word.
|
|
5
5
|
# With python3, one program parses the JSON and detects. Otherwise jq extracts
|
|
6
6
|
# the tool and command and a best-effort shell detection runs. Without either,
|
|
7
|
-
# nothing is blocked.
|
|
7
|
+
# nothing is blocked. The cluster context check runs first: the host override
|
|
8
|
+
# only concerns commands on the host itself, never the administrator context.
|
|
8
9
|
|
|
9
10
|
set -u
|
|
10
11
|
|
|
11
12
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
13
|
MESSAGE_FILE="$SCRIPT_DIR/docker-guard.message"
|
|
14
|
+
KUBE_MESSAGE_FILE="$SCRIPT_DIR/kube-guard.message"
|
|
13
15
|
FALLBACK="devzone is Kubernetes-first: only pods are containers. Use kubectl, or a throwaway pod or namespace. Host action: set DEVZONE_ALLOW_DOCKER to 1."
|
|
16
|
+
FALLBACK_KUBE="Cluster administrator access is reserved for installers. Use the devzone context or the devzone commands (enable, disable, repair). An explicit host override does not lift this refusal."
|
|
14
17
|
MESSAGE="$FALLBACK"
|
|
18
|
+
KUBE_MESSAGE="$FALLBACK_KUBE"
|
|
15
19
|
if [ -r "$MESSAGE_FILE" ]; then
|
|
16
20
|
MESSAGE="$(cat "$MESSAGE_FILE" 2>/dev/null)" || MESSAGE="$FALLBACK"
|
|
17
21
|
fi
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
if [ -r "$KUBE_MESSAGE_FILE" ]; then
|
|
23
|
+
KUBE_MESSAGE="$(cat "$KUBE_MESSAGE_FILE" 2>/dev/null)" || KUBE_MESSAGE="$FALLBACK_KUBE"
|
|
24
|
+
fi
|
|
20
25
|
|
|
21
26
|
FORMAT="opencode"
|
|
22
27
|
[ "${1:-}" = "--format" ] && [ "${2:-}" = "claude" ] && FORMAT="claude"
|
|
@@ -25,6 +30,54 @@ INPUT="$(cat 2>/dev/null)" || exit 0
|
|
|
25
30
|
[ -n "$INPUT" ] || exit 0
|
|
26
31
|
|
|
27
32
|
block() { printf '%s\n' "$MESSAGE" >&2; exit 2; }
|
|
33
|
+
# Refuses a command that reaches the administrator kubeconfig, with a message
|
|
34
|
+
# of its own: the host override never lifts this refusal (#844).
|
|
35
|
+
block_kube() { printf '%s\n' "$KUBE_MESSAGE" >&2; exit 2; }
|
|
36
|
+
|
|
37
|
+
if command -v python3 >/dev/null 2>&1; then
|
|
38
|
+
HIT="$(__DG_INPUT="$INPUT" __DG_FORMAT="$FORMAT" python3 <<'KUBE_PYTHON'
|
|
39
|
+
import json, os, re, sys
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
data = json.loads(os.environ.get("__DG_INPUT", ""))
|
|
43
|
+
except Exception:
|
|
44
|
+
sys.exit(0)
|
|
45
|
+
if not isinstance(data, dict):
|
|
46
|
+
sys.exit(0)
|
|
47
|
+
if os.environ.get("__DG_FORMAT", "opencode") == "claude":
|
|
48
|
+
tool = data.get("tool_name") or ""
|
|
49
|
+
inner = data.get("tool_input")
|
|
50
|
+
else:
|
|
51
|
+
tool = data.get("tool") or ""
|
|
52
|
+
inner = data.get("args")
|
|
53
|
+
cmd = (inner.get("command") if isinstance(inner, dict) else "") or ""
|
|
54
|
+
if tool not in ("bash", "shell", "Bash") or not isinstance(cmd, str) or not cmd:
|
|
55
|
+
sys.exit(0)
|
|
56
|
+
pattern = re.compile(
|
|
57
|
+
r"\.kube/hote\.config|\.kube-host|(?:^|[^\w])KUBECONFIG\s*=|"
|
|
58
|
+
r"(?:^|[^\w])export\s+KUBECONFIG\b|--kubeconfig(?:[=\s]|$)"
|
|
59
|
+
)
|
|
60
|
+
if pattern.search(cmd):
|
|
61
|
+
print("kube")
|
|
62
|
+
KUBE_PYTHON
|
|
63
|
+
)"
|
|
64
|
+
[ "$HIT" = kube ] && block_kube
|
|
65
|
+
elif command -v jq >/dev/null 2>&1; then
|
|
66
|
+
if [ "$FORMAT" = "claude" ]; then
|
|
67
|
+
KUBE_TOOL="$(printf '%s' "$INPUT" | jq -r '.tool_name // ""' 2>/dev/null)" || exit 0
|
|
68
|
+
KUBE_COMMAND="$(printf '%s' "$INPUT" | jq -r '.tool_input.command // ""' 2>/dev/null)" || exit 0
|
|
69
|
+
else
|
|
70
|
+
KUBE_TOOL="$(printf '%s' "$INPUT" | jq -r '.tool // ""' 2>/dev/null)" || exit 0
|
|
71
|
+
KUBE_COMMAND="$(printf '%s' "$INPUT" | jq -r '.args.command // ""' 2>/dev/null)" || exit 0
|
|
72
|
+
fi
|
|
73
|
+
case "$KUBE_TOOL" in bash|shell|Bash) ;; *) exit 0 ;; esac
|
|
74
|
+
[ -n "$KUBE_COMMAND" ] || exit 0
|
|
75
|
+
if printf '%s' "$KUBE_COMMAND" | grep -qE '(^|[^[:alnum:]_])KUBECONFIG[[:space:]]*=|\.kube/hote\.config|\.kube-host|(^|[^[:alnum:]_])export[[:space:]]+KUBECONFIG([^[:alnum:]_]|$)|--kubeconfig([[:space:]]|=|$)'; then
|
|
76
|
+
block_kube
|
|
77
|
+
fi
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
[ "${DEVZONE_ALLOW_DOCKER:-}" = "1" ] && exit 0
|
|
28
81
|
|
|
29
82
|
if command -v python3 >/dev/null 2>&1; then
|
|
30
83
|
__DG_INPUT="$INPUT" __DG_FORMAT="$FORMAT" __DG_MESSAGE="$MESSAGE" python3 <<'PYTHON'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Cluster administrator access is reserved for the installers. Use the devzone context or the devzone commands (enable, disable, repair). An explicit host override does not lift this refusal.
|
package/.devcontainer/devzone
CHANGED
|
@@ -20,6 +20,19 @@ while [ -L "$SOURCE" ]; do
|
|
|
20
20
|
esac
|
|
21
21
|
done
|
|
22
22
|
ICI="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
23
|
+
# Go first (#754): a command ported to Go runs in the devzone-pod binary of the image.
|
|
24
|
+
# DEVZONE_NO_GO=1 forces the shell, DEVZONE_FROM_GO=1 avoids loops.
|
|
25
|
+
if [ -z "${DEVZONE_NO_GO:-}" ] && [ -z "${DEVZONE_FROM_GO:-}" ]; then
|
|
26
|
+
case "$(uname -m)" in
|
|
27
|
+
x86_64) POD_GO_ARCH=amd64 ;;
|
|
28
|
+
aarch64 | arm64) POD_GO_ARCH=arm64 ;;
|
|
29
|
+
*) POD_GO_ARCH="" ;;
|
|
30
|
+
esac
|
|
31
|
+
POD_GO="$ICI/bin/devzone-pod-linux-$POD_GO_ARCH"
|
|
32
|
+
if [ -n "$POD_GO_ARCH" ] && [ -x "$POD_GO" ] && "$POD_GO" handles "${1:-}" >/dev/null 2>&1; then
|
|
33
|
+
exec "$POD_GO" "$@"
|
|
34
|
+
fi
|
|
35
|
+
fi
|
|
23
36
|
# shellcheck source=SCRIPTDIR/help.sh
|
|
24
37
|
# shellcheck disable=SC1091
|
|
25
38
|
. "$ICI/help.sh"
|
|
@@ -64,7 +77,7 @@ fi
|
|
|
64
77
|
# two simultaneous bumps (versions workflow) merge without conflict, git only
|
|
65
78
|
# reporting neighbouring lines changed.
|
|
66
79
|
# Claude Code
|
|
67
|
-
IA_CLAUDE=@anthropic-ai/claude-code@2.1.
|
|
80
|
+
IA_CLAUDE=@anthropic-ai/claude-code@2.1.332
|
|
68
81
|
# opencode
|
|
69
82
|
IA_OPENCODE=opencode-ai@1.19.6
|
|
70
83
|
IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
|
|
@@ -179,7 +192,6 @@ case "${1:-}" in
|
|
|
179
192
|
;;
|
|
180
193
|
esac
|
|
181
194
|
;;
|
|
182
|
-
ticket) bash "$ICI/ticket.sh" "${@:2}" ;;
|
|
183
195
|
build)
|
|
184
196
|
bash "$ICI/workspace-build.sh" "${@:2}"
|
|
185
197
|
;;
|
|
@@ -202,7 +214,6 @@ case "${1:-}" in
|
|
|
202
214
|
bash "$ICI/password.sh" chemin
|
|
203
215
|
;;
|
|
204
216
|
-h | --help | help) devzone_aide ;;
|
|
205
|
-
-v | --version) echo "devzone ${DEVZONE_VERSION:-unknown}" ;;
|
|
206
217
|
test-bash32) bash "$RACINE/manage/test/bash32.sh" ;;
|
|
207
218
|
test-gitlab) DEVZONE_STATE="$ETAT" bash "$ICI/gitlab/test-gitlab.sh" "${@:2}" ;;
|
|
208
219
|
platform)
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
# Docker guard for the folders that are not this repository: a Claude Code
|
|
8
8
|
# PreToolUse hook in the global settings and the two opencode plugins in the
|
|
9
9
|
# global plugins folder. Idempotent, other user settings and hooks preserved.
|
|
10
|
+
# Claude Code also receives the limited Kubernetes context via env.KUBECONFIG.
|
|
10
11
|
install_docker_guard() {
|
|
11
12
|
local script="$ICI/ai/docker-guard.sh" config="$HOME/.claude/settings.json"
|
|
12
13
|
local src="$ICI/ai/plugins" dst="$HOME/.config/opencode/plugins"
|
|
@@ -19,13 +20,17 @@ install_docker_guard() {
|
|
|
19
20
|
echo "devzone : $config unreadable (invalid JSON): docker guard not installed for Claude Code" >&2
|
|
20
21
|
else
|
|
21
22
|
tmp="$(mktemp)"
|
|
22
|
-
if jq --arg cmd "bash \"$script\" --format claude"
|
|
23
|
+
if jq --arg cmd "bash \"$script\" --format claude" \
|
|
24
|
+
--arg kube "$HOME/.kube/agent.config" '
|
|
23
25
|
.hooks = (.hooks // {}) |
|
|
24
26
|
.hooks.PreToolUse = (.hooks.PreToolUse // []) |
|
|
25
27
|
if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-guard.sh")))
|
|
26
28
|
then .
|
|
27
29
|
else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
|
|
28
|
-
end
|
|
30
|
+
end |
|
|
31
|
+
if (.env | type) == "object" then .env = (.env + {"KUBECONFIG": $kube})
|
|
32
|
+
elif (.env | type) == "null" then .env = {"KUBECONFIG": $kube}
|
|
33
|
+
else . end
|
|
29
34
|
' "$config" >"$tmp" 2>/dev/null; then
|
|
30
35
|
mv "$tmp" "$config"
|
|
31
36
|
else
|
|
@@ -43,8 +48,9 @@ install_docker_guard() {
|
|
|
43
48
|
|
|
44
49
|
# Removes only the Docker guard entries (commands containing docker-guard.sh)
|
|
45
50
|
# and the two plugins; the rest of settings.json and of the plugins is kept.
|
|
51
|
+
# The Kubernetes context key is removed too, and an empty env object is dropped.
|
|
46
52
|
remove_docker_guard() {
|
|
47
|
-
local config="$HOME/.claude/settings.json" tmp
|
|
53
|
+
local config="$HOME/.claude/settings.json" tmp tmp2
|
|
48
54
|
if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
|
|
49
55
|
tmp="$(mktemp)"
|
|
50
56
|
if jq '
|
|
@@ -65,7 +71,23 @@ remove_docker_guard() {
|
|
|
65
71
|
if [ "$(cat "$tmp")" = "{}" ]; then
|
|
66
72
|
rm -f "$tmp" "$config"
|
|
67
73
|
else
|
|
68
|
-
|
|
74
|
+
tmp2="$(mktemp)"
|
|
75
|
+
if jq '
|
|
76
|
+
if (.env | type) == "object" then
|
|
77
|
+
.env = (.env | del(.KUBECONFIG)) |
|
|
78
|
+
if (.env | length) == 0 then del(.env) else . end
|
|
79
|
+
else . end
|
|
80
|
+
' "$tmp" >"$tmp2" 2>/dev/null; then
|
|
81
|
+
if [ "$(cat "$tmp2")" = "{}" ]; then
|
|
82
|
+
rm -f "$tmp2" "$config"
|
|
83
|
+
else
|
|
84
|
+
mv "$tmp2" "$config"
|
|
85
|
+
fi
|
|
86
|
+
else
|
|
87
|
+
rm -f "$tmp2"
|
|
88
|
+
mv "$tmp" "$config"
|
|
89
|
+
fi
|
|
90
|
+
rm -f "$tmp"
|
|
69
91
|
fi
|
|
70
92
|
else
|
|
71
93
|
rm -f "$tmp"
|
|
@@ -98,6 +98,14 @@ show_state() {
|
|
|
98
98
|
if [ -n "$current_cluster" ] && ! cluster_is_local "$current_cluster"; then
|
|
99
99
|
printf ' ⚠ cluster remote: %s — services on a remote cluster\n' "$current_cluster"
|
|
100
100
|
fi
|
|
101
|
+
# Limited account token (#845): renewed as soon as it is close to expiry,
|
|
102
|
+
# only outside the pod and with a services cluster chosen (the cases where
|
|
103
|
+
# kube-account.sh is used); a failed renewal is reported for devzone repair
|
|
104
|
+
if ! in_pod && [ -n "$current_cluster" ] && ! account_token_fresh; then
|
|
105
|
+
if ! bash "$ICI/kube-account.sh" jeton >/dev/null 2>&1; then
|
|
106
|
+
echo " ⚠ limited account token expired: devzone repair"
|
|
107
|
+
fi
|
|
108
|
+
fi
|
|
101
109
|
# Old kind-gitlab cluster still present: invite to migrate (#396)
|
|
102
110
|
if kind get clusters 2>/dev/null | grep -qx "gitlab${INSTANCE_SUFFIX}"; then
|
|
103
111
|
printf ' ⚠ old kind-gitlab cluster%s: devzone gitlab migrate\n' "$INSTANCE_SUFFIX"
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
# agents) can only act in the devzone-* namespaces. The account is the
|
|
4
4
|
# ServiceAccount devzone-agent of the devzone-system namespace, bound to the
|
|
5
5
|
# edit ClusterRole (no RBAC, no quotas) in each devzone namespace by a
|
|
6
|
-
# RoleBinding, with a 24 h TokenRequest token renewed at startup (startup.sh)
|
|
7
|
-
# by « devzone repair
|
|
8
|
-
# in ~/.kube/hote.config, kind cluster in
|
|
9
|
-
#
|
|
6
|
+
# RoleBinding, with a 24 h TokenRequest token renewed at startup (startup.sh),
|
|
7
|
+
# by « devzone repair » and by the summary before expiry. The installers alone
|
|
8
|
+
# use the admin context (host context in ~/.kube/hote.config, kind cluster in
|
|
9
|
+
# ~/.kube/config); the shells use ~/.kube/config and the agents the limited
|
|
10
|
+
# ~/.kube/agent.config (devzone context only, #844).
|
|
10
11
|
# Library sourced by cluster.sh; executable for the token:
|
|
11
12
|
# kube-account.sh jeton (argument kept: called by startup.sh and devzone repair)
|
|
12
13
|
|
|
@@ -14,6 +15,7 @@ ACCOUNT_NS=devzone-system
|
|
|
14
15
|
ACCOUNT_SA=devzone-agent
|
|
15
16
|
ACCOUNT_DURATION=24h
|
|
16
17
|
ACCOUNT_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
|
|
18
|
+
ACCOUNT_TOKEN_EXPIRY="${DEVZONE_KUBE_TOKEN_EXPIRY:-$HOME/.kube/devzone-token.expiry}"
|
|
17
19
|
|
|
18
20
|
# kubeconfig file that holds the admin context ctx: hote.config if it lists it
|
|
19
21
|
# (host clusters), otherwise ~/.kube/config (kind clusters of the container).
|
|
@@ -129,16 +131,50 @@ account_catch_up() {
|
|
|
129
131
|
done < <(account_admin "$ctx" get namespaces -l "$label" -o name 2>/dev/null || true)
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
# Epoch seconds of the RFC 3339 expiration timestamp of a TokenRequest
|
|
135
|
+
# response; empty when the local date cannot read it, so the caller falls back
|
|
136
|
+
# to now + 24 h (Bash 3.2: GNU date -d, then the BSD date form).
|
|
137
|
+
account_expiry_epoch() {
|
|
138
|
+
local ts="$1" epoch
|
|
139
|
+
[ -n "$ts" ] || return 0
|
|
140
|
+
epoch="$(date -u -d "$ts" +%s 2>/dev/null || true)"
|
|
141
|
+
if [ -n "$epoch" ]; then
|
|
142
|
+
echo "$epoch"
|
|
143
|
+
return 0
|
|
144
|
+
fi
|
|
145
|
+
epoch="$(date -j -u -f '%Y-%m-%dT%H:%M:%SZ' "$ts" +%s 2>/dev/null || true)"
|
|
146
|
+
[ -n "$epoch" ] && echo "$epoch"
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
# True when the token has more than one hour left, read from the expiry file
|
|
150
|
+
# without any cluster call: absent, unreadable, non-numeric, close or past
|
|
151
|
+
# expiry → false.
|
|
152
|
+
account_token_fresh() {
|
|
153
|
+
local expiry now
|
|
154
|
+
[ -f "$ACCOUNT_TOKEN_EXPIRY" ] || return 1
|
|
155
|
+
expiry="$(cat "$ACCOUNT_TOKEN_EXPIRY" 2>/dev/null || true)"
|
|
156
|
+
case "$expiry" in
|
|
157
|
+
'' | *[!0-9]*) return 1 ;;
|
|
158
|
+
esac
|
|
159
|
+
now="$(date +%s)"
|
|
160
|
+
[ "$expiry" -gt $((now + 3600)) ]
|
|
161
|
+
}
|
|
162
|
+
|
|
132
163
|
# Renews the account's token (24 h TokenRequest) and writes it into the devzone
|
|
133
164
|
# context of ~/.kube/config: user devzone-agent, same cluster as the admin
|
|
134
165
|
# context (cluster entry copied: server, certificate authority and
|
|
135
|
-
# tls-server-name of the host context).
|
|
166
|
+
# tls-server-name of the host context). The expiry timestamp of the TokenRequest
|
|
167
|
+
# response is kept in ACCOUNT_TOKEN_EXPIRY (now + 24 h if it is unreadable), only
|
|
168
|
+
# once a real call through the devzone context has succeeded.
|
|
136
169
|
account_token() {
|
|
137
|
-
local ctx="$1" conf token cluster server tls ca_data ca_file
|
|
170
|
+
local ctx="$1" conf token cluster server tls ca_data ca_file out expires expiry now answer
|
|
138
171
|
local entry=()
|
|
139
172
|
conf="$(account_admin_config "$ctx")"
|
|
140
|
-
|
|
141
|
-
--duration="$ACCOUNT_DURATION"
|
|
173
|
+
out="$(account_admin "$ctx" create token "$ACCOUNT_SA" -n "$ACCOUNT_NS" \
|
|
174
|
+
--duration="$ACCOUNT_DURATION" \
|
|
175
|
+
-o jsonpath='{.status.token}{"\n"}{.status.expirationTimestamp}')" || return 1
|
|
176
|
+
token="$(printf '%s\n' "$out" | sed -n '1p')"
|
|
177
|
+
expires="$(printf '%s\n' "$out" | sed -n '2p')"
|
|
142
178
|
if [ -z "$token" ]; then
|
|
143
179
|
echo "devzone : limited account token is empty" >&2
|
|
144
180
|
return 1
|
|
@@ -155,14 +191,11 @@ account_token() {
|
|
|
155
191
|
echo "devzone : server of cluster $cluster not found in $conf" >&2
|
|
156
192
|
return 1
|
|
157
193
|
fi
|
|
158
|
-
ca_data="$(KUBECONFIG="$conf" kubectl config view \
|
|
159
|
-
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
|
|
194
|
+
ca_data="$(KUBECONFIG="$conf" kubectl config view --raw -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
|
|
160
195
|
ca_file="$(KUBECONFIG="$conf" kubectl config view \
|
|
161
196
|
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || true)"
|
|
162
197
|
entry=(--server="$server")
|
|
163
|
-
if [ -n "$
|
|
164
|
-
entry+=(--certificate-authority-data="$ca_data")
|
|
165
|
-
elif [ -n "$ca_file" ]; then
|
|
198
|
+
if [ -n "$ca_file" ]; then
|
|
166
199
|
entry+=(--certificate-authority="$ca_file" --embed-certs=true)
|
|
167
200
|
fi
|
|
168
201
|
tls="$(KUBECONFIG="$conf" kubectl config view \
|
|
@@ -171,11 +204,46 @@ account_token() {
|
|
|
171
204
|
entry+=(--tls-server-name="$tls")
|
|
172
205
|
fi
|
|
173
206
|
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-cluster "$cluster" \
|
|
174
|
-
${entry[@]+"${entry[@]}"} >/dev/null
|
|
207
|
+
${entry[@]+"${entry[@]}"} >/dev/null || return 1
|
|
208
|
+
if [ -n "$ca_data" ]; then
|
|
209
|
+
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set \
|
|
210
|
+
"clusters.$cluster.certificate-authority-data" "$ca_data" >/dev/null || return 1
|
|
211
|
+
fi
|
|
175
212
|
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-credentials "$ACCOUNT_SA" \
|
|
176
|
-
--token="$token" >/dev/null
|
|
213
|
+
--token="$token" >/dev/null || return 1
|
|
177
214
|
KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-context devzone \
|
|
178
|
-
--cluster="$cluster" --user="$ACCOUNT_SA" >/dev/null
|
|
215
|
+
--cluster="$cluster" --user="$ACCOUNT_SA" >/dev/null || return 1
|
|
216
|
+
answer="$(KUBECONFIG="$ACCOUNT_CONFIG" kubectl --context devzone \
|
|
217
|
+
auth can-i get pods -n "$ACCOUNT_NS" 2>/dev/null || true)"
|
|
218
|
+
case "$answer" in
|
|
219
|
+
yes | no) ;;
|
|
220
|
+
*)
|
|
221
|
+
echo "devzone : limited account context not reachable" >&2
|
|
222
|
+
rm -f "$ACCOUNT_TOKEN_EXPIRY"
|
|
223
|
+
return 1
|
|
224
|
+
;;
|
|
225
|
+
esac
|
|
226
|
+
now="$(date +%s)"
|
|
227
|
+
expiry="$(account_expiry_epoch "$expires")"
|
|
228
|
+
[ -n "$expiry" ] || expiry=$((now + 86400))
|
|
229
|
+
mkdir -p "$(dirname "$ACCOUNT_TOKEN_EXPIRY")"
|
|
230
|
+
printf '%s\n' "$expiry" >"$ACCOUNT_TOKEN_EXPIRY"
|
|
231
|
+
chmod 600 "$ACCOUNT_TOKEN_EXPIRY"
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Writes the limited agent kubeconfig: the devzone context only, current context
|
|
235
|
+
# set to it, for the agents that hold the limited account (Claude Code, #844).
|
|
236
|
+
# The contexts are read from ACCOUNT_CONFIG, never from the file being written:
|
|
237
|
+
# the view goes to a temporary file of the same folder, moved in place (atomic,
|
|
238
|
+
# mode 600); a failure empties the target and returns 1.
|
|
239
|
+
account_agent_config() {
|
|
240
|
+
local conf="${DEVZONE_KUBE_AGENT_CONFIG:-$HOME/.kube/agent.config}" tmp
|
|
241
|
+
tmp="$(mktemp "$(dirname "$conf")/.agent.config.XXXXXX")" || return 1
|
|
242
|
+
# shellcheck disable=SC2015 # the failure branch must empty the target too
|
|
243
|
+
( umask 077; KUBECONFIG="$ACCOUNT_CONFIG" kubectl config view --minify --flatten \
|
|
244
|
+
--context devzone >"$tmp" ) && KUBECONFIG="$tmp" kubectl config use-context devzone >/dev/null 2>&1 \
|
|
245
|
+
|| { rm -f "$tmp"; : >"$conf"; return 1; }
|
|
246
|
+
chmod 600 "$tmp"; mv "$tmp" "$conf"
|
|
179
247
|
}
|
|
180
248
|
|
|
181
249
|
# Direct execution: account token renewed at startup (startup.sh) and by
|
|
@@ -196,4 +264,5 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
|
196
264
|
account_setup "$ctx" || exit 1
|
|
197
265
|
account_catch_up "$ctx" || exit 1
|
|
198
266
|
account_token "$ctx" || exit 1
|
|
267
|
+
account_agent_config || exit 1
|
|
199
268
|
fi
|
|
@@ -190,6 +190,15 @@ state_json() {
|
|
|
190
190
|
clusters_command="devzone use $host_ctx"
|
|
191
191
|
fi
|
|
192
192
|
|
|
193
|
+
# Limited account token (#845): renewed as soon as it is close to expiry,
|
|
194
|
+
# only outside the pod and with a services cluster chosen; a failed renewal
|
|
195
|
+
# becomes an alert with the repair command.
|
|
196
|
+
if ! in_pod && [ -n "$services_cluster" ] && ! account_token_fresh; then
|
|
197
|
+
if ! bash "$ICI/kube-account.sh" jeton >/dev/null 2>&1; then
|
|
198
|
+
append_alert limited_account_token "limited account token expired" "devzone repair"
|
|
199
|
+
fi
|
|
200
|
+
fi
|
|
201
|
+
|
|
193
202
|
if ports_out="$(bash "$ICI/ports.sh" list --json 2>/dev/null)"; then
|
|
194
203
|
if printf '%s' "$ports_out" | jq -e . >/dev/null 2>&1; then
|
|
195
204
|
ports_json="$ports_out"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Single source for the repowarden version used by post-create.sh and workspace-init.sh.
|
|
2
|
-
REPOWARDEN_VERSION=4.
|
|
2
|
+
REPOWARDEN_VERSION=4.18.0
|
|
3
3
|
|
|
4
4
|
# BuildKit client version installed in the workspace image (#514). Must match
|
|
5
5
|
# buildkit.image in charts/devzone-workspace/values.yaml.
|
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ devzone avoids them: the same environment on every workstation, on your machine.
|
|
|
24
24
|
|
|
25
25
|
- No systemd: the services provided by devzone start with devzone, not with `systemctl`.
|
|
26
26
|
- No graphical desktop: everything happens in a terminal or in VS Code.
|
|
27
|
-
-
|
|
27
|
+
- Pod mode (default): the terminal in the pod has no rights on the cluster; the workstation acts as administrator for the time of an operation ([#528](https://github.com/SimBienvenueHoulBoumi/devzone/issues/528)).
|
|
28
|
+
- Container mode: the terminal keeps the cluster administrator; agents (opencode and Claude Code) only have the account limited to the `devzone-*` namespaces (`edit` role, token renewed every 24 h), Claude Code with the reduced kubeconfig `~/.kube/agent.config` ([#430](https://github.com/SimBienvenueHoulBoumi/devzone/issues/430), [#844](https://github.com/SimBienvenueHoulBoumi/devzone/issues/844)).
|
|
28
29
|
|
|
29
30
|
## How it works
|
|
30
31
|
|
package/bin/SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
b6dccc1d9f2bd27f1dfc9b2e841ff4b3b82a362826146fb16d2955200235d8d5 devzone-linux-amd64
|
|
2
|
+
f3bc328b7f266ec1ce878a3df76d5e14496861e3ec376a62e546653ae41f1a11 devzone-linux-arm64
|
|
3
|
+
17e0d97a2b60a064ddbf3d041ad76ed2357b2aeae1d90e0ecdfb4052b7984df5 devzone-darwin-amd64
|
|
4
|
+
6eb07e8d5d2f168f1432bca3c2acb451df063773e7e14428acb6a61d752919b0 devzone-darwin-arm64
|
|
5
|
+
7b4a96e1ef37cf611b3f1abeff3ef516c370e7504bf1dc2acccad45ad05be205 devzone-windows-amd64.exe
|
|
6
|
+
035aaa2d06954d20288a7146a6967a57759dd90603a40b8e0bc4076f323c86eb devzone-windows-arm64.exe
|
package/bin/devzone-darwin-amd64
CHANGED
|
Binary file
|
package/bin/devzone-darwin-arm64
CHANGED
|
Binary file
|
package/bin/devzone-linux-amd64
CHANGED
|
Binary file
|
package/bin/devzone-linux-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -128,7 +128,7 @@ workspace_undeploy() {
|
|
|
128
128
|
argocd_delete_application "$WORKSPACE_APP"
|
|
129
129
|
else
|
|
130
130
|
# shellcheck disable=SC2046
|
|
131
|
-
helm $(
|
|
131
|
+
helm $(helm_flag) uninstall devzone-workspace --namespace devzone-workspace
|
|
132
132
|
fi
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Argo CD of the Kubernetes workspace, driven from the workstation (#516).
|
|
3
|
-
# Sourced by manage/workspace.sh (
|
|
3
|
+
# Sourced by manage/workspace.sh (kubectl_flag, helm_flag, RACINE: the
|
|
4
4
|
# package; $PWD: the devzone folder of the workstation, its .devzone.modules,
|
|
5
5
|
# workspace/.argocd and .password).
|
|
6
6
|
# argocd_wanted 0 unless .devzone.modules says argocd=off (on by default)
|
|
@@ -29,7 +29,7 @@ argocd_secrets_dir() { printf '%s/workspace/.argocd' "$PWD"; }
|
|
|
29
29
|
# kubectl of the workstation, context devzone when it exists
|
|
30
30
|
ak() {
|
|
31
31
|
# shellcheck disable=SC2046
|
|
32
|
-
kubectl $(
|
|
32
|
+
kubectl $(kubectl_flag) "$@"
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
# Last value of a key of .devzone.modules of the workstation (empty if none)
|
|
@@ -146,7 +146,7 @@ argocd_install() {
|
|
|
146
146
|
# first, then installed from the local chart (#538)
|
|
147
147
|
helm dependency build "$(argocd_chart)" >/dev/null
|
|
148
148
|
# shellcheck disable=SC2046
|
|
149
|
-
helm $(
|
|
149
|
+
helm $(helm_flag) upgrade --install argocd "$(argocd_chart)" \
|
|
150
150
|
--namespace "$ARGOCD_NS" \
|
|
151
151
|
--timeout "${ARGOCD_WAIT}s" --wait || return 1
|
|
152
152
|
argocd_save_admin_password
|
|
@@ -179,7 +179,7 @@ argocd_uninstall() {
|
|
|
179
179
|
gitops_direct_delete_application "${app#*/}" keep
|
|
180
180
|
done <<<"$(ak -n "$ARGOCD_NS" get applications.argoproj.io -o name 2>/dev/null || true)"
|
|
181
181
|
# shellcheck disable=SC2046
|
|
182
|
-
helm $(
|
|
182
|
+
helm $(helm_flag) uninstall argocd --namespace "$ARGOCD_NS" >/dev/null 2>&1 || true
|
|
183
183
|
ak delete namespace "$ARGOCD_NS" --wait=true --ignore-not-found >/dev/null
|
|
184
184
|
fi
|
|
185
185
|
rm -rf "$(argocd_secrets_dir)"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# devzone workspace services (#528): installs or removes the devzone services
|
|
3
3
|
# (gitlab, postgres, mysql, argocd) of a Kubernetes workspace from the workstation.
|
|
4
|
-
# Sourced by manage/workspace.sh (
|
|
4
|
+
# Sourced by manage/workspace.sh (kubectl_flag, POD, NAMESPACE).
|
|
5
5
|
# devzone workspace services enable <service> [options]
|
|
6
6
|
# devzone workspace services disable <service> [--yes]
|
|
7
7
|
# devzone workspace services status
|
|
@@ -53,7 +53,7 @@ services_namespace() {
|
|
|
53
53
|
services_pod_running() {
|
|
54
54
|
local phase
|
|
55
55
|
# shellcheck disable=SC2046
|
|
56
|
-
phase="$(kubectl $(
|
|
56
|
+
phase="$(kubectl $(kubectl_flag) get pod "$POD" --namespace "$NAMESPACE" \
|
|
57
57
|
-o jsonpath='{.status.phase}' 2>/dev/null)" || phase=""
|
|
58
58
|
[ "$phase" = Running ]
|
|
59
59
|
}
|
|
@@ -62,7 +62,7 @@ services_pod_running() {
|
|
|
62
62
|
# cluster-admin (idempotent apply)
|
|
63
63
|
services_admin_create() {
|
|
64
64
|
# shellcheck disable=SC2046
|
|
65
|
-
kubectl $(
|
|
65
|
+
kubectl $(kubectl_flag) apply -f - >/dev/null <<EOF
|
|
66
66
|
apiVersion: v1
|
|
67
67
|
kind: ServiceAccount
|
|
68
68
|
metadata:
|
|
@@ -86,10 +86,10 @@ EOF
|
|
|
86
86
|
|
|
87
87
|
services_admin_delete() {
|
|
88
88
|
# shellcheck disable=SC2046
|
|
89
|
-
kubectl $(
|
|
89
|
+
kubectl $(kubectl_flag) delete clusterrolebinding "$SERVICES_ADMIN_SA" \
|
|
90
90
|
--ignore-not-found >/dev/null 2>&1 || true
|
|
91
91
|
# shellcheck disable=SC2046
|
|
92
|
-
kubectl $(
|
|
92
|
+
kubectl $(kubectl_flag) delete serviceaccount "$SERVICES_ADMIN_SA" \
|
|
93
93
|
--namespace "$NAMESPACE" --ignore-not-found >/dev/null 2>&1 || true
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -134,7 +134,7 @@ services_run() {
|
|
|
134
134
|
fi
|
|
135
135
|
trap services_admin_delete EXIT
|
|
136
136
|
# shellcheck disable=SC2046
|
|
137
|
-
if ! token="$(kubectl $(
|
|
137
|
+
if ! token="$(kubectl $(kubectl_flag) create token "$SERVICES_ADMIN_SA" \
|
|
138
138
|
--namespace "$NAMESPACE" --duration "$SERVICES_TOKEN_DURATION")" || [ -z "$token" ]; then
|
|
139
139
|
echo "✖ cannot get a token of the temporary administrator (kubectl 1.24 or more)" >&2
|
|
140
140
|
services_admin_delete
|
|
@@ -144,7 +144,7 @@ services_run() {
|
|
|
144
144
|
echo "▶ $action $service in the pod ${POD}…"
|
|
145
145
|
# The installer of the pod takes --yes (#557) : no translation, no warning
|
|
146
146
|
# shellcheck disable=SC2046
|
|
147
|
-
printf '%s\n' "$token" | kubectl $(
|
|
147
|
+
printf '%s\n' "$token" | kubectl $(kubectl_flag) exec -i "$POD" --namespace "$NAMESPACE" \
|
|
148
148
|
-c workspace -- bash "$SERVICES_ADMIN_SCRIPT" "$action" "$service" "$@" || code=$?
|
|
149
149
|
services_admin_delete
|
|
150
150
|
trap - EXIT
|
|
@@ -162,7 +162,7 @@ services_status() {
|
|
|
162
162
|
for s in gitlab postgres mysql argocd; do
|
|
163
163
|
ns="$(services_namespace "$s")"
|
|
164
164
|
# shellcheck disable=SC2046
|
|
165
|
-
if kubectl $(
|
|
165
|
+
if kubectl $(kubectl_flag) get namespace "$ns" >/dev/null 2>&1; then
|
|
166
166
|
echo " ✔ $s installed (namespace $ns): devzone workspace services disable $s"
|
|
167
167
|
else
|
|
168
168
|
echo " ○ $s not installed: devzone workspace services enable $s"
|
|
@@ -1,69 +1,4 @@
|
|
|
1
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
2
|
|
|
68
3
|
# Guard of the agents in the pod (#558): when the ai module is on there,
|
|
69
4
|
# "repowarden agents init --global" is run (idempotent), so that an agent
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Stale copies in the pod (#558), sourced by manage/workspace.sh:
|
|
3
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
4
|
# Uses kubectl_flag, POD, NAMESPACE and PROJECTS_DIR from workspace.sh.
|
|
6
5
|
|
|
7
6
|
# Shows workspace pod status, then the legacy copies still in the pod.
|
|
@@ -43,32 +42,3 @@ workspace_legacy_copies() {
|
|
|
43
42
|
echo " 2. remove them from the pod shell (devzone workspace shell), one folder at a time:"
|
|
44
43
|
for d in $found; do echo " rm -rf $PROJECTS_DIR/$d"; done
|
|
45
44
|
}
|
|
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
|
@@ -5,8 +5,12 @@ set -euo pipefail
|
|
|
5
5
|
|
|
6
6
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
7
|
ROOT="$(cd "$HERE/.." && pwd)"
|
|
8
|
+
# shellcheck disable=SC2034 # read by the argocd scripts and by .devcontainer/argocd/services.sh (shared with the pod)
|
|
9
|
+
RACINE="$ROOT"
|
|
8
10
|
# Pod, namespace and projects folder inside the container (#399).
|
|
11
|
+
# shellcheck disable=SC2034 # read by the scripts sourced from scripts/workspace/
|
|
9
12
|
POD="devzone-workspace-0"
|
|
13
|
+
# shellcheck disable=SC2034 # read by the scripts sourced from scripts/workspace/
|
|
10
14
|
NAMESPACE="devzone-workspace"
|
|
11
15
|
PROJECTS_DIR="/workspaces/projets"
|
|
12
16
|
# compatibility alias, removed with lot 4 (#509)
|
|
@@ -116,57 +120,6 @@ shell_workspace() {
|
|
|
116
120
|
kubectl $(kubectl_flag) exec -it devzone-workspace-0 --namespace devzone-workspace -c workspace -- bash
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
# VS Code steps (#399): attach to the pod with Kubernetes and Dev Containers
|
|
120
|
-
# extensions, without any command other than devzone.
|
|
121
|
-
vscode_workspace() {
|
|
122
|
-
cat <<EOF
|
|
123
|
-
Attach VS Code to the pod: "Kubernetes" and "Dev Containers" extensions
|
|
124
|
-
1. kubectl context: devzone — namespace $NAMESPACE, pod $POD, container workspace
|
|
125
|
-
2. Kubernetes view: right-click the workspace container,
|
|
126
|
-
"Attach to Running Kubernetes Container"
|
|
127
|
-
(with Dev Containers extension: "Dev Containers: Attach to Running Container")
|
|
128
|
-
3. Open folder $PROJECTS_DIR in the attached window
|
|
129
|
-
Pod not ready: devzone workspace status
|
|
130
|
-
EOF
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
# Copies a workstation folder to $PROJECTS_DIR in the pod (#399, kubectl cp):
|
|
134
|
-
# the project keeps its folder name in the pod.
|
|
135
|
-
copy_to() {
|
|
136
|
-
local folder="${1:-}"
|
|
137
|
-
if [ -z "$folder" ]; then
|
|
138
|
-
echo "✖ provide a workstation folder: devzone workspace copy-to <folder>" >&2
|
|
139
|
-
exit 1
|
|
140
|
-
fi
|
|
141
|
-
if [ ! -d "$folder" ]; then
|
|
142
|
-
echo "✖ folder not found: $folder" >&2
|
|
143
|
-
exit 1
|
|
144
|
-
fi
|
|
145
|
-
folder="$(cd "$folder" && pwd)"
|
|
146
|
-
copy_guard "$folder" || exit 1
|
|
147
|
-
# shellcheck disable=SC2046
|
|
148
|
-
kubectl $(kubectl_flag) cp "$folder" "$POD:$PROJECTS_DIR/$(basename "$folder")" \
|
|
149
|
-
--namespace "$NAMESPACE" -c workspace
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
# Copies a project from $PROJECTS_DIR in the pod to the workstation (#399, kubectl cp):
|
|
153
|
-
# the workstation folder gets the project name.
|
|
154
|
-
copy_from() {
|
|
155
|
-
local folder="${1:-}"
|
|
156
|
-
if [ -z "$folder" ]; then
|
|
157
|
-
echo "✖ provide a workstation folder: devzone workspace copy-from <folder>" >&2
|
|
158
|
-
exit 1
|
|
159
|
-
fi
|
|
160
|
-
# Absolute path: "copy-from ." gives the current folder name.
|
|
161
|
-
folder="$(cd "$folder" 2>/dev/null && pwd || echo "$folder")"
|
|
162
|
-
# shellcheck disable=SC2046
|
|
163
|
-
kubectl $(kubectl_flag) cp "$POD:$PROJECTS_DIR/$(basename "$folder")" "$folder" \
|
|
164
|
-
--namespace "$NAMESPACE" -c workspace
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
# French names of the command and compatibility aliases (lot 3, #508)
|
|
168
|
-
# shellcheck source=manage/scripts/workspace/workspace-aliases.sh
|
|
169
|
-
. "$HERE/scripts/workspace/workspace-aliases.sh"
|
|
170
123
|
# shellcheck source=manage/scripts/kube-ready.sh
|
|
171
124
|
. "$HERE/scripts/kube-ready.sh"
|
|
172
125
|
# shellcheck source=manage/scripts/workspace/workspace-wait.sh
|
|
@@ -208,19 +161,14 @@ case "${1:-}" in
|
|
|
208
161
|
stop) stop_workspace ;;
|
|
209
162
|
status) status_workspace ;;
|
|
210
163
|
shell) shell_workspace ;;
|
|
211
|
-
vscode) vscode_workspace ;;
|
|
212
|
-
copy-to) copy_to "${@:2}" ;;
|
|
213
|
-
copy-from) copy_from "${@:2}" ;;
|
|
214
|
-
clone) workspace_clone "${@:2}" ;;
|
|
215
164
|
ports) ports "${@:2}" ;;
|
|
216
165
|
services) services "${@:2}" ;;
|
|
217
166
|
argocd) argocd_cmd "${@:2}" ;;
|
|
218
167
|
egress) egress_workspace "${@:2}" ;;
|
|
219
168
|
'' | -h | --help | help)
|
|
220
|
-
echo "devzone workspace start|stop|status|shell|
|
|
169
|
+
echo "devzone workspace start|stop|status|shell|ports|services|argocd|update|egress"
|
|
221
170
|
echo " start [--image repository:tag] install workspace (image for devzone version by default)"
|
|
222
171
|
echo " update [--version X.Y.Z] [--yes] move to the latest stable release (or X.Y.Z); the pod is recreated"
|
|
223
|
-
echo " clone <url> [<name>] git clone into the pod projects folder (gh credentials, identity, repowarden hooks)"
|
|
224
172
|
echo " ports [start|stop|status] applications and services from pod on workstation localhost"
|
|
225
173
|
echo " services enable|disable <service> [options] | status"
|
|
226
174
|
echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
|
|
@@ -229,7 +177,7 @@ case "${1:-}" in
|
|
|
229
177
|
echo " egress observation|strict|off|status|allow <domain>|deny <domain> egress proxy of the agent sessions (--pod)"
|
|
230
178
|
;;
|
|
231
179
|
*)
|
|
232
|
-
echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|
|
|
180
|
+
echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|ports|services|argocd|update)" >&2
|
|
233
181
|
exit 1
|
|
234
182
|
;;
|
|
235
183
|
esac
|
package/package.json
CHANGED
package/.devcontainer/ticket.sh
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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 "$@"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Compatibility aliases of the workspace functions renamed during the English
|
|
3
|
-
# migration (#502, lot 3), sourced by manage/workspace.sh. The old French names
|
|
4
|
-
# of the subcommands are refused by reject_renamed (.devcontainer/command-aliases.sh, #695).
|
|
5
|
-
# bash 3.2 (macOS).
|
|
6
|
-
|
|
7
|
-
# compatibility aliases, removed with lot 4 (#509); RACINE and ICI are still
|
|
8
|
-
# read by the scripts of the lot 5 files (argocd-*.sh, services-workspace.sh)
|
|
9
|
-
# shellcheck disable=SC2034
|
|
10
|
-
RACINE="$ROOT"
|
|
11
|
-
# shellcheck disable=SC2034
|
|
12
|
-
ICI="$HERE"
|
|
13
|
-
drapeau_kubectl() { kubectl_flag "$@"; }
|
|
14
|
-
drapeau_helm() { helm_flag "$@"; }
|
|
15
|
-
chemin_chart() { chart_path "$@"; }
|
|
16
|
-
image_par_defaut() { default_image_tag "$@"; }
|
|
17
|
-
demarrer() { start_workspace "$@"; }
|
|
18
|
-
arreter() { stop_workspace "$@"; }
|
|
19
|
-
etat() { status_workspace "$@"; }
|
|
20
|
-
copier_vers() { copy_to "$@"; }
|
|
21
|
-
copier_depuis() { copy_from "$@"; }
|