devzone 0.36.7 → 0.38.0
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/.dockerignore +1 -1
- package/.devcontainer/argocd/application.sh +69 -0
- package/.devcontainer/argocd/apps.sh +262 -0
- package/.devcontainer/argocd/argocd.sh +52 -8
- package/.devcontainer/argocd/catalogue-argocd.sh +114 -0
- package/.devcontainer/argocd/conf.sh +141 -0
- package/.devcontainer/argocd/gitops.sh +214 -0
- package/.devcontainer/argocd/services.sh +138 -0
- package/.devcontainer/catalogue/app.sh +58 -17
- package/.devcontainer/catalogue/mysql/installer.sh +31 -0
- package/.devcontainer/catalogue/mysql/mysql.sh +12 -0
- package/.devcontainer/devzone +2 -1
- package/.devcontainer/password.sh +8 -0
- package/README.md +2 -2
- package/charts/devzone-argocd/Chart.lock +6 -0
- package/charts/devzone-argocd/Chart.yaml +13 -0
- package/charts/devzone-argocd/values.yaml +28 -0
- package/charts/devzone-mysql/Chart.yaml +6 -0
- package/charts/devzone-mysql/templates/service.yaml +15 -0
- package/charts/devzone-mysql/templates/statefulset.yaml +55 -0
- package/charts/devzone-mysql/values.yaml +19 -0
- package/charts/devzone-postgres/Chart.yaml +6 -0
- package/charts/devzone-postgres/templates/service.yaml +15 -0
- package/charts/devzone-postgres/templates/statefulset.yaml +56 -0
- package/charts/devzone-postgres/values.yaml +11 -0
- package/manage/devzone +4 -1
- package/manage/scripts/argocd-services-svc.sh +110 -0
- package/manage/scripts/argocd-services.sh +179 -0
- package/manage/scripts/argocd-workspace.sh +221 -0
- package/manage/scripts/ci-dns.sh +10 -10
- package/manage/scripts/desinstaller.sh +137 -135
- package/manage/scripts/docker.sh +26 -22
- package/manage/scripts/lancer.sh +103 -103
- package/manage/scripts/migrer-retour.sh +37 -34
- package/manage/scripts/migrer.sh +154 -138
- package/manage/scripts/ports-workspace.sh +94 -82
- package/manage/scripts/poste.sh +48 -49
- package/manage/scripts/services-workspace.sh +22 -5
- package/manage/scripts/versions.sh +88 -88
- package/manage/scripts/workspace-aliases.sh +47 -0
- package/manage/scripts/workspace-wait.sh +27 -24
- package/manage/workspace.sh +134 -105
- package/package.json +1 -1
- package/.devcontainer/argocd/values.yaml +0 -21
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Argo CD of the Kubernetes workspace, driven from the workstation (#516).
|
|
3
|
+
# Sourced by manage/workspace.sh (drapeau_kubectl, drapeau_helm, 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 $(drapeau_kubectl) "$@"
|
|
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_RACINE="$PWD" bash "$RACINE/.devcontainer/password.sh" regenerer 2>/dev/null ||
|
|
135
|
+
echo "⚠ .password not updated (bash .devcontainer/password.sh regenerer)" >&2
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Installs Argo CD (pinned chart and values), idempotent (upgrade --install)
|
|
139
|
+
argocd_install() {
|
|
140
|
+
argocd_memory_ok || return 2
|
|
141
|
+
echo "▶ Argo CD $ARGOCD_CHART_VERSION in $ARGOCD_NS (helm, up to ${ARGOCD_WAIT}s)…"
|
|
142
|
+
ak create namespace "$ARGOCD_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
143
|
+
ak label namespace "$ARGOCD_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
144
|
+
# Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
|
|
145
|
+
# first, then installed from the local chart (#538)
|
|
146
|
+
helm dependency build "$(argocd_chart)" >/dev/null
|
|
147
|
+
# shellcheck disable=SC2046
|
|
148
|
+
helm $(drapeau_helm) upgrade --install argocd "$(argocd_chart)" \
|
|
149
|
+
--namespace "$ARGOCD_NS" \
|
|
150
|
+
--timeout "${ARGOCD_WAIT}s" --wait || return 1
|
|
151
|
+
argocd_save_admin_password
|
|
152
|
+
echo "✔ Argo CD ready: https://localhost:$ARGOCD_LOCAL_PORT once devzone workspace ports runs; user admin, password in .password"
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Installs it when wanted and missing (workspace start); a refusal (memory)
|
|
156
|
+
# is told and the start goes on with helm direct
|
|
157
|
+
argocd_ensure() {
|
|
158
|
+
argocd_wanted || return 0
|
|
159
|
+
argocd_installed && return 0
|
|
160
|
+
argocd_install || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
|
|
161
|
+
return 0
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# Applications removed without cascade (finalizer dropped first: the services
|
|
165
|
+
# stay, under helm direct; the GitOps repository keeps its files), then helm
|
|
166
|
+
# uninstall and the namespace
|
|
167
|
+
argocd_uninstall() {
|
|
168
|
+
local app
|
|
169
|
+
if argocd_installed; then
|
|
170
|
+
echo "▶ Argo CD removal: Applications released (their resources stay), release and namespace deleted…"
|
|
171
|
+
while IFS= read -r app; do
|
|
172
|
+
[ -n "$app" ] || continue
|
|
173
|
+
gitops_direct_delete_application "${app#*/}" keep
|
|
174
|
+
done <<<"$(ak -n "$ARGOCD_NS" get applications.argoproj.io -o name 2>/dev/null || true)"
|
|
175
|
+
# shellcheck disable=SC2046
|
|
176
|
+
helm $(drapeau_helm) uninstall argocd --namespace "$ARGOCD_NS" >/dev/null 2>&1 || true
|
|
177
|
+
ak delete namespace "$ARGOCD_NS" --wait=true --ignore-not-found >/dev/null
|
|
178
|
+
fi
|
|
179
|
+
rm -rf "$(argocd_secrets_dir)"
|
|
180
|
+
argocd_passwords_refresh
|
|
181
|
+
echo "✔ Argo CD removed; the services stay, under helm direct"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
# Applies the Application <name> of <kind> to <namespace> from <repo> at
|
|
185
|
+
# <revision>, <path>; the other arguments are Helm parameters key=value.
|
|
186
|
+
# In the GitOps repository when one is designated (gitops.sh), else directly
|
|
187
|
+
argocd_apply_application() {
|
|
188
|
+
gitops_apply_application "$@"
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# Deletes an Application (and its file of the GitOps repository); keep:
|
|
192
|
+
# finalizer dropped first, its resources stay
|
|
193
|
+
argocd_delete_application() {
|
|
194
|
+
gitops_delete_application "$@"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
argocd_application_exists() {
|
|
198
|
+
ak -n "$ARGOCD_NS" get application.argoproj.io "$1" >/dev/null 2>&1
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# Installed or not, then the Applications with their sync and health status
|
|
202
|
+
argocd_status() {
|
|
203
|
+
if ! argocd_installed; then
|
|
204
|
+
echo "○ argocd not installed: devzone workspace services enable argocd"
|
|
205
|
+
return 0
|
|
206
|
+
fi
|
|
207
|
+
if argocd_wanted; then
|
|
208
|
+
echo "✔ argocd installed: https://localhost:$ARGOCD_LOCAL_PORT (devzone workspace ports), user admin, password in .password"
|
|
209
|
+
else
|
|
210
|
+
echo "⚠ argocd installed but argocd=off in .devzone.modules: devzone workspace services enable argocd, or disable to remove it"
|
|
211
|
+
fi
|
|
212
|
+
if gitops_enabled; then
|
|
213
|
+
echo " GitOps repository: $(gitops_repo) (apps/, root Application $GITOPS_ROOT_APP)"
|
|
214
|
+
else
|
|
215
|
+
echo " no GitOps repository: Applications applied directly (devzone workspace argocd init)"
|
|
216
|
+
fi
|
|
217
|
+
ak -n "$ARGOCD_NS" get applications.argoproj.io \
|
|
218
|
+
-o custom-columns='APPLICATION:.metadata.name,KIND:.metadata.labels.devzone\.io/kind,SYNC:.status.sync.status,HEALTH:.status.health.status,REVISION:.spec.source.targetRevision' \
|
|
219
|
+
2>/dev/null | sed 's/^/ /'
|
|
220
|
+
return 0
|
|
221
|
+
}
|
package/manage/scripts/ci-dns.sh
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# DNS
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
2
|
+
# Public DNS for Docker on a GitHub Actions runner (#468): runner ubuntu DNS
|
|
3
|
+
# sometimes fails to resolve archive.ubuntu.com while building the container.
|
|
4
|
+
# Adds 1.1.1.1 and 8.8.8.8 to daemon.json (existing keys are kept), restarts
|
|
5
|
+
# Docker and waits until it responds.
|
|
6
|
+
# Guard: refuses outside CI, never run on a workstation.
|
|
7
7
|
set -euo pipefail
|
|
8
8
|
|
|
9
9
|
if [ "${CI:-}" != true ] || [ "${GITHUB_ACTIONS:-}" != true ]; then
|
|
10
|
-
echo "ci-dns.sh
|
|
10
|
+
echo "ci-dns.sh: reserved for GitHub Actions (CI and GITHUB_ACTIONS must be true)" >&2
|
|
11
11
|
exit 1
|
|
12
12
|
fi
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
# Overridable path for tests
|
|
15
15
|
daemon="${DEVZONE_CI_DOCKER_DAEMON:-/etc/docker/daemon.json}"
|
|
16
16
|
tmp="$(mktemp)"
|
|
17
17
|
trap 'rm -f "$tmp"' EXIT
|
|
18
18
|
|
|
19
|
-
#
|
|
19
|
+
# Merge with existing file, or create it if missing
|
|
20
20
|
if [ -s "$daemon" ]; then
|
|
21
21
|
jq '. + {"dns": ["1.1.1.1", "8.8.8.8"]}' "$daemon" >"$tmp"
|
|
22
22
|
else
|
|
@@ -27,12 +27,12 @@ sudo cp "$tmp" "$daemon"
|
|
|
27
27
|
|
|
28
28
|
sudo systemctl restart docker
|
|
29
29
|
|
|
30
|
-
#
|
|
30
|
+
# Wait for Docker: at most 20 seconds
|
|
31
31
|
for _ in $(seq 1 20); do
|
|
32
32
|
if docker info >/dev/null 2>&1; then
|
|
33
33
|
exit 0
|
|
34
34
|
fi
|
|
35
35
|
sleep 1
|
|
36
36
|
done
|
|
37
|
-
echo "ci-dns.sh
|
|
37
|
+
echo "ci-dns.sh: Docker did not respond after 20 s" >&2
|
|
38
38
|
exit 1
|