devzone 7.1.0 → 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 +17 -9
- package/.devcontainer/devzone-cluster.sh +1 -1
- package/.devcontainer/devzone-modules.sh +7 -2
- package/.devcontainer/devzone-repair.sh +9 -19
- package/.devcontainer/devzone-services.sh +21 -20
- package/.devcontainer/devzone-status.sh +4 -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 +4 -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
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Installation and migration of GitLab in the services cluster (#396).
|
|
3
|
-
# Sourced by gitlab.sh: devzone-gitlab namespace (suffixed per instance),
|
|
4
|
-
# check of the allocatable memory, Helm with the devzone context, port-forward
|
|
5
|
-
# relay, runner and migration from the old kind cluster.
|
|
6
|
-
# The wrapper chart charts/devzone-gitlab (#538) holds the dependencies and the
|
|
7
|
-
# values; chart.sh (direct helm) and argocd.sh (Application) install it.
|
|
8
|
-
|
|
9
|
-
# Shared memory check of the services cluster (#608): quantity_ki,
|
|
10
|
-
# memory_cluster_ki and check_module_memory.
|
|
11
|
-
# shellcheck source=SCRIPTDIR/../memory.sh
|
|
12
|
-
# shellcheck disable=SC1091
|
|
13
|
-
. "$ICI/../memory.sh"
|
|
14
|
-
|
|
15
|
-
# Namespace isolated from the module: one per instance, like postgres
|
|
16
|
-
GITLAB_NS="devzone-gitlab${INSTANCE_SUFFIX}"
|
|
17
|
-
# Old kind cluster of GitLab, deleted by "devzone gitlab migrate"
|
|
18
|
-
GITLAB_OLD_CLUSTER="gitlab${INSTANCE_SUFFIX}"
|
|
19
|
-
GITLAB_OLD_CONTEXT="kind-gitlab${INSTANCE_SUFFIX}"
|
|
20
|
-
|
|
21
|
-
# Namespace present in the services cluster: GitLab is installed.
|
|
22
|
-
# Reading the namespaces is reserved to the administrator (#430).
|
|
23
|
-
gitlab_installed() {
|
|
24
|
-
account_admin "$(account_context)" get namespace "$GITLAB_NS" >/dev/null 2>&1
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
# Creates the namespace, labels it and allows the limited account (#430), sets the isolation.
|
|
28
|
-
gitlab_namespace_prepare() {
|
|
29
|
-
local ctx
|
|
30
|
-
ctx="$(account_context)"
|
|
31
|
-
account_namespace "$ctx" "$GITLAB_NS"
|
|
32
|
-
namespace_isolate "$GITLAB_NS"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
# Installs GitLab and its runner in the services cluster, then prepares the
|
|
36
|
-
# access (web/SSH relay, /etc/hosts) and the seed of the test data.
|
|
37
|
-
gitlab_install() {
|
|
38
|
-
echo "▶ Checking the allocatable memory of the services cluster…"
|
|
39
|
-
check_module_memory gitlab 8 || return 2
|
|
40
|
-
|
|
41
|
-
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
42
|
-
gitlab_namespace_prepare
|
|
43
|
-
|
|
44
|
-
# Rails secret (#347): reinstallation -> apply the kept secret again before
|
|
45
|
-
# the installation (the chart reuses it, browser sessions stay valid)
|
|
46
|
-
gitlab_secrets_apply
|
|
47
|
-
gitlab_runner_ancien_retirer
|
|
48
|
-
|
|
49
|
-
# Argo CD holds the chart when the module is on (#538): the Application
|
|
50
|
-
# syncs it and the seed runs once GitLab answers. Otherwise the wrapper chart
|
|
51
|
-
# is installed by helm, the runner held back until the seed wrote its Secret
|
|
52
|
-
local par_argocd=0
|
|
53
|
-
if gitlab_argocd_active; then
|
|
54
|
-
par_argocd=1
|
|
55
|
-
gitlab_release_adopter
|
|
56
|
-
gitlab_application_apply || return 1
|
|
57
|
-
else
|
|
58
|
-
echo "▶ Installing the GitLab chart in ${GITLAB_NS}…"
|
|
59
|
-
gitlab_chart_depend
|
|
60
|
-
gitlab_helm_pass 0 || return 1
|
|
61
|
-
fi
|
|
62
|
-
|
|
63
|
-
# Relay before the wait: curl and git in HTTP resolve *.localhost to the
|
|
64
|
-
# loopback and reach GitLab only through these port-forwards (#320)
|
|
65
|
-
gitlab_relay_start || return 1
|
|
66
|
-
|
|
67
|
-
# gitlab.localhost name in /etc/hosts before the wait: ssh, glab and
|
|
68
|
-
# getent need it as soon as the service is up (curl resolves it itself)
|
|
69
|
-
gitlab_host_set || true
|
|
70
|
-
|
|
71
|
-
gitlab_wait_ready
|
|
72
|
-
gitlab_seed
|
|
73
|
-
if [ ! -f "$GITLAB_RAILS_FILE" ]; then
|
|
74
|
-
gitlab_secrets_copy
|
|
75
|
-
fi
|
|
76
|
-
if [ "$par_argocd" = 0 ]; then
|
|
77
|
-
echo "▶ GitLab Runner executor…"
|
|
78
|
-
gitlab_helm_pass 1 || return 1
|
|
79
|
-
fi
|
|
80
|
-
|
|
81
|
-
gitlab_secrets_warn
|
|
82
|
-
|
|
83
|
-
echo "▶ Installation complete."
|
|
84
|
-
echo " URL: http://gitlab.localhost:8929"
|
|
85
|
-
echo " User: root"
|
|
86
|
-
echo " Root password: $GITLAB_SECRETS_DIR/root-password (chmod 600)"
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# Removes GitLab: relays, Helm releases and the namespace of the instance only.
|
|
90
|
-
# The Rails secret is kept (browser sessions valid at the reinstallation),
|
|
91
|
-
# unless a complete uninstall is wanted (--yes): it then goes with the data.
|
|
92
|
-
gitlab_uninstall() {
|
|
93
|
-
local delete_secret="" arg
|
|
94
|
-
for arg in "$@"; do
|
|
95
|
-
case "$arg" in
|
|
96
|
-
--yes) delete_secret=1 ;;
|
|
97
|
-
*) echo "devzone : gitlab uninstall : unknown argument : $arg" >&2; return 2 ;;
|
|
98
|
-
esac
|
|
99
|
-
done
|
|
100
|
-
echo "▶ Uninstalling GitLab…"
|
|
101
|
-
gitlab_relay_stop
|
|
102
|
-
rm -rf "$(relay_dir gitlab-web)" "$(relay_dir gitlab-ssh)" \
|
|
103
|
-
"$(relay_dir gitlab-8929)" "$(relay_dir gitlab-2224)"
|
|
104
|
-
# Application held by Argo CD (#538): its resources go with it
|
|
105
|
-
gitlab_application_retirer || true
|
|
106
|
-
account_helm "$(account_context)" uninstall gitlab --namespace "$GITLAB_NS" >/dev/null 2>&1 || true
|
|
107
|
-
gitlab_runner_ancien_retirer
|
|
108
|
-
# RoleBinding removed, then the namespace deleted by the administrator (#430)
|
|
109
|
-
account_remove "$(account_context)" "$GITLAB_NS" >/dev/null 2>&1 || true
|
|
110
|
-
account_admin "$(account_context)" delete namespace "$GITLAB_NS" --ignore-not-found >/dev/null 2>&1 || true
|
|
111
|
-
if [ -n "$delete_secret" ]; then
|
|
112
|
-
rm -rf "$GITLAB_SECRETS_DIR"
|
|
113
|
-
echo "Rails secret deleted with the GitLab data."
|
|
114
|
-
elif [ -d "$GITLAB_SECRETS_DIR" ]; then
|
|
115
|
-
find "$GITLAB_SECRETS_DIR" -mindepth 1 ! -name rails-secret.yaml -exec rm -rf {} + 2>/dev/null || true
|
|
116
|
-
if [ -f "$GITLAB_RAILS_FILE" ]; then
|
|
117
|
-
echo "Rails secret kept in workspace/.gitlab/rails-secret.yaml (browser sessions valid at reinstallation)"
|
|
118
|
-
fi
|
|
119
|
-
fi
|
|
120
|
-
gitlab_host_remove
|
|
121
|
-
echo "✔ GitLab uninstalled."
|
|
122
|
-
regenerer_identifiants
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
# Migration: installs and seeds in the services cluster, then deletes the old
|
|
126
|
-
# kind-gitlab cluster after confirmation (or --yes).
|
|
127
|
-
gitlab_migrate() {
|
|
128
|
-
local yes_flag="" arg answer
|
|
129
|
-
for arg in "$@"; do
|
|
130
|
-
case "$arg" in
|
|
131
|
-
--yes) yes_flag=1 ;;
|
|
132
|
-
*) echo "devzone : gitlab migrate : unknown argument : $arg (devzone gitlab migrate [--yes])" >&2; return 2 ;;
|
|
133
|
-
esac
|
|
134
|
-
done
|
|
135
|
-
|
|
136
|
-
echo "▶ Migrating GitLab from the old kind cluster…"
|
|
137
|
-
echo " This is a test GitLab: the demo project and the runner are recreated, the rest is lost."
|
|
138
|
-
gitlab_install || return $?
|
|
139
|
-
|
|
140
|
-
if ! kind get clusters 2>/dev/null | grep -qx "$GITLAB_OLD_CLUSTER"; then
|
|
141
|
-
echo "✔ No old cluster $GITLAB_OLD_CONTEXT to delete."
|
|
142
|
-
return 0
|
|
143
|
-
fi
|
|
144
|
-
|
|
145
|
-
if [ -z "$yes_flag" ]; then
|
|
146
|
-
if ! cluster_interactive; then
|
|
147
|
-
echo "devzone : gitlab : confirmation impossible without a terminal: devzone gitlab migrate --yes (old cluster $GITLAB_OLD_CONTEXT kept)" >&2
|
|
148
|
-
return 2
|
|
149
|
-
fi
|
|
150
|
-
printf "Delete the old cluster %s and its data? [y/N] " "$GITLAB_OLD_CONTEXT" >&2
|
|
151
|
-
read -r answer || answer=""
|
|
152
|
-
case "$answer" in
|
|
153
|
-
y | Y | yes) ;;
|
|
154
|
-
*) echo "Aborted: old cluster $GITLAB_OLD_CONTEXT kept."; return 0 ;;
|
|
155
|
-
esac
|
|
156
|
-
fi
|
|
157
|
-
|
|
158
|
-
kind delete cluster --name "$GITLAB_OLD_CLUSTER"
|
|
159
|
-
kubectl config delete-context "$GITLAB_OLD_CONTEXT" >/dev/null 2>&1 || true
|
|
160
|
-
kubectl config delete-cluster "$GITLAB_OLD_CONTEXT" >/dev/null 2>&1 || true
|
|
161
|
-
kubectl config delete-user "$GITLAB_OLD_CONTEXT" >/dev/null 2>&1 || true
|
|
162
|
-
echo "✔ Old cluster $GITLAB_OLD_CONTEXT deleted."
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
# Web and SSH access: port-forward to the ClusterIP services of the namespace.
|
|
166
|
-
gitlab_relay_start() {
|
|
167
|
-
relay_start gitlab-web devzone "$GITLAB_NS" svc/gitlab-webservice-default 8929:8181
|
|
168
|
-
relay_start gitlab-ssh devzone "$GITLAB_NS" svc/gitlab-gitlab-shell 2224:22
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
# Stops the two relays of the module.
|
|
172
|
-
gitlab_relay_stop() {
|
|
173
|
-
relay_stop gitlab-web
|
|
174
|
-
relay_stop gitlab-ssh
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
# State of the relays: code 0 only if both are running.
|
|
178
|
-
gitlab_relay_status() {
|
|
179
|
-
local missing=""
|
|
180
|
-
relay_active gitlab-web || missing="$missing 8929"
|
|
181
|
-
relay_active gitlab-ssh || missing="$missing 2224"
|
|
182
|
-
if [ -n "$missing" ]; then
|
|
183
|
-
echo "gitlab relay stopped on${missing}"
|
|
184
|
-
return 1
|
|
185
|
-
fi
|
|
186
|
-
return 0
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
# True if an old kind-gitlab cluster still exists (warning of the summary,
|
|
190
|
-
# as long as the migration has not been done).
|
|
191
|
-
gitlab_old_cluster_exists() {
|
|
192
|
-
kind get clusters 2>/dev/null | grep -qx "$GITLAB_OLD_CLUSTER"
|
|
193
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# GitLab Rails secret (#347): kept in workspace/.gitlab, the gitlab-rails-secret
|
|
3
|
-
# secret of the devzone-gitlab namespace, source of the Rails secrets.
|
|
4
|
-
# At the first installation, the secret of the cluster is copied to
|
|
5
|
-
# workspace/.gitlab/rails-secret.yaml (600, ignored by git); at a reinstallation,
|
|
6
|
-
# if it exists, it is applied again before helm upgrade --install (the chart
|
|
7
|
-
# reuses it and the browser sessions stay valid, without 422). Otherwise, if the
|
|
8
|
-
# secrets were lost, the end of the installation and the summary warn.
|
|
9
|
-
|
|
10
|
-
# Name of the Rails secret and source file of the secrets of the module
|
|
11
|
-
GITLAB_RAILS_SECRET="gitlab-rails-secret"
|
|
12
|
-
GITLAB_RAILS_FILE="$GITLAB_SECRETS_DIR/rails-secret.yaml"
|
|
13
|
-
|
|
14
|
-
# jq filter: removes the fields specific to the cluster (identity, version,
|
|
15
|
-
# management, annotations of the last apply) and keeps a re-appliable JSON manifest.
|
|
16
|
-
GITLAB_RAILS_JQ='del(.metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp, .metadata.managedFields, .metadata.ownerReferences, .metadata.annotations["kubectl.kubernetes.io/last-applied-configuration"])'
|
|
17
|
-
|
|
18
|
-
# Reads the Rails secret of the cluster and writes a real Secret manifest in JSON
|
|
19
|
-
# (first installation). Nothing is written if the read fails or if the secret is missing.
|
|
20
|
-
gitlab_secrets_copy() {
|
|
21
|
-
local secret tmp
|
|
22
|
-
secret="$(kubectl --context devzone get secret -n "$GITLAB_NS" \
|
|
23
|
-
"$GITLAB_RAILS_SECRET" -o json 2>/dev/null)" || return 0
|
|
24
|
-
[ -n "$secret" ] || return 0
|
|
25
|
-
mkdir -p "$GITLAB_SECRETS_DIR" || return 0
|
|
26
|
-
tmp="$(umask 077; mktemp "$GITLAB_SECRETS_DIR/.rails-secret.XXXXXX")" || return 0
|
|
27
|
-
if ! printf '%s\n' "$secret" | jq "$GITLAB_RAILS_JQ" >"$tmp" || [ ! -s "$tmp" ]; then
|
|
28
|
-
rm -f "$tmp"
|
|
29
|
-
return 0
|
|
30
|
-
fi
|
|
31
|
-
chmod 600 "$tmp" || {
|
|
32
|
-
rm -f "$tmp"
|
|
33
|
-
return 0
|
|
34
|
-
}
|
|
35
|
-
mv -f "$tmp" "$GITLAB_RAILS_FILE"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# Applies the Rails secret again from the source file before a helm upgrade
|
|
39
|
-
# --install: the chart reuses the existing secret, the browser sessions stay
|
|
40
|
-
# valid after a reinstallation. A failure is shown and returned.
|
|
41
|
-
gitlab_secrets_apply() {
|
|
42
|
-
if [ ! -f "$GITLAB_RAILS_FILE" ]; then
|
|
43
|
-
return 0
|
|
44
|
-
fi
|
|
45
|
-
kubectl --context devzone -n "$GITLAB_NS" apply -f "$GITLAB_RAILS_FILE"
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
# Warns if the Rails secret could not be kept: the reinstallation generates a new
|
|
49
|
-
# secret and the browser sessions are invalidated (422).
|
|
50
|
-
gitlab_secrets_warn() {
|
|
51
|
-
if [ ! -f "$GITLAB_RAILS_FILE" ]; then
|
|
52
|
-
echo "GitLab reinstalled: if the browser shows 422, delete the site data of gitlab.localhost"
|
|
53
|
-
fi
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
# Random password (root | dev): Ruby script passed on the standard input of
|
|
57
|
-
# gitlab-rails runner (never on the pod command line), then the source file and
|
|
58
|
-
# the grouped .password are updated if the runner confirms. Nothing is shown,
|
|
59
|
-
# only the path.
|
|
60
|
-
gitlab_new_password() {
|
|
61
|
-
local user="${1:-}" pass pod script output file
|
|
62
|
-
case "$user" in
|
|
63
|
-
root | dev) ;;
|
|
64
|
-
*)
|
|
65
|
-
echo "devzone : gitlab : unknown user : ${user:-(missing)} (devzone gitlab new-password [root|dev])" >&2
|
|
66
|
-
return 2
|
|
67
|
-
;;
|
|
68
|
-
esac
|
|
69
|
-
pass="$(openssl rand -hex 24)"
|
|
70
|
-
pod="$(kubectl --context devzone get pod -n "$GITLAB_NS" -l app=toolbox -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
|
|
71
|
-
if [ -z "$pod" ]; then
|
|
72
|
-
echo "devzone : gitlab : toolbox pod (label app=toolbox) not found, password not changed." >&2
|
|
73
|
-
return 1
|
|
74
|
-
fi
|
|
75
|
-
script="u = User.find_by_username(\"$user\")
|
|
76
|
-
u.password = \"$pass\"
|
|
77
|
-
u.password_confirmation = \"$pass\"
|
|
78
|
-
u.save!
|
|
79
|
-
puts \"OK\""
|
|
80
|
-
if ! output="$(printf '%s\n' "$script" | kubectl --context devzone exec -i -n "$GITLAB_NS" "$pod" -- gitlab-rails runner -)"; then
|
|
81
|
-
echo "devzone : gitlab : password (gitlab-rails runner) not applied." >&2
|
|
82
|
-
return 1
|
|
83
|
-
fi
|
|
84
|
-
if [[ "$output" != *OK* ]]; then
|
|
85
|
-
echo "devzone : gitlab : password not confirmed by gitlab-rails runner." >&2
|
|
86
|
-
return 1
|
|
87
|
-
fi
|
|
88
|
-
file="$GITLAB_SECRETS_DIR/$user-password"
|
|
89
|
-
mkdir -p "$GITLAB_SECRETS_DIR" || return 1
|
|
90
|
-
(umask 077 && printf '%s' "$pass" >"$file") || return 1
|
|
91
|
-
chmod 600 "$file"
|
|
92
|
-
password_regenerate ||
|
|
93
|
-
echo "devzone : gitlab : grouped credentials not updated (devzone passwords)" >&2
|
|
94
|
-
printf '%s\n' "$RACINE/.password"
|
|
95
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
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_command).
|
|
7
|
-
# gitlab_wait_ready waits for the readiness of GitLab (GITLAB_ATTENTE)
|
|
8
|
-
# gitlab_seed group, project, user, runner token and its Secret
|
|
9
|
-
# gitlab_seed_command devzone gitlab seed: relays, readiness, seed
|
|
10
|
-
|
|
11
|
-
# ---- Helper: wait until GitLab is ready ----
|
|
12
|
-
gitlab_wait_ready() {
|
|
13
|
-
local start
|
|
14
|
-
start=$(date +%s)
|
|
15
|
-
echo "▶ Waiting for GitLab to be ready (timeout ${GITLAB_ATTENTE}s)…"
|
|
16
|
-
while [ $(( $(date +%s) - start )) -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 ready."
|
|
19
|
-
return 0
|
|
20
|
-
fi
|
|
21
|
-
sleep 5
|
|
22
|
-
done
|
|
23
|
-
echo "devzone : timeout waiting for GitLab." >&2
|
|
24
|
-
return 1
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
# ---- seed: fill GitLab with the base data ----
|
|
28
|
-
gitlab_seed() {
|
|
29
|
-
echo "▶ Seeding GitLab…"
|
|
30
|
-
|
|
31
|
-
mkdir -p "$GITLAB_SECRETS_DIR"
|
|
32
|
-
|
|
33
|
-
# Root password read from the gitlab-gitlab-initial-root-password secret
|
|
34
|
-
local password
|
|
35
|
-
password="$(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 "$password" ]; then
|
|
37
|
-
echo "devzone : seed GitLab : root secret (gitlab-gitlab-initial-root-password) not found, seed stopped." >&2
|
|
38
|
-
return 1
|
|
39
|
-
fi
|
|
40
|
-
printf '%s' "$password" > "$GITLAB_SECRETS_DIR/root-password"
|
|
41
|
-
chmod 600 "$GITLAB_SECRETS_DIR/root-password"
|
|
42
|
-
|
|
43
|
-
# Root access token created by kubectl exec in the toolbox pod with 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 : toolbox pod (label app=toolbox) not found, seed stopped." >&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 : creation of the root token (gitlab-rails runner) failed, seed stopped." >&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
|
-
# Through the curl API with the token (never shown in clear)
|
|
59
|
-
local token group_id
|
|
60
|
-
token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
61
|
-
|
|
62
|
-
# Group devzone (tested before creation)
|
|
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 : creation of the devzone group failed, seed stopped." >&2
|
|
66
|
-
return 1
|
|
67
|
-
fi
|
|
68
|
-
fi
|
|
69
|
-
group_id="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/groups/devzone" | jq -r '.id // empty')"
|
|
70
|
-
if [ -z "$group_id" ]; then
|
|
71
|
-
echo "devzone : seed GitLab : reading the numeric id of the devzone group failed, seed stopped." >&2
|
|
72
|
-
return 1
|
|
73
|
-
fi
|
|
74
|
-
|
|
75
|
-
# Project devzone/demo (tested before creation, namespace_id = numeric ID of the group)
|
|
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=$group_id" >/dev/null 2>&1; then
|
|
78
|
-
echo "devzone : seed GitLab : creation of the devzone/demo project failed, seed stopped." >&2
|
|
79
|
-
return 1
|
|
80
|
-
fi
|
|
81
|
-
fi
|
|
82
|
-
|
|
83
|
-
# Dev user (tested before creation, password generated at random):
|
|
84
|
-
# an existing dev-password is reused only if the dev user still exists
|
|
85
|
-
# (checked through the API); otherwise it is created again with a new user.
|
|
86
|
-
local users_json dev_password
|
|
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
|
-
dev_password="$(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=$dev_password" >/dev/null 2>&1; then
|
|
91
|
-
echo "devzone : seed GitLab : creation of the dev user failed, seed stopped." >&2
|
|
92
|
-
return 1
|
|
93
|
-
fi
|
|
94
|
-
printf '%s' "$dev_password" > "$GITLAB_SECRETS_DIR/dev-password"
|
|
95
|
-
chmod 600 "$GITLAB_SECRETS_DIR/dev-password"
|
|
96
|
-
fi
|
|
97
|
-
|
|
98
|
-
# Runner token: checked through POST /api/v4/runners/verify; a valid token
|
|
99
|
-
# is kept, a refused token (403/404) is created again, GitLab unreachable stops the seed.
|
|
100
|
-
local runner_saved runner_code runner_token
|
|
101
|
-
if [ -f "$GITLAB_SECRETS_DIR/runner-token" ]; then
|
|
102
|
-
runner_saved="$(cat "$GITLAB_SECRETS_DIR/runner-token")"
|
|
103
|
-
runner_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=${runner_saved}" || true)"
|
|
104
|
-
if [ "$runner_code" = "200" ]; then
|
|
105
|
-
echo "✔ Runner token valid: kept."
|
|
106
|
-
elif [ "$runner_code" = "403" ] || [ "$runner_code" = "404" ]; then
|
|
107
|
-
echo "devzone : runner token of a previous installation refused: recreated."
|
|
108
|
-
runner_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 "$runner_token" ]; then
|
|
110
|
-
echo "devzone : seed GitLab : creation of the runner token (POST /api/v4/user/runners) failed, seed stopped." >&2
|
|
111
|
-
return 1
|
|
112
|
-
fi
|
|
113
|
-
printf '%s' "$runner_token" > "$GITLAB_SECRETS_DIR/runner-token"
|
|
114
|
-
chmod 600 "$GITLAB_SECRETS_DIR/runner-token"
|
|
115
|
-
else
|
|
116
|
-
echo "devzone : seed GitLab : runner token check impossible (code ${runner_code}), seed stopped." >&2
|
|
117
|
-
return 1
|
|
118
|
-
fi
|
|
119
|
-
else
|
|
120
|
-
runner_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 "$runner_token" ]; then
|
|
122
|
-
echo "devzone : seed GitLab : creation of the runner token (POST /api/v4/user/runners) failed, seed stopped." >&2
|
|
123
|
-
return 1
|
|
124
|
-
fi
|
|
125
|
-
printf '%s' "$runner_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 not created, seed stopped." >&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 of the content of demo/ to devzone/demo (temporary git repository, http remote with the token in the URL, never shown; branch main)
|
|
145
|
-
# The push uses the root token (write_repository): the runner token cannot push.
|
|
146
|
-
local push_token=""
|
|
147
|
-
push_token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
|
|
148
|
-
if [ -z "$push_token" ]; then
|
|
149
|
-
echo "devzone : seed GitLab : root token not found, seed stopped." >&2
|
|
150
|
-
return 1
|
|
151
|
-
fi
|
|
152
|
-
# Already pushed (installation run again): nothing to do
|
|
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 "✔ GitLab seed complete (demo project already pushed)."
|
|
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
|
-
# Throwaway repository of the script: the global git hooks (repowarden)
|
|
165
|
-
# have nothing to check here and would refuse the 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 is not always resolved by git: local address,
|
|
171
|
-
# and the host expected by the ingress passed as a header
|
|
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
|
-
# Checks the push: the main branch exists on the project
|
|
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 of the demo project to /devzone/demo.git succeeded but branch main is missing, seed stopped." >&2
|
|
178
|
-
rm -rf "$tmpdir"
|
|
179
|
-
return 1
|
|
180
|
-
fi
|
|
181
|
-
else
|
|
182
|
-
echo "devzone : seed GitLab : push of the demo project to /devzone/demo.git failed, seed stopped." >&2
|
|
183
|
-
rm -rf "$tmpdir"
|
|
184
|
-
return 1
|
|
185
|
-
fi
|
|
186
|
-
rm -rf "$tmpdir"
|
|
187
|
-
fi
|
|
188
|
-
|
|
189
|
-
echo "✔ GitLab seed complete."
|
|
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_command() {
|
|
198
|
-
gitlab_relay_start || return 1
|
|
199
|
-
gitlab_wait_ready || return 1
|
|
200
|
-
gitlab_seed || return 1
|
|
201
|
-
if [ ! -f "$GITLAB_RAILS_FILE" ]; then
|
|
202
|
-
gitlab_secrets_copy
|
|
203
|
-
fi
|
|
204
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Leftovers of the gitlab instance after disable (test-gitlab.sh --complet, #517).
|
|
3
|
-
# Sourced by test-gitlab.sh. Docker workstation: containers labelled with the
|
|
4
|
-
# instance, from docker ps. Kubernetes workspace (DEVZONE_WORKSPACE=kubernetes):
|
|
5
|
-
# pods labelled with the instance, from kubectl get pods. Read-only commands.
|
|
6
|
-
|
|
7
|
-
# Prints the leftovers of instance $1, one per line (nothing when clean).
|
|
8
|
-
gitlab_restes_conteneurs() {
|
|
9
|
-
local instance="$1"
|
|
10
|
-
if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
|
|
11
|
-
kubectl --context devzone get pods --all-namespaces \
|
|
12
|
-
-l "devzone.instance=$instance" -o name 2>/dev/null || true
|
|
13
|
-
else
|
|
14
|
-
docker ps -aq --filter "label=devzone.instance=$instance" 2>/dev/null || true
|
|
15
|
-
fi
|
|
16
|
-
}
|