devzone 1.1.0 → 3.0.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/Dockerfile +4 -4
- package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
- package/.devcontainer/agent-local.sh +2 -2
- package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
- package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
- package/.devcontainer/agent-session.sh +3 -3
- package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +14 -14
- package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
- package/.devcontainer/{ia → ai}/host-models.sh +2 -2
- package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
- package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
- package/.devcontainer/argocd/argocd.sh +94 -93
- package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
- package/.devcontainer/argocd/services-hook.sh +8 -8
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +209 -0
- package/.devcontainer/catalog/catalog-watcher.sh +130 -0
- package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +87 -0
- package/.devcontainer/catalog/mysql/mysql.sh +262 -0
- package/.devcontainer/catalog/mysql/volume.sh +71 -0
- package/.devcontainer/catalog.sh +231 -0
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +222 -224
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +103 -1506
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/argocd.sh +2 -2
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +83 -84
- package/.devcontainer/gitlab/installation.sh +111 -111
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +65 -0
- package/.devcontainer/kind-wrapper.sh +45 -0
- package/.devcontainer/kube-account.sh +199 -0
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +64 -0
- package/.devcontainer/{memoire.sh → memory.sh} +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +228 -0
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +127 -123
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +176 -176
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +5 -5
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +65 -0
- package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
- package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
- package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
- package/.devcontainer/{etat.sh → state.sh} +4 -4
- package/.devcontainer/workspace-init.sh +17 -3
- package/Makefile +8 -8
- package/README.md +195 -194
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +8 -10
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/check-go-layout.sh +40 -0
- package/manage/scripts/check-names.sh +61 -0
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +2 -2
- package/manage/scripts/devzone-create.sh +5 -5
- package/manage/scripts/devzone-manifest.sh +3 -3
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/docker-workstation.sh +2 -2
- package/manage/scripts/docker.sh +2 -2
- package/manage/scripts/{lancer.sh → launch.sh} +10 -51
- package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
- package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +4 -4
- package/package.json +1 -1
- package/.devcontainer/catalogue/app.sh +0 -211
- package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
- package/.devcontainer/catalogue/mysql/installer.sh +0 -87
- package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
- package/.devcontainer/catalogue/mysql/volume.sh +0 -71
- package/.devcontainer/catalogue.sh +0 -231
- package/.devcontainer/demarrage.sh +0 -66
- package/.devcontainer/docker-relais.sh +0 -149
- package/.devcontainer/docker-sans-hote.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/.devcontainer/isolement.sh +0 -65
- package/.devcontainer/kind-enveloppe.sh +0 -45
- package/.devcontainer/kube-compte.sh +0 -200
- package/.devcontainer/kube-joignable.sh +0 -64
- package/.devcontainer/paquets.sh +0 -227
- /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
- /package/.devcontainer/{ia → ai}/host-check.message +0 -0
- /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
|
@@ -1,92 +1,92 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Module argocd (#411)
|
|
2
|
+
# Module argocd (#411): Argo CD in the devzone services cluster.
|
|
3
3
|
# argocd.sh install | uninstall | status | relay-start | relay-stop
|
|
4
4
|
# argocd.sh app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# .
|
|
5
|
+
# Isolated devzone-argocd namespace, relay 127.0.0.1:8443 in the container.
|
|
6
|
+
# Admin password in workspace/.argocd/admin.env (600), copied to .password;
|
|
7
|
+
# never displayed.
|
|
8
8
|
set -euo pipefail
|
|
9
9
|
|
|
10
10
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
11
|
-
RACINE="${
|
|
12
|
-
# shellcheck disable=SC2034 #
|
|
13
|
-
ETAT="${
|
|
11
|
+
RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
|
|
12
|
+
# shellcheck disable=SC2034 # read by cluster.sh (sourced library)
|
|
13
|
+
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
14
14
|
# shellcheck source=SCRIPTDIR/../cluster.sh
|
|
15
15
|
# shellcheck disable=SC1091
|
|
16
16
|
. "$ICI/../cluster.sh"
|
|
17
17
|
# shellcheck source=SCRIPTDIR/../password.sh
|
|
18
18
|
# shellcheck disable=SC1091
|
|
19
19
|
. "$ICI/../password.sh"
|
|
20
|
-
#
|
|
21
|
-
# shellcheck source=SCRIPTDIR/../
|
|
20
|
+
# Network isolation: namespace_isolate, applied with the devzone-argocd namespace
|
|
21
|
+
# shellcheck source=SCRIPTDIR/../isolation.sh
|
|
22
22
|
# shellcheck disable=SC1091
|
|
23
|
-
. "$ICI/../
|
|
23
|
+
. "$ICI/../isolation.sh"
|
|
24
24
|
# Shared memory check of the services cluster (#608): quantity_ki and
|
|
25
25
|
# memory_cluster_ki.
|
|
26
|
-
# shellcheck source=SCRIPTDIR/../
|
|
26
|
+
# shellcheck source=SCRIPTDIR/../memory.sh
|
|
27
27
|
# shellcheck disable=SC1091
|
|
28
|
-
. "$ICI/../
|
|
28
|
+
. "$ICI/../memory.sh"
|
|
29
29
|
|
|
30
30
|
NS=devzone-argocd
|
|
31
31
|
SECRETS="$RACINE/workspace/.argocd"
|
|
32
|
-
#
|
|
32
|
+
# Pinned argo-cd chart version, relay port and install wait
|
|
33
33
|
ARGOCD_VERSION="${ARGOCD_VERSION:-10.14.0}"
|
|
34
34
|
ARGOCD_PORT="${ARGOCD_PORT:-8443}"
|
|
35
35
|
ARGOCD_ATTENTE="${ARGOCD_ATTENTE:-600}"
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
# Module refusal: prefixed message and code 2 (same convention as postgres)
|
|
38
38
|
refuse() { echo "devzone : argocd : $*" >&2; exit 2; }
|
|
39
39
|
|
|
40
|
-
#
|
|
41
|
-
|
|
40
|
+
# Grouped credentials view: a failure never blocks the operation
|
|
41
|
+
regenerate_credentials() {
|
|
42
42
|
password_regenerate ||
|
|
43
|
-
echo "devzone : argocd :
|
|
43
|
+
echo "devzone : argocd : grouped credentials not updated (devzone passwords)" >&2
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
#
|
|
47
|
-
# message
|
|
48
|
-
|
|
49
|
-
local
|
|
50
|
-
if !
|
|
51
|
-
echo "devzone : argocd :
|
|
46
|
+
# Refuses the install below 1 GB of allocatable memory in the cluster; the
|
|
47
|
+
# message says where to enlarge the cluster and the command to run again.
|
|
48
|
+
check_memory() {
|
|
49
|
+
local mem
|
|
50
|
+
if ! mem="$(memory_cluster_ki)"; then
|
|
51
|
+
echo "devzone : argocd : services cluster unreachable: devzone cluster" >&2
|
|
52
52
|
return 2
|
|
53
53
|
fi
|
|
54
|
-
if [ "$
|
|
55
|
-
echo "devzone : argocd :
|
|
54
|
+
if [ "$mem" -lt 1048576 ]; then
|
|
55
|
+
echo "devzone : argocd : at least 1 GB of allocatable memory is needed in the cluster (available: $((mem / 1024)) MB); enlarge the cluster (Docker Desktop → Settings → Resources) then run again: devzone enable argocd" >&2
|
|
56
56
|
return 2
|
|
57
57
|
fi
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
# Namespace
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
# Namespace present in the services cluster: Argo CD is installed.
|
|
61
|
+
# Reading namespaces is reserved to the administrator (#430).
|
|
62
|
+
is_installed() {
|
|
63
|
+
account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
|
|
66
|
+
# Creates the namespace and labels it through the administrator, allows the
|
|
67
|
+
# limited account, then applies the module's isolating NetworkPolicy (#430).
|
|
68
|
+
prepare_namespace() {
|
|
69
69
|
local ctx
|
|
70
|
-
ctx="$(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
ctx="$(account_context)"
|
|
71
|
+
account_admin "$ctx" create namespace "$NS" --dry-run=client -o yaml |
|
|
72
|
+
account_admin "$ctx" apply -f - >/dev/null
|
|
73
|
+
account_admin "$ctx" label namespace "$NS" "$CLUSTER_LABEL" --overwrite >/dev/null
|
|
74
|
+
account_allow "$ctx" "$NS"
|
|
75
|
+
namespace_isolate "$NS"
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
#
|
|
79
|
-
# workspace/.argocd/admin.env (600)
|
|
80
|
-
|
|
81
|
-
local
|
|
82
|
-
if !
|
|
78
|
+
# Reads the initial password from the chart's Secret and writes it to
|
|
79
|
+
# workspace/.argocd/admin.env (600); the content is never displayed.
|
|
80
|
+
save_admin() {
|
|
81
|
+
local raw pw
|
|
82
|
+
if ! raw="$(kubectl --context devzone -n "$NS" get secret argocd-initial-admin-secret \
|
|
83
83
|
-o jsonpath='{.data.password}' 2>/dev/null)"; then
|
|
84
|
-
echo "devzone : argocd : secret argocd-initial-admin-secret
|
|
84
|
+
echo "devzone : argocd : secret argocd-initial-admin-secret not found" >&2
|
|
85
85
|
return 1
|
|
86
86
|
fi
|
|
87
|
-
|
|
88
|
-
if [ -z "$
|
|
89
|
-
echo "devzone : argocd :
|
|
87
|
+
pw="$(printf '%s' "$raw" | base64 -d 2>/dev/null || true)"
|
|
88
|
+
if [ -z "$pw" ]; then
|
|
89
|
+
echo "devzone : argocd : admin password unreadable in the secret" >&2
|
|
90
90
|
return 1
|
|
91
91
|
fi
|
|
92
92
|
mkdir -p "$SECRETS"
|
|
@@ -96,71 +96,72 @@ enregistrer_admin() {
|
|
|
96
96
|
cat >"$SECRETS/admin.env" <<ENV
|
|
97
97
|
ARGOCD_URL=https://127.0.0.1:$ARGOCD_PORT
|
|
98
98
|
ARGOCD_USER=admin
|
|
99
|
-
ARGOCD_PASSWORD=$
|
|
99
|
+
ARGOCD_PASSWORD=$pw
|
|
100
100
|
ENV
|
|
101
101
|
)
|
|
102
102
|
chmod 600 "$SECRETS/admin.env"
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
echo "▶
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
echo "▶
|
|
105
|
+
# Installs Argo CD with the pinned chart, prepares the namespace, stores the
|
|
106
|
+
# admin password and starts the access relay; idempotent (upgrade --install).
|
|
107
|
+
do_install() {
|
|
108
|
+
echo "▶ Checking the allocatable memory of the services cluster…"
|
|
109
|
+
check_memory || return 2
|
|
110
|
+
prepare_namespace
|
|
111
|
+
echo "▶ Installing Argo CD $ARGOCD_VERSION in $NS (chart charts/devzone-argocd)…"
|
|
112
112
|
# Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
|
|
113
113
|
# first, then installed from the local chart (#538)
|
|
114
114
|
helm dependency build "$RACINE/charts/devzone-argocd" >/dev/null
|
|
115
|
-
|
|
115
|
+
account_helm "$(account_context)" upgrade --install argocd \
|
|
116
116
|
"$RACINE/charts/devzone-argocd" \
|
|
117
117
|
--namespace "$NS" \
|
|
118
118
|
--create-namespace \
|
|
119
119
|
--timeout "${ARGOCD_ATTENTE}s" \
|
|
120
120
|
--wait
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
echo "✔
|
|
121
|
+
save_admin
|
|
122
|
+
relay_start argocd devzone "$NS" svc/argocd-server "$ARGOCD_PORT:443"
|
|
123
|
+
regenerate_credentials
|
|
124
|
+
echo "✔ argocd module ready: https://127.0.0.1:$ARGOCD_PORT"
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
|
|
127
|
+
# Uninstalls the Helm release and deletes the namespace; the other services
|
|
128
|
+
# of the cluster stay, under direct helm. The RoleBinding and the namespace
|
|
129
|
+
# are removed by the administrator (#430).
|
|
130
|
+
do_uninstall() {
|
|
131
131
|
local ctx
|
|
132
|
-
|
|
133
|
-
if
|
|
134
|
-
echo "▶
|
|
135
|
-
if !
|
|
136
|
-
echo "devzone : argocd : helm uninstall
|
|
132
|
+
relay_stop argocd
|
|
133
|
+
if is_installed; then
|
|
134
|
+
echo "▶ Deleting Argo CD on the services cluster…"
|
|
135
|
+
if ! account_helm "$(account_context)" uninstall argocd -n "$NS" >/dev/null 2>&1; then
|
|
136
|
+
echo "devzone : argocd : helm uninstall failed (release already absent?)" >&2
|
|
137
137
|
fi
|
|
138
|
-
ctx="$(
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
ctx="$(account_context)"
|
|
139
|
+
account_remove "$ctx" "$NS" >/dev/null 2>&1 || true
|
|
140
|
+
account_admin "$ctx" delete namespace "$NS" --wait=true >/dev/null
|
|
141
141
|
fi
|
|
142
142
|
rm -rf "$SECRETS"
|
|
143
|
-
echo "✔
|
|
144
|
-
|
|
143
|
+
echo "✔ argocd module disabled; the services stay, under direct helm."
|
|
144
|
+
regenerate_credentials
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
#
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
# Module status: disabled without namespace, ready with the relay active.
|
|
148
|
+
# The status texts are read by devzone: keep them unchanged.
|
|
149
|
+
do_status() {
|
|
150
|
+
if ! is_installed; then
|
|
151
|
+
echo "disabled"
|
|
151
152
|
return 0
|
|
152
153
|
fi
|
|
153
|
-
if !
|
|
154
|
-
echo "
|
|
154
|
+
if ! relay_active argocd; then
|
|
155
|
+
echo "ready, relay stopped: devzone apply"
|
|
155
156
|
else
|
|
156
|
-
echo "
|
|
157
|
+
echo "ready: https://127.0.0.1:$ARGOCD_PORT"
|
|
157
158
|
fi
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
#
|
|
161
|
-
|
|
162
|
-
if
|
|
163
|
-
|
|
161
|
+
# Starts the access relay again only if the Argo CD namespace exists.
|
|
162
|
+
do_relay_start() {
|
|
163
|
+
if is_installed; then
|
|
164
|
+
relay_start argocd devzone "$NS" svc/argocd-server "$ARGOCD_PORT:443"
|
|
164
165
|
fi
|
|
165
166
|
}
|
|
166
167
|
|
|
@@ -192,26 +193,26 @@ ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
|
|
|
192
193
|
argocd_kubectl() { kubectl --context devzone "$@"; }
|
|
193
194
|
|
|
194
195
|
case "${1:-}" in
|
|
195
|
-
install)
|
|
196
|
-
uninstall)
|
|
197
|
-
status)
|
|
198
|
-
relay-start)
|
|
199
|
-
relay-stop)
|
|
196
|
+
install) do_install ;;
|
|
197
|
+
uninstall) do_uninstall ;;
|
|
198
|
+
status) do_status ;;
|
|
199
|
+
relay-start) do_relay_start ;;
|
|
200
|
+
relay-stop) relay_stop argocd ;;
|
|
200
201
|
init)
|
|
201
202
|
# GitOps repository of the user (#516): created or designated, then
|
|
202
203
|
# the root Application when the module is installed
|
|
203
204
|
gitops_init "${@:2}" || exit $?
|
|
204
|
-
if
|
|
205
|
+
if is_installed; then gitops_root; fi
|
|
205
206
|
;;
|
|
206
207
|
apply)
|
|
207
|
-
|
|
208
|
+
is_installed || refuse "module off: devzone enable argocd"
|
|
208
209
|
gitops_init && gitops_root && apps_reconcile
|
|
209
210
|
;;
|
|
210
211
|
app)
|
|
211
212
|
if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
|
|
212
213
|
refuse "in the workspace pod, on the workstation: devzone workspace argocd app ${*:2}"
|
|
213
214
|
fi
|
|
214
|
-
|
|
215
|
+
is_installed || refuse "module off: devzone enable argocd"
|
|
215
216
|
argocd_app "${@:2}"
|
|
216
217
|
;;
|
|
217
218
|
*)
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# Argo CD for the catalogue applications in the container (#538): the module
|
|
3
3
|
# mysql and the catalogue install their application as the Application
|
|
4
4
|
# devzone-<app> (services.sh) when the module argocd is active, instead of
|
|
5
|
-
# the manifest applied by hand. The namespace (
|
|
6
|
-
# cluster.sh,
|
|
5
|
+
# the manifest applied by hand. The namespace (account_namespace of
|
|
6
|
+
# cluster.sh, isolation.sh) and the secret <app>-admin (mirror
|
|
7
7
|
# workspace/.<app>/) stay created apart, out of Git; Argo CD holds the chart
|
|
8
8
|
# charts/devzone-<app> of the devzone repository at the revision.
|
|
9
9
|
# catalogue_argocd_active <app> on, installed, chart and revision
|
|
@@ -79,7 +79,7 @@ catalogue_argocd_active() {
|
|
|
79
79
|
local app="$1"
|
|
80
80
|
catalogue_argocd_module_on || return 1
|
|
81
81
|
[ -d "$RACINE/charts/devzone-$app" ] || return 1
|
|
82
|
-
|
|
82
|
+
account_admin "$(account_context)" get namespace devzone-argocd >/dev/null 2>&1 || return 1
|
|
83
83
|
catalogue_argocd_load
|
|
84
84
|
[ -n "$(argocd_revision)" ]
|
|
85
85
|
}
|
|
@@ -16,20 +16,20 @@
|
|
|
16
16
|
|
|
17
17
|
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
18
18
|
# RACINE: the code tree (libraries, charts); STATE_RACINE: the devzone folder
|
|
19
|
-
# (workspace/ secrets, .argocd.conf), the same folder unless
|
|
19
|
+
# (workspace/ secrets, .argocd.conf), the same folder unless DEVZONE_ROOT says so
|
|
20
20
|
RACINE="$(dirname "$(dirname "$ICI")")"
|
|
21
|
-
STATE_RACINE="${
|
|
22
|
-
# shellcheck disable=SC2034 # read by
|
|
23
|
-
ETAT="${
|
|
24
|
-
APP_CONF="$RACINE/.devcontainer/
|
|
21
|
+
STATE_RACINE="${DEVZONE_ROOT:-$RACINE}"
|
|
22
|
+
# shellcheck disable=SC2034 # read by catalog-argocd.sh
|
|
23
|
+
ETAT="${DEVZONE_STATE:-$STATE_RACINE/.devzone.modules}"
|
|
24
|
+
APP_CONF="$RACINE/.devcontainer/catalog/mysql/app.conf"
|
|
25
25
|
HOOK_SERVICES="postgres mysql"
|
|
26
26
|
|
|
27
27
|
# shellcheck source=SCRIPTDIR/../cluster.sh
|
|
28
28
|
# shellcheck disable=SC1091
|
|
29
29
|
. "$ICI/../cluster.sh"
|
|
30
|
-
# shellcheck source=SCRIPTDIR/
|
|
30
|
+
# shellcheck source=SCRIPTDIR/catalog-argocd.sh
|
|
31
31
|
# shellcheck disable=SC1091
|
|
32
|
-
. "$ICI/
|
|
32
|
+
. "$ICI/catalog-argocd.sh"
|
|
33
33
|
|
|
34
34
|
# Loads the Argo CD pieces (conf, gitops, services with the context devzone)
|
|
35
35
|
# and the list of services reconciled here
|
|
@@ -45,7 +45,7 @@ hook_load() {
|
|
|
45
45
|
hook_script() {
|
|
46
46
|
case "$1" in
|
|
47
47
|
postgres) printf '%s' "$ICI/../postgres/postgres.sh" ;;
|
|
48
|
-
mysql) printf '%s' "$ICI/../
|
|
48
|
+
mysql) printf '%s' "$ICI/../catalog/mysql/mysql.sh" ;;
|
|
49
49
|
esac
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -44,7 +44,7 @@ chart_require() {
|
|
|
44
44
|
if [ -f "$chart/Chart.yaml" ] && grep -qxF "name: devzone-$svc" "$chart/Chart.yaml"; then
|
|
45
45
|
return 0
|
|
46
46
|
fi
|
|
47
|
-
echo "✖ $svc : chart charts/devzone-$svc missing or misnamed (manage/docs/reference.md#charts
|
|
47
|
+
echo "✖ $svc : chart charts/devzone-$svc missing or misnamed (manage/docs/reference.md#devzone-charts)" >&2
|
|
48
48
|
return 2
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install operations of the catalog (#414): sourced by catalog.sh.
|
|
3
|
+
# With the argocd module on, the installed application is an Argo CD Application
|
|
4
|
+
# devzone-<app> (chart charts/devzone-<app> of the devzone repository, #538) instead
|
|
5
|
+
# of the manifest of the direct helm path.
|
|
6
|
+
|
|
7
|
+
WAIT_SECONDS="${DEVZONE_CATALOG_WAIT:-300}"
|
|
8
|
+
|
|
9
|
+
# shellcheck source=SCRIPTDIR/argocd/catalog-argocd.sh
|
|
10
|
+
# shellcheck disable=SC1091
|
|
11
|
+
. "$ICI/argocd/catalog-argocd.sh"
|
|
12
|
+
# shellcheck source=SCRIPTDIR/chart-direct.sh
|
|
13
|
+
# shellcheck disable=SC1091
|
|
14
|
+
. "$ICI/chart-direct.sh"
|
|
15
|
+
|
|
16
|
+
# Waits for the StatefulSet to be ready: a single rollout command on the manifest
|
|
17
|
+
# path, polled on the Argo CD path (the sync runs in the background)
|
|
18
|
+
app_wait() {
|
|
19
|
+
local app="$1" ns="$2" argo="$3" end=$((SECONDS + WAIT_SECONDS))
|
|
20
|
+
if [ "$argo" = 1 ]; then
|
|
21
|
+
while [ "$SECONDS" -lt "$end" ]; do
|
|
22
|
+
kubectl --context devzone -n "$ns" rollout status "statefulset/$app" --timeout=10s >/dev/null 2>&1 && return 0
|
|
23
|
+
sleep 5
|
|
24
|
+
done
|
|
25
|
+
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
26
|
+
return 1
|
|
27
|
+
fi
|
|
28
|
+
if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
|
|
29
|
+
--timeout="${WAIT_SECONDS}s" >/dev/null; then
|
|
30
|
+
echo "devzone : catalog : $app not ready after ${WAIT_SECONDS}s" >&2
|
|
31
|
+
return 1
|
|
32
|
+
fi
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Application secret: password generated once, local mirror
|
|
36
|
+
# (workspace/.$app/admin-password, 600, never shown). Re-run: a password already
|
|
37
|
+
# there (cluster secret or root.env) is kept, never regenerated.
|
|
38
|
+
app_secret() {
|
|
39
|
+
local app="$1" ns="$2" password file
|
|
40
|
+
file="$RACINE/workspace/.$app/admin-password"
|
|
41
|
+
mkdir -p "$(dirname "$file")"
|
|
42
|
+
chmod 700 "$(dirname "$file")"
|
|
43
|
+
if kubectl --context devzone -n "$ns" get secret "$app-admin" >/dev/null 2>&1; then
|
|
44
|
+
password="$(kubectl --context devzone -n "$ns" get secret "$app-admin" \
|
|
45
|
+
-o jsonpath='{.data.password}' | tr -d '\n')"
|
|
46
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
47
|
+
return 0
|
|
48
|
+
fi
|
|
49
|
+
password="$(sed -n 's/^\(MYSQL_\|\)PASSWORD=//p' "$RACINE/workspace/.$app/root.env" 2>/dev/null | tail -1 || true)"
|
|
50
|
+
if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
|
|
51
|
+
if [ -z "$password" ]; then
|
|
52
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
53
|
+
elif [ ! -s "$file" ]; then
|
|
54
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
55
|
+
fi
|
|
56
|
+
kubectl --context devzone -n "$ns" create secret generic "$app-admin" \
|
|
57
|
+
--from-file=password="$file" >/dev/null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Grouped view of the credentials: a failure never blocks the operation
|
|
61
|
+
regenerer_identifiants() {
|
|
62
|
+
password_regenerate ||
|
|
63
|
+
echo "devzone : catalog : grouped credentials not updated (devzone passwords)" >&2
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Installs an application: devzone context set (#396), namespace created and
|
|
67
|
+
# isolated (#396), secret generated, then the Argo CD Application (argocd module
|
|
68
|
+
# on, #538) or the manifest, wait until ready, relay started to 127.0.0.1:<port>
|
|
69
|
+
# of the container; returns non-zero on failure
|
|
70
|
+
app_install() {
|
|
71
|
+
local app="$1" ns port image CTX extra="" argo=0
|
|
72
|
+
ns="$(app_namespace "$app")"
|
|
73
|
+
port="$(app_read "$app" port)"
|
|
74
|
+
image="$(app_read "$app" image)"
|
|
75
|
+
CTX="$(cluster_saved)"
|
|
76
|
+
[ -n "$CTX" ] || refuse "no cluster chosen: devzone enable $app"
|
|
77
|
+
if ! devzone_context_set "$CTX"; then
|
|
78
|
+
echo "devzone : catalog : cannot set the devzone context on $CTX" >&2
|
|
79
|
+
return 1
|
|
80
|
+
fi
|
|
81
|
+
echo "▶ Application $app on cluster $CTX (namespace $ns)…"
|
|
82
|
+
# Namespace created and labelled by the administrator (#430), then the limited
|
|
83
|
+
# account allowed in the namespace
|
|
84
|
+
account_admin "$CTX" create namespace "$ns" --dry-run=client -o yaml |
|
|
85
|
+
account_admin "$CTX" apply -f - >/dev/null
|
|
86
|
+
account_admin "$CTX" label namespace "$ns" "$CLUSTER_LABEL" --overwrite >/dev/null
|
|
87
|
+
account_allow "$CTX" "$ns"
|
|
88
|
+
namespace_isolate "$ns" >/dev/null
|
|
89
|
+
app_secret "$app" "$ns"
|
|
90
|
+
local claim=donnees
|
|
91
|
+
if [ "$app" = mysql ]; then
|
|
92
|
+
# shellcheck source=SCRIPTDIR/mysql/volume.sh
|
|
93
|
+
# shellcheck disable=SC1091
|
|
94
|
+
. "$(catalog_dir)/mysql/volume.sh"
|
|
95
|
+
claim="$(mysql_claim_choose "$ns")" || return 2
|
|
96
|
+
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
97
|
+
fi
|
|
98
|
+
if catalogue_argocd_active "$app"; then
|
|
99
|
+
argo=1
|
|
100
|
+
echo "▶ Application $app through Argo CD (chart charts/devzone-$app)…"
|
|
101
|
+
catalogue_argocd_apply "$app" "$ns" "$image" "$port" \
|
|
102
|
+
"$(app_read "$app" memoire)" "$(app_read "$app" taille)" "$extra" || return 1
|
|
103
|
+
else
|
|
104
|
+
# Direct helm: the chart charts/devzone-<app>, the one definition (#559)
|
|
105
|
+
chart_install "$app" "$ns" "image=$image" "port=$port" \
|
|
106
|
+
"memory=$(app_read "$app" memoire)" "size=$(app_read "$app" taille)" "claim=$claim" || return 1
|
|
107
|
+
fi
|
|
108
|
+
app_wait "$app" "$ns" "$argo" || return 1
|
|
109
|
+
relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
|
|
110
|
+
echo "✔ $app ready: 127.0.0.1:$port in the container"
|
|
111
|
+
regenerer_identifiants
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# Uninstalls an application: relay stopped, Argo CD Application removed (argocd
|
|
115
|
+
# module on, #538) or the manifest, failure marker forgotten. The volume (PVC) and
|
|
116
|
+
# the data stay (#441): deleting the data is confirmed apart (devzone mysql delete-data)
|
|
117
|
+
app_remove() {
|
|
118
|
+
local app="$1" ns claim pvc CTX
|
|
119
|
+
ns="$(app_namespace "$app")"
|
|
120
|
+
relay_stop "$app"
|
|
121
|
+
rm -f "$(failure_file "$app")"
|
|
122
|
+
# RoleBinding removed by the administrator (#430): the namespace and the volume
|
|
123
|
+
# stay, the account authorization must not linger
|
|
124
|
+
CTX="$(cluster_saved)" || true
|
|
125
|
+
if [ -n "$CTX" ]; then
|
|
126
|
+
account_remove "$CTX" "$ns" >/dev/null 2>&1 || true
|
|
127
|
+
fi
|
|
128
|
+
claim="$(kubectl --context devzone -n "$ns" get statefulset "$app" \
|
|
129
|
+
-o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
130
|
+
if catalogue_argocd_application_exists "$app"; then
|
|
131
|
+
catalogue_argocd_delete "$app" >/dev/null 2>&1 || true
|
|
132
|
+
kubectl --context devzone -n "$ns" delete "secret/$app-admin" >/dev/null 2>&1 || true
|
|
133
|
+
pvc="${claim:-donnees}-$app-0"
|
|
134
|
+
echo "✔ $app removed: Application deleted; volume $pvc and databases kept: devzone $app volume"
|
|
135
|
+
regenerer_identifiants
|
|
136
|
+
return 0
|
|
137
|
+
fi
|
|
138
|
+
kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
|
|
139
|
+
"secret/$app-admin" >/dev/null 2>&1 || true
|
|
140
|
+
pvc="${claim:-donnees}-$app-0"
|
|
141
|
+
echo "✔ $app removed from the cluster; volume $pvc and databases kept: devzone $app volume"
|
|
142
|
+
regenerer_identifiants
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Failure marker of an attempt: last line of the message kept and shown
|
|
146
|
+
app_failure() {
|
|
147
|
+
printf '%s\n' "$2" | tail -1 >"$(failure_file "$1")"
|
|
148
|
+
printf '%s\n' "$2" >&2
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# Warns about the mysql PVCs not mounted by the StatefulSet (#440). Reading the
|
|
152
|
+
# namespaces is reserved to the administrator (#430).
|
|
153
|
+
app_unused_mysql_volumes() {
|
|
154
|
+
local ctx ns mounted pvc list
|
|
155
|
+
ctx="$(cluster_saved)"
|
|
156
|
+
[ -n "$ctx" ] || return 0
|
|
157
|
+
ns="$(app_namespace mysql)"
|
|
158
|
+
account_admin "$ctx" get namespace "$ns" >/dev/null 2>&1 || return 0
|
|
159
|
+
mounted="$(kubectl --context devzone -n "$ns" get statefulset mysql -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
160
|
+
[ -n "$mounted" ] || return 0
|
|
161
|
+
list="$(kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
162
|
+
while IFS= read -r pvc; do
|
|
163
|
+
[ -n "$pvc" ] || continue
|
|
164
|
+
[ "$pvc" != "${mounted}-mysql-0" ] || continue
|
|
165
|
+
printf ' ⚠ volume %s not used : devzone mysql volume\n' "$pvc"
|
|
166
|
+
done <<<"$list"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# Closes the gap between wanted and actual: installs, removes, restarts the
|
|
170
|
+
# permanent relay; marks the first failure then moves on
|
|
171
|
+
catalog_apply() {
|
|
172
|
+
local app output code=0 port CTX ns
|
|
173
|
+
while IFS= read -r app; do
|
|
174
|
+
[ -n "$app" ] || continue
|
|
175
|
+
port="$(app_read "$app" port)"
|
|
176
|
+
if [ "$(wanted "$app")" != on ] && present "$app"; then
|
|
177
|
+
if ! output="$(app_remove "$app" 2>&1)"; then
|
|
178
|
+
code=1; app_failure "$app" "$output"
|
|
179
|
+
else
|
|
180
|
+
printf '%s\n' "$output"
|
|
181
|
+
fi
|
|
182
|
+
elif [ "$(wanted "$app")" = on ] && present "$app"; then
|
|
183
|
+
if ! app_ready "$app"; then
|
|
184
|
+
code=1
|
|
185
|
+
echo "devzone : catalog : $app installed but not ready: devzone apply" >&2
|
|
186
|
+
echo "not ready" >"$(failure_file "$app")"
|
|
187
|
+
else
|
|
188
|
+
rm -f "$(failure_file "$app")"
|
|
189
|
+
fi
|
|
190
|
+
# Permanent relay: restarted if stopped
|
|
191
|
+
CTX="$(cluster_saved)" || true
|
|
192
|
+
ns="$(app_namespace "$app")"
|
|
193
|
+
if [ -n "$CTX" ]; then
|
|
194
|
+
if ! output="$(relay_start "$app" "$CTX" "$ns" "svc/$app" "$port:$port" 2>&1)"; then
|
|
195
|
+
code=1; app_failure "$app" "$output"
|
|
196
|
+
else
|
|
197
|
+
[ -n "$output" ] && printf '%s\n' "$output"
|
|
198
|
+
fi
|
|
199
|
+
fi
|
|
200
|
+
elif [ "$(wanted "$app")" = on ]; then
|
|
201
|
+
if ! output="$(app_install "$app" 2>&1)"; then
|
|
202
|
+
code=1; app_failure "$app" "$output"
|
|
203
|
+
else
|
|
204
|
+
printf '%s\n' "$output"
|
|
205
|
+
fi
|
|
206
|
+
fi
|
|
207
|
+
done <<<"$(catalog_apps)"
|
|
208
|
+
return "$code"
|
|
209
|
+
}
|