devzone 7.5.0 → 7.5.2

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.
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>
3
- # (#633), sourced by manage/workspace.sh after workspace-update.sh.
4
- # egress_workspace <subcommand> [domain] dispatch of the command above
5
- # egress_params key=value parameters of the chart, replayed
6
- # by workspace_deploy at each start and update
7
- # The mode and the added domains are kept in .devzone.modules (egress=,
8
- # egress_domains=, state_read and state_note of argocd-workspace.sh). Each
9
- # change redeploys the workspace at the image it runs: same image tag, same
10
- # Argo CD revision, the pod is not recreated. Only the devzone agent sessions
11
- # started with --pod go through the proxy in strict mode. bash 3.2 (macOS).
12
-
13
- # Base list of the chart (egressProxy.allowedDomains in values.yaml): not
14
- # editable with allow or deny, changed in the chart
15
- EGRESS_BASE=".opencode.ai .npmjs.org .github.com"
16
-
17
- # Domain: lowercase letters, digits, hyphens and dots, at least one dot, an
18
- # optional leading dot (subdomains); no space, comma, * or /
19
- egress_domain_ok() {
20
- printf '%s\n' "$1" | grep -Eq '^\.?[a-z0-9-]+(\.[a-z0-9-]+)+$'
21
- }
22
-
23
- # Chart parameters of the proxy from .devzone.modules: nothing when off (or
24
- # unset), else enabled, mode and the added domains (comma-separated)
25
- egress_params() {
26
- local mode domains
27
- mode="$(state_read egress)"
28
- case "$mode" in
29
- observation | strict) ;;
30
- *) return 0 ;;
31
- esac
32
- printf 'egressProxy.enabled=true egressProxy.mode=%s' "$mode"
33
- domains="$(state_read egress_domains)"
34
- if [ -n "$domains" ]; then printf ' egressProxy.extraDomains=%s' "$domains"; fi
35
- }
36
-
37
- # Waits for the proxy after the redeploy. Argo CD creates its Deployment a few
38
- # seconds to a minute after the sync: the Deployment is looked up every
39
- # DEVZONE_EGRESS_STEP s (3 by default) up to DEVZONE_EGRESS_WAIT s (90 by
40
- # default); then its rollout is awaited for DEVZONE_EGRESS_ROLLOUT s (120 by
41
- # default). Returns 1 when either is not reached.
42
- egress_wait_proxy() {
43
- local limit="${DEVZONE_EGRESS_WAIT:-90}" rollout="${DEVZONE_EGRESS_ROLLOUT:-120}" pas="${DEVZONE_EGRESS_STEP:-3}" attendu=0
44
- until ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy >/dev/null 2>&1; do
45
- if [ "$attendu" -ge "$limit" ]; then
46
- echo "⚠ the egress proxy was not created by Argo CD after $limit s: the setting is kept, check devzone workspace argocd status" >&2
47
- return 1
48
- fi
49
- if [ $((limit - attendu)) -lt "$pas" ]; then pas=$((limit - attendu)); fi
50
- sleep "$pas"
51
- attendu=$((attendu + pas))
52
- done
53
- if ! ak -n "$NAMESPACE" rollout status deployment/devzone-workspace-egress-proxy --timeout="${rollout}s"; then
54
- echo "⚠ egress proxy not ready after $rollout s: the setting is kept, see devzone workspace egress status" >&2
55
- return 1
56
- fi
57
- }
58
-
59
- # Redeploys the workspace at the image of the current Argo CD Application
60
- # (targetRevision and image.tag, as update_current); then waits for the proxy
61
- # when it is on. Without Application (helm direct), the setting is only kept:
62
- # devzone workspace start applies it.
63
- egress_redeploy() {
64
- local rev tag
65
- read -r rev tag <<<"$(update_current)" || true
66
- if [ -z "$rev" ] || [ -z "$tag" ]; then
67
- echo "ℹ no Argo CD Application: the setting is kept, devzone workspace start applies it"
68
- return 0
69
- fi
70
- export DEVZONE_ARGOCD_REVISION="$rev"
71
- workspace_deploy "$IMAGE_REPO" "$tag" "" || return 1
72
- if [ -n "$(egress_params)" ]; then
73
- echo "▶ waiting for the egress proxy…"
74
- egress_wait_proxy || return 1
75
- fi
76
- }
77
-
78
- # observation | strict | off: memorised, then the workspace is redeployed
79
- egress_set_mode() {
80
- kube_ready_reason --hint >&2 || return 1
81
- state_note egress "$1"
82
- egress_redeploy || return 1
83
- echo "✔ egress $1"
84
- if [ "$1" = strict ]; then
85
- echo "ℹ strict: only the devzone agent sessions started with --pod are filtered; the workspace stays open"
86
- fi
87
- }
88
-
89
- # allow | deny <domain>: the list of added domains has no duplicate; deny only
90
- # removes what was added, never the base list
91
- egress_domain_edit() {
92
- local action="$1" domain="$2" list new base=no present=no
93
- if ! egress_domain_ok "$domain"; then
94
- echo "✖ domain not valid: $domain (lowercase letters, digits, hyphens and dots, at least one dot, optional leading dot; no space, comma, * or /)" >&2
95
- return 1
96
- fi
97
- case " $EGRESS_BASE " in *" $domain "*) base=yes ;; esac
98
- list="$(state_read egress_domains)"
99
- case ",$list," in *",$domain,"*) present=yes ;; esac
100
- if [ "$action" = allow ]; then
101
- if [ "$base" = yes ]; then
102
- echo "ℹ $domain is in the base list (egressProxy.allowedDomains): already allowed"
103
- return 0
104
- fi
105
- if [ "$present" = yes ]; then
106
- echo "ℹ already allowed: $domain"
107
- return 0
108
- fi
109
- new="${list:+$list,}$domain"
110
- else
111
- if [ "$base" = yes ]; then
112
- echo "✖ $domain is in the base list: change it in egressProxy.allowedDomains of the chart (nothing changed)" >&2
113
- return 1
114
- fi
115
- if [ "$present" = no ]; then
116
- echo "✖ $domain was not added with allow: nothing changed" >&2
117
- return 1
118
- fi
119
- new="$(printf '%s' "$list" | tr ',' '\n' | grep -vxF -- "$domain" | paste -sd, -)" || new=""
120
- fi
121
- kube_ready_reason --hint >&2 || return 1
122
- state_note egress_domains "$new"
123
- echo "✔ $action $domain"
124
- egress_redeploy
125
- }
126
-
127
- # Mode of the proxy (label of its Service, off when none), readiness, number of
128
- # allowed domains (ACL lines of the ConfigMap), then the domains contacted in
129
- # the last 2000 lines of the access log: count and state (allowed, refused, or
130
- # observed in observation mode). Columns of the squid native log: 4 result, 6
131
- # method, 7 host:port.
132
- egress_status() {
133
- local mode ready count table
134
- kube_ready_reason --hint >&2 || return 1
135
- mode="$(ak -n "$NAMESPACE" get service egress-proxy -o 'jsonpath={.metadata.labels.devzone\.io/egress-mode}' 2>/dev/null)" || mode=""
136
- if [ -z "$mode" ]; then
137
- echo "egress off"
138
- return 0
139
- fi
140
- ready="$(ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy -o 'jsonpath={.status.readyReplicas}' 2>/dev/null || true)"
141
- if [ "${ready:-0}" -ge 1 ] 2>/dev/null; then ready="ready"; else ready="not ready"; fi
142
- count="$(ak -n "$NAMESPACE" get configmap devzone-workspace-egress-proxy -o 'jsonpath={.data.squid\.conf}' 2>/dev/null |
143
- grep -c 'acl allowed dstdomain ' || true)"
144
- echo "egress $mode, proxy $ready, allowed domains: ${count:-0}"
145
- table="$(ak -n "$NAMESPACE" logs deployment/devzone-workspace-egress-proxy -c access-log --tail=2000 2>/dev/null |
146
- awk -v mode="$mode" '
147
- $6 == "CONNECT" {
148
- host = $7
149
- sub(/:[0-9]+$/, "", host)
150
- hits[host]++
151
- if ($4 ~ /DENIED/) refused[host] = 1
152
- }
153
- END {
154
- for (h in hits) {
155
- state = refused[h] ? "refused" : (mode == "observation" ? "observed" : "allowed")
156
- printf " %-40s %6d %s\n", h, hits[h], state
157
- }
158
- }' | sort)" || table=""
159
- if [ -z "$table" ]; then
160
- echo " no domain contacted in the recent log"
161
- else
162
- printf ' %-40s %6s %s\n' domain accesses state
163
- echo "$table"
164
- fi
165
- }
166
-
167
- # Dispatch of devzone workspace egress
168
- egress_workspace() {
169
- case "${1:-}" in
170
- observation | strict | off) egress_set_mode "$1" ;;
171
- status) egress_status ;;
172
- allow | deny)
173
- if [ "$#" -ne 2 ]; then
174
- echo "✖ egress $1 takes one domain: devzone workspace egress $1 <domain>" >&2
175
- return 1
176
- fi
177
- egress_domain_edit "$1" "$2"
178
- ;;
179
- *)
180
- echo "✖ unknown egress argument: ${1:-none} (devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>)" >&2
181
- return 1
182
- ;;
183
- esac
184
- }
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone workspace update [--version X.Y.Z] [--yes] (#622): the workspace moves
3
- # to the latest stable release, or to X.Y.Z: image, charts and Argo CD
4
- # Application at that tag. Sourced by manage/workspace.sh, which defines
5
- # IMAGE_REPO, kube_ready_reason, workspace_deploy, services_reconcile and the
6
- # Argo CD helpers (argocd-workspace.sh, argocd-services.sh).
7
- # update_workspace [--version X.Y.Z] [--yes]
8
- # Nothing is written before the image of the release is seen on ghcr.io and
9
- # the update is confirmed (--yes is required without a terminal). No gh, no
10
- # Docker: git ls-remote for the tags, curl for the registry. The registry token
11
- # is read into a variable and only sent in a request, never printed. bash 3.2
12
- # (macOS).
13
-
14
- # Latest stable release: tags vX.Y.Z only (no pre-release), in version order;
15
- # prints its number without the v, nothing when none is found
16
- update_latest_version() {
17
- git ls-remote --tags --refs "$DEVZONE_REPO_URL" 2>/dev/null |
18
- awk '$2 ~ /^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+$/ { sub("refs/tags/v", "", $2); print $2 }' |
19
- sort -V | tail -1
20
- }
21
-
22
- # The image of the release on ghcr.io: anonymous pull token, then the manifest
23
- # headers. Status 0 when the image exists; a failing network counts as absent
24
- update_image_exists() {
25
- local repo_path="${IMAGE_REPO#ghcr.io/}" token
26
- token="$(curl -fsS "https://ghcr.io/token?scope=repository:$repo_path:pull" 2>/dev/null |
27
- sed -n 's/.*"token" *: *"\([^"]*\)".*/\1/p')" || token=""
28
- [ -n "$token" ] || return 1
29
- curl -fsSI -H "Authorization: Bearer $token" \
30
- -H "Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json" \
31
- "https://ghcr.io/v2/$repo_path/manifests/$1" >/dev/null 2>&1
32
- }
33
-
34
- # "<targetRevision> <image.tag>" of the Application devzone-workspace; empty
35
- # when there is none (workspace installed with helm direct)
36
- update_current() {
37
- ak -n "$ARGOCD_NS" get application.argoproj.io "$WORKSPACE_APP" \
38
- -o jsonpath='{.spec.source.targetRevision} {.spec.source.helm.parameters[?(@.name=="image.tag")].value}' 2>/dev/null || true
39
- }
40
-
41
- update_workspace() {
42
- local version="" yes=no answer
43
- while [ $# -gt 0 ]; do
44
- case "$1" in
45
- --version)
46
- if [ $# -lt 2 ] || [ -z "$2" ]; then
47
- echo "✖ option --version: give X.Y.Z (devzone workspace update [--version X.Y.Z] [--yes])" >&2
48
- return 1
49
- fi
50
- version="$2"
51
- shift 2
52
- ;;
53
- --yes)
54
- yes=yes
55
- shift
56
- ;;
57
- *)
58
- echo "✖ unknown option: $1 (devzone workspace update [--version X.Y.Z] [--yes])" >&2
59
- return 1
60
- ;;
61
- esac
62
- done
63
- kube_ready_reason --hint >&2 || return 1
64
- if [ -n "$version" ]; then
65
- grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$' <<<"$version" || {
66
- echo "✖ option --version: expected X.Y.Z, got: $version" >&2
67
- return 1
68
- }
69
- else
70
- version="$(update_latest_version || true)"
71
- [ -n "$version" ] || {
72
- echo "✖ no stable release found in $DEVZONE_REPO_URL (network, or no vX.Y.Z tag): nothing changed" >&2
73
- return 1
74
- }
75
- fi
76
- if ! update_image_exists "$version"; then
77
- echo "✖ image $IMAGE_REPO:$version not found on ghcr.io (the release may still be publishing, or the network is down): nothing changed" >&2
78
- return 1
79
- fi
80
- if [ "$(update_current)" = "v$version $version" ]; then
81
- echo "✔ already up to date: v$version"
82
- return 0
83
- fi
84
- echo "⚠ the workspace pod will be recreated: the VS Code windows attached to it will disconnect"
85
- if [ "$yes" != yes ]; then
86
- if [ ! -t 0 ]; then
87
- echo "✖ no terminal to confirm: run again with --yes (devzone workspace update --yes)" >&2
88
- return 1
89
- fi
90
- read -r -p "Update the workspace to v$version? [y/N] " answer || answer=""
91
- case "$answer" in
92
- y | Y | yes) ;;
93
- *)
94
- echo "✖ canceled, nothing changed" >&2
95
- return 1
96
- ;;
97
- esac
98
- fi
99
- # Same path as workspace start, at the release: Argo CD revision and image tag
100
- export DEVZONE_ARGOCD_REVISION="v$version"
101
- workspace_deploy "$IMAGE_REPO" "$version" ""
102
- if argocd_holds_charts; then
103
- services_reconcile || return 1
104
- fi
105
- echo "✔ workspace on v$version; follow the rollout: devzone workspace status"
106
- }
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Waits for the workspace pod after helm upgrade (#486, #494, #512), sourced by
3
- # manage/workspace.sh: moved here to keep workspace.sh under 250 lines (#515).
4
- # Uses kubectl_flag and helm_flag from workspace.sh.
5
-
6
- # Waits for the workspace pod; missing image or slow pod are reported clearly.
7
- wait_for_pod() {
8
- local image="$1" timeout step start state events arch target_revision pod_revision
9
- timeout="${DEVZONE_WORKSPACE_WAIT:-120}"
10
- step="${DEVZONE_WORKSPACE_STEP:-2}"
11
- start="$SECONDS"
12
- while [ $((SECONDS - start)) -lt "$timeout" ]; do
13
- # Why: after helm upgrade the pod is still the old one; judge only the revision the StatefulSet is updating to, within the same wait bound.
14
- # shellcheck disable=SC2046
15
- target_revision="$(kubectl $(kubectl_flag) get statefulset devzone-workspace --namespace devzone-workspace -o jsonpath='{.status.updateRevision}' 2>/dev/null)" || true
16
- # shellcheck disable=SC2046
17
- pod_revision="$(kubectl $(kubectl_flag) get pod devzone-workspace-0 --namespace devzone-workspace -o jsonpath='{.metadata.labels.controller-revision-hash}' 2>/dev/null)" || true
18
- if [ -z "$target_revision" ] || [ -z "$pod_revision" ] || [ "$target_revision" != "$pod_revision" ]; then sleep "$step"; continue; fi
19
- # shellcheck disable=SC2046
20
- state="$(kubectl $(kubectl_flag) get pod devzone-workspace-0 --namespace devzone-workspace \
21
- -o jsonpath='{.status.phase} {.status.initContainerStatuses[*].state.waiting.reason} {.status.containerStatuses[*].state.waiting.reason}' 2>/dev/null)" || true
22
- case "$state" in
23
- *ErrImagePull* | *ImagePullBackOff*)
24
- # shellcheck disable=SC2046
25
- events="$(kubectl $(kubectl_flag) get events --namespace devzone-workspace \
26
- --field-selector involvedObject.name=devzone-workspace-0 \
27
- -o jsonpath='{.items[*].message}' 2>/dev/null)" || true
28
- case "$events" in
29
- *"no match for platform"*)
30
- # shellcheck disable=SC2046
31
- arch="$(kubectl $(kubectl_flag) get nodes \
32
- -o jsonpath='{.items[0].status.nodeInfo.architecture}' 2>/dev/null)" || true
33
- echo "✖ image $image has no build for $arch: devzone releases publish it for amd64 and arm64." >&2
34
- ;;
35
- *)
36
- echo "✖ image $image not found: it is published at each devzone release." >&2
37
- ;;
38
- esac
39
- echo " For a manually built image: devzone workspace start --image <repository:tag>" >&2
40
- # Argo CD Application or helm release (#516): selfHeal would otherwise recreate the pod
41
- workspace_undeploy >/dev/null 2>&1 || true
42
- return 1
43
- ;;
44
- Running*)
45
- echo "✔ workspace started ($image)"
46
- return 0
47
- ;;
48
- esac
49
- sleep "$step"
50
- done
51
- echo "⚠ pod not ready after $timeout s: devzone workspace status" >&2
52
- return 0
53
- }
54
-
55
- # compatibility alias, removed with lot 4 (#509)
56
- attendre_pod() { wait_for_pod "$@"; }