devzone 7.3.0 → 7.4.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.
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +13 -20
- package/.devcontainer/devzone-modules.sh +1 -1
- package/.devcontainer/devzone-repair.sh +2 -2
- package/.devcontainer/devzone-services.sh +7 -7
- package/.devcontainer/devzone-status.sh +5 -5
- package/.devcontainer/help.sh +3 -1
- package/.devcontainer/versions.env +3 -0
- package/.devcontainer/workspace-init.sh +8 -9
- package/.gitattributes +8 -0
- package/README.md +1 -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/charts/devzone-mysql/values.yaml +1 -1
- package/charts/devzone-postgres/values.yaml +1 -1
- package/manage/devzone +2 -2
- package/manage/scripts/uninstall.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +2 -2
- package/package.json +1 -1
- package/.devcontainer/agent-errors.sh +0 -156
- package/.devcontainer/agent-local.sh +0 -63
- package/.devcontainer/agent-model.sh +0 -113
- package/.devcontainer/agent-pod-egress.sh +0 -36
- package/.devcontainer/agent-pod-manifest.sh +0 -250
- package/.devcontainer/agent-pod.sh +0 -243
- package/.devcontainer/agent-session.sh +0 -242
- package/.devcontainer/agent-state-json.sh +0 -117
- package/.devcontainer/agent-workspace.sh +0 -97
- package/.devcontainer/agent.sh +0 -247
- package/.devcontainer/catalog/app.sh +0 -202
- package/.devcontainer/catalog/catalog-watcher.sh +0 -127
- package/.devcontainer/catalog.sh +0 -208
- package/.devcontainer/chart-direct.sh +0 -49
- package/.devcontainer/cluster.sh +0 -388
- package/.devcontainer/clusters.sh +0 -86
- package/.devcontainer/devzone-cluster.sh +0 -209
- package/.devcontainer/isolation.sh +0 -65
- package/.devcontainer/kube-account.sh +0 -107
- package/.devcontainer/kube-prompt.sh +0 -42
- package/.devcontainer/memory.sh +0 -113
- package/.devcontainer/metrics-server.sh +0 -100
- package/.devcontainer/packages.sh +0 -228
- package/.devcontainer/password.sh +0 -148
- package/.devcontainer/ports-json.sh +0 -31
- package/.devcontainer/ports.sh +0 -132
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Installs metrics-server (CPU/RAM in k9s, kubectl top) on the clusters that
|
|
3
|
-
# have no Metrics API. Docker Desktop and kind do not have it by default.
|
|
4
|
-
# Usage: metrics-server.sh [context...] | metrics-server.sh retirer [context...]
|
|
5
|
-
# (default: reachable local clusters; retirer, the public subcommand
|
|
6
|
-
# name kept as is: removal from the clusters where devzone installed it)
|
|
7
|
-
# --kubelet-insecure-tls: the kubelet of Docker Desktop and kind has a
|
|
8
|
-
# self-signed certificate, without this option the pod never becomes Ready.
|
|
9
|
-
# Exits in error if a requested context is unknown or unreachable, or if an
|
|
10
|
-
# installation fails.
|
|
11
|
-
set -euo pipefail
|
|
12
|
-
|
|
13
|
-
# shellcheck source=SCRIPTDIR/cluster.sh
|
|
14
|
-
. "$(dirname "$0")/cluster.sh"
|
|
15
|
-
|
|
16
|
-
VERSION=v0.9.0
|
|
17
|
-
MANIFEST="https://github.com/kubernetes-sigs/metrics-server/releases/download/${VERSION}/components.yaml"
|
|
18
|
-
|
|
19
|
-
mapfile -t known < <(kubectl config get-contexts -o name 2>/dev/null || true)
|
|
20
|
-
|
|
21
|
-
if [ "${1:-}" = retirer ]; then
|
|
22
|
-
shift
|
|
23
|
-
# Removal (kubernetes module disabled): only the contexts where devzone
|
|
24
|
-
# installed metrics-server (devzone=installe mark) are removed
|
|
25
|
-
requested=$#
|
|
26
|
-
if [ "$requested" -eq 0 ]; then
|
|
27
|
-
# Local clusters only: removal on a remote cluster has nothing to remove
|
|
28
|
-
# (devzone never installs there)
|
|
29
|
-
mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
|
|
30
|
-
while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
|
|
31
|
-
set -- ${contexts[@]+"${contexts[@]}"}
|
|
32
|
-
fi
|
|
33
|
-
code=0
|
|
34
|
-
for context in "$@"; do
|
|
35
|
-
# Mark read on the deployment by its name: kubectl refuses a name with
|
|
36
|
-
# a selector (-l), the test would always be false (#255)
|
|
37
|
-
mark="$(kubectl --context "$context" -n kube-system get deployment metrics-server \
|
|
38
|
-
-o jsonpath='{.metadata.labels.devzone}' 2>/dev/null || true)"
|
|
39
|
-
if [ "$mark" = installe ]; then
|
|
40
|
-
if kubectl --context "$context" delete -f "$MANIFEST" --ignore-not-found >/dev/null 2>&1; then
|
|
41
|
-
echo "metrics-server removed ($VERSION) : $context"
|
|
42
|
-
else
|
|
43
|
-
echo "metrics-server : removal failed: $context" >&2
|
|
44
|
-
code=1
|
|
45
|
-
fi
|
|
46
|
-
elif kubectl --context "$context" -n kube-system get deployment metrics-server >/dev/null 2>&1; then
|
|
47
|
-
# Installed by someone else: not up to devzone to remove it
|
|
48
|
-
echo "metrics-server present without a devzone mark, left: $context" >&2
|
|
49
|
-
fi
|
|
50
|
-
done
|
|
51
|
-
exit "$code"
|
|
52
|
-
fi
|
|
53
|
-
|
|
54
|
-
requested=$#
|
|
55
|
-
if [ "$requested" -eq 0 ]; then
|
|
56
|
-
# Local clusters only: never an automatic installation on a remote cluster
|
|
57
|
-
# of the host (prod, staging…); for another one, name it as an argument
|
|
58
|
-
mapfile -t contexts < <(printf '%s\n' ${known[@]+"${known[@]}"} |
|
|
59
|
-
while IFS= read -r c; do cluster_is_local "$c" && echo "$c"; done || true)
|
|
60
|
-
set -- ${contexts[@]+"${contexts[@]}"}
|
|
61
|
-
fi
|
|
62
|
-
|
|
63
|
-
code=0
|
|
64
|
-
reachable=0
|
|
65
|
-
for context in "$@"; do
|
|
66
|
-
if [ "$requested" -gt 0 ] && ! printf '%s\n' ${known[@]+"${known[@]}"} | grep -qxF -- "$context"; then
|
|
67
|
-
echo "metrics-server : unknown context: $context (see kubectl config get-contexts)" >&2
|
|
68
|
-
code=1
|
|
69
|
-
continue
|
|
70
|
-
fi
|
|
71
|
-
k=(kubectl --context "$context" --request-timeout=5s)
|
|
72
|
-
if ! "${k[@]}" get --raw /readyz >/dev/null 2>&1; then
|
|
73
|
-
# Without argument: kind may still be starting, ignored
|
|
74
|
-
if [ "$requested" -gt 0 ]; then
|
|
75
|
-
echo "metrics-server : cluster unreachable: $context" >&2
|
|
76
|
-
code=1
|
|
77
|
-
fi
|
|
78
|
-
continue
|
|
79
|
-
fi
|
|
80
|
-
reachable=$((reachable + 1))
|
|
81
|
-
if "${k[@]}" get apiservice v1beta1.metrics.k8s.io >/dev/null 2>&1; then
|
|
82
|
-
echo "metrics-server : already present: $context"
|
|
83
|
-
continue
|
|
84
|
-
fi
|
|
85
|
-
if "${k[@]}" apply -f "$MANIFEST" >/dev/null &&
|
|
86
|
-
"${k[@]}" -n kube-system patch deployment metrics-server --type=json \
|
|
87
|
-
-p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]' >/dev/null &&
|
|
88
|
-
# Mark: make desinstaller only removes what devzone installed
|
|
89
|
-
"${k[@]}" -n kube-system label deployment metrics-server devzone=installe app.kubernetes.io/managed-by=devzone --overwrite >/dev/null; then
|
|
90
|
-
echo "metrics-server : installed ($VERSION): $context (metrics within ~1 min)"
|
|
91
|
-
else
|
|
92
|
-
echo "metrics-server : installation failed: $context" >&2
|
|
93
|
-
code=1
|
|
94
|
-
fi
|
|
95
|
-
done
|
|
96
|
-
|
|
97
|
-
if [ "$requested" -eq 0 ] && [ "$reachable" -eq 0 ]; then
|
|
98
|
-
echo "metrics-server : no reachable local cluster; after kind create cluster: bash .devcontainer/metrics-server.sh"
|
|
99
|
-
fi
|
|
100
|
-
exit "$code"
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# System packages kept after a rebuild (#351): a list in the devzone folder
|
|
3
|
-
# (<root>/.devzone.packages, a comment header + one package name per line, sorted,
|
|
4
|
-
# without duplicates), reinstalled at each container creation.
|
|
5
|
-
# A package installed by hand is lost by a rebuild, unless it is in this list.
|
|
6
|
-
# packages.sh or packages.sh list list with the state of each package
|
|
7
|
-
# packages.sh add <name>… validates, installs, adds to the list
|
|
8
|
-
# packages.sh remove <name>… removes from the list and uninstalls (except image packages)
|
|
9
|
-
# packages.sh apply installs everything missing
|
|
10
|
-
# The state of a package comes from dpkg-query -W -f='${Status}'; the system
|
|
11
|
-
# commands go through overridable variables for the tests (sudo, apt-get,
|
|
12
|
-
# apt-cache, dpkg-query, mark, timestamp). Compatible with bash 3.2 (macOS).
|
|
13
|
-
set -euo pipefail
|
|
14
|
-
|
|
15
|
-
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
16
|
-
ROOT="${DEVZONE_ROOT:-$(dirname "$HERE")}"
|
|
17
|
-
LIST="${ROOT}/.devzone.packages"
|
|
18
|
-
MARK="${DEVZONE_PACKAGES_MARKER:-/tmp/devzone-packages.failed}"
|
|
19
|
-
UPDATED="${DEVZONE_PACKAGES_UPDATE:-/tmp/devzone-packages.updated}"
|
|
20
|
-
SUDO="${DEVZONE_PACKAGES_SUDO-sudo}"
|
|
21
|
-
APT="${DEVZONE_PACKAGES_APT:-apt-get}"
|
|
22
|
-
APTCACHE="${DEVZONE_PACKAGES_APTCACHE:-apt-cache}"
|
|
23
|
-
DPKGQUERY="${DEVZONE_PACKAGES_DPKG_QUERY:-dpkg-query}"
|
|
24
|
-
FORMAT="-f=\${Status}"
|
|
25
|
-
# Stored values, kept byte for byte (the users' list file): the header and the
|
|
26
|
-
# « already present » mark are written in UTF-8 as byte escapes (contract).
|
|
27
|
-
HEADER=$'# paquets ajout\303\251s par devzone packages add ; r\303\251install\303\251s \303\240 chaque cr\303\251ation du conteneur'
|
|
28
|
-
PRESENT_MARK=$'# d\303\251j\303\240 pr\303\251sent'
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
refuse() { echo "devzone : packages : $*" >&2; exit 1; }
|
|
32
|
-
|
|
33
|
-
as_root() {
|
|
34
|
-
if [ -n "$SUDO" ]; then
|
|
35
|
-
"$SUDO" "$@"
|
|
36
|
-
else
|
|
37
|
-
env "$@"
|
|
38
|
-
fi
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
is_installed() {
|
|
42
|
-
"$DPKGQUERY" -W "$FORMAT" "$1" 2>/dev/null | grep -q 'install ok installed'
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
# List lines as they are (name, or name followed by the present mark).
|
|
46
|
-
list_lines() {
|
|
47
|
-
[ -f "$LIST" ] || return 0
|
|
48
|
-
grep -vE '^[[:space:]]*(#|$)' "$LIST" 2>/dev/null |
|
|
49
|
-
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d' |
|
|
50
|
-
sort -k1,1 -u || true
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
# Names only: the end-of-line mark is ignored.
|
|
54
|
-
list_names() {
|
|
55
|
-
list_lines | sed -e 's/[[:space:]]*#.*$//' | sort -u || true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
name_listed() {
|
|
59
|
-
local name
|
|
60
|
-
while IFS= read -r name; do
|
|
61
|
-
[ "$name" = "$1" ] && return 0
|
|
62
|
-
done < <(list_names)
|
|
63
|
-
return 1
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
# True if the package was marked as already present in the image.
|
|
67
|
-
mark_present() {
|
|
68
|
-
grep -qxF -e "$1 $PRESENT_MARK" "$LIST" 2>/dev/null
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
# Rewrites the list: a single header, then the given lines (sorted by name).
|
|
72
|
-
write_list() {
|
|
73
|
-
local tmp
|
|
74
|
-
tmp="$(mktemp)"
|
|
75
|
-
{
|
|
76
|
-
echo "$HEADER"
|
|
77
|
-
[ "$#" -eq 0 ] || printf '%s\n' "$@" | sort -k1,1 -u
|
|
78
|
-
} >"$tmp"
|
|
79
|
-
mv "$tmp" "$LIST"
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
update_index() {
|
|
83
|
-
local last
|
|
84
|
-
last="$(cat "$UPDATED" 2>/dev/null || true)"
|
|
85
|
-
if [ -n "$last" ] && [ $(( $(date +%s) - last )) -lt 3600 ]; then
|
|
86
|
-
return 0
|
|
87
|
-
fi
|
|
88
|
-
as_root "$APT" update || return 1
|
|
89
|
-
date +%s >"$UPDATED"
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
list_packages() {
|
|
93
|
-
local packages package
|
|
94
|
-
packages="$(list_names)"
|
|
95
|
-
if [ -z "$packages" ]; then
|
|
96
|
-
echo "no package (devzone packages add <name>)"
|
|
97
|
-
return 0
|
|
98
|
-
fi
|
|
99
|
-
while IFS= read -r package; do
|
|
100
|
-
[ -n "$package" ] || continue
|
|
101
|
-
if is_installed "$package"; then
|
|
102
|
-
echo " ✔ $package"
|
|
103
|
-
else
|
|
104
|
-
echo " ○ $package"
|
|
105
|
-
fi
|
|
106
|
-
done < <(printf '%s\n' "$packages")
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
add_packages() {
|
|
110
|
-
local -a a=()
|
|
111
|
-
local -a entries=()
|
|
112
|
-
local arg name line already=""
|
|
113
|
-
for arg in "$@"; do
|
|
114
|
-
case "$arg" in
|
|
115
|
-
-*) refuse "unknown argument: $arg (devzone packages add <name>…)" ;;
|
|
116
|
-
*) a+=("$arg") ;;
|
|
117
|
-
esac
|
|
118
|
-
done
|
|
119
|
-
[ "${#a[@]}" -gt 0 ] || refuse "add expects at least one name: devzone packages add <name>…"
|
|
120
|
-
update_index || echo "apt index not updated" >&2
|
|
121
|
-
for name in "${a[@]}"; do
|
|
122
|
-
if ! "$APTCACHE" show "$name" >/dev/null 2>&1; then
|
|
123
|
-
refuse "unknown package: $name (list unchanged)"
|
|
124
|
-
fi
|
|
125
|
-
done
|
|
126
|
-
# What is already installed before the installation comes from the image: marked
|
|
127
|
-
for name in "${a[@]}"; do
|
|
128
|
-
if is_installed "$name"; then
|
|
129
|
-
already="$already $name"
|
|
130
|
-
fi
|
|
131
|
-
done
|
|
132
|
-
if as_root DEBIAN_FRONTEND=noninteractive "$APT" install -y --no-install-recommends "${a[@]}"; then
|
|
133
|
-
while IFS= read -r line; do
|
|
134
|
-
entries+=("$line")
|
|
135
|
-
done < <(list_lines)
|
|
136
|
-
for name in "${a[@]}"; do
|
|
137
|
-
if name_listed "$name"; then
|
|
138
|
-
continue
|
|
139
|
-
fi
|
|
140
|
-
case " $already " in
|
|
141
|
-
*" $name "*)
|
|
142
|
-
entries+=("$name $PRESENT_MARK")
|
|
143
|
-
echo "$name : already present before devzone packages (marked ; removing will leave it installed)"
|
|
144
|
-
;;
|
|
145
|
-
*) entries+=("$name") ;;
|
|
146
|
-
esac
|
|
147
|
-
done
|
|
148
|
-
write_list "${entries[@]}"
|
|
149
|
-
else
|
|
150
|
-
refuse "installation failed: ${a[*]} (list unchanged)"
|
|
151
|
-
fi
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
remove_packages() {
|
|
155
|
-
local -a a=()
|
|
156
|
-
local -a removals=()
|
|
157
|
-
local -a remaining=()
|
|
158
|
-
local arg name line name_line
|
|
159
|
-
for arg in "$@"; do
|
|
160
|
-
case "$arg" in
|
|
161
|
-
-*) refuse "unknown argument: $arg (devzone packages remove <name>…)" ;;
|
|
162
|
-
*) a+=("$arg") ;;
|
|
163
|
-
esac
|
|
164
|
-
done
|
|
165
|
-
[ "${#a[@]}" -gt 0 ] || refuse "remove expects at least one name: devzone packages remove <name>…"
|
|
166
|
-
for name in "${a[@]}"; do
|
|
167
|
-
name_listed "$name" ||
|
|
168
|
-
refuse "package not listed: $name (provided by the image?) : devzone packages remove does not add image packages"
|
|
169
|
-
if ! mark_present "$name"; then
|
|
170
|
-
removals+=("$name")
|
|
171
|
-
fi
|
|
172
|
-
done
|
|
173
|
-
if [ "${#removals[@]}" -gt 0 ] && ! as_root "$APT" remove -y "${removals[@]}"; then
|
|
174
|
-
refuse "removal failed: ${removals[*]} (list unchanged)"
|
|
175
|
-
fi
|
|
176
|
-
for name in "${a[@]}"; do
|
|
177
|
-
if mark_present "$name"; then
|
|
178
|
-
echo "$name : removed from the list, left installed (present before devzone packages)"
|
|
179
|
-
fi
|
|
180
|
-
done
|
|
181
|
-
while IFS= read -r line; do
|
|
182
|
-
name_line="${line%% *}"
|
|
183
|
-
case " ${a[*]} " in
|
|
184
|
-
*" $name_line "*) ;;
|
|
185
|
-
*) remaining+=("$line") ;;
|
|
186
|
-
esac
|
|
187
|
-
done < <(list_lines)
|
|
188
|
-
write_list "${remaining[@]+"${remaining[@]}"}"
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
apply_packages() {
|
|
192
|
-
local package
|
|
193
|
-
local -a missing=()
|
|
194
|
-
while IFS= read -r package; do
|
|
195
|
-
[ -n "$package" ] || continue
|
|
196
|
-
if ! is_installed "$package"; then
|
|
197
|
-
missing+=("$package")
|
|
198
|
-
fi
|
|
199
|
-
done < <(printf '%s\n' "$(list_names)")
|
|
200
|
-
if [ "${#missing[@]}" -eq 0 ]; then
|
|
201
|
-
rm -f "$MARK"
|
|
202
|
-
return 0
|
|
203
|
-
fi
|
|
204
|
-
update_index || echo "apt index not updated" >&2
|
|
205
|
-
for package in "${missing[@]}"; do
|
|
206
|
-
as_root DEBIAN_FRONTEND=noninteractive "$APT" install -y --no-install-recommends "$package" || true
|
|
207
|
-
done
|
|
208
|
-
local -a still_missing=()
|
|
209
|
-
for package in "${missing[@]}"; do
|
|
210
|
-
if ! is_installed "$package"; then
|
|
211
|
-
still_missing+=("$package")
|
|
212
|
-
fi
|
|
213
|
-
done
|
|
214
|
-
if [ "${#still_missing[@]}" -gt 0 ]; then
|
|
215
|
-
printf '%s\n' "${still_missing[@]}" >"$MARK"
|
|
216
|
-
return 1
|
|
217
|
-
fi
|
|
218
|
-
rm -f "$MARK"
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
case "${1:-}" in
|
|
222
|
-
'' | list) list_packages ;;
|
|
223
|
-
add) add_packages "${@:2}" ;;
|
|
224
|
-
remove) remove_packages "${@:2}" ;;
|
|
225
|
-
apply) apply_packages ;;
|
|
226
|
-
-h | --help) awk 'NR==1{next} /^#$/{exit} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}" ;;
|
|
227
|
-
*) refuse "unknown command: ${1:-(none)} (devzone packages --help)" ;;
|
|
228
|
-
esac
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Grouped credentials of the accounts created by devzone (#332).
|
|
3
|
-
# password.sh regenerate reads the module files, writes $ROOT/.password
|
|
4
|
-
# password.sh path prints the path of $ROOT/.password
|
|
5
|
-
# The module files stay the source: .password is a regenerated view.
|
|
6
|
-
# Plain-text secrets: never printed, never committed (.gitignore), mode 600.
|
|
7
|
-
set -euo pipefail
|
|
8
|
-
|
|
9
|
-
PASSWORD_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
-
PASSWORD_ROOT="${DEVZONE_ROOT:-$(dirname "$PASSWORD_HERE")}"
|
|
11
|
-
PASSWORD_TARGET="$PASSWORD_ROOT/.password"
|
|
12
|
-
|
|
13
|
-
# Regenerates $ROOT/.password from workspace/.gitlab, workspace/.postgres,
|
|
14
|
-
# workspace/.argocd, workspace/.mysql and the other workspace/.<app>/ folders.
|
|
15
|
-
# Silent on success; without any account, the file is removed.
|
|
16
|
-
password_regenerate() (
|
|
17
|
-
umask 077
|
|
18
|
-
local target="$PASSWORD_TARGET" root="$PASSWORD_ROOT"
|
|
19
|
-
local gl="$root/workspace/.gitlab" pg="$root/workspace/.postgres"
|
|
20
|
-
local ar="$root/workspace/.argocd"
|
|
21
|
-
local my="$root/workspace/.mysql"
|
|
22
|
-
local tab entries tmp file name service address user secret
|
|
23
|
-
tab="$(printf '\t')"
|
|
24
|
-
entries="$(mktemp "$root/.password.entries.XXXXXX")" || return 1
|
|
25
|
-
tmp=""
|
|
26
|
-
|
|
27
|
-
if [ -s "$gl/root-password" ]; then
|
|
28
|
-
secret="$(cat "$gl/root-password")"
|
|
29
|
-
if [ -n "$secret" ]; then
|
|
30
|
-
printf 'gitlab\t%s\troot\t%s\n' "http://gitlab.localhost:8929" "$secret" >>"$entries"
|
|
31
|
-
fi
|
|
32
|
-
fi
|
|
33
|
-
if [ -s "$gl/dev-password" ]; then
|
|
34
|
-
secret="$(cat "$gl/dev-password")"
|
|
35
|
-
if [ -n "$secret" ]; then
|
|
36
|
-
printf 'gitlab\t%s\tdev\t%s\n' "http://gitlab.localhost:8929" "$secret" >>"$entries"
|
|
37
|
-
fi
|
|
38
|
-
fi
|
|
39
|
-
if [ -s "$pg/admin-password" ]; then
|
|
40
|
-
secret="$(cat "$pg/admin-password")"
|
|
41
|
-
if [ -n "$secret" ]; then
|
|
42
|
-
printf 'postgres\t%s\tpostgres\t%s\n' "127.0.0.1:5432" "$secret" >>"$entries"
|
|
43
|
-
fi
|
|
44
|
-
fi
|
|
45
|
-
# Catalogue MySQL root (direct helm or Argo CD, #538): mirror of the workstation
|
|
46
|
-
if [ -s "$my/admin-password" ]; then
|
|
47
|
-
secret="$(cat "$my/admin-password")"
|
|
48
|
-
if [ -n "$secret" ]; then
|
|
49
|
-
printf 'mysql\t%s\troot\t%s\n' "127.0.0.1:3306" "$secret" >>"$entries"
|
|
50
|
-
fi
|
|
51
|
-
fi
|
|
52
|
-
if [ -s "$ar/admin.env" ]; then
|
|
53
|
-
user="$(sed -n 's/^ARGOCD_USER=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
|
|
54
|
-
secret="$(sed -n 's/^ARGOCD_PASSWORD=//p' "$ar/admin.env" 2>/dev/null | tail -1 || true)"
|
|
55
|
-
if [ -n "$user" ] && [ -n "$secret" ]; then
|
|
56
|
-
printf 'argocd\t%s\t%s\t%s\n' "https://127.0.0.1:8443" "$user" "$secret" >>"$entries"
|
|
57
|
-
fi
|
|
58
|
-
fi
|
|
59
|
-
for file in "$pg"/*.env; do
|
|
60
|
-
[ -f "$file" ] || continue
|
|
61
|
-
name="${file##*/}"
|
|
62
|
-
name="${name%.env}"
|
|
63
|
-
service="postgres:$name"
|
|
64
|
-
user="$(sed -n 's/^DB_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
65
|
-
secret="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
66
|
-
address="$(sed -n 's/^DB_NAME=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
67
|
-
if [ -z "$user" ] || [ -z "$secret" ]; then
|
|
68
|
-
continue
|
|
69
|
-
fi
|
|
70
|
-
address="127.0.0.1:5432/${address:-$name}"
|
|
71
|
-
printf '%s\t%s\t%s\t%s\n' "$service" "$address" "$user" "$secret" >>"$entries"
|
|
72
|
-
done
|
|
73
|
-
# Each other catalogue application: workspace/.<app>/*.env, keys <APP>_HOST,
|
|
74
|
-
# <APP>_PORT, <APP>_USER, <APP>_PASSWORD (or MYSQL_* for mysql)
|
|
75
|
-
for dir in "$root"/workspace/.*/; do
|
|
76
|
-
[ -d "$dir" ] || continue
|
|
77
|
-
app="${dir%/}"
|
|
78
|
-
app="${app##*/}"
|
|
79
|
-
case "$app" in . | .. | .gitlab | .postgres | .argocd) continue ;; esac
|
|
80
|
-
app="${app#.}"
|
|
81
|
-
app_upper="$(printf '%s' "$app" | tr '[:lower:]' '[:upper:]')"
|
|
82
|
-
for file in "$dir"*.env; do
|
|
83
|
-
[ -f "$file" ] || continue
|
|
84
|
-
base="${file##*/}"
|
|
85
|
-
base="${base%.env}"
|
|
86
|
-
user="$(sed -n "s/^${app_upper}_USER=//p" "$file" 2>/dev/null | tail -1 || true)"
|
|
87
|
-
[ -z "$user" ] && user="$(sed -n 's/^DB_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
88
|
-
[ -z "$user" ] && user="$(sed -n 's/^MYSQL_USER=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
89
|
-
secret="$(sed -n "s/^${app_upper}_PASSWORD=//p" "$file" 2>/dev/null | tail -1 || true)"
|
|
90
|
-
[ -z "$secret" ] && secret="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
91
|
-
[ -z "$secret" ] && secret="$(sed -n 's/^MYSQL_PASSWORD=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
92
|
-
[ -z "$user" ] || [ -z "$secret" ] && continue
|
|
93
|
-
host="$(sed -n "s/^${app_upper}_HOST=//p" "$file" 2>/dev/null | tail -1 || true)"
|
|
94
|
-
[ -z "$host" ] && host="$(sed -n 's/^DB_HOST=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
95
|
-
[ -z "$host" ] && host="$(sed -n 's/^MYSQL_HOST=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
96
|
-
[ -z "$host" ] && host=127.0.0.1
|
|
97
|
-
port="$(sed -n "s/^${app_upper}_PORT=//p" "$file" 2>/dev/null | tail -1 || true)"
|
|
98
|
-
[ -z "$port" ] && port="$(sed -n 's/^DB_PORT=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
99
|
-
[ -z "$port" ] && port="$(sed -n 's/^MYSQL_PORT=//p' "$file" 2>/dev/null | tail -1 || true)"
|
|
100
|
-
[ -z "$port" ] && port=3306
|
|
101
|
-
printf '%s\t%s\t%s\t%s\n' "$app:$base" "$host:$port" "$user" "$secret" >>"$entries"
|
|
102
|
-
done
|
|
103
|
-
done
|
|
104
|
-
|
|
105
|
-
if [ ! -s "$entries" ]; then
|
|
106
|
-
rm -f "$entries" "$target"
|
|
107
|
-
return 0
|
|
108
|
-
fi
|
|
109
|
-
|
|
110
|
-
tmp="$(mktemp "$root/.password.XXXXXX")" || {
|
|
111
|
-
rm -f "$entries"
|
|
112
|
-
return 1
|
|
113
|
-
}
|
|
114
|
-
{
|
|
115
|
-
printf '%s\n' \
|
|
116
|
-
'# devzone : identifiers of the accounts created by devzone. Plain-text secrets:' \
|
|
117
|
-
'# never commit, copy or paste them into a ticket. Regenerated by devzone.' \
|
|
118
|
-
"# service${tab}address${tab}user${tab}password"
|
|
119
|
-
LC_ALL=C sort -t "$tab" -k1,1 -k3,3 "$entries"
|
|
120
|
-
} >"$tmp" || {
|
|
121
|
-
rm -f "$entries" "$tmp"
|
|
122
|
-
return 1
|
|
123
|
-
}
|
|
124
|
-
chmod 600 "$tmp" || {
|
|
125
|
-
rm -f "$entries" "$tmp"
|
|
126
|
-
return 1
|
|
127
|
-
}
|
|
128
|
-
mv "$tmp" "$target" || {
|
|
129
|
-
rm -f "$entries" "$tmp"
|
|
130
|
-
return 1
|
|
131
|
-
}
|
|
132
|
-
chmod 600 "$target" || {
|
|
133
|
-
rm -f "$entries"
|
|
134
|
-
return 1
|
|
135
|
-
}
|
|
136
|
-
rm -f "$entries"
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
140
|
-
case "${1:-}" in
|
|
141
|
-
regenerate) password_regenerate ;;
|
|
142
|
-
path) printf '%s\n' "$PASSWORD_TARGET" ;;
|
|
143
|
-
*)
|
|
144
|
-
echo "devzone : password.sh : regenerate | path" >&2
|
|
145
|
-
exit 1
|
|
146
|
-
;;
|
|
147
|
-
esac
|
|
148
|
-
fi
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# JSON output of the port relays (#557): the array
|
|
3
|
-
# [{port,active,application,auto}] read by the tools (devzone status --json).
|
|
4
|
-
# The keys and the application values are a contract.
|
|
5
|
-
# Sourced by ports.sh, which holds the functions used here.
|
|
6
|
-
|
|
7
|
-
# JSON list of the relays of the state: jq only
|
|
8
|
-
list_json() {
|
|
9
|
-
local ports port active app json='[]'
|
|
10
|
-
ports="$(sort_ports "$(read_ports)")"
|
|
11
|
-
if [ -z "$ports" ]; then
|
|
12
|
-
printf '[]\n'
|
|
13
|
-
return 0
|
|
14
|
-
fi
|
|
15
|
-
# shellcheck disable=SC2046 # list of ports separated by commas
|
|
16
|
-
for port in $(printf '%s' "$ports" | tr ',' ' '); do
|
|
17
|
-
if relay_active "$port"; then
|
|
18
|
-
active=true
|
|
19
|
-
else
|
|
20
|
-
active=false
|
|
21
|
-
fi
|
|
22
|
-
if app_responds "$port"; then
|
|
23
|
-
app="$JSON_APP_RESPONDS"
|
|
24
|
-
else
|
|
25
|
-
app="$JSON_APP_NONE"
|
|
26
|
-
fi
|
|
27
|
-
json="$(jq -c --argjson port "$port" --argjson active "$active" --arg app "$app" \
|
|
28
|
-
'. + [{port:$port,active:$active,application:$app,auto:false}]' <<<"$json")"
|
|
29
|
-
done
|
|
30
|
-
printf '%s\n' "$json"
|
|
31
|
-
}
|
package/.devcontainer/ports.sh
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Port relays of the workstation (#290): applications reachable from
|
|
3
|
-
# 127.0.0.1 of the workstation, kept in the state of devzone.
|
|
4
|
-
# ports.sh list relays of the state: port, active, application
|
|
5
|
-
# ports.sh close <n> removes the relay and the port from the state
|
|
6
|
-
# ports.sh resume one-line summary for the devzone recap
|
|
7
|
-
# The state is the line "ports=8080,3000" of DEVZONE_STATE (sorted, no duplicate).
|
|
8
|
-
# ROOT: a single dirname from HERE (.devcontainer) = root of the devzone repository.
|
|
9
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then set -euo pipefail; fi
|
|
10
|
-
|
|
11
|
-
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
-
ROOT="${DEVZONE_ROOT:-$(dirname "$HERE")}"
|
|
13
|
-
ETAT="${DEVZONE_STATE:-$ROOT/.devzone.modules}"
|
|
14
|
-
INSTANCE="${DEVZONE_INSTANCE:-devzone}"
|
|
15
|
-
|
|
16
|
-
# Safe state write (#417): lock, temporary file in the state folder, backup copy
|
|
17
|
-
|
|
18
|
-
refuse() { echo "devzone : port : $*" >&2; exit 1; }
|
|
19
|
-
|
|
20
|
-
# Application labels: the list shows them in English. The JSON output keeps its
|
|
21
|
-
# French values (read by the tools, #557): a contract, UTF-8 written as byte escapes.
|
|
22
|
-
APP_RESPONDS="application responds"
|
|
23
|
-
APP_NONE="no application"
|
|
24
|
-
# shellcheck disable=SC2034 # read by ports-json.sh (sourced)
|
|
25
|
-
JSON_APP_RESPONDS=$'application r\303\251pond'
|
|
26
|
-
# shellcheck disable=SC2034 # read by ports-json.sh (sourced)
|
|
27
|
-
JSON_APP_NONE="aucune application"
|
|
28
|
-
|
|
29
|
-
relay_name() { echo "devzone-$INSTANCE-port-$1"; }
|
|
30
|
-
|
|
31
|
-
port_valid() { case "${1:-}" in '' | *[!0-9]*) return 1 ;; esac; [ "$1" -ge 1 ] 2>/dev/null && [ "$1" -le 65535 ] 2>/dev/null; }
|
|
32
|
-
|
|
33
|
-
validate_port() { port_valid "${1:-}" || refuse "invalid port : ${1:-(none)} (1-65535)"; }
|
|
34
|
-
|
|
35
|
-
read_ports() { grep -E '^ports=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true; }
|
|
36
|
-
|
|
37
|
-
sort_ports() {
|
|
38
|
-
printf '%s\n' "${1:-}" | tr ',' '\n' | awk 'NF && $0 ~ /^[0-9]+$/ { print }' | sort -n -u | paste -sd, -
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# Writes the ports= line of the state (#417: never mv outside Go state command)
|
|
42
|
-
write_ports() {
|
|
43
|
-
DEVZONE_STATE="$ETAT" bash "$HERE/devzone" state write ports "${1:-}" || { echo "devzone : port : state not saved : $ETAT" >&2; exit 1; }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
add_port() {
|
|
47
|
-
local port="$1"
|
|
48
|
-
write_ports "$(sort_ports "$(read_ports),$port")"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
remove_port() {
|
|
52
|
-
local port="$1" rest="" p
|
|
53
|
-
# shellcheck disable=SC2046 # list of ports separated by commas
|
|
54
|
-
for p in $(printf '%s' "$(read_ports)" | tr ',' ' '); do
|
|
55
|
-
[ "$p" = "$port" ] || rest="$rest${rest:+,}$p"
|
|
56
|
-
done
|
|
57
|
-
write_ports "$(sort_ports "$rest")"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
relay_active() {
|
|
61
|
-
local name
|
|
62
|
-
name="$(relay_name "$1")"
|
|
63
|
-
command -v docker >/dev/null 2>&1 || return 1
|
|
64
|
-
[ -n "$(docker ps --filter "name=^$name$" --format '{{.Names}}' 2>/dev/null |
|
|
65
|
-
grep -Fx "$name" || true)" ]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
close_port() {
|
|
69
|
-
local port="${1:-}"
|
|
70
|
-
validate_port "$port"
|
|
71
|
-
docker rm -f "$(relay_name "$port")" >/dev/null 2>&1 || true
|
|
72
|
-
remove_port "$port"
|
|
73
|
-
echo "✔ relay closed: $port"
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
app_responds() { curl -s -o /dev/null --max-time 2 "http://127.0.0.1:$1" >/dev/null 2>&1; }
|
|
77
|
-
|
|
78
|
-
list_ports() {
|
|
79
|
-
local ports port mark app
|
|
80
|
-
ports="$(sort_ports "$(read_ports)")"
|
|
81
|
-
if [ -z "$ports" ]; then
|
|
82
|
-
echo "no relay"
|
|
83
|
-
return 0
|
|
84
|
-
fi
|
|
85
|
-
# shellcheck disable=SC2046 # list of ports separated by commas
|
|
86
|
-
for port in $(printf '%s' "$ports" | tr ',' ' '); do
|
|
87
|
-
if relay_active "$port"; then
|
|
88
|
-
mark="● active"
|
|
89
|
-
else
|
|
90
|
-
mark="○ stopped"
|
|
91
|
-
fi
|
|
92
|
-
if app_responds "$port"; then
|
|
93
|
-
app="$APP_RESPONDS"
|
|
94
|
-
else
|
|
95
|
-
app="$APP_NONE"
|
|
96
|
-
fi
|
|
97
|
-
printf ' %-5s %s %s\n' "$port" "$mark" "$app"
|
|
98
|
-
done
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
summary() {
|
|
102
|
-
local ports port output=""
|
|
103
|
-
ports="$(sort_ports "$(read_ports)")"
|
|
104
|
-
if [ -z "$ports" ]; then
|
|
105
|
-
echo "none"
|
|
106
|
-
return 0
|
|
107
|
-
fi
|
|
108
|
-
# shellcheck disable=SC2046 # list of ports separated by commas
|
|
109
|
-
for port in $(printf '%s' "$ports" | tr ',' ' '); do
|
|
110
|
-
if relay_active "$port"; then
|
|
111
|
-
output="$output${output:+, }$port ●"
|
|
112
|
-
else
|
|
113
|
-
output="$output${output:+, }$port ○"
|
|
114
|
-
fi
|
|
115
|
-
done
|
|
116
|
-
echo "$output"
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
# Machine-readable output of list: a JSON array [{port,active,application,auto}], jq only.
|
|
120
|
-
# shellcheck source=SCRIPTDIR/ports-json.sh
|
|
121
|
-
# shellcheck disable=SC1091
|
|
122
|
-
. "$HERE/ports-json.sh"
|
|
123
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
124
|
-
case "${1:-}" in
|
|
125
|
-
'' | list)
|
|
126
|
-
if [ "${2:-}" = "--json" ]; then list_json; else list_ports; fi
|
|
127
|
-
;;
|
|
128
|
-
close | --close) close_port "${2:-}" ;;
|
|
129
|
-
resume) summary ;;
|
|
130
|
-
-h | --help) sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//' ;;
|
|
131
|
-
esac
|
|
132
|
-
fi
|