devzone 7.0.3 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +1 -8
- package/.devcontainer/catalog/app.sh +5 -12
- package/.devcontainer/cluster.sh +1 -11
- package/.devcontainer/devcontainer.json +1 -11
- package/.devcontainer/devzone +18 -10
- package/.devcontainer/devzone-cluster.sh +1 -1
- package/.devcontainer/devzone-modules.sh +7 -2
- package/.devcontainer/devzone-repair.sh +10 -19
- package/.devcontainer/devzone-services.sh +21 -20
- package/.devcontainer/devzone-status.sh +5 -12
- package/.devcontainer/help.sh +3 -4
- package/.devcontainer/isolation.sh +1 -1
- package/.devcontainer/kube-account.sh +12 -173
- package/.devcontainer/metrics-server.sh +1 -1
- package/.devcontainer/packages.sh +2 -2
- package/.devcontainer/ports-json.sh +0 -4
- package/.devcontainer/ports.sh +6 -102
- package/.devcontainer/state-json.sh +5 -14
- package/.devcontainer/versions.env +2 -2
- package/.devcontainer/workspace-init.sh +1 -2
- package/Makefile +4 -4
- package/README.md +13 -20
- 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/manage/devzone +4 -4
- package/package.json +1 -1
- package/.devcontainer/argocd/argocd.sh +0 -222
- package/.devcontainer/argocd/catalog-argocd.sh +0 -119
- package/.devcontainer/argocd/services-hook.sh +0 -181
- package/.devcontainer/catalog/mysql/install.sh +0 -87
- package/.devcontainer/catalog/mysql/mysql.sh +0 -262
- package/.devcontainer/catalog/mysql/volume.sh +0 -71
- package/.devcontainer/git-identity.sh +0 -28
- package/.devcontainer/gitlab/argocd.sh +0 -54
- package/.devcontainer/gitlab/chart.sh +0 -39
- package/.devcontainer/gitlab/gitlab.sh +0 -168
- package/.devcontainer/gitlab/installation.sh +0 -193
- package/.devcontainer/gitlab/secrets.sh +0 -95
- package/.devcontainer/gitlab/seed.sh +0 -204
- package/.devcontainer/gitlab/test-gitlab-restes.sh +0 -16
- package/.devcontainer/gitlab/test-gitlab.sh +0 -489
- package/.devcontainer/kind-wrapper.sh +0 -45
- package/.devcontainer/kube-config.sh +0 -78
- package/.devcontainer/kube-reachable.sh +0 -64
- package/.devcontainer/ports-auto.sh +0 -247
- package/.devcontainer/post-create.sh +0 -91
- package/.devcontainer/postgres/postgres.sh +0 -309
- package/.devcontainer/startup.sh +0 -65
package/manage/devzone
CHANGED
|
@@ -161,10 +161,10 @@ devzone $(version): development workspace in a Kubernetes cluster
|
|
|
161
161
|
in a devzone folder: replaces the package files with those of
|
|
162
162
|
the installed package, after backing up the replaced files in
|
|
163
163
|
.devzone.backup/ (the new image is used at the next workspace start)
|
|
164
|
-
devzone uninstall
|
|
165
|
-
folder
|
|
166
|
-
|
|
167
|
-
workspace/ is kept
|
|
164
|
+
devzone uninstall [--yes]
|
|
165
|
+
in a devzone folder: removes Kubernetes objects of this devzone
|
|
166
|
+
instance (namespaces, Argo CD Applications, temporary accounts,
|
|
167
|
+
.devzone.* files); workspace/ is kept; asks for confirmation
|
|
168
168
|
devzone workspace start|stop|status|shell|update
|
|
169
169
|
devzone workspace vscode|copy-to|copy-from|clone
|
|
170
170
|
Kubernetes workspace: drives the devzone-workspace chart
|
package/package.json
CHANGED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Module argocd (#411): Argo CD in the devzone services cluster.
|
|
3
|
-
# argocd.sh install | uninstall | status | relay-start | relay-stop
|
|
4
|
-
# argocd.sh app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>
|
|
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
|
-
set -euo pipefail
|
|
9
|
-
|
|
10
|
-
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
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
|
-
# shellcheck source=SCRIPTDIR/../cluster.sh
|
|
15
|
-
# shellcheck disable=SC1091
|
|
16
|
-
. "$ICI/../cluster.sh"
|
|
17
|
-
# shellcheck source=SCRIPTDIR/../password.sh
|
|
18
|
-
# shellcheck disable=SC1091
|
|
19
|
-
. "$ICI/../password.sh"
|
|
20
|
-
# Network isolation: namespace_isolate, applied with the devzone-argocd namespace
|
|
21
|
-
# shellcheck source=SCRIPTDIR/../isolation.sh
|
|
22
|
-
# shellcheck disable=SC1091
|
|
23
|
-
. "$ICI/../isolation.sh"
|
|
24
|
-
# Shared memory check of the services cluster (#608): quantity_ki and
|
|
25
|
-
# memory_cluster_ki.
|
|
26
|
-
# shellcheck source=SCRIPTDIR/../memory.sh
|
|
27
|
-
# shellcheck disable=SC1091
|
|
28
|
-
. "$ICI/../memory.sh"
|
|
29
|
-
|
|
30
|
-
NS=devzone-argocd
|
|
31
|
-
SECRETS="$RACINE/workspace/.argocd"
|
|
32
|
-
# Pinned argo-cd chart version, relay port and install wait
|
|
33
|
-
ARGOCD_VERSION="${ARGOCD_VERSION:-10.14.0}"
|
|
34
|
-
ARGOCD_PORT="${ARGOCD_PORT:-8443}"
|
|
35
|
-
ARGOCD_ATTENTE="${ARGOCD_ATTENTE:-600}"
|
|
36
|
-
|
|
37
|
-
# Module refusal: prefixed message and code 2 (same convention as postgres)
|
|
38
|
-
refuse() { echo "devzone : argocd : $*" >&2; exit 2; }
|
|
39
|
-
|
|
40
|
-
# Grouped credentials view: a failure never blocks the operation
|
|
41
|
-
regenerate_credentials() {
|
|
42
|
-
password_regenerate ||
|
|
43
|
-
echo "devzone : argocd : grouped credentials not updated (devzone passwords)" >&2
|
|
44
|
-
}
|
|
45
|
-
|
|
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
|
-
return 2
|
|
53
|
-
fi
|
|
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
|
-
return 2
|
|
57
|
-
fi
|
|
58
|
-
}
|
|
59
|
-
|
|
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
|
-
}
|
|
65
|
-
|
|
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
|
-
local ctx
|
|
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
|
-
}
|
|
77
|
-
|
|
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
|
-
-o jsonpath='{.data.password}' 2>/dev/null)"; then
|
|
84
|
-
echo "devzone : argocd : secret argocd-initial-admin-secret not found" >&2
|
|
85
|
-
return 1
|
|
86
|
-
fi
|
|
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
|
-
return 1
|
|
91
|
-
fi
|
|
92
|
-
mkdir -p "$SECRETS"
|
|
93
|
-
chmod 700 "$SECRETS"
|
|
94
|
-
(
|
|
95
|
-
umask 077
|
|
96
|
-
cat >"$SECRETS/admin.env" <<ENV
|
|
97
|
-
ARGOCD_URL=https://127.0.0.1:$ARGOCD_PORT
|
|
98
|
-
ARGOCD_USER=admin
|
|
99
|
-
ARGOCD_PASSWORD=$pw
|
|
100
|
-
ENV
|
|
101
|
-
)
|
|
102
|
-
chmod 600 "$SECRETS/admin.env"
|
|
103
|
-
}
|
|
104
|
-
|
|
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
|
-
# Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
|
|
113
|
-
# first, then installed from the local chart (#538)
|
|
114
|
-
helm dependency build "$RACINE/charts/devzone-argocd" >/dev/null
|
|
115
|
-
account_helm "$(account_context)" upgrade --install argocd \
|
|
116
|
-
"$RACINE/charts/devzone-argocd" \
|
|
117
|
-
--namespace "$NS" \
|
|
118
|
-
--create-namespace \
|
|
119
|
-
--timeout "${ARGOCD_ATTENTE}s" \
|
|
120
|
-
--wait
|
|
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
|
-
}
|
|
126
|
-
|
|
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
|
-
local ctx
|
|
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
|
-
fi
|
|
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
|
-
fi
|
|
142
|
-
rm -rf "$SECRETS"
|
|
143
|
-
echo "✔ argocd module disabled; the services stay, under direct helm."
|
|
144
|
-
regenerate_credentials
|
|
145
|
-
}
|
|
146
|
-
|
|
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"
|
|
152
|
-
return 0
|
|
153
|
-
fi
|
|
154
|
-
if ! relay_active argocd; then
|
|
155
|
-
echo "ready, relay stopped: devzone apply"
|
|
156
|
-
else
|
|
157
|
-
echo "ready: https://127.0.0.1:$ARGOCD_PORT"
|
|
158
|
-
fi
|
|
159
|
-
}
|
|
160
|
-
|
|
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"
|
|
165
|
-
fi
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
# Applications of the projects (#516): shared with the workstation (apps.sh),
|
|
169
|
-
# here with the limited devzone context (aggregate roles of the chart)
|
|
170
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
171
|
-
APPS_CMD="devzone argocd app"
|
|
172
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
173
|
-
APPS_GENERATOR="$ICI/application.sh"
|
|
174
|
-
# shellcheck disable=SC2034 # read by apps.sh: GitLab namespace of this instance
|
|
175
|
-
APPS_GITLAB_NS="devzone-gitlab${INSTANCE_SUFFIX}"
|
|
176
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
177
|
-
APPS_GITLAB_TOKEN_FILE="$RACINE/workspace/.gitlab/root-token"
|
|
178
|
-
# shellcheck disable=SC2034 # read by gitops.sh
|
|
179
|
-
GITOPS_CMD="devzone argocd init"
|
|
180
|
-
# shellcheck disable=SC2034 # read by conf.sh and apps.sh: .argocd.conf of the instance
|
|
181
|
-
ARGOCD_CONF_DIR="$RACINE"
|
|
182
|
-
# shellcheck disable=SC2034
|
|
183
|
-
ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
|
|
184
|
-
# shellcheck source=SCRIPTDIR/conf.sh
|
|
185
|
-
# shellcheck disable=SC1091
|
|
186
|
-
. "$ICI/conf.sh"
|
|
187
|
-
# shellcheck source=SCRIPTDIR/gitops.sh
|
|
188
|
-
# shellcheck disable=SC1091
|
|
189
|
-
. "$ICI/gitops.sh"
|
|
190
|
-
# shellcheck source=SCRIPTDIR/apps.sh
|
|
191
|
-
# shellcheck disable=SC1091
|
|
192
|
-
. "$ICI/apps.sh"
|
|
193
|
-
argocd_kubectl() { kubectl --context devzone "$@"; }
|
|
194
|
-
|
|
195
|
-
case "${1:-}" in
|
|
196
|
-
install) do_install ;;
|
|
197
|
-
uninstall) do_uninstall ;;
|
|
198
|
-
status) do_status ;;
|
|
199
|
-
relay-start) do_relay_start ;;
|
|
200
|
-
relay-stop) relay_stop argocd ;;
|
|
201
|
-
init)
|
|
202
|
-
# GitOps repository of the user (#516): created or designated, then
|
|
203
|
-
# the root Application when the module is installed
|
|
204
|
-
gitops_init "${@:2}" || exit $?
|
|
205
|
-
if is_installed; then gitops_root; fi
|
|
206
|
-
;;
|
|
207
|
-
apply)
|
|
208
|
-
is_installed || refuse "module off: devzone enable argocd"
|
|
209
|
-
gitops_init && gitops_root && apps_reconcile
|
|
210
|
-
;;
|
|
211
|
-
app)
|
|
212
|
-
if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
|
|
213
|
-
refuse "in the workspace pod, on the workstation: devzone workspace argocd app ${*:2}"
|
|
214
|
-
fi
|
|
215
|
-
is_installed || refuse "module off: devzone enable argocd"
|
|
216
|
-
argocd_app "${@:2}"
|
|
217
|
-
;;
|
|
218
|
-
*)
|
|
219
|
-
echo "devzone argocd : install | uninstall | status | init [--repo <url>|--none] | apply | app add|list|remove" >&2
|
|
220
|
-
exit 1
|
|
221
|
-
;;
|
|
222
|
-
esac
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Argo CD for the catalogue applications in the container (#538): the module
|
|
3
|
-
# mysql and the catalogue install their application as the Application
|
|
4
|
-
# devzone-<app> (services.sh) when the module argocd is active, instead of
|
|
5
|
-
# the manifest applied by hand. The namespace (account_namespace of
|
|
6
|
-
# cluster.sh, isolation.sh) and the secret <app>-admin (mirror
|
|
7
|
-
# workspace/.<app>/) stay created apart, out of Git; Argo CD holds the chart
|
|
8
|
-
# charts/devzone-<app> of the devzone repository at the revision.
|
|
9
|
-
# catalogue_argocd_active <app> on, installed, chart and revision
|
|
10
|
-
# catalogue_argocd_apply <app> <ns> ... the Application, then refreshed
|
|
11
|
-
# catalogue_argocd_application_exists <app>
|
|
12
|
-
# catalogue_argocd_delete <app> Application deleted (namespace
|
|
13
|
-
# and volumes stay)
|
|
14
|
-
# argocd_revision: DEVZONE_ARGOCD_REVISION, else v<package.json version>;
|
|
15
|
-
# empty on a development clone (0.0.0): the local chart is not in Git, the
|
|
16
|
-
# manifest path keeps serving. The includer defines RACINE and ETAT (the
|
|
17
|
-
# devzone modules file), and the secret hook services_secret_<app> (mirrored,
|
|
18
|
-
# never printed). bash 3.2 (macOS).
|
|
19
|
-
|
|
20
|
-
CATALOGUE_ARGOCD_WIRED="${CATALOGUE_ARGOCD_WIRED:-}"
|
|
21
|
-
|
|
22
|
-
# Line argocd=on of .devzone.modules of the container
|
|
23
|
-
catalogue_argocd_module_on() {
|
|
24
|
-
grep -E '^argocd=' "${ETAT:-}" 2>/dev/null | tail -1 | cut -d= -f2- | grep -qx on
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
# Git revision for the Applications: DEVZONE_ARGOCD_REVISION, else the tag of
|
|
28
|
-
# the package version of the image; empty on a development clone
|
|
29
|
-
argocd_revision() {
|
|
30
|
-
local version
|
|
31
|
-
if [ -n "${DEVZONE_ARGOCD_REVISION:-}" ]; then
|
|
32
|
-
printf '%s' "$DEVZONE_ARGOCD_REVISION"
|
|
33
|
-
return 0
|
|
34
|
-
fi
|
|
35
|
-
version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$RACINE/package.json" | head -1)"
|
|
36
|
-
case "$version" in
|
|
37
|
-
'' | 0.0.0) ;;
|
|
38
|
-
*) printf 'v%s' "$version" ;;
|
|
39
|
-
esac
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
# Sources the shared pieces once: conf.sh and gitops.sh with the
|
|
43
|
-
# .argocd.conf of the devzone folder, services.sh with the hooks of the
|
|
44
|
-
# container (limited devzone context)
|
|
45
|
-
catalogue_argocd_load() {
|
|
46
|
-
[ -n "$CATALOGUE_ARGOCD_WIRED" ] && return 0
|
|
47
|
-
# The Applications are applied with the devzone context, the only one the
|
|
48
|
-
# container holds (services.sh and gitops.sh call argocd_kubectl)
|
|
49
|
-
# shellcheck disable=SC2317 # called by services.sh and gitops.sh
|
|
50
|
-
argocd_kubectl() { kubectl --context devzone "$@"; }
|
|
51
|
-
# shellcheck disable=SC2034 # read by apps.sh
|
|
52
|
-
APPS_CMD="devzone argocd app"
|
|
53
|
-
# shellcheck disable=SC2034 # read by apps.sh and services.sh
|
|
54
|
-
APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
|
|
55
|
-
# shellcheck disable=SC2034 # read by gitops.sh
|
|
56
|
-
GITOPS_CMD="devzone argocd init"
|
|
57
|
-
# shellcheck disable=SC2034 # read by conf.sh and apps.sh
|
|
58
|
-
ARGOCD_CONF_DIR="$RACINE"
|
|
59
|
-
# shellcheck disable=SC2034
|
|
60
|
-
ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
|
|
61
|
-
# shellcheck source=SCRIPTDIR/conf.sh
|
|
62
|
-
# shellcheck disable=SC1091
|
|
63
|
-
. "$RACINE/.devcontainer/argocd/conf.sh"
|
|
64
|
-
# shellcheck source=SCRIPTDIR/gitops.sh
|
|
65
|
-
# shellcheck disable=SC1091
|
|
66
|
-
. "$RACINE/.devcontainer/argocd/gitops.sh"
|
|
67
|
-
# shellcheck source=SCRIPTDIR/services.sh
|
|
68
|
-
# shellcheck disable=SC1091
|
|
69
|
-
. "$RACINE/.devcontainer/argocd/services.sh"
|
|
70
|
-
# shellcheck disable=SC2034 # read by services.sh
|
|
71
|
-
DEVZONE_REPO_URL="${DEVZONE_REPO_URL:-https://github.com/SimBienvenueHoulBoumi/devzone.git}"
|
|
72
|
-
CATALOGUE_ARGOCD_WIRED=1
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
# The catalogue application <app> can be an Argo CD Application: the module
|
|
76
|
-
# argocd is on and installed, the chart exists in charts/, the revision is
|
|
77
|
-
# known (a development clone keeps the manifest path)
|
|
78
|
-
catalogue_argocd_active() {
|
|
79
|
-
local app="$1"
|
|
80
|
-
catalogue_argocd_module_on || return 1
|
|
81
|
-
[ -d "$RACINE/charts/devzone-$app" ] || return 1
|
|
82
|
-
account_admin "$(account_context)" get namespace devzone-argocd >/dev/null 2>&1 || return 1
|
|
83
|
-
catalogue_argocd_load
|
|
84
|
-
[ -n "$(argocd_revision)" ]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
# Applies the Application devzone-<app> (kind service) with the chart
|
|
88
|
-
# charts/devzone-<app> at the revision; image, port, memory and size are the
|
|
89
|
-
# values of app.conf passed as helm parameters, <extra> holds the ones of the
|
|
90
|
-
# application itself (claim). In the GitOps repository when one is designated
|
|
91
|
-
# (.argocd.conf), applied directly otherwise (gitops.sh)
|
|
92
|
-
catalogue_argocd_apply() {
|
|
93
|
-
local app="$1" ns="$2" image="$3" port="$4" memory="$5" size="$6" params extra="${7:-}"
|
|
94
|
-
catalogue_argocd_load
|
|
95
|
-
chart_require "$app" || return $?
|
|
96
|
-
params="image=$image port=$port memory=$memory size=$size"
|
|
97
|
-
[ -n "$extra" ] && params="$params $extra"
|
|
98
|
-
# shellcheck disable=SC2086
|
|
99
|
-
gitops_apply_application "devzone-$app" service "$ns" "$DEVZONE_REPO_URL" \
|
|
100
|
-
"$(argocd_revision)" "charts/devzone-$app" $params || return 1
|
|
101
|
-
# Argo CD reads Git every 3 min: an immediate refresh of the Application
|
|
102
|
-
kubectl --context devzone -n devzone-argocd annotate application.argoproj.io \
|
|
103
|
-
"devzone-$app" argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
# The Application devzone-<app> exists in devzone-argocd
|
|
107
|
-
catalogue_argocd_application_exists() {
|
|
108
|
-
catalogue_argocd_module_on || return 1
|
|
109
|
-
kubectl --context devzone -n devzone-argocd get application.argoproj.io "devzone-$1" >/dev/null 2>&1
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
# Deletes the Application devzone-<app>: its resources go with it, the
|
|
113
|
-
# namespace and the volumes stay (the explicit removal of the data keeps its
|
|
114
|
-
# own command); nothing to delete when the Application is absent
|
|
115
|
-
catalogue_argocd_delete() {
|
|
116
|
-
catalogue_argocd_application_exists "$1" || return 0
|
|
117
|
-
catalogue_argocd_load
|
|
118
|
-
gitops_delete_application "devzone-$1"
|
|
119
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Services of the container held by Argo CD (#559, step 5). Called by devzone
|
|
3
|
-
# (changer) after the state line is written, before the helm-direct path:
|
|
4
|
-
# services-hook.sh <svc> <on|off>
|
|
5
|
-
# postgres and mysql with the module argocd installed and held: enable writes
|
|
6
|
-
# [services] <svc> = on and reconciles it (services_reconcile, services.sh),
|
|
7
|
-
# then waits for the pods and starts the relay; disable removes the
|
|
8
|
-
# Application (its resources leave with it, namespace and volumes stay).
|
|
9
|
-
# argocd off: the Applications of postgres, mysql and gitlab leave with their
|
|
10
|
-
# finalizer dropped first, so the resources stay for the helm-direct path
|
|
11
|
-
# (adoption, no recreation); then devzone removes Argo CD.
|
|
12
|
-
# Exit codes read by devzone: 0 done through Argo CD (devzone stops there),
|
|
13
|
-
# 3 not concerned or released (devzone goes on as before), 1 failed.
|
|
14
|
-
# gitlab is not held here: its Application comes from gitlab/argocd.sh (step 4).
|
|
15
|
-
# Sourced by the tests with stubs; run as a script by devzone. bash 3.2.
|
|
16
|
-
|
|
17
|
-
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
18
|
-
# RACINE: the code tree (libraries, charts); STATE_RACINE: the devzone folder
|
|
19
|
-
# (workspace/ secrets, .argocd.conf), the same folder unless DEVZONE_ROOT says so
|
|
20
|
-
RACINE="$(dirname "$(dirname "$ICI")")"
|
|
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
|
-
HOOK_SERVICES="postgres mysql"
|
|
26
|
-
|
|
27
|
-
# shellcheck source=SCRIPTDIR/../cluster.sh
|
|
28
|
-
# shellcheck disable=SC1091
|
|
29
|
-
. "$ICI/../cluster.sh"
|
|
30
|
-
# shellcheck source=SCRIPTDIR/catalog-argocd.sh
|
|
31
|
-
# shellcheck disable=SC1091
|
|
32
|
-
. "$ICI/catalog-argocd.sh"
|
|
33
|
-
|
|
34
|
-
# Loads the Argo CD pieces (conf, gitops, services with the context devzone)
|
|
35
|
-
# and the list of services reconciled here
|
|
36
|
-
hook_load() {
|
|
37
|
-
DEVZONE_ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$STATE_RACINE/.argocd.conf}"
|
|
38
|
-
export DEVZONE_ARGOCD_CONF
|
|
39
|
-
catalogue_argocd_load
|
|
40
|
-
# shellcheck disable=SC2034 # read by services.sh (services_reconcile)
|
|
41
|
-
SERVICES_LIST="$HOOK_SERVICES"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
# The relay script of a service (started once its pods are ready)
|
|
45
|
-
hook_script() {
|
|
46
|
-
case "$1" in
|
|
47
|
-
postgres) printf '%s' "$ICI/../postgres/postgres.sh" ;;
|
|
48
|
-
mysql) printf '%s' "$ICI/../catalog/mysql/mysql.sh" ;;
|
|
49
|
-
esac
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
# Waits for the pods of devzone-<svc> to be ready (the Application syncs
|
|
53
|
-
# within a few minutes); the relay needs a ready pod to forward to
|
|
54
|
-
hook_wait() {
|
|
55
|
-
local ns="devzone-$1" tour=0
|
|
56
|
-
while [ "$tour" -lt 60 ]; do
|
|
57
|
-
if argocd_kubectl -n "$ns" get pods -o name 2>/dev/null | grep -q .; then
|
|
58
|
-
argocd_kubectl -n "$ns" wait --for=condition=Ready pod --all --timeout=300s >/dev/null 2>&1 && return 0
|
|
59
|
-
fi
|
|
60
|
-
tour=$((tour + 1))
|
|
61
|
-
sleep 5
|
|
62
|
-
done
|
|
63
|
-
echo "✖ $1 : pods not ready in devzone-$1 (devzone argocd status)" >&2
|
|
64
|
-
return 1
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
# Starts the relay of the service, after the pods are ready
|
|
68
|
-
hook_relay() {
|
|
69
|
-
bash "$(hook_script "$1")" relay-start
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
# Admin secret <svc>-admin of the namespace, created apart and mirrored in
|
|
73
|
-
# workspace/.<svc>/admin-password (600); an existing secret is kept, never
|
|
74
|
-
# printed. The same mirror the helm-direct installers read.
|
|
75
|
-
services_secret_admin() {
|
|
76
|
-
local svc="$1" ns="$2" secret="$3" dir file password=""
|
|
77
|
-
dir="$STATE_RACINE/workspace/.$svc"
|
|
78
|
-
file="$dir/admin-password"
|
|
79
|
-
mkdir -p "$dir"
|
|
80
|
-
chmod 700 "$dir"
|
|
81
|
-
password="$(argocd_kubectl -n "$ns" get secret "$secret" -o jsonpath='{.data.password}' 2>/dev/null | base64 -d 2>/dev/null)" || password=""
|
|
82
|
-
if [ -n "$password" ]; then
|
|
83
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
84
|
-
else
|
|
85
|
-
if [ ! -s "$file" ]; then
|
|
86
|
-
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
87
|
-
fi
|
|
88
|
-
argocd_kubectl -n "$ns" create secret generic "$secret" --from-file=password="$file" >/dev/null
|
|
89
|
-
fi
|
|
90
|
-
chmod 600 "$file"
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
# Secret hooks of services_reconcile: the superuser secret of each service
|
|
94
|
-
services_secret_postgres() { services_secret_admin postgres devzone-postgres postgres-admin; }
|
|
95
|
-
# The superuser secret of MySQL, the same way
|
|
96
|
-
services_secret_mysql() { services_secret_admin mysql devzone-mysql mysql-admin; }
|
|
97
|
-
|
|
98
|
-
# Value of a key of the MySQL application file (app.conf, read as text)
|
|
99
|
-
app_value() { sed -n "s/^$1=//p" "$APP_CONF" 2>/dev/null | tail -1; }
|
|
100
|
-
|
|
101
|
-
# Parameters of the MySQL chart: image, port, memory and size of app.conf, and
|
|
102
|
-
# the claim of the one existing volume (*-mysql-0); several volumes: refused,
|
|
103
|
-
# as the helm-direct installer does (#440)
|
|
104
|
-
services_chart_mysql() {
|
|
105
|
-
local liste claim="" image port memoire taille
|
|
106
|
-
image="$(app_value image)"
|
|
107
|
-
port="$(app_value port)"
|
|
108
|
-
memoire="$(app_value memoire)"
|
|
109
|
-
taille="$(app_value taille)"
|
|
110
|
-
liste="$(argocd_kubectl -n devzone-mysql get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | grep -E '\-mysql-0$' || true)"
|
|
111
|
-
if [ -n "$liste" ]; then
|
|
112
|
-
if [ "$(printf '%s\n' "$liste" | grep -c .)" -gt 1 ]; then
|
|
113
|
-
echo "✖ several MySQL volumes in devzone-mysql: devzone mysql volume <name> picks the mounted one" >&2
|
|
114
|
-
return 2
|
|
115
|
-
fi
|
|
116
|
-
claim=" claim=${liste%-mysql-0}"
|
|
117
|
-
fi
|
|
118
|
-
printf 'image=%s port=%s memory=%s size=%s%s' "${image:-mysql:8.4}" "${port:-3306}" \
|
|
119
|
-
"${memoire:-1Gi}" "${taille:-5Gi}" "$claim"
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
# Enable: through Argo CD only when the module is held (installed, chart and
|
|
123
|
-
# revision known); otherwise 3, the helm-direct installer runs as before
|
|
124
|
-
hook_on() {
|
|
125
|
-
local svc="$1"
|
|
126
|
-
catalogue_argocd_active "$svc" || return 3
|
|
127
|
-
services_note "$svc" on || return 1
|
|
128
|
-
services_reconcile || return 1
|
|
129
|
-
echo "▶ $svc as an Argo CD Application (charts/devzone-$svc at $(argocd_revision))…"
|
|
130
|
-
hook_wait "$svc" || return 1
|
|
131
|
-
hook_relay "$svc" || return 1
|
|
132
|
-
echo "✔ $svc held by Argo CD ([services] $svc = on in .argocd.conf)"
|
|
133
|
-
return 0
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
# Disable: the Application leaves with its resources (cascade); 3 so that the
|
|
137
|
-
# usual uninstall of the service goes on and keeps its data rules
|
|
138
|
-
hook_off() {
|
|
139
|
-
local svc="$1"
|
|
140
|
-
catalogue_argocd_application_exists "$svc" || return 3
|
|
141
|
-
services_note "$svc" off || return 1
|
|
142
|
-
gitops_delete_application "devzone-$svc" || return 1
|
|
143
|
-
echo "✔ Application devzone-$svc removed (its resources leave with it)"
|
|
144
|
-
return 3
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
# argocd off: each Application of the services leaves with its finalizer
|
|
148
|
-
# dropped first (gitops_delete_application keep): the resources stay for the
|
|
149
|
-
# helm-direct path. The module is already off when this runs, so the check
|
|
150
|
-
# is on the Application itself, not on the module state.
|
|
151
|
-
hook_release() {
|
|
152
|
-
local svc app
|
|
153
|
-
for svc in postgres mysql gitlab; do
|
|
154
|
-
app="devzone-$svc"
|
|
155
|
-
argocd_kubectl -n devzone-argocd get application.argoproj.io "$app" >/dev/null 2>&1 || continue
|
|
156
|
-
argocd_kubectl -n devzone-argocd patch application.argoproj.io "$app" --type merge \
|
|
157
|
-
-p '{"metadata":{"finalizers":null}}' >/dev/null 2>&1 || true
|
|
158
|
-
gitops_delete_application "$app" keep || return 1
|
|
159
|
-
case "$svc" in
|
|
160
|
-
postgres | mysql) services_note "$svc" off || return 1 ;;
|
|
161
|
-
esac
|
|
162
|
-
echo "✔ Application $app released: its resources stay for the helm-direct path"
|
|
163
|
-
done
|
|
164
|
-
return 3
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
# Dispatch: the pair service and action decides; anything else is not concerned
|
|
168
|
-
hook_main() {
|
|
169
|
-
local svc="${1:-}" action="${2:-}"
|
|
170
|
-
case "$svc:$action" in
|
|
171
|
-
argocd:off) hook_load && hook_release ;;
|
|
172
|
-
postgres:on | mysql:on) hook_load && hook_on "$svc" "${@:3}" ;;
|
|
173
|
-
postgres:off | mysql:off) hook_load && hook_off "$svc" ;;
|
|
174
|
-
*) return 3 ;;
|
|
175
|
-
esac
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
179
|
-
hook_main "$@"
|
|
180
|
-
exit $?
|
|
181
|
-
fi
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# MySQL installation (#440): secret, chart and reinstallation on a volume.
|
|
3
|
-
# shellcheck source=SCRIPTDIR/../../chart-direct.sh
|
|
4
|
-
# shellcheck disable=SC1091
|
|
5
|
-
. "$ICI/../../chart-direct.sh"
|
|
6
|
-
|
|
7
|
-
# Admin secret (mysql-admin): root.env or existing secret, never regenerated.
|
|
8
|
-
mysql_secret() {
|
|
9
|
-
local password file="$SECRETS/admin-password"
|
|
10
|
-
mkdir -p "$SECRETS"
|
|
11
|
-
chmod 700 "$SECRETS"
|
|
12
|
-
if k get secret mysql-admin >/dev/null 2>&1; then
|
|
13
|
-
password="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
|
|
14
|
-
(umask 077 && printf '%s' "$password" >"$file")
|
|
15
|
-
return 0
|
|
16
|
-
fi
|
|
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
|
-
fi
|
|
25
|
-
}
|
|
26
|
-
|
|
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
|
-
if k rollout status statefulset/mysql --timeout=10s >/dev/null 2>&1; then
|
|
33
|
-
return 0
|
|
34
|
-
fi
|
|
35
|
-
sleep 5
|
|
36
|
-
done
|
|
37
|
-
echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $1 -n $NS describe pod mysql-0" >&2
|
|
38
|
-
return 1
|
|
39
|
-
}
|
|
40
|
-
|
|
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
|
-
local CTX="$1" claim extra=""
|
|
46
|
-
mysql_secret
|
|
47
|
-
claim="$(mysql_claim_choose "$NS")" || return 2
|
|
48
|
-
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
49
|
-
catalogue_argocd_apply mysql "$NS" "$MYSQL_IMAGE" "$MYSQL_PORT" \
|
|
50
|
-
"$MYSQL_MEMOIRE" "$MYSQL_TAILLE" "$extra" || return 1
|
|
51
|
-
mysql_wait "$CTX" || return 1
|
|
52
|
-
mysql_secret
|
|
53
|
-
relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
54
|
-
echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
|
|
55
|
-
regenerer_identifiants
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
# Installs the chart charts/devzone-mysql with the chosen claim (#440, #559)
|
|
59
|
-
mysql_apply_chart() {
|
|
60
|
-
local ns="$1" claim="$2"
|
|
61
|
-
chart_install mysql "$ns" "image=$MYSQL_IMAGE" "port=$MYSQL_PORT" \
|
|
62
|
-
"memory=$MYSQL_MEMOIRE" "size=$MYSQL_TAILLE" "claim=$claim"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
# (Re)installs MySQL on the requested claim, PVC data kept (#440)
|
|
66
|
-
mysql_install_claim() {
|
|
67
|
-
local ns="$1" claim="$2" CTX
|
|
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
|
-
return 1
|
|
72
|
-
fi
|
|
73
|
-
echo "▶ MySQL on cluster $CTX (namespace $ns, volume ${claim}-mysql-0)…"
|
|
74
|
-
account_namespace "$CTX" "$ns"
|
|
75
|
-
namespace_isolate "$ns" >/dev/null
|
|
76
|
-
mysql_secret
|
|
77
|
-
k delete statefulset mysql --ignore-not-found >/dev/null 2>&1 || true
|
|
78
|
-
mysql_apply_chart "$ns" "$claim" || return 1
|
|
79
|
-
if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
|
|
80
|
-
echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $ns describe pod mysql-0" >&2
|
|
81
|
-
return 1
|
|
82
|
-
fi
|
|
83
|
-
mysql_secret
|
|
84
|
-
relay_start mysql "$CTX" "$ns" svc/mysql 3306:3306
|
|
85
|
-
echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
|
|
86
|
-
regenerer_identifiants
|
|
87
|
-
}
|