devzone 7.5.4 → 7.5.5
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/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-workspace/templates/statefulset.yaml +4 -3
- package/charts/devzone-workspace/values.yaml +16 -5
- package/manage/devzone +0 -18
- package/manage/workspace.sh +25 -9
- package/package.json +1 -1
- package/manage/scripts/devzone-manifest.sh +0 -171
- package/manage/scripts/workspace/argocd-services-svc.sh +0 -112
- package/manage/scripts/workspace/argocd-services.sh +0 -182
- package/manage/scripts/workspace/argocd-workspace.sh +0 -227
package/bin/SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
75d21c891a3e83fd5037a9610283e5aa4f144186bb0f1ba6bb364a78a25d053d devzone-linux-amd64
|
|
2
|
+
b23cc5f02fcf6dfec9acc5b1a8a958005e1b95920e61f7329d84899fe9b55dab devzone-linux-arm64
|
|
3
|
+
28972dbafb6f975e10d0de5efe9b2fe0b0782e2459364e422ceacc9fc722bee1 devzone-darwin-amd64
|
|
4
|
+
64e8f635263f13cc11519fb1fe7be3b985f2f3eec612179e50fb825cc036d9a9 devzone-darwin-arm64
|
|
5
|
+
13ca4aa8e024752eac26cd5d5dd398d16287d04f134ee3617c8d941ad232173b devzone-windows-amd64.exe
|
|
6
|
+
2c4a240fa2e87921f2502dc49c2814874e471389b697689c29cc59f2b60dc81f 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
|
|
@@ -144,9 +144,10 @@ spec:
|
|
|
144
144
|
{{- /*
|
|
145
145
|
Without command, the container runs the entrypoint of the image (bash
|
|
146
146
|
for a devcontainer), which ends at once without a terminal: the pod
|
|
147
|
-
loops on restarts.
|
|
148
|
-
|
|
149
|
-
comment: not in
|
|
147
|
+
loops on restarts. The command keeps it alive as PID 1 (a wait loop
|
|
148
|
+
that reaps the orphans, #967), like VS Code for a devcontainer; the
|
|
149
|
+
workstation then enters through kubectl exec. Helm comment: not in
|
|
150
|
+
the rendering.
|
|
150
151
|
*/}}
|
|
151
152
|
{{- with .Values.workspace.command }}
|
|
152
153
|
command: {{ toJson . }}
|
|
@@ -50,21 +50,32 @@ buildkit:
|
|
|
50
50
|
# is mounted on /workspaces/projets, where the container starts (workingDir).
|
|
51
51
|
workspace:
|
|
52
52
|
# Command: run workspace-init.sh in the foreground first, then keep the pod
|
|
53
|
-
# alive
|
|
54
|
-
#
|
|
53
|
+
# alive as PID 1 (like VS Code for a devcontainer) (#503). The init script
|
|
54
|
+
# runs before the loop, its errors are ignored (|| true) and its journal is
|
|
55
55
|
# ~/.local/state/devzone/init.log. Empty = image default command.
|
|
56
|
-
|
|
56
|
+
# PID 1 must reap the orphans (#967): sleep infinity did not, so the zombies
|
|
57
|
+
# piled up (20 000 in 2.5 days). The loop calls wait, which reaps every child
|
|
58
|
+
# of the shell, orphans included (they are re-parented to PID 1). TERM and INT
|
|
59
|
+
# exit at once, so the pod stops on time.
|
|
60
|
+
command: ["bash", "-c", "mkdir -p \"$HOME/.local/state/devzone\"; bash /usr/local/share/devzone/.devcontainer/workspace-init.sh >>\"$HOME/.local/state/devzone/init.log\" 2>&1 || true; trap 'exit 0' TERM INT; while true; do wait -n 2>/dev/null; sleep 1; done"]
|
|
57
61
|
# Size of the projects volume.
|
|
58
62
|
size: 20Gi
|
|
59
63
|
storageClass: ""
|
|
60
64
|
|
|
65
|
+
# Resources of the workspace container (#967). Zombie processes accumulated in
|
|
66
|
+
# the pod (its process limit is 24 006), and the command's reaper now fixes that.
|
|
67
|
+
# The memory limit is raised to 8Gi as a precaution: the measured memory of the
|
|
68
|
+
# pod, page cache included, regularly reached 4Gi while several agents compiled
|
|
69
|
+
# in parallel. A zombie uses almost no memory. The cause of the claude.exe
|
|
70
|
+
# crashes is not proven. The limit is adjustable: change this value, or pass
|
|
71
|
+
# helm --set resources.limits.memory=<N>Gi on a release.
|
|
61
72
|
resources:
|
|
62
73
|
limits:
|
|
63
74
|
cpu: "2"
|
|
64
|
-
memory: "
|
|
75
|
+
memory: "8Gi"
|
|
65
76
|
requests:
|
|
66
77
|
cpu: "500m"
|
|
67
|
-
memory: "
|
|
78
|
+
memory: "4Gi"
|
|
68
79
|
|
|
69
80
|
persistence:
|
|
70
81
|
# Identities, logins and caches, kept from one restart to the next. Each path
|
package/manage/devzone
CHANGED
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
# In the container, « devzone » is another command: the modules
|
|
8
8
|
# (.devcontainer/devzone).
|
|
9
9
|
# DEVZONE_NO_START=1: copy only, without starting the container (tests).
|
|
10
|
-
# The helpers live in manage/scripts/devzone-*.sh, sourced by the command that
|
|
11
|
-
# needs them (so --version and --help work with this file alone).
|
|
12
|
-
# shellcheck disable=SC2034 # PACKAGE_ITEMS, GITIGNORE_LINES: read by the sourced devzone-*.sh
|
|
13
10
|
set -euo pipefail
|
|
14
11
|
|
|
15
12
|
# Script path. From cmd, the npm .cmd shim calls bash with the Windows path
|
|
@@ -21,21 +18,6 @@ case "$SCRIPT" in
|
|
|
21
18
|
[A-Za-z]:[\\/]*) SCRIPT="$(cygpath -u "$SCRIPT" 2>/dev/null || echo "${SCRIPT//\\//}")" ;;
|
|
22
19
|
esac
|
|
23
20
|
PAQUET="$(cd "$(dirname "$(readlink -f "$SCRIPT" 2>/dev/null || echo "$SCRIPT")")/.." && pwd)"
|
|
24
|
-
# Items copied into a devzone (same list as the « files » of package.json,
|
|
25
|
-
# without the command manage/devzone); manage/scripts is copied apart, under manage/
|
|
26
|
-
PACKAGE_ITEMS=(.devcontainer Makefile .gitattributes README.md LICENSE)
|
|
27
|
-
# Lines always present in the .gitignore of a devzone: added to, never overwritten
|
|
28
|
-
GITIGNORE_LINES=(
|
|
29
|
-
'# Each workspace project has its own git repository'
|
|
30
|
-
'workspace/*'
|
|
31
|
-
'!workspace/.gitkeep'
|
|
32
|
-
'.DS_Store'
|
|
33
|
-
'.devzone.log'
|
|
34
|
-
'.devzone.state'
|
|
35
|
-
'.password'
|
|
36
|
-
'.devzone.backup/'
|
|
37
|
-
)
|
|
38
|
-
|
|
39
21
|
# Version of the package (package.json next to manage/)
|
|
40
22
|
version() {
|
|
41
23
|
# Path passed as an argument to node, never written in the JavaScript code of -p:
|
package/manage/workspace.sh
CHANGED
|
@@ -84,10 +84,18 @@ start_workspace() {
|
|
|
84
84
|
done
|
|
85
85
|
image="$repo:$tag"
|
|
86
86
|
# Argo CD first when wanted (#516): the workspace is then an Application
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if [ "$(grep '^argocd=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2-)" != off ]; then
|
|
88
|
+
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace services enable argocd || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
|
|
89
|
+
fi
|
|
90
|
+
rc=0
|
|
91
|
+
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace deploy "$repo" "$tag" "$with_image" || rc=$?
|
|
92
|
+
if [ "$rc" -eq 3 ]; then
|
|
93
|
+
workspace_helm_deploy "$repo" "$tag" "$with_image"
|
|
94
|
+
elif [ "$rc" -ne 0 ]; then
|
|
95
|
+
return "$rc"
|
|
96
|
+
fi
|
|
89
97
|
# Projects of .argocd.conf held too (#516)
|
|
90
|
-
|
|
98
|
+
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd reconcile || true
|
|
91
99
|
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace wait "$image" || return 1
|
|
92
100
|
"${DEVZONE_HOST_BIN:-false}" workspace agents-guard || true
|
|
93
101
|
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports start
|
|
@@ -111,7 +119,7 @@ workspace_helm_deploy() {
|
|
|
111
119
|
# Uninstalls the workspace from the cluster (Argo CD Application or helm release).
|
|
112
120
|
stop_workspace() {
|
|
113
121
|
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports stop || true
|
|
114
|
-
|
|
122
|
+
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace stop
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
# Opens a shell in the workspace container.
|
|
@@ -120,10 +128,6 @@ shell_workspace() {
|
|
|
120
128
|
kubectl $(kubectl_flag) exec -it devzone-workspace-0 --namespace devzone-workspace -c workspace -- bash
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
# shellcheck source=manage/scripts/workspace/argocd-workspace.sh
|
|
124
|
-
. "$HERE/scripts/workspace/argocd-workspace.sh"
|
|
125
|
-
# shellcheck source=manage/scripts/workspace/argocd-services.sh
|
|
126
|
-
. "$HERE/scripts/workspace/argocd-services.sh"
|
|
127
131
|
|
|
128
132
|
case "${1:-}" in
|
|
129
133
|
start) start_workspace "${@:2}" ;;
|
|
@@ -133,7 +137,19 @@ case "${1:-}" in
|
|
|
133
137
|
shell) shell_workspace ;;
|
|
134
138
|
ports) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports "${@:2}" ;;
|
|
135
139
|
services) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace services "${@:2}" ;;
|
|
136
|
-
argocd)
|
|
140
|
+
argocd)
|
|
141
|
+
sub="${2:-status}"
|
|
142
|
+
case "$sub" in
|
|
143
|
+
status) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd status ;;
|
|
144
|
+
init) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd init "${@:3}" ;;
|
|
145
|
+
apply) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd apply ;;
|
|
146
|
+
app) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd app "${@:3}" ;;
|
|
147
|
+
*)
|
|
148
|
+
echo "✖ devzone workspace argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>" >&2
|
|
149
|
+
exit 1
|
|
150
|
+
;;
|
|
151
|
+
esac
|
|
152
|
+
;;
|
|
137
153
|
egress) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace egress "${@:2}" ;;
|
|
138
154
|
'' | -h | --help | help)
|
|
139
155
|
echo "devzone workspace start|stop|status|shell|ports|services|argocd|update|egress"
|
package/package.json
CHANGED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Manifest of a devzone (.devzone.version) and the paths read back from it:
|
|
3
|
-
# checksum of each copied file, safe relative paths, the .gitignore lines of a
|
|
4
|
-
# devzone. Sourced by manage/devzone (update and create), which defines PAQUET
|
|
5
|
-
# (package folder), PACKAGE_ITEMS, GITIGNORE_LINES and version().
|
|
6
|
-
# shellcheck disable=SC2154 # PAQUET, PACKAGE_ITEMS, GITIGNORE_LINES: set by manage/devzone
|
|
7
|
-
|
|
8
|
-
# SHA-256 checksum of a file, computed by node (portable: macOS, Linux, Windows
|
|
9
|
-
# Git Bash); the path is passed as an argument, as for version()
|
|
10
|
-
checksum() {
|
|
11
|
-
node -e 'const fs = require("fs"), crypto = require("crypto"); const h = crypto.createHash("sha256"); h.update(fs.readFileSync(process.argv[1])); process.stdout.write(h.digest("hex"))' "$1"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
# Files of the package copied into a devzone, absolute paths
|
|
15
|
-
package_files() {
|
|
16
|
-
local base
|
|
17
|
-
for base in "${PACKAGE_ITEMS[@]}"; do
|
|
18
|
-
if [ -d "$PAQUET/$base" ]; then
|
|
19
|
-
find "$PAQUET/$base" -type f -print
|
|
20
|
-
elif [ -f "$PAQUET/$base" ]; then
|
|
21
|
-
printf '%s\n' "$PAQUET/$base"
|
|
22
|
-
fi
|
|
23
|
-
done
|
|
24
|
-
if [ -d "$PAQUET/manage/scripts" ]; then
|
|
25
|
-
find "$PAQUET/manage/scripts" -type f -print
|
|
26
|
-
fi
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
# The same files, relative to the package, sorted
|
|
30
|
-
relative_package_files() {
|
|
31
|
-
local f
|
|
32
|
-
package_files | while IFS= read -r f; do
|
|
33
|
-
printf '%s\n' "${f#"$PAQUET"/}"
|
|
34
|
-
done | LC_ALL=C sort
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
# .devzone.version: version of the folder, then one checksum per copied file
|
|
38
|
-
write_manifest() {
|
|
39
|
-
local folder="$1" rel
|
|
40
|
-
{
|
|
41
|
-
printf 'version %s\n' "$(version)"
|
|
42
|
-
relative_package_files | while IFS= read -r rel; do
|
|
43
|
-
printf '%s %s\n' "$(checksum "$folder/$rel")" "$rel"
|
|
44
|
-
done
|
|
45
|
-
} >"$folder/.devzone.version"
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
# Version written in the manifest of a folder, 'inconnue' when there is none
|
|
49
|
-
folder_version() {
|
|
50
|
-
local folder="${1:-.}" v
|
|
51
|
-
if [ -f "$folder/.devzone.version" ]; then
|
|
52
|
-
v="$(sed -n '1s/^version //p' "$folder/.devzone.version" 2>/dev/null | head -1 || true)"
|
|
53
|
-
if [ -n "$v" ]; then
|
|
54
|
-
printf '%s\n' "$v"
|
|
55
|
-
return 0
|
|
56
|
-
fi
|
|
57
|
-
fi
|
|
58
|
-
printf 'inconnue\n'
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
# Checksum recorded in the manifest of a folder for one path; fails if absent
|
|
62
|
-
manifest_checksum() {
|
|
63
|
-
local folder="$1" target="$2" line h p
|
|
64
|
-
[ -f "$folder/.devzone.version" ] || return 1
|
|
65
|
-
while IFS= read -r line; do
|
|
66
|
-
case "$line" in
|
|
67
|
-
version\ * | '') continue ;;
|
|
68
|
-
esac
|
|
69
|
-
h="${line%% *}"
|
|
70
|
-
p="${line#* }"
|
|
71
|
-
if [ "$p" = "$target" ]; then
|
|
72
|
-
printf '%s\n' "$h"
|
|
73
|
-
return 0
|
|
74
|
-
fi
|
|
75
|
-
done <"$folder/.devzone.version"
|
|
76
|
-
return 1
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
# Paths listed in the manifest of a folder
|
|
80
|
-
manifest_files() {
|
|
81
|
-
local folder="$1" line
|
|
82
|
-
[ -f "$folder/.devzone.version" ] || return 0
|
|
83
|
-
while IFS= read -r line; do
|
|
84
|
-
case "$line" in
|
|
85
|
-
version\ * | '') continue ;;
|
|
86
|
-
esac
|
|
87
|
-
printf '%s\n' "${line#* }"
|
|
88
|
-
done <"$folder/.devzone.version"
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
# A path read from the manifest is accepted only if it is relative and simple
|
|
92
|
-
# (no '..', '.', '//', newline or tab), under a folder managed by the package
|
|
93
|
-
# or a file at its root. Otherwise it is refused.
|
|
94
|
-
path_allowed() {
|
|
95
|
-
local rel="$1"
|
|
96
|
-
case "$rel" in
|
|
97
|
-
'' | /* | *//* | *$'\n'* | *$'\t'*) return 1 ;;
|
|
98
|
-
esac
|
|
99
|
-
case "/$rel/" in
|
|
100
|
-
*/../* | */./*) return 1 ;;
|
|
101
|
-
esac
|
|
102
|
-
case "$rel" in
|
|
103
|
-
.devcontainer/* | manage/* | core/* | scripts/* | \
|
|
104
|
-
Makefile | README.md | LICENSE | .gitattributes) return 0 ;;
|
|
105
|
-
esac
|
|
106
|
-
return 1
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
# Defense in depth: the real parent folder must stay under the real devzone
|
|
110
|
-
# folder (pwd -P), so a symbolic link leading out of it is refused.
|
|
111
|
-
inside_folder() {
|
|
112
|
-
local folder="$1" rel="$2" root parent
|
|
113
|
-
root="$(cd "$folder" && pwd -P)" || return 1
|
|
114
|
-
parent="$(cd "$folder/$(dirname "$rel")" 2>/dev/null && pwd -P)" || return 1
|
|
115
|
-
case "$parent" in
|
|
116
|
-
"$root" | "$root"/*) return 0 ;;
|
|
117
|
-
esac
|
|
118
|
-
return 1
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
# Never touched by update, even when an old manifest lists them
|
|
122
|
-
is_protected() {
|
|
123
|
-
case "$1" in
|
|
124
|
-
workspace | workspace/* | .devzone.version | .devzone.modules | .devzone.modules-* | \
|
|
125
|
-
.devzone.packages | .password | .app | .devzone.log | .git | .git/*) return 0 ;;
|
|
126
|
-
esac
|
|
127
|
-
return 1
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
# True when the whole line $2 is in the file $1
|
|
131
|
-
in_list() {
|
|
132
|
-
grep -Fqx -- "$2" "$1"
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
# Old devzone layout (before manage/): core/ is recognized only by its marker
|
|
136
|
-
# files, scripts/ only by its two own files. Otherwise it is a folder of the
|
|
137
|
-
# user: never touched.
|
|
138
|
-
old_tree() {
|
|
139
|
-
local folder="$1" tree="$2"
|
|
140
|
-
case "$tree" in
|
|
141
|
-
core)
|
|
142
|
-
[ -f "$folder/core/devzone" ] || [ -f "$folder/core/scripts/uninstall.sh" ]
|
|
143
|
-
;;
|
|
144
|
-
scripts)
|
|
145
|
-
[ -f "$folder/scripts/uninstall.sh" ] && [ -f "$folder/scripts/launch.sh" ]
|
|
146
|
-
;;
|
|
147
|
-
*) return 1 ;;
|
|
148
|
-
esac
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
# File known from the old package: the names of manage/scripts/ moved into
|
|
152
|
-
# core/scripts/ or scripts/, core/devzone, and all of core/test/ and core/docs/.
|
|
153
|
-
known_old_file() {
|
|
154
|
-
local rel="$1" name
|
|
155
|
-
case "$rel" in
|
|
156
|
-
core/devzone | core/test/* | core/docs/*) return 0 ;;
|
|
157
|
-
core/scripts/*) name="${rel#core/scripts/}" ;;
|
|
158
|
-
scripts/*) name="${rel#scripts/}" ;;
|
|
159
|
-
*) return 1 ;;
|
|
160
|
-
esac
|
|
161
|
-
[ -f "$PAQUET/manage/scripts/$name" ]
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
# Adds the missing lines of GITIGNORE_LINES to the .gitignore of a folder
|
|
165
|
-
complete_gitignore() {
|
|
166
|
-
local folder="$1" line
|
|
167
|
-
touch "$folder/.gitignore"
|
|
168
|
-
for line in "${GITIGNORE_LINES[@]}"; do
|
|
169
|
-
grep -qxF -- "$line" "$folder/.gitignore" || printf '%s\n' "$line" >>"$folder/.gitignore"
|
|
170
|
-
done
|
|
171
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Service hooks of the workstation for services.sh (#538): secrets created
|
|
3
|
-
# apart (postgres-admin, mysql-admin, mirrored and never printed), Helm
|
|
4
|
-
# parameters of the mysql chart (existing volume claim), and the
|
|
5
|
-
# devzone workspace services enable|disable switch when Argo CD holds the
|
|
6
|
-
# charts. Sourced by manage/scripts/workspace/argocd-services.sh. bash 3.2 (macOS).
|
|
7
|
-
|
|
8
|
-
# Namespace of the service: labelled, isolated like the other devzone-*
|
|
9
|
-
# (services.sh: services_namespace_prepare)
|
|
10
|
-
|
|
11
|
-
# Superuser secret postgres-admin, created apart: an existing secret is kept
|
|
12
|
-
# and mirrored; otherwise a password generated on the workstation. Mirror
|
|
13
|
-
# workspace/.postgres/admin-password (600) and .password; never printed
|
|
14
|
-
services_secret_postgres() {
|
|
15
|
-
local dir="$PWD/workspace/.postgres" file password
|
|
16
|
-
file="$dir/admin-password"
|
|
17
|
-
mkdir -p "$dir"
|
|
18
|
-
chmod 700 "$dir"
|
|
19
|
-
password="$(ak -n "$POSTGRES_NS" get secret postgres-admin \
|
|
20
|
-
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
21
|
-
if [ -n "$password" ]; then
|
|
22
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
23
|
-
else
|
|
24
|
-
if [ ! -s "$file" ]; then
|
|
25
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
26
|
-
fi
|
|
27
|
-
ak -n "$POSTGRES_NS" create secret generic postgres-admin --from-file=password="$file" >/dev/null
|
|
28
|
-
fi
|
|
29
|
-
chmod 600 "$file"
|
|
30
|
-
argocd_passwords_refresh
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
# Superuser secret mysql-admin, created apart, the same way; the mirror
|
|
34
|
-
# workspace/.mysql/admin-password feeds the mysql entry of .password
|
|
35
|
-
services_secret_mysql() {
|
|
36
|
-
local dir="$PWD/workspace/.mysql" file password
|
|
37
|
-
file="$dir/admin-password"
|
|
38
|
-
mkdir -p "$dir"
|
|
39
|
-
chmod 700 "$dir"
|
|
40
|
-
password="$(ak -n "$MYSQL_NS" get secret mysql-admin \
|
|
41
|
-
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
42
|
-
if [ -n "$password" ]; then
|
|
43
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
44
|
-
else
|
|
45
|
-
if [ ! -s "$file" ]; then
|
|
46
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
47
|
-
fi
|
|
48
|
-
ak -n "$MYSQL_NS" create secret generic mysql-admin --from-file=password="$file" >/dev/null
|
|
49
|
-
fi
|
|
50
|
-
chmod 600 "$file"
|
|
51
|
-
argocd_passwords_refresh
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
# Values of the MySQL chart: image, port, memory and size (catalogue defaults),
|
|
55
|
-
# and the claim to mount chosen among the existing volumes (one PVC *-mysql-0:
|
|
56
|
-
# its prefix; none: the chart default donnees; several: refused)
|
|
57
|
-
services_chart_mysql() {
|
|
58
|
-
local liste claim=""
|
|
59
|
-
liste="$(ak -n "$MYSQL_NS" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
60
|
-
if [ -n "$liste" ]; then
|
|
61
|
-
if [ "$(printf '%s\n' "$liste" | grep -c .)" -gt 1 ]; then
|
|
62
|
-
echo "✖ several MySQL volumes in $MYSQL_NS: devzone mysql volume <name> picks the mounted one" >&2
|
|
63
|
-
return 2
|
|
64
|
-
fi
|
|
65
|
-
claim=" claim=${liste%-mysql-0}"
|
|
66
|
-
fi
|
|
67
|
-
printf 'image=mysql:8.4 port=3306 memory=1Gi size=5Gi%s' "$claim"
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
# devzone workspace services enable|disable postgres|mysql when Argo CD holds
|
|
71
|
-
# the charts: the [services] section written, then reconciled (services.sh).
|
|
72
|
-
# disable keeps the namespace, the volumes and the data; --yes is the explicit
|
|
73
|
-
# data removal (namespace deleted; the mirror workspace/.mysql stays, like
|
|
74
|
-
# supprimer-donnees of the module, the one of .postgres goes)
|
|
75
|
-
services_argocd_toggle() {
|
|
76
|
-
local svc="$1" action="$2" yes
|
|
77
|
-
shift 2
|
|
78
|
-
case "$action" in
|
|
79
|
-
enable)
|
|
80
|
-
if [ "$#" -ne 0 ]; then
|
|
81
|
-
echo "✖ $svc through Argo CD takes no option (got: $*)" >&2
|
|
82
|
-
return 1
|
|
83
|
-
fi
|
|
84
|
-
# Before [services] is written: a refused chart leaves the state unchanged
|
|
85
|
-
chart_require "$svc" || return $?
|
|
86
|
-
echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
|
|
87
|
-
services_note "$svc" on
|
|
88
|
-
services_reconcile || return $?
|
|
89
|
-
echo "✔ Application devzone-$svc declared ([services] $svc = on in $ARGOCD_CONF); status: devzone workspace argocd status; local access: devzone workspace ports"
|
|
90
|
-
;;
|
|
91
|
-
disable)
|
|
92
|
-
yes="$(yes_flag "services disable $svc [--yes]" "$@")" || return 1
|
|
93
|
-
services_note "$svc" off
|
|
94
|
-
services_reconcile || return $?
|
|
95
|
-
if [ "$yes" = 1 ]; then
|
|
96
|
-
ak delete namespace "devzone-$svc" --wait=true --ignore-not-found >/dev/null
|
|
97
|
-
case "$svc" in
|
|
98
|
-
postgres) rm -rf "$PWD/workspace/.$svc" ;;
|
|
99
|
-
esac
|
|
100
|
-
argocd_passwords_refresh
|
|
101
|
-
echo "✔ $svc removed: Application, namespace devzone-$svc and data ([services] $svc = off)"
|
|
102
|
-
else
|
|
103
|
-
echo "✔ $svc stopped: Application removed, the namespace devzone-$svc, the volumes and the data stay (devzone workspace services disable $svc --yes to remove the data)"
|
|
104
|
-
fi
|
|
105
|
-
;;
|
|
106
|
-
esac
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
# Toggles postgres on/off as an Argo CD Application (charts/devzone-postgres).
|
|
110
|
-
# Calls services_argocd_toggle to write the [services] section and reconcile.
|
|
111
|
-
postgres_argocd() { services_argocd_toggle postgres "$@"; }
|
|
112
|
-
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Deployments held by Argo CD in the Kubernetes workspace (#516), sourced by
|
|
3
|
-
# manage/workspace.sh after argocd-workspace.sh: the workspace itself, the
|
|
4
|
-
# services of the [services] section (services.sh), the argocd services
|
|
5
|
-
# switch and devzone workspace argocd.
|
|
6
|
-
# workspace_deploy <repository> <tag> <with-image> start: Application, else helm direct
|
|
7
|
-
# workspace_undeploy stop: Application, else helm uninstall
|
|
8
|
-
# argocd_toggle enable|disable devzone workspace services … argocd
|
|
9
|
-
# services_secret_postgres postgres secret created apart
|
|
10
|
-
# postgres_argocd enable|disable [--yes] postgres: [services] written, then reconciled
|
|
11
|
-
# argocd_cmd status | init | apply | app add|list|remove devzone workspace argocd …
|
|
12
|
-
# Secrets stay out of Git: created here, only referenced by the charts.
|
|
13
|
-
# bash 3.2 (macOS).
|
|
14
|
-
|
|
15
|
-
WORKSPACE_APP="devzone-workspace"
|
|
16
|
-
# shellcheck disable=SC2034 # read by argocd-services-svc.sh
|
|
17
|
-
POSTGRES_NS="devzone-postgres"
|
|
18
|
-
# shellcheck disable=SC2034 # read by argocd-services-svc.sh
|
|
19
|
-
MYSQL_NS="devzone-mysql"
|
|
20
|
-
# Services held by Argo CD ([services] of .argocd.conf, services.sh); gitlab
|
|
21
|
-
# joins in its step (#538)
|
|
22
|
-
# shellcheck disable=SC2034 # read by services.sh
|
|
23
|
-
SERVICES_LIST="postgres mysql"
|
|
24
|
-
|
|
25
|
-
# The only option of a removal: --yes; prints 1 or 0
|
|
26
|
-
yes_flag() {
|
|
27
|
-
local usage="$1" arg found=0
|
|
28
|
-
shift
|
|
29
|
-
for arg in "$@"; do
|
|
30
|
-
case "$arg" in
|
|
31
|
-
--yes) found=1 ;;
|
|
32
|
-
*) echo "✖ unknown option: $arg (devzone workspace $usage)" >&2; return 1 ;;
|
|
33
|
-
esac
|
|
34
|
-
done
|
|
35
|
-
echo "$found"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
39
|
-
APPS_CMD="devzone workspace argocd app"
|
|
40
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
41
|
-
APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
|
|
42
|
-
# shellcheck disable=SC2034 # read by gitops.sh
|
|
43
|
-
GITOPS_CMD="devzone workspace argocd init"
|
|
44
|
-
# .argocd.conf of the devzone folder of the workstation (conf.sh)
|
|
45
|
-
# shellcheck disable=SC2034 # read by conf.sh and apps.sh
|
|
46
|
-
ARGOCD_CONF_DIR="$PWD"
|
|
47
|
-
# shellcheck disable=SC2034
|
|
48
|
-
ARGOCD_CONF="$PWD/.argocd.conf"
|
|
49
|
-
# shellcheck source=../../../.devcontainer/argocd/conf.sh
|
|
50
|
-
# shellcheck disable=SC1091
|
|
51
|
-
. "$RACINE/.devcontainer/argocd/conf.sh"
|
|
52
|
-
# shellcheck source=../../../.devcontainer/argocd/gitops.sh
|
|
53
|
-
# shellcheck disable=SC1091
|
|
54
|
-
. "$RACINE/.devcontainer/argocd/gitops.sh"
|
|
55
|
-
# shellcheck source=../../../.devcontainer/argocd/apps.sh
|
|
56
|
-
# shellcheck disable=SC1091
|
|
57
|
-
. "$RACINE/.devcontainer/argocd/apps.sh"
|
|
58
|
-
# shellcheck source=../../../.devcontainer/argocd/services.sh
|
|
59
|
-
# shellcheck disable=SC1091
|
|
60
|
-
. "$RACINE/.devcontainer/argocd/services.sh"
|
|
61
|
-
argocd_kubectl() { ak "$@"; }
|
|
62
|
-
|
|
63
|
-
# workspace start and argocd apply: the declarations of .argocd.conf held
|
|
64
|
-
argocd_reconcile() {
|
|
65
|
-
argocd_installed || return 0
|
|
66
|
-
gitops_init || return 1
|
|
67
|
-
gitops_root || return 1
|
|
68
|
-
apps_reconcile
|
|
69
|
-
if argocd_holds_charts; then
|
|
70
|
-
services_reconcile
|
|
71
|
-
fi
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
# Root token of the devzone GitLab for app add: the file of the workstation,
|
|
75
|
-
# else the one of the pod (the module was installed there, #528); never printed
|
|
76
|
-
apps_gitlab_token() {
|
|
77
|
-
if [ -s "$PWD/workspace/.gitlab/root-token" ]; then
|
|
78
|
-
cat "$PWD/workspace/.gitlab/root-token"
|
|
79
|
-
else
|
|
80
|
-
ak -n "$NAMESPACE" exec "$POD" -c workspace -- cat "$DOSSIER_PROJETS/workspace/.gitlab/root-token" 2>/dev/null || true
|
|
81
|
-
fi
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
# Argo CD holds the devzone charts only with a Git revision (release tag or
|
|
85
|
-
# DEVZONE_ARGOCD_REVISION): a development clone stays on helm direct
|
|
86
|
-
argocd_holds_charts() {
|
|
87
|
-
argocd_active && [ -n "$(argocd_revision)" ]
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
argocd_clone_notice() {
|
|
91
|
-
if argocd_active && [ -z "$(argocd_revision)" ]; then
|
|
92
|
-
echo "ℹ development clone (version 0.0.0): helm direct; DEVZONE_ARGOCD_REVISION=<branch> to go through Argo CD"
|
|
93
|
-
fi
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
# Release secrets of a release deployed with helm before: deleted, so that
|
|
97
|
-
# Argo CD adopts the live resources without any helm uninstall (no downtime)
|
|
98
|
-
helm_release_forget() {
|
|
99
|
-
ak -n "$2" delete secret -l "owner=helm,name=$1" --ignore-not-found >/dev/null 2>&1 || true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
workspace_deploy() {
|
|
103
|
-
local repository="$1" tag="$2" with_image="$3" params
|
|
104
|
-
if ! argocd_holds_charts; then
|
|
105
|
-
argocd_clone_notice
|
|
106
|
-
workspace_helm_deploy "$repository" "$tag" "$with_image"
|
|
107
|
-
return
|
|
108
|
-
fi
|
|
109
|
-
params="image.tag=$tag"
|
|
110
|
-
[ -z "$with_image" ] || params="$params image.repository=$repository"
|
|
111
|
-
[ "$tag" != latest ] || params="$params image.pullPolicy=Always"
|
|
112
|
-
# egress proxy settings of .devzone.modules (#633): replayed at each start and update
|
|
113
|
-
params="$params $("${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace egress params)"
|
|
114
|
-
chart_require workspace || return $?
|
|
115
|
-
# GitOps repository created or designated first, with its root Application
|
|
116
|
-
gitops_init || return 1
|
|
117
|
-
gitops_root || return 1
|
|
118
|
-
echo "▶ Application $WORKSPACE_APP (Argo CD, charts/devzone-workspace at $(argocd_revision))…"
|
|
119
|
-
helm_release_forget devzone-workspace devzone-workspace
|
|
120
|
-
# shellcheck disable=SC2086
|
|
121
|
-
argocd_apply_application "$WORKSPACE_APP" workspace devzone-workspace \
|
|
122
|
-
"$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-workspace $params
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
workspace_undeploy() {
|
|
126
|
-
if argocd_installed && argocd_application_exists "$WORKSPACE_APP"; then
|
|
127
|
-
echo "▶ Application $WORKSPACE_APP deleted (Argo CD removes the pod, the volumes stay)…"
|
|
128
|
-
argocd_delete_application "$WORKSPACE_APP"
|
|
129
|
-
else
|
|
130
|
-
# shellcheck disable=SC2046
|
|
131
|
-
helm $(helm_flag) uninstall devzone-workspace --namespace devzone-workspace
|
|
132
|
-
fi
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
# devzone workspace services enable|disable argocd: the workstation installs
|
|
136
|
-
# or removes it itself; the state line follows what succeeded
|
|
137
|
-
argocd_toggle() {
|
|
138
|
-
local action="$1"
|
|
139
|
-
shift
|
|
140
|
-
if [ "$#" -ne 0 ]; then
|
|
141
|
-
echo "✖ services $action argocd takes no option (got: $*)" >&2
|
|
142
|
-
return 1
|
|
143
|
-
fi
|
|
144
|
-
case "$action" in
|
|
145
|
-
enable) argocd_install && state_note argocd on && gitops_init && gitops_root ;;
|
|
146
|
-
disable) argocd_uninstall && state_note argocd off ;;
|
|
147
|
-
esac
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
# Service hooks (secrets, mysql chart parameters, services switch)
|
|
151
|
-
# shellcheck source=argocd-services-svc.sh
|
|
152
|
-
# shellcheck disable=SC1091
|
|
153
|
-
. "$(dirname "${BASH_SOURCE[0]}")/argocd-services-svc.sh"
|
|
154
|
-
|
|
155
|
-
# devzone workspace argocd status | app …
|
|
156
|
-
argocd_cmd() {
|
|
157
|
-
case "${1:-status}" in
|
|
158
|
-
status) argocd_status ;;
|
|
159
|
-
init)
|
|
160
|
-
gitops_init "${@:2}" || return $?
|
|
161
|
-
if argocd_installed; then gitops_root; fi
|
|
162
|
-
;;
|
|
163
|
-
apply)
|
|
164
|
-
if ! argocd_installed; then
|
|
165
|
-
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
166
|
-
return 1
|
|
167
|
-
fi
|
|
168
|
-
argocd_reconcile
|
|
169
|
-
;;
|
|
170
|
-
app)
|
|
171
|
-
if ! argocd_installed; then
|
|
172
|
-
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
173
|
-
return 1
|
|
174
|
-
fi
|
|
175
|
-
argocd_app "${@:2}"
|
|
176
|
-
;;
|
|
177
|
-
*)
|
|
178
|
-
echo "✖ devzone workspace argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>" >&2
|
|
179
|
-
return 1
|
|
180
|
-
;;
|
|
181
|
-
esac
|
|
182
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Argo CD of the Kubernetes workspace, driven from the workstation (#516).
|
|
3
|
-
# Sourced by manage/workspace.sh (kubectl_flag, helm_flag, RACINE: the
|
|
4
|
-
# package; $PWD: the devzone folder of the workstation, its .devzone.modules,
|
|
5
|
-
# workspace/.argocd and .password).
|
|
6
|
-
# argocd_wanted 0 unless .devzone.modules says argocd=off (on by default)
|
|
7
|
-
# argocd_installed namespace devzone-argocd present
|
|
8
|
-
# argocd_active wanted and installed: Applications instead of helm direct
|
|
9
|
-
# argocd_ensure installs it when wanted and missing (workspace start)
|
|
10
|
-
# argocd_install | argocd_uninstall | argocd_status
|
|
11
|
-
# argocd_revision Git revision of the devzone charts; empty on a dev clone
|
|
12
|
-
# argocd_apply_application / argocd_delete_application
|
|
13
|
-
# Why: the pod has no administrator access (#430); the workstation has helm
|
|
14
|
-
# and kubectl. The admin password goes to workspace/.argocd/admin.env and
|
|
15
|
-
# .password of the workstation, never on screen. bash 3.2 (macOS).
|
|
16
|
-
|
|
17
|
-
ARGOCD_NS="devzone-argocd"
|
|
18
|
-
ARGOCD_CHART_VERSION="${ARGOCD_VERSION:-10.14.0}"
|
|
19
|
-
ARGOCD_LOCAL_PORT="${ARGOCD_PORT:-8443}"
|
|
20
|
-
ARGOCD_WAIT="${ARGOCD_ATTENTE:-600}"
|
|
21
|
-
ARGOCD_MIN_MEMORY_KI=1048576
|
|
22
|
-
DEVZONE_REPO_URL="${DEVZONE_REPO_URL:-https://github.com/SimBienvenueHoulBoumi/devzone.git}"
|
|
23
|
-
|
|
24
|
-
# Wrapper chart installed by the workstation and by the container (#538)
|
|
25
|
-
argocd_chart() { printf '%s/charts/devzone-argocd' "$RACINE"; }
|
|
26
|
-
argocd_generator() { printf '%s/.devcontainer/argocd/application.sh' "$RACINE"; }
|
|
27
|
-
argocd_secrets_dir() { printf '%s/workspace/.argocd' "$PWD"; }
|
|
28
|
-
|
|
29
|
-
# kubectl of the workstation, context devzone when it exists
|
|
30
|
-
ak() {
|
|
31
|
-
# shellcheck disable=SC2046
|
|
32
|
-
kubectl $(kubectl_flag) "$@"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# Last value of a key of .devzone.modules of the workstation (empty if none)
|
|
36
|
-
state_read() {
|
|
37
|
-
grep "^$1=" .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2- || true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
# key=value written in .devzone.modules of the workstation, other lines kept
|
|
41
|
-
state_note() {
|
|
42
|
-
local f=".devzone.modules" tmp
|
|
43
|
-
tmp="$f.tmp.$$"
|
|
44
|
-
{
|
|
45
|
-
if [ -f "$f" ]; then grep -v "^$1=" "$f" || true; fi
|
|
46
|
-
echo "$1=$2"
|
|
47
|
-
} >"$tmp" && mv "$tmp" "$f"
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
argocd_wanted() { [ "$(state_read argocd)" != off ]; }
|
|
51
|
-
|
|
52
|
-
argocd_installed() { ak get namespace "$ARGOCD_NS" >/dev/null 2>&1; }
|
|
53
|
-
|
|
54
|
-
argocd_active() { argocd_wanted && argocd_installed; }
|
|
55
|
-
|
|
56
|
-
# Git revision of the devzone charts: DEVZONE_ARGOCD_REVISION, else the tag of
|
|
57
|
-
# the package version; empty on a development clone (0.0.0: the local chart
|
|
58
|
-
# is not in Git)
|
|
59
|
-
argocd_revision() {
|
|
60
|
-
local version
|
|
61
|
-
if [ -n "${DEVZONE_ARGOCD_REVISION:-}" ]; then
|
|
62
|
-
printf '%s' "$DEVZONE_ARGOCD_REVISION"
|
|
63
|
-
return 0
|
|
64
|
-
fi
|
|
65
|
-
version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$RACINE/package.json" | head -1)"
|
|
66
|
-
case "$version" in
|
|
67
|
-
'' | 0.0.0) ;;
|
|
68
|
-
*) printf 'v%s' "$version" ;;
|
|
69
|
-
esac
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
# Kubernetes memory quantity in Ki (Ki, Mi, Gi, Ti, K, M, G, bytes)
|
|
73
|
-
argocd_quantity_ki() {
|
|
74
|
-
local q="${1:-}" n
|
|
75
|
-
case "$q" in
|
|
76
|
-
*Ki) n="${q%Ki}"; echo $((n)) ;;
|
|
77
|
-
*Mi) n="${q%Mi}"; echo $((n * 1024)) ;;
|
|
78
|
-
*Gi) n="${q%Gi}"; echo $((n * 1024 * 1024)) ;;
|
|
79
|
-
*Ti) n="${q%Ti}"; echo $((n * 1024 * 1024 * 1024)) ;;
|
|
80
|
-
*K | *k) n="${q%[Kk]}"; echo $((n * 1000 / 1024)) ;;
|
|
81
|
-
*M) n="${q%M}"; echo $((n * 1000 * 1000 / 1024)) ;;
|
|
82
|
-
*G) n="${q%G}"; echo $((n * 1000 * 1000 * 1000 / 1024)) ;;
|
|
83
|
-
*)
|
|
84
|
-
case "$q" in
|
|
85
|
-
'' | *[!0-9]*) echo 0 ;;
|
|
86
|
-
*) echo $((q / 1024)) ;;
|
|
87
|
-
esac
|
|
88
|
-
;;
|
|
89
|
-
esac
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
# Refuses under 1 Gi of allocatable memory in the cluster (sum of the nodes)
|
|
93
|
-
argocd_memory_ok() {
|
|
94
|
-
local lines value total=0
|
|
95
|
-
lines="$(ak get nodes -o jsonpath='{range .items[*]}{.status.allocatable.memory}{"\n"}{end}' 2>/dev/null)" || lines=""
|
|
96
|
-
if [ -z "$lines" ]; then
|
|
97
|
-
echo "✖ argocd: cluster unreachable or nodes unreadable (kubectl config get-contexts)" >&2
|
|
98
|
-
return 2
|
|
99
|
-
fi
|
|
100
|
-
while IFS= read -r value; do
|
|
101
|
-
[ -n "$value" ] || continue
|
|
102
|
-
total=$((total + $(argocd_quantity_ki "$value")))
|
|
103
|
-
done <<<"$lines"
|
|
104
|
-
if [ "$total" -lt "$ARGOCD_MIN_MEMORY_KI" ]; then
|
|
105
|
-
echo "✖ argocd: at least 1 Gi of allocatable memory is needed in the cluster (available: $((total / 1024)) Mi); enlarge the cluster (Docker Desktop → Settings → Resources), then: devzone workspace services enable argocd" >&2
|
|
106
|
-
return 2
|
|
107
|
-
fi
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
# Initial admin password, read with kubectl (go-template base64decode: no
|
|
111
|
-
# base64 of the workstation involved), written in workspace/.argocd/admin.env
|
|
112
|
-
# (600) and in .password; never printed
|
|
113
|
-
argocd_save_admin_password() {
|
|
114
|
-
local dir password
|
|
115
|
-
dir="$(argocd_secrets_dir)"
|
|
116
|
-
password="$(ak -n "$ARGOCD_NS" get secret argocd-initial-admin-secret \
|
|
117
|
-
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
118
|
-
if [ -z "$password" ]; then
|
|
119
|
-
echo "⚠ argocd: admin password unreadable (secret argocd-initial-admin-secret); .password not updated" >&2
|
|
120
|
-
return 0
|
|
121
|
-
fi
|
|
122
|
-
mkdir -p "$dir"
|
|
123
|
-
chmod 700 "$dir"
|
|
124
|
-
(
|
|
125
|
-
umask 077
|
|
126
|
-
printf 'ARGOCD_URL=https://localhost:%s\nARGOCD_USER=admin\nARGOCD_PASSWORD=%s\n' "$ARGOCD_LOCAL_PORT" "$password" >"$dir/admin.env"
|
|
127
|
-
)
|
|
128
|
-
chmod 600 "$dir/admin.env"
|
|
129
|
-
argocd_passwords_refresh
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
# .password of the workstation regenerated from workspace/.*/ (password.sh of the package)
|
|
133
|
-
argocd_passwords_refresh() {
|
|
134
|
-
DEVZONE_ROOT="$PWD" devzone passwords regenerate 2>/dev/null ||
|
|
135
|
-
echo "⚠ .password not updated (devzone passwords regenerate)" >&2
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
# Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
|
|
139
|
-
argocd_install() {
|
|
140
|
-
chart_require argocd || return 2
|
|
141
|
-
argocd_memory_ok || return 2
|
|
142
|
-
echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
|
|
143
|
-
ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
144
|
-
ak label namespace "$ARGOCD_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
145
|
-
# Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
|
|
146
|
-
# first, then installed from the local chart (#538)
|
|
147
|
-
helm dependency build "$(argocd_chart)" >/dev/null
|
|
148
|
-
# shellcheck disable=SC2046
|
|
149
|
-
helm $(helm_flag) upgrade --install argocd "$(argocd_chart)" \
|
|
150
|
-
--namespace "$ARGOCD_NS" \
|
|
151
|
-
--timeout "${ARGOCD_WAIT}s" --wait || return 1
|
|
152
|
-
argocd_save_admin_password
|
|
153
|
-
echo "✔ Argo CD ready: https://localhost:$ARGOCD_LOCAL_PORT once devzone workspace ports runs; user admin, password in .password"
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
# Installs it when wanted and missing (workspace start); a refusal (memory)
|
|
157
|
-
# is told and the start goes on with helm direct. A cluster that does not
|
|
158
|
-
# answer is not "helm direct": the start has already stopped on it (#565)
|
|
159
|
-
argocd_ensure() {
|
|
160
|
-
argocd_wanted || return 0
|
|
161
|
-
argocd_installed && return 0
|
|
162
|
-
if ! "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" kube-ready >/dev/null; then
|
|
163
|
-
echo "⚠ Argo CD not checked: the cluster does not answer (devzone workspace services enable argocd once it does)" >&2
|
|
164
|
-
return 0
|
|
165
|
-
fi
|
|
166
|
-
argocd_install || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
|
|
167
|
-
return 0
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
# Applications removed without cascade (finalizer dropped first: the services
|
|
171
|
-
# stay, under helm direct; the GitOps repository keeps its files), then helm
|
|
172
|
-
# uninstall and the namespace
|
|
173
|
-
argocd_uninstall() {
|
|
174
|
-
local app
|
|
175
|
-
if argocd_installed; then
|
|
176
|
-
echo "▶ Argo CD removal: Applications released (their resources stay), release and namespace deleted…"
|
|
177
|
-
while IFS= read -r app; do
|
|
178
|
-
[ -n "$app" ] || continue
|
|
179
|
-
gitops_direct_delete_application "${app#*/}" keep
|
|
180
|
-
done <<<"$(ak -n "$ARGOCD_NS" get applications.argoproj.io -o name 2>/dev/null || true)"
|
|
181
|
-
# shellcheck disable=SC2046
|
|
182
|
-
helm $(helm_flag) uninstall argocd --namespace "$ARGOCD_NS" >/dev/null 2>&1 || true
|
|
183
|
-
ak delete namespace "$ARGOCD_NS" --wait=true --ignore-not-found >/dev/null
|
|
184
|
-
fi
|
|
185
|
-
rm -rf "$(argocd_secrets_dir)"
|
|
186
|
-
argocd_passwords_refresh
|
|
187
|
-
echo "✔ Argo CD removed; the services stay, under helm direct"
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
# Applies the Application <name> of <kind> to <namespace> from <repo> at
|
|
191
|
-
# <revision>, <path>; the other arguments are Helm parameters key=value.
|
|
192
|
-
# In the GitOps repository when one is designated (gitops.sh), else directly
|
|
193
|
-
argocd_apply_application() {
|
|
194
|
-
gitops_apply_application "$@"
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
# Deletes an Application (and its file of the GitOps repository); keep:
|
|
198
|
-
# finalizer dropped first, its resources stay
|
|
199
|
-
argocd_delete_application() {
|
|
200
|
-
gitops_delete_application "$@"
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
argocd_application_exists() {
|
|
204
|
-
ak -n "$ARGOCD_NS" get application.argoproj.io "$1" >/dev/null 2>&1
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
# Installed or not, then the Applications with their sync and health status
|
|
208
|
-
argocd_status() {
|
|
209
|
-
if ! argocd_installed; then
|
|
210
|
-
echo "○ argocd not installed: devzone workspace services enable argocd"
|
|
211
|
-
return 0
|
|
212
|
-
fi
|
|
213
|
-
if argocd_wanted; then
|
|
214
|
-
echo "✔ argocd installed: https://localhost:$ARGOCD_LOCAL_PORT (devzone workspace ports), user admin, password in .password"
|
|
215
|
-
else
|
|
216
|
-
echo "⚠ argocd installed but argocd=off in .devzone.modules: devzone workspace services enable argocd, or disable to remove it"
|
|
217
|
-
fi
|
|
218
|
-
if gitops_enabled; then
|
|
219
|
-
echo " GitOps repository: $(gitops_repo) (apps/, root Application $GITOPS_ROOT_APP)"
|
|
220
|
-
else
|
|
221
|
-
echo " no GitOps repository: Applications applied directly (devzone workspace argocd init)"
|
|
222
|
-
fi
|
|
223
|
-
ak -n "$ARGOCD_NS" get applications.argoproj.io \
|
|
224
|
-
-o custom-columns='APPLICATION:.metadata.name,KIND:.metadata.labels.devzone\.io/kind,SYNC:.status.sync.status,HEALTH:.status.health.status,REVISION:.spec.source.targetRevision' \
|
|
225
|
-
2>/dev/null | sed 's/^/ /'
|
|
226
|
-
return 0
|
|
227
|
-
}
|