devzone 2.0.0 → 4.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/agent-errors.sh +6 -6
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/agent-session.sh +2 -2
- package/.devcontainer/agent-state-json.sh +2 -2
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +7 -7
- package/.devcontainer/ai/host-models.sh +2 -2
- package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
- package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
- package/.devcontainer/argocd/argocd.sh +90 -89
- package/.devcontainer/argocd/catalog-argocd.sh +2 -2
- package/.devcontainer/argocd/services-hook.sh +3 -3
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +114 -116
- package/.devcontainer/catalog/catalog-watcher.sh +62 -62
- package/.devcontainer/catalog/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +40 -40
- package/.devcontainer/catalog/mysql/mysql.sh +141 -141
- package/.devcontainer/catalog/mysql/volume.sh +39 -39
- package/.devcontainer/catalog.sh +112 -112
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +216 -218
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/command-aliases.sh +17 -8
- package/.devcontainer/devzone +93 -1496
- 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/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +81 -82
- package/.devcontainer/gitlab/installation.sh +109 -109
- 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 +30 -30
- package/.devcontainer/kind-wrapper.sh +17 -17
- package/.devcontainer/kube-account.sh +112 -113
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +40 -40
- package/.devcontainer/memory.sh +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +136 -135
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +126 -122
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +174 -174
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +3 -3
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +48 -49
- package/.devcontainer/state-gitops.sh +1 -1
- package/.devcontainer/state-json.sh +36 -62
- package/.devcontainer/state.sh +2 -2
- package/.devcontainer/workspace-init.sh +16 -2
- package/Makefile +1 -1
- package/README.md +191 -195
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +7 -11
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/{check-charts.sh → ci/check-charts.sh} +1 -1
- package/manage/scripts/{check-english.sh → ci/check-english.sh} +1 -1
- package/manage/scripts/{check-go-layout.sh → ci/check-go-layout.sh} +1 -1
- package/manage/scripts/{check-names.sh → ci/check-names.sh} +7 -6
- package/manage/scripts/{check-utf8-vars.sh → ci/check-utf8-vars.sh} +1 -1
- package/manage/scripts/{versions.sh → ci/versions.sh} +8 -8
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +11 -18
- package/manage/scripts/devzone-create.sh +7 -35
- package/manage/scripts/devzone-manifest.sh +1 -1
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/launch.sh +7 -48
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/poste.sh +6 -7
- package/manage/scripts/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 +2 -12
- package/package.json +1 -1
- package/.devcontainer/docker-relay.sh +0 -149
- package/.devcontainer/docker-without-host.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/manage/scripts/docker-workstation.sh +0 -73
- package/manage/scripts/migrate-revert.sh +0 -60
- package/manage/scripts/migrate.sh +0 -243
- /package/manage/scripts/{ci-dns.sh → ci/ci-dns.sh} +0 -0
|
@@ -1,87 +1,87 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
2
|
+
# MySQL installation (#440): secret, chart and reinstallation on a volume.
|
|
3
3
|
# shellcheck source=SCRIPTDIR/../../chart-direct.sh
|
|
4
4
|
# shellcheck disable=SC1091
|
|
5
5
|
. "$ICI/../../chart-direct.sh"
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Admin secret (mysql-admin): root.env or existing secret, never regenerated.
|
|
8
8
|
mysql_secret() {
|
|
9
|
-
local
|
|
9
|
+
local password file="$SECRETS/admin-password"
|
|
10
10
|
mkdir -p "$SECRETS"
|
|
11
11
|
chmod 700 "$SECRETS"
|
|
12
12
|
if k get secret mysql-admin >/dev/null 2>&1; then
|
|
13
|
-
|
|
14
|
-
(umask 077 && printf '%s' "$
|
|
13
|
+
password="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
|
|
14
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
15
15
|
return 0
|
|
16
16
|
fi
|
|
17
|
-
|
|
18
|
-
if [ -z "$
|
|
19
|
-
if [ -z "$
|
|
20
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$
|
|
21
|
-
k create secret generic mysql-admin --from-file=password="$
|
|
22
|
-
elif [ ! -s "$
|
|
23
|
-
(umask 077 && printf '%s' "$
|
|
17
|
+
password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
18
|
+
if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
|
|
19
|
+
if [ -z "$password" ]; then
|
|
20
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
21
|
+
k create secret generic mysql-admin --from-file=password="$file" >/dev/null
|
|
22
|
+
elif [ ! -s "$file" ]; then
|
|
23
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
24
24
|
fi
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
local
|
|
31
|
-
while [ "$SECONDS" -lt "$
|
|
27
|
+
# Wait for the StatefulSet created by Argo CD (#538): the sync runs in the
|
|
28
|
+
# background, the rollout is polled up to MYSQL_ATTENTE
|
|
29
|
+
mysql_wait() {
|
|
30
|
+
local end=$((SECONDS + MYSQL_ATTENTE))
|
|
31
|
+
while [ "$SECONDS" -lt "$end" ]; do
|
|
32
32
|
if k rollout status statefulset/mysql --timeout=10s >/dev/null 2>&1; then
|
|
33
33
|
return 0
|
|
34
34
|
fi
|
|
35
35
|
sleep 5
|
|
36
36
|
done
|
|
37
|
-
echo "devzone :
|
|
37
|
+
echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $1 -n $NS describe pod mysql-0" >&2
|
|
38
38
|
return 1
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
#
|
|
42
|
-
# charts/devzone-mysql
|
|
43
|
-
#
|
|
44
|
-
|
|
41
|
+
# MySQL installation by Argo CD (#538): Application devzone-mysql (chart
|
|
42
|
+
# charts/devzone-mysql of the devzone repository), namespace and secret created
|
|
43
|
+
# apart; the claim follows the existing volumes, as the manifest path does
|
|
44
|
+
mysql_install_argocd() {
|
|
45
45
|
local CTX="$1" claim extra=""
|
|
46
46
|
mysql_secret
|
|
47
|
-
claim="$(
|
|
47
|
+
claim="$(mysql_claim_choose "$NS")" || return 2
|
|
48
48
|
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
49
49
|
catalogue_argocd_apply mysql "$NS" "$MYSQL_IMAGE" "$MYSQL_PORT" \
|
|
50
50
|
"$MYSQL_MEMOIRE" "$MYSQL_TAILLE" "$extra" || return 1
|
|
51
|
-
|
|
51
|
+
mysql_wait "$CTX" || return 1
|
|
52
52
|
mysql_secret
|
|
53
|
-
|
|
54
|
-
echo "✔ MySQL
|
|
53
|
+
relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
54
|
+
echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
|
|
55
55
|
regenerer_identifiants
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
#
|
|
59
|
-
|
|
58
|
+
# Installs the chart charts/devzone-mysql with the chosen claim (#440, #559)
|
|
59
|
+
mysql_apply_chart() {
|
|
60
60
|
local ns="$1" claim="$2"
|
|
61
61
|
chart_install mysql "$ns" "image=$MYSQL_IMAGE" "port=$MYSQL_PORT" \
|
|
62
62
|
"memory=$MYSQL_MEMOIRE" "size=$MYSQL_TAILLE" "claim=$claim"
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
# (
|
|
66
|
-
|
|
65
|
+
# (Re)installs MySQL on the requested claim, PVC data kept (#440)
|
|
66
|
+
mysql_install_claim() {
|
|
67
67
|
local ns="$1" claim="$2" CTX
|
|
68
|
-
CTX="$(
|
|
69
|
-
if !
|
|
70
|
-
echo "devzone :
|
|
68
|
+
CTX="$(module_context)"
|
|
69
|
+
if ! devzone_context_set "$CTX"; then
|
|
70
|
+
echo "devzone : catalog mysql : cannot set the devzone context on $CTX" >&2
|
|
71
71
|
return 1
|
|
72
72
|
fi
|
|
73
|
-
echo "▶ MySQL
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
echo "▶ MySQL on cluster $CTX (namespace $ns, volume ${claim}-mysql-0)…"
|
|
74
|
+
account_namespace "$CTX" "$ns"
|
|
75
|
+
namespace_isolate "$ns" >/dev/null
|
|
76
76
|
mysql_secret
|
|
77
77
|
k delete statefulset mysql --ignore-not-found >/dev/null 2>&1 || true
|
|
78
|
-
|
|
78
|
+
mysql_apply_chart "$ns" "$claim" || return 1
|
|
79
79
|
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
80
|
-
echo "devzone :
|
|
80
|
+
echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $ns describe pod mysql-0" >&2
|
|
81
81
|
return 1
|
|
82
82
|
fi
|
|
83
83
|
mysql_secret
|
|
84
|
-
|
|
85
|
-
echo "✔ MySQL
|
|
84
|
+
relay_start mysql "$CTX" "$ns" svc/mysql 3306:3306
|
|
85
|
+
echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
|
|
86
86
|
regenerer_identifiants
|
|
87
87
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# MySQL
|
|
2
|
+
# MySQL of the catalog (#414): create, list, delete, status, relay-start, relay-stop, install, delete-data.
|
|
3
3
|
set -euo pipefail
|
|
4
4
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
-
RACINE="${
|
|
6
|
-
ETAT="${
|
|
5
|
+
RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$(dirname "$ICI")")")}"
|
|
6
|
+
ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
7
7
|
# shellcheck source=SCRIPTDIR/../../cluster.sh
|
|
8
8
|
# shellcheck disable=SC1091
|
|
9
9
|
. "$ICI/../../cluster.sh"
|
|
@@ -19,7 +19,7 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
|
19
19
|
# shellcheck source=SCRIPTDIR/install.sh
|
|
20
20
|
# shellcheck disable=SC1091
|
|
21
21
|
. "$ICI/install.sh"
|
|
22
|
-
#
|
|
22
|
+
# The argocd module on: MySQL installed by an Application (#538)
|
|
23
23
|
# shellcheck source=SCRIPTDIR/../../argocd/catalog-argocd.sh
|
|
24
24
|
# shellcheck disable=SC1091
|
|
25
25
|
. "$ICI/../../argocd/catalog-argocd.sh"
|
|
@@ -30,233 +30,233 @@ MYSQL_IMAGE="${MYSQL_IMAGE:-mysql:8.4}"
|
|
|
30
30
|
MYSQL_MEMOIRE="${MYSQL_MEMOIRE:-1Gi}"
|
|
31
31
|
MYSQL_TAILLE="${MYSQL_TAILLE:-5Gi}"
|
|
32
32
|
MYSQL_ATTENTE="${MYSQL_ATTENTE:-300}"
|
|
33
|
-
#
|
|
34
|
-
refuse() { echo "devzone :
|
|
35
|
-
# Secret mysql-admin
|
|
33
|
+
# Standard refusal with a message and code 2
|
|
34
|
+
refuse() { echo "devzone : catalog mysql : $*" >&2; exit 2; }
|
|
35
|
+
# Secret mysql-admin of the services.sh hook: the same as the direct installation
|
|
36
36
|
services_secret_mysql() { mysql_secret; }
|
|
37
|
-
#
|
|
37
|
+
# Regenerates the .password view (non-blocking failure)
|
|
38
38
|
regenerer_identifiants() {
|
|
39
39
|
password_regenerate ||
|
|
40
|
-
echo "devzone :
|
|
40
|
+
echo "devzone : catalog mysql : grouped credentials not updated (devzone passwords)" >&2
|
|
41
41
|
}
|
|
42
|
-
#
|
|
42
|
+
# Shortcut for kubectl in the devzone-mysql namespace
|
|
43
43
|
k() { kubectl --context devzone -n "$NS" "$@"; }
|
|
44
|
-
#
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
contexte() {
|
|
44
|
+
# Does the devzone-mysql namespace exist? Administrator only (#430)
|
|
45
|
+
installed() { account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1; }
|
|
46
|
+
# Context of the module: the one of the devzone cluster
|
|
47
|
+
module_context() {
|
|
49
48
|
local c
|
|
50
|
-
c="$(
|
|
51
|
-
[ -n "$c" ] || refuse "
|
|
49
|
+
c="$(cluster_saved)"
|
|
50
|
+
[ -n "$c" ] || refuse "no cluster chosen: devzone enable mysql"
|
|
52
51
|
echo "$c"
|
|
53
52
|
}
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
|
|
53
|
+
# Failure marker of the module (same scheme as devzone's failure_file)
|
|
54
|
+
failure_file() { echo "$ETAT-failed-mysql"; }
|
|
55
|
+
# Project name: a simple SQL identifier, never escaped, not a reserved name
|
|
56
|
+
check_project_name() {
|
|
58
57
|
local p="${1:-}"
|
|
59
|
-
[ -n "$p" ] || refuse "
|
|
60
|
-
[[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "
|
|
58
|
+
[ -n "$p" ] || refuse "missing project name"
|
|
59
|
+
[[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "invalid project name: $p (lowercase, digits, _; starts with a letter)"
|
|
61
60
|
case "$p" in
|
|
62
|
-
mysql | information_schema | performance_schema | sys) refuse "
|
|
61
|
+
mysql | information_schema | performance_schema | sys) refuse "reserved name: $p" ;;
|
|
63
62
|
esac
|
|
64
63
|
}
|
|
65
|
-
#
|
|
66
|
-
|
|
67
|
-
#
|
|
64
|
+
# Random password for a new project
|
|
65
|
+
new_password() { openssl rand -hex 24; }
|
|
66
|
+
# Root password: from root.env of an existing installation, else admin-password
|
|
68
67
|
root_password() {
|
|
69
|
-
local
|
|
70
|
-
|
|
71
|
-
[ -z "$
|
|
72
|
-
[ -n "$
|
|
73
|
-
echo "$
|
|
68
|
+
local password
|
|
69
|
+
password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
|
|
70
|
+
[ -z "$password" ] && [ -f "$SECRETS/admin-password" ] && password="$(cat "$SECRETS/admin-password" 2>/dev/null || true)"
|
|
71
|
+
[ -n "$password" ] || refuse "MySQL root password not found (workspace/.mysql/root.env)"
|
|
72
|
+
echo "$password"
|
|
74
73
|
}
|
|
75
|
-
# mysql
|
|
74
|
+
# mysql as superuser in the pod; the password is never shown
|
|
76
75
|
mysql_admin() { k exec -i mysql-0 -c mysql -- mysql -uroot -p"$(root_password)" "$@"; }
|
|
77
|
-
#
|
|
78
|
-
|
|
76
|
+
# Number of databases, system databases excluded
|
|
77
|
+
database_count() {
|
|
79
78
|
local n
|
|
80
79
|
n="$(mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null | grep -vE '^(information_schema|mysql|performance_schema|sys)$' | grep -c . || true)"
|
|
81
80
|
echo "${n:-0}"
|
|
82
81
|
}
|
|
83
|
-
|
|
82
|
+
# Installs the module (the Argo CD path when the argocd module is on)
|
|
83
|
+
install_module() {
|
|
84
84
|
local CTX claim
|
|
85
|
-
CTX="$(
|
|
86
|
-
if !
|
|
87
|
-
echo "devzone :
|
|
85
|
+
CTX="$(module_context)"
|
|
86
|
+
if ! devzone_context_set "$CTX"; then
|
|
87
|
+
echo "devzone : catalog mysql : cannot set the devzone context on $CTX" >&2
|
|
88
88
|
return 1
|
|
89
89
|
fi
|
|
90
|
-
echo "▶ MySQL
|
|
90
|
+
echo "▶ MySQL on cluster $CTX (namespace $NS)…"
|
|
91
91
|
if catalogue_argocd_active mysql; then
|
|
92
|
-
|
|
92
|
+
mysql_install_argocd "$CTX"
|
|
93
93
|
return
|
|
94
94
|
fi
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
account_namespace "$CTX" "$NS"
|
|
96
|
+
namespace_isolate "$NS" >/dev/null
|
|
97
97
|
if k get statefulset mysql >/dev/null 2>&1; then
|
|
98
|
-
echo "devzone :
|
|
98
|
+
echo "devzone : catalog mysql : existing installation in $NS, adopted (volume and root.env kept)"
|
|
99
99
|
else
|
|
100
100
|
mysql_secret
|
|
101
|
-
claim="$(
|
|
102
|
-
|
|
101
|
+
claim="$(mysql_claim_choose "$NS")" || return 2
|
|
102
|
+
mysql_apply_chart "$NS" "$claim" || return 1
|
|
103
103
|
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
104
|
-
echo "devzone :
|
|
104
|
+
echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $NS describe pod mysql-0" >&2
|
|
105
105
|
return 1
|
|
106
106
|
fi
|
|
107
107
|
fi
|
|
108
108
|
mysql_secret
|
|
109
|
-
|
|
110
|
-
echo "✔ MySQL
|
|
109
|
+
relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
110
|
+
echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
|
|
111
111
|
regenerer_identifiants
|
|
112
112
|
}
|
|
113
|
-
#
|
|
114
|
-
# confirmation
|
|
115
|
-
|
|
116
|
-
local CTX
|
|
113
|
+
# Deletes the namespace (so the PVCs), keeps workspace/.mysql (#441):
|
|
114
|
+
# terminal confirmation [y/N], --yes required otherwise (refusal, code 2)
|
|
115
|
+
delete_data() {
|
|
116
|
+
local CTX yes="" arg answer
|
|
117
117
|
for arg in "$@"; do
|
|
118
118
|
case "$arg" in
|
|
119
|
-
--yes)
|
|
120
|
-
*) refuse "argument
|
|
119
|
+
--yes) yes=1 ;;
|
|
120
|
+
*) refuse "unknown argument: $arg" ;;
|
|
121
121
|
esac
|
|
122
122
|
done
|
|
123
|
-
if [ -z "$
|
|
124
|
-
|
|
125
|
-
printf '
|
|
126
|
-
read -r
|
|
127
|
-
case "$
|
|
128
|
-
|
|
129
|
-
*) echo "
|
|
123
|
+
if [ -z "$yes" ]; then
|
|
124
|
+
cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete-data --yes"
|
|
125
|
+
printf 'Delete namespace %s and all its volumes? [y/N] ' "$NS" >&2
|
|
126
|
+
read -r answer || answer=""
|
|
127
|
+
case "$answer" in
|
|
128
|
+
y | Y | yes) ;;
|
|
129
|
+
*) echo "Aborted: nothing was deleted."; return 0 ;;
|
|
130
130
|
esac
|
|
131
131
|
fi
|
|
132
|
-
CTX="$(
|
|
133
|
-
[ -n "$CTX" ] || refuse "
|
|
134
|
-
|
|
135
|
-
echo "▶
|
|
136
|
-
#
|
|
132
|
+
CTX="$(cluster_saved)"
|
|
133
|
+
[ -n "$CTX" ] || refuse "no cluster chosen: devzone enable mysql"
|
|
134
|
+
installed || refuse "module disabled: devzone enable mysql"
|
|
135
|
+
echo "▶ Deleting MySQL and its volumes on ${CTX}…"
|
|
136
|
+
# The Application goes first (#538): otherwise Argo CD recreates the namespace
|
|
137
137
|
catalogue_argocd_delete mysql >/dev/null 2>&1 || true
|
|
138
|
-
# RoleBinding
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
rm -f "$(
|
|
143
|
-
echo "✔ namespace $NS
|
|
138
|
+
# RoleBinding removed, then the namespace deleted by the administrator (#430)
|
|
139
|
+
account_remove "$CTX" "$NS" >/dev/null 2>&1 || true
|
|
140
|
+
account_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
|
|
141
|
+
relay_stop mysql
|
|
142
|
+
rm -f "$(failure_file)"
|
|
143
|
+
echo "✔ namespace $NS and volume deleted; workspace/.mysql/root.env kept"
|
|
144
144
|
regenerer_identifiants
|
|
145
145
|
}
|
|
146
|
-
#
|
|
147
|
-
|
|
146
|
+
# State (disabled, failed, ready, relay stopped): read by devzone, keep the words
|
|
147
|
+
module_status() {
|
|
148
148
|
local CTX
|
|
149
|
-
CTX="$(
|
|
150
|
-
if [ -z "$CTX" ] || !
|
|
151
|
-
echo "
|
|
149
|
+
CTX="$(cluster_saved)"
|
|
150
|
+
if [ -z "$CTX" ] || ! installed; then
|
|
151
|
+
echo "disabled"
|
|
152
152
|
return 0
|
|
153
153
|
fi
|
|
154
154
|
if [ "$(k get statefulset mysql -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
|
|
155
|
-
echo "
|
|
155
|
+
echo "failed on $CTX: devzone apply"
|
|
156
156
|
return 0
|
|
157
157
|
fi
|
|
158
|
-
if !
|
|
159
|
-
echo "
|
|
158
|
+
if ! relay_active mysql; then
|
|
159
|
+
echo "ready on $CTX, relay stopped: devzone apply"
|
|
160
160
|
return 0
|
|
161
161
|
fi
|
|
162
|
-
echo "
|
|
162
|
+
echo "ready on $CTX: 127.0.0.1:$MYSQL_PORT, $(database_count) database(s)"
|
|
163
163
|
}
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
local
|
|
167
|
-
|
|
164
|
+
# Creates the user and the database of a project; .env in 600, password kept
|
|
165
|
+
create_project() {
|
|
166
|
+
local project="${1:-}" renew="" file password arg
|
|
167
|
+
check_project_name "$project"
|
|
168
168
|
for arg in "${@:2}"; do
|
|
169
169
|
case "$arg" in
|
|
170
|
-
--new-password)
|
|
171
|
-
*) refuse "argument
|
|
170
|
+
--new-password) renew=1 ;;
|
|
171
|
+
*) refuse "unknown argument: $arg" ;;
|
|
172
172
|
esac
|
|
173
173
|
done
|
|
174
|
-
CTX="$(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if [ -z "$
|
|
178
|
-
|
|
174
|
+
CTX="$(module_context)"
|
|
175
|
+
installed || refuse "module disabled: devzone enable mysql"
|
|
176
|
+
file="$SECRETS/$project.env"
|
|
177
|
+
if [ -z "$renew" ] && [ -s "$file" ]; then
|
|
178
|
+
password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$file" 2>/dev/null | tail -1)"
|
|
179
179
|
else
|
|
180
|
-
|
|
180
|
+
password="$(new_password)"
|
|
181
181
|
fi
|
|
182
182
|
mysql_admin <<SQL
|
|
183
|
-
CREATE USER IF NOT EXISTS '$
|
|
184
|
-
ALTER USER '$
|
|
185
|
-
CREATE DATABASE IF NOT EXISTS $
|
|
186
|
-
GRANT ALL ON $
|
|
183
|
+
CREATE USER IF NOT EXISTS '$project'@'%' IDENTIFIED BY '$password';
|
|
184
|
+
ALTER USER '$project'@'%' IDENTIFIED BY '$password';
|
|
185
|
+
CREATE DATABASE IF NOT EXISTS $project;
|
|
186
|
+
GRANT ALL ON $project.* TO '$project'@'%';
|
|
187
187
|
SQL
|
|
188
188
|
mkdir -p "$SECRETS"
|
|
189
189
|
chmod 700 "$SECRETS"
|
|
190
190
|
(
|
|
191
191
|
umask 077
|
|
192
|
-
cat >"$
|
|
192
|
+
cat >"$file" <<ENV
|
|
193
193
|
MYSQL_HOST=127.0.0.1
|
|
194
194
|
MYSQL_PORT=$MYSQL_PORT
|
|
195
|
-
MYSQL_USER=$
|
|
196
|
-
MYSQL_PASSWORD=$
|
|
197
|
-
MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$
|
|
195
|
+
MYSQL_USER=$project
|
|
196
|
+
MYSQL_PASSWORD=$password
|
|
197
|
+
MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$project
|
|
198
198
|
ENV
|
|
199
199
|
)
|
|
200
|
-
echo "✔
|
|
200
|
+
echo "✔ database $project ready; credentials: $file"
|
|
201
201
|
regenerer_identifiants
|
|
202
202
|
}
|
|
203
|
-
#
|
|
204
|
-
|
|
203
|
+
# Lists the databases of the server
|
|
204
|
+
list_databases() {
|
|
205
205
|
local CTX
|
|
206
|
-
CTX="$(
|
|
207
|
-
|
|
208
|
-
# grep -v
|
|
206
|
+
CTX="$(module_context)"
|
|
207
|
+
installed || refuse "module disabled: devzone enable mysql"
|
|
208
|
+
# grep -v exits 1 with no user database: under pipefail, the list stays at 0
|
|
209
209
|
mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null |
|
|
210
210
|
{ grep -vE '^(information_schema|mysql|performance_schema|sys)$' || true; } |
|
|
211
|
-
awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (
|
|
211
|
+
awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (no database: devzone mysql create <project>)" }'
|
|
212
212
|
}
|
|
213
|
-
#
|
|
214
|
-
|
|
215
|
-
local
|
|
216
|
-
|
|
213
|
+
# Deletes the database and the user of a project (confirmation without --yes)
|
|
214
|
+
delete_project() {
|
|
215
|
+
local project="${1:-}" yes="" arg answer
|
|
216
|
+
check_project_name "$project"
|
|
217
217
|
for arg in "${@:2}"; do
|
|
218
218
|
case "$arg" in
|
|
219
|
-
--yes)
|
|
220
|
-
*) refuse "argument
|
|
219
|
+
--yes) yes=1 ;;
|
|
220
|
+
*) refuse "unknown argument: $arg" ;;
|
|
221
221
|
esac
|
|
222
222
|
done
|
|
223
|
-
CTX="$(
|
|
224
|
-
|
|
225
|
-
if [ -z "$
|
|
226
|
-
|
|
227
|
-
printf '
|
|
228
|
-
read -r
|
|
229
|
-
case "$
|
|
230
|
-
|
|
231
|
-
*) echo "
|
|
223
|
+
CTX="$(module_context)"
|
|
224
|
+
installed || refuse "module disabled: devzone enable mysql"
|
|
225
|
+
if [ -z "$yes" ]; then
|
|
226
|
+
cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete $project --yes"
|
|
227
|
+
printf 'Delete database %s and its user? [y/N] ' "$project" >&2
|
|
228
|
+
read -r answer || answer=""
|
|
229
|
+
case "$answer" in
|
|
230
|
+
y | Y | yes) ;;
|
|
231
|
+
*) echo "Aborted: nothing was deleted."; return 0 ;;
|
|
232
232
|
esac
|
|
233
233
|
fi
|
|
234
234
|
mysql_admin <<SQL
|
|
235
|
-
DROP DATABASE IF EXISTS $
|
|
236
|
-
DROP USER IF EXISTS '$
|
|
235
|
+
DROP DATABASE IF EXISTS $project;
|
|
236
|
+
DROP USER IF EXISTS '$project'@'%';
|
|
237
237
|
SQL
|
|
238
|
-
rm -f "$SECRETS/$
|
|
239
|
-
echo "✔
|
|
238
|
+
rm -f "$SECRETS/$project.env"
|
|
239
|
+
echo "✔ database $project deleted"
|
|
240
240
|
regenerer_identifiants
|
|
241
241
|
}
|
|
242
|
-
#
|
|
243
|
-
|
|
242
|
+
# Restarts the relay 127.0.0.1:3306 if the namespace exists
|
|
243
|
+
relay_restart() {
|
|
244
244
|
local CTX
|
|
245
|
-
CTX="$(
|
|
246
|
-
[ -n "$CTX" ] &&
|
|
245
|
+
CTX="$(cluster_saved)"
|
|
246
|
+
[ -n "$CTX" ] && installed && relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
247
247
|
}
|
|
248
248
|
case "${1:-}" in
|
|
249
|
-
install)
|
|
250
|
-
delete-data)
|
|
251
|
-
status)
|
|
252
|
-
create)
|
|
253
|
-
list)
|
|
254
|
-
delete)
|
|
249
|
+
install) install_module ;;
|
|
250
|
+
delete-data) delete_data "${@:2}" ;;
|
|
251
|
+
status) module_status ;;
|
|
252
|
+
create) create_project "${@:2}" ;;
|
|
253
|
+
list) list_databases ;;
|
|
254
|
+
delete) delete_project "${@:2}" ;;
|
|
255
255
|
volume) mysql_volume "$NS" "${@:2}" ;;
|
|
256
|
-
relay-start)
|
|
257
|
-
relay-stop)
|
|
256
|
+
relay-start) relay_restart ;;
|
|
257
|
+
relay-stop) relay_stop mysql ;;
|
|
258
258
|
*)
|
|
259
|
-
echo "devzone :
|
|
259
|
+
echo "devzone : catalog mysql : create <project> [--new-password] | list | delete <project> [--yes] | volume [<name>] [--delete <name>] [--yes] | delete-data [--yes]" >&2
|
|
260
260
|
exit 1
|
|
261
261
|
;;
|
|
262
262
|
esac
|