devzone 0.42.1 → 0.43.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 +1 -1
- package/.devcontainer/argocd/catalogue-argocd.sh +4 -0
- package/.devcontainer/argocd/gitops-gitlab.sh +127 -0
- package/.devcontainer/argocd/gitops.sh +12 -2
- package/.devcontainer/argocd/services-hook.sh +181 -0
- package/.devcontainer/catalogue/app.sh +7 -8
- package/.devcontainer/catalogue/mysql/installer.sh +9 -8
- package/.devcontainer/catalogue/mysql/mysql.sh +1 -1
- package/.devcontainer/catalogue.sh +1 -1
- package/.devcontainer/chart-direct.sh +49 -0
- package/.devcontainer/devzone +8 -4
- package/.devcontainer/gitlab/argocd.sh +54 -0
- package/.devcontainer/gitlab/chart.sh +39 -0
- package/.devcontainer/gitlab/gitlab.sh +11 -168
- package/.devcontainer/gitlab/installation.sh +25 -38
- package/.devcontainer/gitlab/seed.sh +204 -0
- package/.devcontainer/postgres/postgres.sh +4 -2
- package/.devcontainer/services-admin.sh +12 -2
- package/.devcontainer/versions.env +1 -1
- package/README.md +55 -23
- package/charts/devzone-gitlab/Chart.lock +9 -0
- package/charts/devzone-gitlab/Chart.yaml +15 -0
- package/charts/devzone-gitlab/values.yaml +94 -0
- package/charts/devzone-mysql/values.yaml +3 -3
- package/charts/devzone-postgres/values.yaml +2 -2
- package/manage/scripts/check-charts.sh +67 -19
- package/manage/scripts/services-workspace.sh +10 -1
- package/package.json +1 -1
- package/.devcontainer/catalogue/mysql/manifeste.yaml +0 -81
- package/.devcontainer/gitlab/runner-values.yaml +0 -27
- package/.devcontainer/gitlab/values.yaml +0 -83
- package/.devcontainer/postgres/postgres.yaml +0 -84
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# GitLab installed from the wrapper chart charts/devzone-gitlab (#538): the
|
|
3
|
+
# official gitlab 9.11.16 and gitlab-runner 0.88.2 are dependencies pinned in
|
|
4
|
+
# the chart, its values.yaml holds the values of the GitLab of devzone
|
|
5
|
+
# (under the gitlab and gitlab-runner keys). This file is the helm-direct
|
|
6
|
+
# path, the Application of Argo CD is argocd.sh. Sourced by installation.sh.
|
|
7
|
+
# gitlab_chart_depend repository HTTP gitlab added, dependency build
|
|
8
|
+
# gitlab_helm_pass <replicas> upgrade --install of the chart, runner replicas
|
|
9
|
+
# gitlab_runner_ancien_retirer release gitlab-runner of before #538 removed
|
|
10
|
+
# The runner is held back (replicas 0) on the first pass: its Secret
|
|
11
|
+
# gitlab-runner-secret is written by the seed, and a runner pod waiting for it
|
|
12
|
+
# would hold --wait until the timeout.
|
|
13
|
+
|
|
14
|
+
# The dependencies come from https://charts.gitlab.io (no OCI repository is
|
|
15
|
+
# published): the repository is added before the build, idempotent
|
|
16
|
+
gitlab_chart_depend() {
|
|
17
|
+
helm repo add gitlab https://charts.gitlab.io --force-update >/dev/null 2>&1 || true
|
|
18
|
+
helm dependency build "$RACINE/charts/devzone-gitlab" >/dev/null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# One helm pass of the wrapper chart. The webservice URL of the runner follows
|
|
22
|
+
# the namespace of the instance: the chart value is not templated, its default
|
|
23
|
+
# is the main instance, so it is passed here
|
|
24
|
+
gitlab_helm_pass() {
|
|
25
|
+
local replicas="$1"
|
|
26
|
+
compte_helm "$(compte_ctx)" upgrade --install gitlab "$RACINE/charts/devzone-gitlab" \
|
|
27
|
+
--namespace "$GITLAB_NS" \
|
|
28
|
+
--create-namespace \
|
|
29
|
+
--timeout "${GITLAB_ATTENTE}s" \
|
|
30
|
+
--wait \
|
|
31
|
+
--set "gitlab-runner.gitlabUrl=http://gitlab-webservice-default.$GITLAB_NS.svc:8181" \
|
|
32
|
+
--set "gitlab-runner.replicas=$replicas"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Release gitlab-runner of the installations before the wrapper chart (#396):
|
|
36
|
+
# its runner now comes with the chart, the release leaves without touching data
|
|
37
|
+
gitlab_runner_ancien_retirer() {
|
|
38
|
+
compte_helm "$(compte_ctx)" uninstall gitlab-runner --namespace "$GITLAB_NS" >/dev/null 2>&1 || true
|
|
39
|
+
}
|
|
@@ -61,173 +61,16 @@ GITLAB_HOTE_MARQUE="# devzone:gitlab"
|
|
|
61
61
|
# shellcheck source=SCRIPTDIR/installation.sh
|
|
62
62
|
# shellcheck disable=SC1091
|
|
63
63
|
. "$ICI/installation.sh"
|
|
64
|
-
|
|
65
|
-
#
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
fi
|
|
75
|
-
sleep 5
|
|
76
|
-
done
|
|
77
|
-
echo "devzone : timeout attente GitLab." >&2
|
|
78
|
-
return 1
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
# ---- seed : peupler GitLab de données de base ----
|
|
82
|
-
gitlab_seed() {
|
|
83
|
-
echo "▶ Seed de GitLab…"
|
|
84
|
-
|
|
85
|
-
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
86
|
-
|
|
87
|
-
# Mot de passe root lu dans le secret gitlab-gitlab-initial-root-password
|
|
88
|
-
local mot_de_passe
|
|
89
|
-
mot_de_passe="$(kubectl --context devzone get secret -n "$GITLAB_NS" gitlab-gitlab-initial-root-password -o jsonpath='{.data.password}' 2>/dev/null | base64 -d 2>/dev/null || true)"
|
|
90
|
-
if [ -z "$mot_de_passe" ]; then
|
|
91
|
-
echo "devzone : seed GitLab : secret root (gitlab-gitlab-initial-root-password) introuvable, arrêt du seed." >&2
|
|
92
|
-
return 1
|
|
93
|
-
fi
|
|
94
|
-
printf '%s' "$mot_de_passe" > "$GITLAB_SECRETS_DIR/root-password"
|
|
95
|
-
chmod 600 "$GITLAB_SECRETS_DIR/root-password"
|
|
96
|
-
|
|
97
|
-
# Token d'accès root créé par kubectl exec dans le pod toolbox avec gitlab-rails runner
|
|
98
|
-
local toolbox_pod root_token
|
|
99
|
-
toolbox_pod="$(kubectl --context devzone get pod -n "$GITLAB_NS" -l app=toolbox -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
|
|
100
|
-
if [ -z "$toolbox_pod" ]; then
|
|
101
|
-
echo "devzone : seed GitLab : pod toolbox (label app=toolbox) introuvable, arrêt du seed." >&2
|
|
102
|
-
return 1
|
|
103
|
-
fi
|
|
104
|
-
root_token="$(kubectl --context devzone exec -n "$GITLAB_NS" "$toolbox_pod" -- gitlab-rails runner 'puts User.find_by_username("root").personal_access_tokens.create(name: "devzone", scopes: ["api", "write_repository"], expires_at: 30.days.from_now).token' 2>/dev/null | tail -n 1 || true)"
|
|
105
|
-
if [ -z "$root_token" ]; then
|
|
106
|
-
echo "devzone : seed GitLab : création du jeton root (gitlab-rails runner) échouée, arrêt du seed." >&2
|
|
107
|
-
return 1
|
|
108
|
-
fi
|
|
109
|
-
printf '%s' "$root_token" > "$GITLAB_SECRETS_DIR/root-token"
|
|
110
|
-
chmod 600 "$GITLAB_SECRETS_DIR/root-token"
|
|
111
|
-
|
|
112
|
-
# Via l'API curl avec le token (jamais affiché en clair)
|
|
113
|
-
local token groupe_id
|
|
114
|
-
token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
115
|
-
|
|
116
|
-
# Groupe devzone (testé avant création)
|
|
117
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" >/dev/null 2>&1; then
|
|
118
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/groups" --data "name=devzone&path=devzone&visibility=private" >/dev/null 2>&1; then
|
|
119
|
-
echo "devzone : seed GitLab : création du groupe devzone échouée, arrêt du seed." >&2
|
|
120
|
-
return 1
|
|
121
|
-
fi
|
|
122
|
-
fi
|
|
123
|
-
groupe_id="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" | jq -r '.id // empty')"
|
|
124
|
-
if [ -z "$groupe_id" ]; then
|
|
125
|
-
echo "devzone : seed GitLab : lecture de l'identifiant numérique du groupe devzone échouée, arrêt du seed." >&2
|
|
126
|
-
return 1
|
|
127
|
-
fi
|
|
128
|
-
|
|
129
|
-
# Projet devzone/demo (testé avant création, namespace_id = ID numérique du groupe)
|
|
130
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo" >/dev/null 2>&1; then
|
|
131
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/projects" --data "name=demo&namespace_id=$groupe_id" >/dev/null 2>&1; then
|
|
132
|
-
echo "devzone : seed GitLab : création du projet devzone/demo échouée, arrêt du seed." >&2
|
|
133
|
-
return 1
|
|
134
|
-
fi
|
|
135
|
-
fi
|
|
136
|
-
|
|
137
|
-
# Utilisateur dev (testé avant création, mot de passe généré aléatoirement) :
|
|
138
|
-
# un dev-password existant n'est réutilisé que si l'utilisateur dev existe
|
|
139
|
-
# encore (vérifié via l'API) ; sinon il est recréé avec un utilisateur nouveau.
|
|
140
|
-
local users_json devpass
|
|
141
|
-
users_json="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/users?username=dev")"
|
|
142
|
-
if [ "$(jq length <<<"$users_json")" -eq 0 ]; then
|
|
143
|
-
devpass="$(openssl rand -base64 18 | tr -d '\n')"
|
|
144
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/users" --data "email=dev@gitlab.localhost&username=dev&name=dev&skip_confirmation=true" --data-urlencode "password=$devpass" >/dev/null 2>&1; then
|
|
145
|
-
echo "devzone : seed GitLab : création de l'utilisateur dev échouée, arrêt du seed." >&2
|
|
146
|
-
return 1
|
|
147
|
-
fi
|
|
148
|
-
printf '%s' "$devpass" > "$GITLAB_SECRETS_DIR/dev-password"
|
|
149
|
-
chmod 600 "$GITLAB_SECRETS_DIR/dev-password"
|
|
150
|
-
fi
|
|
151
|
-
|
|
152
|
-
# Token de runner : vérifié via POST /api/v4/runners/verify ; un jeton valide
|
|
153
|
-
# est gardé, un jeton refusé (403/404) est recréé, GitLab injoignable arrête le seed.
|
|
154
|
-
local rt_jeton rt_code rt_token
|
|
155
|
-
if [ -f "$GITLAB_SECRETS_DIR/runner-token" ]; then
|
|
156
|
-
rt_jeton="$(cat "$GITLAB_SECRETS_DIR/runner-token")"
|
|
157
|
-
rt_code="$(curl -s -o /dev/null -w '%{http_code}' --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/runners/verify" --data "token=${rt_jeton}" || true)"
|
|
158
|
-
if [ "$rt_code" = "200" ]; then
|
|
159
|
-
echo "✔ Jeton de runner valide : gardé."
|
|
160
|
-
elif [ "$rt_code" = "403" ] || [ "$rt_code" = "404" ]; then
|
|
161
|
-
echo "devzone : jeton de runner d'une installation précédente refusé : recréé."
|
|
162
|
-
rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
|
|
163
|
-
if [ -z "$rt_token" ]; then
|
|
164
|
-
echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
|
|
165
|
-
return 1
|
|
166
|
-
fi
|
|
167
|
-
printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
|
|
168
|
-
chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
|
|
169
|
-
else
|
|
170
|
-
echo "devzone : seed GitLab : vérification du jeton de runner impossible (code ${rt_code}), arrêt du seed." >&2
|
|
171
|
-
return 1
|
|
172
|
-
fi
|
|
173
|
-
else
|
|
174
|
-
rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
|
|
175
|
-
if [ -z "$rt_token" ]; then
|
|
176
|
-
echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
|
|
177
|
-
return 1
|
|
178
|
-
fi
|
|
179
|
-
printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
|
|
180
|
-
chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
|
|
181
|
-
fi
|
|
182
|
-
|
|
183
|
-
# Push du contenu de demo/ dans devzone/demo (dépôt git temporaire, remote http avec le jeton dans l'URL, jamais affiché ; branche main)
|
|
184
|
-
# Le push utilise le jeton root (write_repository) : le jeton de runner ne peut pas pousser.
|
|
185
|
-
local push_token=""
|
|
186
|
-
push_token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
187
|
-
if [ -z "$push_token" ]; then
|
|
188
|
-
echo "devzone : seed GitLab : jeton root introuvable, arrêt du seed." >&2
|
|
189
|
-
return 1
|
|
190
|
-
fi
|
|
191
|
-
# Déjà poussé (installation relancée) : rien à refaire
|
|
192
|
-
if curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
|
|
193
|
-
echo "✔ Seed GitLab terminé (projet demo déjà poussé)."
|
|
194
|
-
regenerer_identifiants
|
|
195
|
-
return 0
|
|
196
|
-
fi
|
|
197
|
-
if [ -d "$ICI/demo" ]; then
|
|
198
|
-
local tmpdir
|
|
199
|
-
tmpdir="$(mktemp -d)"
|
|
200
|
-
cp -r "$ICI/demo/." "$tmpdir/"
|
|
201
|
-
if (
|
|
202
|
-
cd "$tmpdir"
|
|
203
|
-
# Dépôt jetable du script : les hooks git globaux (repowarden) n'ont
|
|
204
|
-
# rien à vérifier ici et refuseraient le commit
|
|
205
|
-
export GIT_CONFIG_PARAMETERS="'core.hooksPath=/dev/null'"
|
|
206
|
-
git init -q -b main
|
|
207
|
-
git add -A
|
|
208
|
-
git -c user.email=dev@gitlab.localhost -c user.name=dev commit -q -m "chore: projet de démonstration"
|
|
209
|
-
# gitlab.localhost n'est pas toujours résolu par git : adresse
|
|
210
|
-
# locale, et l'hôte attendu par l'ingress passé en en-tête
|
|
211
|
-
git remote add origin "http://oauth2:${push_token}@127.0.0.1:8929/devzone/demo.git"
|
|
212
|
-
git -c http.extraHeader="Host: gitlab.localhost" push -q -u origin main >/dev/null 2>&1
|
|
213
|
-
); then
|
|
214
|
-
# Vérifie le push : la branche main existe bien sur le projet
|
|
215
|
-
if ! curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
|
|
216
|
-
echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git réussi mais branche main absente, arrêt du seed." >&2
|
|
217
|
-
rm -rf "$tmpdir"
|
|
218
|
-
return 1
|
|
219
|
-
fi
|
|
220
|
-
else
|
|
221
|
-
echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git échoué, arrêt du seed." >&2
|
|
222
|
-
rm -rf "$tmpdir"
|
|
223
|
-
return 1
|
|
224
|
-
fi
|
|
225
|
-
rm -rf "$tmpdir"
|
|
226
|
-
fi
|
|
227
|
-
|
|
228
|
-
echo "✔ Seed GitLab terminé."
|
|
229
|
-
regenerer_identifiants
|
|
230
|
-
}
|
|
64
|
+
# Chart enveloppe (helm direct, chart.sh), Argo CD (argocd.sh), seed (seed.sh) (#538)
|
|
65
|
+
# shellcheck source=SCRIPTDIR/chart.sh
|
|
66
|
+
# shellcheck disable=SC1091
|
|
67
|
+
. "$ICI/chart.sh"
|
|
68
|
+
# shellcheck source=SCRIPTDIR/argocd.sh
|
|
69
|
+
# shellcheck disable=SC1091
|
|
70
|
+
. "$ICI/argocd.sh"
|
|
71
|
+
# shellcheck source=SCRIPTDIR/seed.sh
|
|
72
|
+
# shellcheck disable=SC1091
|
|
73
|
+
. "$ICI/seed.sh"
|
|
231
74
|
|
|
232
75
|
# ---- hote-poser / hote-retirer : gitlab.localhost dans /etc/hosts ----
|
|
233
76
|
# Pourquoi : ssh (clone ssh://git@gitlab.localhost:2224/…), glab et getent
|
|
@@ -325,7 +168,7 @@ case "${1:-}" in
|
|
|
325
168
|
migrate) shift; gitlab_migrer "$@" ;;
|
|
326
169
|
installe) gitlab_installe ;;
|
|
327
170
|
status) gitlab_etat ;;
|
|
328
|
-
seed)
|
|
171
|
+
seed) gitlab_seed_commande ;;
|
|
329
172
|
new-password) gitlab_nouveau_mdp "${@:2}" ;;
|
|
330
173
|
relay-start) gitlab_relais_lancer ;;
|
|
331
174
|
relay-stop) gitlab_relais_arreter ;;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
# Sourcé par gitlab.sh : namespace devzone-gitlab (suffixé par instance),
|
|
4
4
|
# vérification de la mémoire allouable, Helm avec le contexte devzone,
|
|
5
5
|
# relais port-forward, runner et migration depuis l'ancien cluster kind.
|
|
6
|
-
#
|
|
6
|
+
# Le chart enveloppe charts/devzone-gitlab (#538) porte les dépendances et les
|
|
7
|
+
# valeurs ; chart.sh (helm direct) et argocd.sh (Application) l'installent.
|
|
7
8
|
|
|
8
9
|
# Namespace isolé du module : un par instance, comme postgres
|
|
9
10
|
GITLAB_NS="devzone-gitlab${INSTANCE_SUFFIX}"
|
|
@@ -84,26 +85,23 @@ gitlab_installer() {
|
|
|
84
85
|
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
85
86
|
gitlab_namespace_preparer
|
|
86
87
|
|
|
87
|
-
# Dépôt Helm GitLab (idempotent)
|
|
88
|
-
echo "▶ Ajout du dépôt Helm GitLab…"
|
|
89
|
-
helm repo add gitlab https://charts.gitlab.io 2>/dev/null || true
|
|
90
|
-
helm repo update >/dev/null 2>&1 || true
|
|
91
|
-
|
|
92
|
-
# Installation des services en ClusterIP, sans exposition directe :
|
|
93
|
-
# l'accès passe uniquement par le relais port-forward du conteneur
|
|
94
|
-
echo "▶ Installation du chart GitLab dans $GITLAB_NS…"
|
|
95
88
|
# Secret Rails (#347) : réinstallation -> réappliquer le secret conservé avant
|
|
96
|
-
#
|
|
89
|
+
# l'installation (le chart le réutilise, sessions navigateur valides)
|
|
97
90
|
gitlab_secrets_appliquer
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
gitlab_runner_ancien_retirer
|
|
92
|
+
|
|
93
|
+
# Argo CD holds the chart when the module is on (#538): the Application
|
|
94
|
+
# syncs it and the seed runs once GitLab answers. Otherwise the wrapper chart
|
|
95
|
+
# is installed by helm, the runner held back until the seed wrote its Secret
|
|
96
|
+
local par_argocd=0
|
|
97
|
+
if gitlab_argocd_active; then
|
|
98
|
+
par_argocd=1
|
|
99
|
+
gitlab_release_adopter
|
|
100
|
+
gitlab_application_apply || return 1
|
|
101
|
+
else
|
|
102
|
+
echo "▶ Installation du chart GitLab dans $GITLAB_NS…"
|
|
103
|
+
gitlab_chart_depend
|
|
104
|
+
gitlab_helm_pass 0 || return 1
|
|
107
105
|
fi
|
|
108
106
|
|
|
109
107
|
# Relais avant l'attente : curl et git en HTTP résolvent *.localhost vers
|
|
@@ -116,26 +114,13 @@ gitlab_installer() {
|
|
|
116
114
|
|
|
117
115
|
gitlab_attendre_pret
|
|
118
116
|
gitlab_seed
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
# de l'instance (jamais le namespace fixe « gitlab » d'avant #396)
|
|
122
|
-
echo "▶ Installation de l'exécuteur GitLab Runner…"
|
|
123
|
-
local runner_token="" valeurs_runner
|
|
124
|
-
if [ -f "$GITLAB_SECRETS_DIR/runner-token" ]; then
|
|
125
|
-
runner_token="$(cat "$GITLAB_SECRETS_DIR/runner-token")"
|
|
117
|
+
if [ ! -f "$GITLAB_RAILS_FICHIER" ]; then
|
|
118
|
+
gitlab_secrets_copier
|
|
126
119
|
fi
|
|
127
|
-
if [
|
|
128
|
-
echo "
|
|
129
|
-
return 1
|
|
120
|
+
if [ "$par_argocd" = 0 ]; then
|
|
121
|
+
echo "▶ Exécuteur GitLab Runner…"
|
|
122
|
+
gitlab_helm_pass 1 || return 1
|
|
130
123
|
fi
|
|
131
|
-
valeurs_runner="$(mktemp)"
|
|
132
|
-
sed "s/__NAMESPACE__/$GITLAB_NS/g" "$ICI/runner-values.yaml" >"$valeurs_runner"
|
|
133
|
-
compte_helm "$(compte_ctx)" upgrade --install gitlab-runner gitlab/gitlab-runner \
|
|
134
|
-
--version 0.88.2 \
|
|
135
|
-
--namespace "$GITLAB_NS" \
|
|
136
|
-
-f "$valeurs_runner" \
|
|
137
|
-
--set "runnerToken=${runner_token}"
|
|
138
|
-
rm -f "$valeurs_runner"
|
|
139
124
|
|
|
140
125
|
gitlab_secrets_avertir
|
|
141
126
|
|
|
@@ -160,8 +145,10 @@ gitlab_desinstaller() {
|
|
|
160
145
|
gitlab_relais_arreter
|
|
161
146
|
rm -rf "$(relais_dossier gitlab-web)" "$(relais_dossier gitlab-ssh)" \
|
|
162
147
|
"$(relais_dossier gitlab-8929)" "$(relais_dossier gitlab-2224)"
|
|
148
|
+
# Application tenue par Argo CD (#538) : ses ressources partent avec elle
|
|
149
|
+
gitlab_application_retirer || true
|
|
163
150
|
compte_helm "$(compte_ctx)" uninstall gitlab --namespace "$GITLAB_NS" >/dev/null 2>&1 || true
|
|
164
|
-
|
|
151
|
+
gitlab_runner_ancien_retirer
|
|
165
152
|
# RoleBinding retiré puis namespace supprimé par l'administrateur (#430)
|
|
166
153
|
compte_retirer "$(compte_ctx)" "$GITLAB_NS" >/dev/null 2>&1 || true
|
|
167
154
|
compte_admin "$(compte_ctx)" delete namespace "$GITLAB_NS" --ignore-not-found >/dev/null 2>&1 || true
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Seed of the GitLab of devzone (#396, #538): the data a fresh instance needs,
|
|
3
|
+
# group devzone, demo project, dev user, runner. Sourced by gitlab.sh. The
|
|
4
|
+
# installer starts the relays and waits for GitLab before the seed; the seed
|
|
5
|
+
# command (devzone gitlab seed, run in the pod by services-admin.sh when Argo
|
|
6
|
+
# CD holds the chart) does it itself (gitlab_seed_commande).
|
|
7
|
+
# gitlab_attendre_pret waits for the readiness of GitLab (GITLAB_ATTENTE)
|
|
8
|
+
# gitlab_seed group, project, user, runner token and its Secret
|
|
9
|
+
# gitlab_seed_commande devzone gitlab seed: relays, readiness, seed
|
|
10
|
+
|
|
11
|
+
# ---- Helper : attendre que GitLab soit prêt ----
|
|
12
|
+
gitlab_attendre_pret() {
|
|
13
|
+
local debut
|
|
14
|
+
debut=$(date +%s)
|
|
15
|
+
echo "▶ Attente de GitLab prêt (timeout ${GITLAB_ATTENTE}s)…"
|
|
16
|
+
while [ $(( $(date +%s) - debut )) -lt "$GITLAB_ATTENTE" ]; do
|
|
17
|
+
if curl -sf http://gitlab.localhost:8929/-/readiness >/dev/null 2>&1 || curl -sf http://gitlab.localhost:8929/users/sign_in >/dev/null 2>&1; then
|
|
18
|
+
echo "▶ GitLab prêt."
|
|
19
|
+
return 0
|
|
20
|
+
fi
|
|
21
|
+
sleep 5
|
|
22
|
+
done
|
|
23
|
+
echo "devzone : timeout attente GitLab." >&2
|
|
24
|
+
return 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# ---- seed : peupler GitLab de données de base ----
|
|
28
|
+
gitlab_seed() {
|
|
29
|
+
echo "▶ Seed de GitLab…"
|
|
30
|
+
|
|
31
|
+
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
32
|
+
|
|
33
|
+
# Mot de passe root lu dans le secret gitlab-gitlab-initial-root-password
|
|
34
|
+
local mot_de_passe
|
|
35
|
+
mot_de_passe="$(kubectl --context devzone get secret -n "$GITLAB_NS" gitlab-gitlab-initial-root-password -o jsonpath='{.data.password}' 2>/dev/null | base64 -d 2>/dev/null || true)"
|
|
36
|
+
if [ -z "$mot_de_passe" ]; then
|
|
37
|
+
echo "devzone : seed GitLab : secret root (gitlab-gitlab-initial-root-password) introuvable, arrêt du seed." >&2
|
|
38
|
+
return 1
|
|
39
|
+
fi
|
|
40
|
+
printf '%s' "$mot_de_passe" > "$GITLAB_SECRETS_DIR/root-password"
|
|
41
|
+
chmod 600 "$GITLAB_SECRETS_DIR/root-password"
|
|
42
|
+
|
|
43
|
+
# Token d'accès root créé par kubectl exec dans le pod toolbox avec gitlab-rails runner
|
|
44
|
+
local toolbox_pod root_token
|
|
45
|
+
toolbox_pod="$(kubectl --context devzone get pod -n "$GITLAB_NS" -l app=toolbox -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
|
|
46
|
+
if [ -z "$toolbox_pod" ]; then
|
|
47
|
+
echo "devzone : seed GitLab : pod toolbox (label app=toolbox) introuvable, arrêt du seed." >&2
|
|
48
|
+
return 1
|
|
49
|
+
fi
|
|
50
|
+
root_token="$(kubectl --context devzone exec -n "$GITLAB_NS" "$toolbox_pod" -- gitlab-rails runner 'puts User.find_by_username("root").personal_access_tokens.create(name: "devzone", scopes: ["api", "write_repository"], expires_at: 30.days.from_now).token' 2>/dev/null | tail -n 1 || true)"
|
|
51
|
+
if [ -z "$root_token" ]; then
|
|
52
|
+
echo "devzone : seed GitLab : création du jeton root (gitlab-rails runner) échouée, arrêt du seed." >&2
|
|
53
|
+
return 1
|
|
54
|
+
fi
|
|
55
|
+
printf '%s' "$root_token" > "$GITLAB_SECRETS_DIR/root-token"
|
|
56
|
+
chmod 600 "$GITLAB_SECRETS_DIR/root-token"
|
|
57
|
+
|
|
58
|
+
# Via l'API curl avec le token (jamais affiché en clair)
|
|
59
|
+
local token groupe_id
|
|
60
|
+
token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
61
|
+
|
|
62
|
+
# Groupe devzone (testé avant création)
|
|
63
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" >/dev/null 2>&1; then
|
|
64
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/groups" --data "name=devzone&path=devzone&visibility=private" >/dev/null 2>&1; then
|
|
65
|
+
echo "devzone : seed GitLab : création du groupe devzone échouée, arrêt du seed." >&2
|
|
66
|
+
return 1
|
|
67
|
+
fi
|
|
68
|
+
fi
|
|
69
|
+
groupe_id="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" | jq -r '.id // empty')"
|
|
70
|
+
if [ -z "$groupe_id" ]; then
|
|
71
|
+
echo "devzone : seed GitLab : lecture de l'identifiant numérique du groupe devzone échouée, arrêt du seed." >&2
|
|
72
|
+
return 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
# Projet devzone/demo (testé avant création, namespace_id = ID numérique du groupe)
|
|
76
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo" >/dev/null 2>&1; then
|
|
77
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/projects" --data "name=demo&namespace_id=$groupe_id" >/dev/null 2>&1; then
|
|
78
|
+
echo "devzone : seed GitLab : création du projet devzone/demo échouée, arrêt du seed." >&2
|
|
79
|
+
return 1
|
|
80
|
+
fi
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
# Utilisateur dev (testé avant création, mot de passe généré aléatoirement) :
|
|
84
|
+
# un dev-password existant n'est réutilisé que si l'utilisateur dev existe
|
|
85
|
+
# encore (vérifié via l'API) ; sinon il est recréé avec un utilisateur nouveau.
|
|
86
|
+
local users_json devpass
|
|
87
|
+
users_json="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/users?username=dev")"
|
|
88
|
+
if [ "$(jq length <<<"$users_json")" -eq 0 ]; then
|
|
89
|
+
devpass="$(openssl rand -base64 18 | tr -d '\n')"
|
|
90
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/users" --data "email=dev@gitlab.localhost&username=dev&name=dev&skip_confirmation=true" --data-urlencode "password=$devpass" >/dev/null 2>&1; then
|
|
91
|
+
echo "devzone : seed GitLab : création de l'utilisateur dev échouée, arrêt du seed." >&2
|
|
92
|
+
return 1
|
|
93
|
+
fi
|
|
94
|
+
printf '%s' "$devpass" > "$GITLAB_SECRETS_DIR/dev-password"
|
|
95
|
+
chmod 600 "$GITLAB_SECRETS_DIR/dev-password"
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# Token de runner : vérifié via POST /api/v4/runners/verify ; un jeton valide
|
|
99
|
+
# est gardé, un jeton refusé (403/404) est recréé, GitLab injoignable arrête le seed.
|
|
100
|
+
local rt_jeton rt_code rt_token
|
|
101
|
+
if [ -f "$GITLAB_SECRETS_DIR/runner-token" ]; then
|
|
102
|
+
rt_jeton="$(cat "$GITLAB_SECRETS_DIR/runner-token")"
|
|
103
|
+
rt_code="$(curl -s -o /dev/null -w '%{http_code}' --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/runners/verify" --data "token=${rt_jeton}" || true)"
|
|
104
|
+
if [ "$rt_code" = "200" ]; then
|
|
105
|
+
echo "✔ Jeton de runner valide : gardé."
|
|
106
|
+
elif [ "$rt_code" = "403" ] || [ "$rt_code" = "404" ]; then
|
|
107
|
+
echo "devzone : jeton de runner d'une installation précédente refusé : recréé."
|
|
108
|
+
rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
|
|
109
|
+
if [ -z "$rt_token" ]; then
|
|
110
|
+
echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
|
|
111
|
+
return 1
|
|
112
|
+
fi
|
|
113
|
+
printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
|
|
114
|
+
chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
|
|
115
|
+
else
|
|
116
|
+
echo "devzone : seed GitLab : vérification du jeton de runner impossible (code ${rt_code}), arrêt du seed." >&2
|
|
117
|
+
return 1
|
|
118
|
+
fi
|
|
119
|
+
else
|
|
120
|
+
rt_token="$(curl -s --header "PRIVATE-TOKEN: $token" --request POST "http://gitlab.localhost:8929/api/v4/user/runners" --data "runner_type=instance_type" 2>/dev/null | jq -r '.token // empty' || true)"
|
|
121
|
+
if [ -z "$rt_token" ]; then
|
|
122
|
+
echo "devzone : seed GitLab : création du jeton de runner (POST /api/v4/user/runners) échouée, arrêt du seed." >&2
|
|
123
|
+
return 1
|
|
124
|
+
fi
|
|
125
|
+
printf '%s' "$rt_token" > "$GITLAB_SECRETS_DIR/runner-token"
|
|
126
|
+
chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# Secret of the runner of the chart (runners.secret, #538): created apart, out
|
|
130
|
+
# of Git; the token is read from its file, never on a command line
|
|
131
|
+
if ! kubectl --context devzone -n "$GITLAB_NS" create secret generic gitlab-runner-secret \
|
|
132
|
+
--from-file=runner-token="$GITLAB_SECRETS_DIR/runner-token" \
|
|
133
|
+
--from-literal=runner-registration-token= \
|
|
134
|
+
--dry-run=client -o yaml |
|
|
135
|
+
kubectl --context devzone -n "$GITLAB_NS" apply -f - >/dev/null 2>&1; then
|
|
136
|
+
echo "devzone : seed GitLab : secret gitlab-runner-secret non créé, arrêt du seed." >&2
|
|
137
|
+
return 1
|
|
138
|
+
fi
|
|
139
|
+
# A runner already running may hold the previous token: restarted on the
|
|
140
|
+
# one just written (no runner yet: nothing to restart)
|
|
141
|
+
kubectl --context devzone -n "$GITLAB_NS" rollout restart deployment \
|
|
142
|
+
--selector=app=gitlab-gitlab-runner >/dev/null 2>&1 || true
|
|
143
|
+
|
|
144
|
+
# Push du contenu de demo/ dans devzone/demo (dépôt git temporaire, remote http avec le jeton dans l'URL, jamais affiché ; branche main)
|
|
145
|
+
# Le push utilise le jeton root (write_repository) : le jeton de runner ne peut pas pousser.
|
|
146
|
+
local push_token=""
|
|
147
|
+
push_token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
148
|
+
if [ -z "$push_token" ]; then
|
|
149
|
+
echo "devzone : seed GitLab : jeton root introuvable, arrêt du seed." >&2
|
|
150
|
+
return 1
|
|
151
|
+
fi
|
|
152
|
+
# Déjà poussé (installation relancée) : rien à refaire
|
|
153
|
+
if curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
|
|
154
|
+
echo "✔ Seed GitLab terminé (projet demo déjà poussé)."
|
|
155
|
+
regenerer_identifiants
|
|
156
|
+
return 0
|
|
157
|
+
fi
|
|
158
|
+
if [ -d "$ICI/demo" ]; then
|
|
159
|
+
local tmpdir
|
|
160
|
+
tmpdir="$(mktemp -d)"
|
|
161
|
+
cp -r "$ICI/demo/." "$tmpdir/"
|
|
162
|
+
if (
|
|
163
|
+
cd "$tmpdir"
|
|
164
|
+
# Dépôt jetable du script : les hooks git globaux (repowarden) n'ont
|
|
165
|
+
# rien à vérifier ici et refuseraient le commit
|
|
166
|
+
export GIT_CONFIG_PARAMETERS="'core.hooksPath=/dev/null'"
|
|
167
|
+
git init -q -b main
|
|
168
|
+
git add -A
|
|
169
|
+
git -c user.email=dev@gitlab.localhost -c user.name=dev commit -q -m "chore: projet de démonstration"
|
|
170
|
+
# gitlab.localhost n'est pas toujours résolu par git : adresse
|
|
171
|
+
# locale, et l'hôte attendu par l'ingress passé en en-tête
|
|
172
|
+
git remote add origin "http://oauth2:${push_token}@127.0.0.1:8929/devzone/demo.git"
|
|
173
|
+
git -c http.extraHeader="Host: gitlab.localhost" push -q -u origin main >/dev/null 2>&1
|
|
174
|
+
); then
|
|
175
|
+
# Vérifie le push : la branche main existe bien sur le projet
|
|
176
|
+
if ! curl -sf --header "PRIVATE-TOKEN: $push_token" "http://gitlab.localhost:8929/api/v4/projects/devzone%2Fdemo/repository/branches/main" >/dev/null 2>&1; then
|
|
177
|
+
echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git réussi mais branche main absente, arrêt du seed." >&2
|
|
178
|
+
rm -rf "$tmpdir"
|
|
179
|
+
return 1
|
|
180
|
+
fi
|
|
181
|
+
else
|
|
182
|
+
echo "devzone : seed GitLab : push du projet demo sur /devzone/demo.git échoué, arrêt du seed." >&2
|
|
183
|
+
rm -rf "$tmpdir"
|
|
184
|
+
return 1
|
|
185
|
+
fi
|
|
186
|
+
rm -rf "$tmpdir"
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
echo "✔ Seed GitLab terminé."
|
|
190
|
+
regenerer_identifiants
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# devzone gitlab seed: the seed alone, when Argo CD holds the chart (the
|
|
194
|
+
# workstation runs it in the pod, services-admin.sh seed gitlab). The API and
|
|
195
|
+
# the push go through the relays: they start, GitLab is awaited, then the seed.
|
|
196
|
+
# The Rails secret of the pod is mirrored when it is not kept yet.
|
|
197
|
+
gitlab_seed_commande() {
|
|
198
|
+
gitlab_relais_lancer || return 1
|
|
199
|
+
gitlab_attendre_pret || return 1
|
|
200
|
+
gitlab_seed || return 1
|
|
201
|
+
if [ ! -f "$GITLAB_RAILS_FICHIER" ]; then
|
|
202
|
+
gitlab_secrets_copier
|
|
203
|
+
fi
|
|
204
|
+
}
|
|
@@ -18,6 +18,9 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
|
18
18
|
# shellcheck source=SCRIPTDIR/../password.sh
|
|
19
19
|
# shellcheck disable=SC1091
|
|
20
20
|
. "$ICI/../password.sh"
|
|
21
|
+
# shellcheck source=SCRIPTDIR/../chart-direct.sh
|
|
22
|
+
# shellcheck disable=SC1091
|
|
23
|
+
. "$ICI/../chart-direct.sh"
|
|
21
24
|
# Isolation réseau : namespace_isoler, d'où viennent les NetworkPolicies
|
|
22
25
|
# shellcheck source=SCRIPTDIR/../isolement.sh
|
|
23
26
|
# shellcheck disable=SC1091
|
|
@@ -126,8 +129,7 @@ installer() {
|
|
|
126
129
|
# Compte limité autorisé dans le namespace : RoleBinding vers edit
|
|
127
130
|
compte_autoriser "$CTX" "$NS"
|
|
128
131
|
secret_admin
|
|
129
|
-
|
|
130
|
-
kubectl --context devzone apply -f - >/dev/null
|
|
132
|
+
chart_install postgres "$NS" "size=$POSTGRES_TAILLE" || return 1
|
|
131
133
|
echo "▶ Attente de PostgreSQL (timeout ${POSTGRES_ATTENTE}s)…"
|
|
132
134
|
if ! k rollout status statefulset/postgres --timeout="${POSTGRES_ATTENTE}s" >/dev/null; then
|
|
133
135
|
echo "devzone : postgres : pas prêt après ${POSTGRES_ATTENTE}s : kubectl --context $CTX -n $NS describe pod postgres-0" >&2
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# Installs or removes a devzone service (gitlab, postgres, argocd) from inside
|
|
3
3
|
# the Kubernetes workspace pod, with a temporary administrator token (#528).
|
|
4
4
|
# services-admin.sh enable|disable <service> [options of devzone enable]
|
|
5
|
+
# services-admin.sh seed gitlab data of gitlab seeded again, in the pod (#538)
|
|
5
6
|
# Run by the workstation (manage/scripts/services-workspace.sh) through
|
|
6
7
|
# kubectl exec -i: the token comes on stdin, is never printed and lives only
|
|
7
8
|
# in a temporary kubeconfig removed at the end.
|
|
@@ -39,12 +40,17 @@ service="${2:-}"
|
|
|
39
40
|
case "$action" in
|
|
40
41
|
enable | activer) action=enable ;;
|
|
41
42
|
disable | desactiver) action=disable ;;
|
|
42
|
-
|
|
43
|
+
seed) ;;
|
|
44
|
+
*) refuse "usage: services-admin.sh enable|disable|seed gitlab|postgres|argocd [options]" ;;
|
|
43
45
|
esac
|
|
44
46
|
case "$service" in
|
|
45
47
|
gitlab | postgres | argocd) ;;
|
|
46
48
|
*) refuse "unknown service: ${service:-(none)} (gitlab, postgres, argocd)" ;;
|
|
47
49
|
esac
|
|
50
|
+
# The seed of the data (group, demo project, dev user, runner) is gitlab's (#538)
|
|
51
|
+
if [ "$action" = seed ] && [ "$service" != gitlab ]; then
|
|
52
|
+
refuse "seed: only gitlab"
|
|
53
|
+
fi
|
|
48
54
|
[ "${DEVZONE_WORKSPACE:-}" = kubernetes ] || refuse "only in the Kubernetes workspace pod"
|
|
49
55
|
[ -f "$SA_DIR/ca.crt" ] || refuse "cluster CA not found: $SA_DIR/ca.crt"
|
|
50
56
|
if [ -t 0 ]; then
|
|
@@ -102,4 +108,8 @@ export DEVZONE_KUBE_CONFIG="$kubeconfig"
|
|
|
102
108
|
export DEVZONE_SERVICES_ADMIN=1
|
|
103
109
|
etat_ecrire cluster "$ADMIN_CONTEXT" || refuse "cannot write the state: $ETAT"
|
|
104
110
|
echo "devzone services: $action $service in the cluster of the pod (temporary administrator)"
|
|
105
|
-
|
|
111
|
+
case "$action" in
|
|
112
|
+
# The seed is a module command: devzone gitlab seed (#538)
|
|
113
|
+
seed) devzone gitlab seed "${@:3}" ;;
|
|
114
|
+
*) devzone "$action" "$service" "${@:3}" ;;
|
|
115
|
+
esac
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Single source for the repowarden version used by post-create.sh and workspace-init.sh.
|
|
2
|
-
REPOWARDEN_VERSION=4.17.
|
|
2
|
+
REPOWARDEN_VERSION=4.17.3
|
|
3
3
|
|
|
4
4
|
# BuildKit client version installed in the workspace image (#514). Must match
|
|
5
5
|
# buildkit.image in charts/devzone-workspace/values.yaml.
|