devzone 1.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +4 -4
- package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
- package/.devcontainer/agent-local.sh +2 -2
- package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
- package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
- package/.devcontainer/agent-session.sh +3 -3
- package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +14 -14
- package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
- package/.devcontainer/{ia → ai}/host-models.sh +2 -2
- package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
- package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
- package/.devcontainer/argocd/argocd.sh +94 -93
- package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
- package/.devcontainer/argocd/services-hook.sh +8 -8
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +209 -0
- package/.devcontainer/catalog/catalog-watcher.sh +130 -0
- package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +87 -0
- package/.devcontainer/catalog/mysql/mysql.sh +262 -0
- package/.devcontainer/catalog/mysql/volume.sh +71 -0
- package/.devcontainer/catalog.sh +231 -0
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +222 -224
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +103 -1506
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/argocd.sh +2 -2
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +83 -84
- package/.devcontainer/gitlab/installation.sh +111 -111
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +65 -0
- package/.devcontainer/kind-wrapper.sh +45 -0
- package/.devcontainer/kube-account.sh +199 -0
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +64 -0
- package/.devcontainer/{memoire.sh → memory.sh} +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +228 -0
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +127 -123
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +176 -176
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +5 -5
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +65 -0
- package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
- package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
- package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
- package/.devcontainer/{etat.sh → state.sh} +4 -4
- package/.devcontainer/workspace-init.sh +17 -3
- package/Makefile +8 -8
- package/README.md +195 -194
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +8 -10
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/check-go-layout.sh +40 -0
- package/manage/scripts/check-names.sh +61 -0
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +2 -2
- package/manage/scripts/devzone-create.sh +5 -5
- package/manage/scripts/devzone-manifest.sh +3 -3
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/docker-workstation.sh +2 -2
- package/manage/scripts/docker.sh +2 -2
- package/manage/scripts/{lancer.sh → launch.sh} +10 -51
- package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
- package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +4 -4
- package/package.json +1 -1
- package/.devcontainer/catalogue/app.sh +0 -211
- package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
- package/.devcontainer/catalogue/mysql/installer.sh +0 -87
- package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
- package/.devcontainer/catalogue/mysql/volume.sh +0 -71
- package/.devcontainer/catalogue.sh +0 -231
- package/.devcontainer/demarrage.sh +0 -66
- package/.devcontainer/docker-relais.sh +0 -149
- package/.devcontainer/docker-sans-hote.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/.devcontainer/isolement.sh +0 -65
- package/.devcontainer/kind-enveloppe.sh +0 -45
- package/.devcontainer/kube-compte.sh +0 -200
- package/.devcontainer/kube-joignable.sh +0 -64
- package/.devcontainer/paquets.sh +0 -227
- /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
- /package/.devcontainer/{ia → ai}/host-check.message +0 -0
- /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# devzone test-gitlab
|
|
3
|
-
#
|
|
4
|
-
#
|
|
2
|
+
# devzone test-gitlab: end-to-end test of the gitlab module and of the GitLab
|
|
3
|
+
# platform, in the container. Each step is timed; the final summary gives
|
|
4
|
+
# ✔/✖/skipped and the exit code is 0 only without ✖.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
6
|
+
# Why a separate script: the GitHub CI does not have the 8 GB of RAM of the gitlab
|
|
7
|
+
# module. This test therefore replays by hand, on the workstation, what the CI
|
|
8
|
+
# cannot do, and possibly publishes its result as a commit status.
|
|
9
9
|
#
|
|
10
|
-
# Options
|
|
11
|
-
# gitlab-integration
|
|
12
|
-
#
|
|
13
|
-
#
|
|
10
|
+
# Options: --complet (disables then reinstalls), --statut (publishes the
|
|
11
|
+
# gitlab-integration status on HEAD with gh).
|
|
12
|
+
# The steps are called indirectly by run_step: shellcheck cannot see it and
|
|
13
|
+
# would take them for unreachable (SC2317).
|
|
14
14
|
# shellcheck disable=SC2317
|
|
15
15
|
set -uo pipefail
|
|
16
16
|
|
|
17
17
|
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
18
|
-
#
|
|
19
|
-
RACINE="${
|
|
18
|
+
# Same root as gitlab.sh: DEVZONE_ROOT for the tests
|
|
19
|
+
RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
|
|
20
20
|
GITLAB="$ICI/gitlab.sh"
|
|
21
21
|
SECRETS="$RACINE/workspace/.gitlab"
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
TOKEN_FILE="$SECRETS/root-token"
|
|
23
|
+
STATE_FILE="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
|
|
24
24
|
HOSTS="${DEVZONE_HOSTS:-/etc/hosts}"
|
|
25
|
-
#
|
|
26
|
-
# gitlab.sh (
|
|
25
|
+
# Instance name: DEVZONE_INSTANCE suffix computed by cluster.sh, as in
|
|
26
|
+
# gitlab.sh (suffixed devzone-gitlab namespace).
|
|
27
27
|
# shellcheck source=SCRIPTDIR/../cluster.sh
|
|
28
28
|
# shellcheck disable=SC1091
|
|
29
29
|
. "$ICI/../cluster.sh"
|
|
@@ -31,15 +31,15 @@ HOSTS="${DEVZONE_HOSTS:-/etc/hosts}"
|
|
|
31
31
|
# shellcheck disable=SC1091
|
|
32
32
|
. "$ICI/test-gitlab-restes.sh"
|
|
33
33
|
URL="${GITLAB_TEST_URL:-http://gitlab.localhost:8929}"
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
|
|
34
|
+
# Pipeline timeout: 600 s by default, short in the tests
|
|
35
|
+
PIPELINE_TIMEOUT="${GITLAB_TEST_PIPELINE:-600}"
|
|
36
|
+
# Pipeline polling interval: 5 s by default, short in the tests
|
|
37
|
+
INTERVAL="${GITLAB_TEST_INTERVALLE:-5}"
|
|
38
|
+
# Ref of the repowarden integration suite (#533)
|
|
39
|
+
REPOWARDEN_REF="${REPOWARDEN_TEST_REF:-develop}"
|
|
40
40
|
|
|
41
|
-
# devzone
|
|
42
|
-
#
|
|
41
|
+
# devzone itself: the command of the PATH (link set by post-create.sh), otherwise
|
|
42
|
+
# the script of the repository. DEVZONE_TEST_DEVZONE allows a test double.
|
|
43
43
|
DEVZONE_BIN="${DEVZONE_TEST_DEVZONE:-}"
|
|
44
44
|
if [ -z "$DEVZONE_BIN" ]; then
|
|
45
45
|
if command -v devzone >/dev/null 2>&1; then
|
|
@@ -48,443 +48,442 @@ if [ -z "$DEVZONE_BIN" ]; then
|
|
|
48
48
|
DEVZONE_BIN="$RACINE/.devcontainer/devzone"
|
|
49
49
|
fi
|
|
50
50
|
fi
|
|
51
|
-
#
|
|
51
|
+
# Same path as devzone: glab lives in ~/.local/bin, never in the PATH
|
|
52
52
|
GLAB="$HOME/.local/bin/glab"
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
FULL=0
|
|
55
|
+
PUBLISH=0
|
|
56
|
+
TOKEN=""
|
|
57
|
+
KEY_ID=""
|
|
58
|
+
FAILED=0
|
|
59
59
|
TOTAL=0
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
REASON=""
|
|
61
|
+
PLATFORM_CHANGED=0
|
|
62
62
|
TMP_DIRS=()
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
NAMES=()
|
|
64
|
+
SYMBOLS=()
|
|
65
|
+
DURATIONS=()
|
|
66
66
|
SUFFIXES=()
|
|
67
67
|
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
[ "$
|
|
72
|
-
|
|
68
|
+
# Previous platform, read from the same state file as devzone: the trap
|
|
69
|
+
# must be able to restore it even if step 6 fails midway.
|
|
70
|
+
PLATFORM_BEFORE="$(grep -E '^platform=' "$STATE_FILE" 2>/dev/null | tail -1 | cut -d= -f2 || true)"
|
|
71
|
+
[ "$PLATFORM_BEFORE" = gitlab ] || PLATFORM_BEFORE=github
|
|
72
|
+
URL_BEFORE="$(grep -E '^gitlab_url=' "$STATE_FILE" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
|
|
73
73
|
|
|
74
74
|
usage() {
|
|
75
75
|
cat <<'USAGE'
|
|
76
76
|
devzone test-gitlab [--complet] [--statut]
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
--complet
|
|
80
|
-
--statut
|
|
78
|
+
End-to-end test of the gitlab module and of the GitLab platform.
|
|
79
|
+
--complet disables gitlab, checks that nothing remains, then reinstalls
|
|
80
|
+
--statut publishes the result as the gitlab-integration status on HEAD (gh)
|
|
81
81
|
USAGE
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
#
|
|
85
|
-
#
|
|
84
|
+
# GitLab API call: the token never appears in a message nor in a file of the
|
|
85
|
+
# clone. curl receives it in a header, as the seed of gitlab.sh does.
|
|
86
86
|
api() {
|
|
87
|
-
local
|
|
87
|
+
local method="$1" path="$2"
|
|
88
88
|
shift 2
|
|
89
|
-
curl -sS --fail --request "$
|
|
90
|
-
"${URL}/api/v4${
|
|
89
|
+
curl -sS --fail --request "$method" --header "PRIVATE-TOKEN: ${TOKEN:-}" \
|
|
90
|
+
"${URL}/api/v4${path}" "$@"
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
if [ ! -f "$
|
|
95
|
-
|
|
93
|
+
read_token() {
|
|
94
|
+
if [ ! -f "$TOKEN_FILE" ]; then
|
|
95
|
+
REASON="root token missing ($TOKEN_FILE): run with the devzone test-gitlab command of the PATH, or set DEVZONE_ROOT to the root of the enabled repository"
|
|
96
96
|
return 1
|
|
97
97
|
fi
|
|
98
|
-
|
|
99
|
-
if [ -z "$
|
|
100
|
-
|
|
98
|
+
TOKEN="$(cat "$TOKEN_FILE")"
|
|
99
|
+
if [ -z "$TOKEN" ]; then
|
|
100
|
+
REASON="root token empty ($TOKEN_FILE)"
|
|
101
101
|
return 1
|
|
102
102
|
fi
|
|
103
103
|
return 0
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
#
|
|
107
|
-
# URL).
|
|
108
|
-
#
|
|
109
|
-
|
|
110
|
-
if [ "$
|
|
111
|
-
"$DEVZONE_BIN" platform gitlab --url "$
|
|
106
|
+
# Restores the previous platform (github by default, or the GitLab instance with its
|
|
107
|
+
# URL). The trap calls it too: an interrupted step 6 does not leave the
|
|
108
|
+
# platform of the user changed.
|
|
109
|
+
restore_platform() {
|
|
110
|
+
if [ "$PLATFORM_BEFORE" = gitlab ] && [ -n "$URL_BEFORE" ]; then
|
|
111
|
+
"$DEVZONE_BIN" platform gitlab --url "$URL_BEFORE" >/dev/null 2>&1
|
|
112
112
|
else
|
|
113
113
|
"$DEVZONE_BIN" platform github >/dev/null 2>&1
|
|
114
114
|
fi
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
#
|
|
118
|
-
#
|
|
119
|
-
|
|
117
|
+
# Guaranteed cleanup: throwaway SSH key removed from GitLab, temporary folders
|
|
118
|
+
# deleted, previous platform restored. Even when a step failed.
|
|
119
|
+
cleanup() {
|
|
120
120
|
local code=$? d
|
|
121
121
|
trap - EXIT
|
|
122
|
-
if [ -n "${
|
|
123
|
-
api DELETE "/user/keys/$
|
|
122
|
+
if [ -n "${KEY_ID:-}" ]; then
|
|
123
|
+
api DELETE "/user/keys/$KEY_ID" >/dev/null 2>&1 || true
|
|
124
124
|
fi
|
|
125
|
-
if [ "$
|
|
126
|
-
|
|
125
|
+
if [ "$PLATFORM_CHANGED" = 1 ]; then
|
|
126
|
+
restore_platform || true
|
|
127
127
|
fi
|
|
128
128
|
for d in ${TMP_DIRS[@]+"${TMP_DIRS[@]}"}; do
|
|
129
129
|
[ -n "$d" ] && rm -rf "$d"
|
|
130
130
|
done
|
|
131
131
|
exit "$code"
|
|
132
132
|
}
|
|
133
|
-
trap
|
|
133
|
+
trap cleanup EXIT
|
|
134
134
|
|
|
135
|
-
# ----
|
|
135
|
+
# ---- The steps, one function per step ----
|
|
136
136
|
|
|
137
|
-
# 1. Module
|
|
138
|
-
|
|
137
|
+
# 1. Module: active, otherwise enabled (the activation also installs if needed).
|
|
138
|
+
step_module() {
|
|
139
139
|
if "$DEVZONE_BIN" is-enabled gitlab >/dev/null 2>&1; then
|
|
140
140
|
return 0
|
|
141
141
|
fi
|
|
142
142
|
if ! "$DEVZONE_BIN" enable gitlab >/dev/null 2>&1; then
|
|
143
|
-
|
|
143
|
+
REASON="devzone enable gitlab failed"
|
|
144
144
|
return 1
|
|
145
145
|
fi
|
|
146
146
|
return 0
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
# 2.
|
|
150
|
-
# pipeline
|
|
151
|
-
|
|
152
|
-
local
|
|
153
|
-
|
|
154
|
-
if [[ "$
|
|
155
|
-
|
|
149
|
+
# 2. State: the module must be ready and its runner online (without a runner, the
|
|
150
|
+
# pipeline would wait forever).
|
|
151
|
+
step_state() {
|
|
152
|
+
local state
|
|
153
|
+
state="$(bash "$GITLAB" status 2>&1 || true)"
|
|
154
|
+
if [[ "$state" != *"ready"* ]]; then
|
|
155
|
+
REASON="state: ${state:-unreadable}"
|
|
156
156
|
return 1
|
|
157
157
|
fi
|
|
158
|
-
if [[ "$
|
|
159
|
-
|
|
158
|
+
if [[ "$state" != *"runner online"* ]]; then
|
|
159
|
+
REASON="runner offline ($state)"
|
|
160
160
|
return 1
|
|
161
161
|
fi
|
|
162
162
|
return 0
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
# 3.
|
|
166
|
-
# git
|
|
167
|
-
# gitlab.localhost
|
|
168
|
-
#
|
|
169
|
-
|
|
170
|
-
local
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if [ -z "$
|
|
174
|
-
|
|
165
|
+
# 3. Name and relays: ssh and glab go through the system resolver; curl and
|
|
166
|
+
# git in HTTP resolve *.localhost to the loopback without reading /etc/hosts.
|
|
167
|
+
# gitlab.localhost must therefore point to 127.0.0.1 AND the relays 8929/2224
|
|
168
|
+
# must run in the container (gitlab.sh hote-poser, relay-start).
|
|
169
|
+
step_name() {
|
|
170
|
+
local host ip_name relays
|
|
171
|
+
host="$(getent hosts gitlab.localhost 2>/dev/null || true)"
|
|
172
|
+
ip_name="$(printf '%s\n' "$host" | awk '{print $1; exit}')"
|
|
173
|
+
if [ -z "$ip_name" ]; then
|
|
174
|
+
REASON="gitlab.localhost not resolved (getent hosts)"
|
|
175
175
|
return 1
|
|
176
176
|
fi
|
|
177
|
-
if [ "$
|
|
178
|
-
|
|
177
|
+
if [ "$ip_name" != "127.0.0.1" ]; then
|
|
178
|
+
REASON="gitlab.localhost resolves to $ip_name, expected 127.0.0.1"
|
|
179
179
|
return 1
|
|
180
180
|
fi
|
|
181
|
-
if !
|
|
182
|
-
|
|
181
|
+
if ! relays="$(bash "$GITLAB" relay-status 2>&1)"; then
|
|
182
|
+
REASON="gitlab.localhost points to 127.0.0.1, but ${relays:-gitlab relay stopped}"
|
|
183
183
|
return 1
|
|
184
184
|
fi
|
|
185
185
|
return 0
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
# 4. Pipeline
|
|
189
|
-
|
|
190
|
-
local
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
# 4. Pipeline: starts the one of devzone/demo on main and waits for success.
|
|
189
|
+
step_pipeline() {
|
|
190
|
+
local response id web_url state start
|
|
191
|
+
read_token || return 1
|
|
192
|
+
response="$(api POST "/projects/devzone%2Fdemo/pipeline" --data "ref=main" 2>/dev/null)" || {
|
|
193
|
+
REASON="creation of the pipeline of devzone/demo impossible"
|
|
194
194
|
return 1
|
|
195
195
|
}
|
|
196
|
-
id="$(printf '%s' "$
|
|
197
|
-
web_url="$(printf '%s' "$
|
|
196
|
+
id="$(printf '%s' "$response" | jq -r '.id // empty' 2>/dev/null || true)"
|
|
197
|
+
web_url="$(printf '%s' "$response" | jq -r '.web_url // empty' 2>/dev/null || true)"
|
|
198
198
|
if [ -z "$id" ]; then
|
|
199
|
-
|
|
199
|
+
REASON="pipeline creation response without id"
|
|
200
200
|
return 1
|
|
201
201
|
fi
|
|
202
|
-
|
|
202
|
+
start="$(date +%s)"
|
|
203
203
|
while :; do
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
case "$
|
|
204
|
+
response="$(api GET "/projects/devzone%2Fdemo/pipelines/$id" 2>/dev/null || true)"
|
|
205
|
+
state="$(printf '%s' "$response" | jq -r '.status // empty' 2>/dev/null || true)"
|
|
206
|
+
case "$state" in
|
|
207
207
|
success) return 0 ;;
|
|
208
208
|
failed | canceled | skipped)
|
|
209
|
-
|
|
209
|
+
REASON="pipeline $state: ${web_url:-$URL/devzone/demo/-/pipelines/$id}"
|
|
210
210
|
return 1
|
|
211
211
|
;;
|
|
212
212
|
esac
|
|
213
|
-
if [ $(( $(date +%s) -
|
|
214
|
-
|
|
213
|
+
if [ $(( $(date +%s) - start )) -ge "$PIPELINE_TIMEOUT" ]; then
|
|
214
|
+
REASON="timeout ${PIPELINE_TIMEOUT} s exceeded (state ${state:-unknown}): ${web_url:-$URL/devzone/demo/-/pipelines/$id}"
|
|
215
215
|
return 1
|
|
216
216
|
fi
|
|
217
|
-
sleep "$
|
|
217
|
+
sleep "$INTERVAL"
|
|
218
218
|
done
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
# 5.
|
|
222
|
-
#
|
|
223
|
-
#
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
lire_jeton || return 1
|
|
221
|
+
# 5. HTTP and SSH clones: throwaway ed25519 key placed on root, then removed
|
|
222
|
+
# by the trap. The HTTP clone authenticates with Basic oauth2 + token, provided
|
|
223
|
+
# by a credential helper that reads the file (a git http.extraHeader would pass
|
|
224
|
+
# the token in clear in the arguments of a process): the token appears neither
|
|
225
|
+
# in these arguments, nor in the URL, nor in .git/config.
|
|
226
|
+
step_clones() {
|
|
227
|
+
local d pub response
|
|
228
|
+
read_token || return 1
|
|
230
229
|
d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-clones.XXXXXX")" || {
|
|
231
|
-
|
|
230
|
+
REASON="temporary directory impossible"
|
|
232
231
|
return 1
|
|
233
232
|
}
|
|
234
233
|
TMP_DIRS+=("$d")
|
|
235
234
|
if ! ssh-keygen -q -t ed25519 -N '' -f "$d/id_ed25519" >/dev/null 2>&1; then
|
|
236
|
-
|
|
235
|
+
REASON="ed25519 key generation impossible"
|
|
237
236
|
return 1
|
|
238
237
|
fi
|
|
239
238
|
pub="$(cat "$d/id_ed25519.pub" 2>/dev/null || true)"
|
|
240
|
-
|
|
239
|
+
response="$(api POST "/user/keys" --data-urlencode "title=devzone test-gitlab" \
|
|
241
240
|
--data-urlencode "key=$pub" 2>/dev/null)" || {
|
|
242
|
-
|
|
241
|
+
REASON="SSH key upload to GitLab impossible"
|
|
243
242
|
return 1
|
|
244
243
|
}
|
|
245
|
-
|
|
246
|
-
if [ -z "$
|
|
247
|
-
|
|
244
|
+
KEY_ID="$(printf '%s' "$response" | jq -r '.id // empty' 2>/dev/null || true)"
|
|
245
|
+
if [ -z "$KEY_ID" ]; then
|
|
246
|
+
REASON="key upload response without id"
|
|
248
247
|
return 1
|
|
249
248
|
fi
|
|
250
249
|
if ! git clone -q \
|
|
251
250
|
-c "core.sshCommand=ssh -i $d/id_ed25519 -o UserKnownHostsFile=$d/known_hosts -o StrictHostKeyChecking=accept-new" \
|
|
252
251
|
"ssh://git@gitlab.localhost:2224/devzone/demo.git" "$d/ssh-demo" >/dev/null 2>&1; then
|
|
253
|
-
|
|
252
|
+
REASON="SSH clone (ssh://git@gitlab.localhost:2224/devzone/demo.git) impossible"
|
|
254
253
|
return 1
|
|
255
254
|
fi
|
|
256
255
|
if ! git -c credential.helper= \
|
|
257
|
-
-c "credential.helper=!f() { echo username=oauth2; printf 'password='; cat \"$
|
|
256
|
+
-c "credential.helper=!f() { echo username=oauth2; printf 'password='; cat \"$TOKEN_FILE\"; echo; }; f" \
|
|
258
257
|
clone -q "$URL/devzone/demo.git" "$d/http-demo" >/dev/null 2>&1; then
|
|
259
|
-
|
|
258
|
+
REASON="HTTP clone of devzone/demo impossible"
|
|
260
259
|
return 1
|
|
261
260
|
fi
|
|
262
|
-
if grep -qF "$
|
|
263
|
-
|
|
261
|
+
if grep -qF "$TOKEN" "$d/http-demo/.git/config" 2>/dev/null; then
|
|
262
|
+
REASON="the token was written to .git/config of the clone"
|
|
264
263
|
return 1
|
|
265
264
|
fi
|
|
266
265
|
return 0
|
|
267
266
|
}
|
|
268
267
|
|
|
269
|
-
# 6.
|
|
270
|
-
#
|
|
271
|
-
|
|
268
|
+
# 6. Platform: gitlab (glab clone), then back to the previous platform;
|
|
269
|
+
# when back to github, glab and its configuration must no longer be there.
|
|
270
|
+
step_platform() {
|
|
272
271
|
local d
|
|
273
272
|
d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-plateforme.XXXXXX")" || {
|
|
274
|
-
|
|
273
|
+
REASON="temporary directory impossible"
|
|
275
274
|
return 1
|
|
276
275
|
}
|
|
277
276
|
TMP_DIRS+=("$d")
|
|
278
|
-
|
|
277
|
+
PLATFORM_CHANGED=1
|
|
279
278
|
if ! "$DEVZONE_BIN" platform gitlab >/dev/null 2>&1; then
|
|
280
|
-
|
|
279
|
+
REASON="devzone platform gitlab failed"
|
|
281
280
|
return 1
|
|
282
281
|
fi
|
|
283
282
|
if ! "$GLAB" repo clone devzone/demo "$d/demo" >/dev/null 2>&1; then
|
|
284
|
-
|
|
283
|
+
REASON="glab repo clone devzone/demo failed"
|
|
285
284
|
return 1
|
|
286
285
|
fi
|
|
287
|
-
if !
|
|
288
|
-
|
|
286
|
+
if ! restore_platform; then
|
|
287
|
+
REASON="return to platform $PLATFORM_BEFORE impossible"
|
|
289
288
|
return 1
|
|
290
289
|
fi
|
|
291
|
-
if [ "$
|
|
290
|
+
if [ "$PLATFORM_BEFORE" = github ]; then
|
|
292
291
|
if [ -e "$GLAB" ] || [ -e "$HOME/.config/glab-cli" ]; then
|
|
293
|
-
|
|
292
|
+
REASON="glab or its configuration remains after returning to github"
|
|
294
293
|
return 1
|
|
295
294
|
fi
|
|
296
295
|
fi
|
|
297
|
-
|
|
296
|
+
PLATFORM_CHANGED=0
|
|
298
297
|
return 0
|
|
299
298
|
}
|
|
300
299
|
|
|
301
|
-
# 7.
|
|
302
|
-
# module,
|
|
303
|
-
#
|
|
304
|
-
|
|
300
|
+
# 7. repowarden integration: test/gitlab/ suite (#533) against the instance of the
|
|
301
|
+
# module, with the URL and the token as environment variables. Missing at the
|
|
302
|
+
# chosen ref -> step skipped, not failed.
|
|
303
|
+
step_repowarden() {
|
|
305
304
|
local d log bats_exit bats_output
|
|
306
|
-
|
|
305
|
+
read_token || return 1
|
|
307
306
|
d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-repowarden.XXXXXX")" || {
|
|
308
|
-
|
|
307
|
+
REASON="temporary directory impossible"
|
|
309
308
|
return 1
|
|
310
309
|
}
|
|
311
310
|
TMP_DIRS+=("$d")
|
|
312
311
|
log="${TMPDIR:-/tmp}/devzone-test-gitlab-repowarden.log"
|
|
313
|
-
if ! git clone -q --depth 1 --branch "$
|
|
312
|
+
if ! git clone -q --depth 1 --branch "$REPOWARDEN_REF" \
|
|
314
313
|
https://github.com/simdevWarden/repowarden.git "$d/repowarden" >/dev/null 2>&1; then
|
|
315
|
-
|
|
314
|
+
REASON="clone of repowarden (ref $REPOWARDEN_REF) impossible"
|
|
316
315
|
return 1
|
|
317
316
|
fi
|
|
318
317
|
if [ ! -d "$d/repowarden/test/gitlab" ]; then
|
|
319
|
-
|
|
318
|
+
REASON="test/gitlab missing at ref $REPOWARDEN_REF"
|
|
320
319
|
return 2
|
|
321
320
|
fi
|
|
322
321
|
if ! command -v bats >/dev/null 2>&1; then
|
|
323
|
-
|
|
322
|
+
REASON="bats not found"
|
|
324
323
|
return 1
|
|
325
324
|
fi
|
|
326
|
-
if bats_output="$(REPOWARDEN_IT_GITLAB_URL="$URL" REPOWARDEN_IT_GITLAB_TOKEN="$
|
|
325
|
+
if bats_output="$(REPOWARDEN_IT_GITLAB_URL="$URL" REPOWARDEN_IT_GITLAB_TOKEN="$TOKEN" \
|
|
327
326
|
bats "$d/repowarden/test/gitlab/" 2>&1)"; then
|
|
328
327
|
bats_exit=0
|
|
329
328
|
else
|
|
330
329
|
bats_exit=$?
|
|
331
330
|
fi
|
|
332
|
-
printf '%s' "$bats_output" | sed "s/${
|
|
331
|
+
printf '%s' "$bats_output" | sed "s/${TOKEN}/TOKEN_MASKED/g" > "$log"
|
|
333
332
|
if [ "$bats_exit" -ne 0 ]; then
|
|
334
|
-
|
|
333
|
+
REASON="the test/gitlab suite failed (log: $log)"
|
|
335
334
|
return 1
|
|
336
335
|
fi
|
|
337
336
|
return 0
|
|
338
337
|
}
|
|
339
338
|
|
|
340
|
-
# 8. --complet
|
|
341
|
-
#
|
|
342
|
-
#
|
|
343
|
-
|
|
344
|
-
local
|
|
339
|
+
# 8. --complet: disabling first, then checks that no namespace, container, secret
|
|
340
|
+
# or /etc/hosts line remains. Steps 1 to 7 then reinstall. The namespace is
|
|
341
|
+
# suffixed per instance, as in gitlab.sh.
|
|
342
|
+
step_full() {
|
|
343
|
+
local leftovers="" instance namespace containers
|
|
345
344
|
instance="${DEVZONE_INSTANCE:-devzone}"
|
|
346
345
|
namespace="devzone-gitlab${INSTANCE_SUFFIX}"
|
|
347
346
|
if ! "$DEVZONE_BIN" disable gitlab >/dev/null 2>&1; then
|
|
348
|
-
|
|
347
|
+
leftovers="$leftovers disable failed;"
|
|
349
348
|
fi
|
|
350
349
|
if kubectl --context devzone get namespace "$namespace" >/dev/null 2>&1; then
|
|
351
|
-
|
|
350
|
+
leftovers="$leftovers namespace $namespace;"
|
|
352
351
|
fi
|
|
353
|
-
|
|
354
|
-
if [ -n "$
|
|
355
|
-
|
|
352
|
+
containers="$(gitlab_restes_conteneurs "$instance")"
|
|
353
|
+
if [ -n "$containers" ]; then
|
|
354
|
+
leftovers="$leftovers labelled container(s) devzone.instance=$instance;"
|
|
356
355
|
fi
|
|
357
356
|
if [ -e "$SECRETS" ]; then
|
|
358
|
-
|
|
357
|
+
leftovers="$leftovers $SECRETS;"
|
|
359
358
|
fi
|
|
360
359
|
if grep -q '# devzone:gitlab' "$HOSTS" 2>/dev/null; then
|
|
361
|
-
|
|
360
|
+
leftovers="$leftovers /etc/hosts line;"
|
|
362
361
|
fi
|
|
363
|
-
if [ -n "$
|
|
364
|
-
|
|
362
|
+
if [ -n "$leftovers" ]; then
|
|
363
|
+
REASON="remaining:$leftovers"
|
|
365
364
|
return 1
|
|
366
365
|
fi
|
|
367
366
|
return 0
|
|
368
367
|
}
|
|
369
368
|
|
|
370
|
-
# ----
|
|
369
|
+
# ---- Common frame: times, records ✔/✖/skipped + reason ----
|
|
371
370
|
|
|
372
|
-
|
|
373
|
-
local
|
|
374
|
-
|
|
375
|
-
printf '▶ %s…\n' "$
|
|
376
|
-
|
|
377
|
-
"$
|
|
371
|
+
run_step() {
|
|
372
|
+
local name="$1" func="$2" start end duration code symbol suffix
|
|
373
|
+
REASON=""
|
|
374
|
+
printf '▶ %s…\n' "$name"
|
|
375
|
+
start="$(date +%s)"
|
|
376
|
+
"$func"
|
|
378
377
|
code=$?
|
|
379
|
-
|
|
380
|
-
|
|
378
|
+
end="$(date +%s)"
|
|
379
|
+
duration=$((end - start))
|
|
381
380
|
case "$code" in
|
|
382
|
-
0)
|
|
383
|
-
2)
|
|
384
|
-
*)
|
|
381
|
+
0) symbol="✔"; suffix="" ;;
|
|
382
|
+
2) symbol="–"; suffix=" — skipped: ${REASON:-no reason}" ;;
|
|
383
|
+
*) symbol="✖"; FAILED=1; suffix=" — ${REASON:-failed}" ;;
|
|
385
384
|
esac
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
SUFFIXES+=("$
|
|
390
|
-
printf ' %s %s (%d s)%s\n' "$
|
|
385
|
+
NAMES+=("$name")
|
|
386
|
+
SYMBOLS+=("$symbol")
|
|
387
|
+
DURATIONS+=("$duration")
|
|
388
|
+
SUFFIXES+=("$suffix")
|
|
389
|
+
printf ' %s %s (%d s)%s\n' "$symbol" "$name" "$duration" "$suffix"
|
|
391
390
|
}
|
|
392
391
|
|
|
393
|
-
#
|
|
394
|
-
|
|
395
|
-
local i ok=0
|
|
396
|
-
for i in "${!
|
|
397
|
-
case "${
|
|
392
|
+
# Short summary for the status: never a token, a description < 140 characters.
|
|
393
|
+
short_summary() {
|
|
394
|
+
local i ok=0 failed=0 skipped=0 first_failed=""
|
|
395
|
+
for i in "${!SYMBOLS[@]}"; do
|
|
396
|
+
case "${SYMBOLS[$i]}" in
|
|
398
397
|
✔) ok=$((ok + 1)) ;;
|
|
399
|
-
✖)
|
|
400
|
-
*)
|
|
398
|
+
✖) failed=$((failed + 1)); [ -n "$first_failed" ] || first_failed="${NAMES[$i]}" ;;
|
|
399
|
+
*) skipped=$((skipped + 1)) ;;
|
|
401
400
|
esac
|
|
402
401
|
done
|
|
403
|
-
if [ "$
|
|
404
|
-
printf '%d ✔, %d ✖ (%s), %d
|
|
402
|
+
if [ "$failed" -gt 0 ]; then
|
|
403
|
+
printf '%d ✔, %d ✖ (%s), %d skipped — %d s' "$ok" "$failed" "$first_failed" "$skipped" "$TOTAL"
|
|
405
404
|
else
|
|
406
|
-
printf '%d ✔, %d
|
|
405
|
+
printf '%d ✔, %d skipped — %d s' "$ok" "$skipped" "$TOTAL"
|
|
407
406
|
fi
|
|
408
407
|
}
|
|
409
408
|
|
|
410
|
-
|
|
411
|
-
local i ok=0
|
|
409
|
+
summary() {
|
|
410
|
+
local i ok=0 failed=0 skipped=0
|
|
412
411
|
echo
|
|
413
|
-
echo "devzone test-gitlab :
|
|
414
|
-
for i in "${!
|
|
415
|
-
printf ' %s %-28s %3d s%s\n' "${
|
|
416
|
-
case "${
|
|
412
|
+
echo "devzone test-gitlab : summary"
|
|
413
|
+
for i in "${!SYMBOLS[@]}"; do
|
|
414
|
+
printf ' %s %-28s %3d s%s\n' "${SYMBOLS[$i]}" "${NAMES[$i]}" "${DURATIONS[$i]}" "${SUFFIXES[$i]}"
|
|
415
|
+
case "${SYMBOLS[$i]}" in
|
|
417
416
|
✔) ok=$((ok + 1)) ;;
|
|
418
|
-
✖)
|
|
419
|
-
*)
|
|
417
|
+
✖) failed=$((failed + 1)) ;;
|
|
418
|
+
*) skipped=$((skipped + 1)) ;;
|
|
420
419
|
esac
|
|
421
420
|
done
|
|
422
|
-
printf ' total
|
|
423
|
-
"${#
|
|
421
|
+
printf ' total: %d step(s), %d s, %d ✔, %d ✖, %d skipped\n' \
|
|
422
|
+
"${#NAMES[@]}" "$TOTAL" "$ok" "$failed" "$skipped"
|
|
424
423
|
}
|
|
425
424
|
|
|
426
|
-
# --statut
|
|
427
|
-
# GitHub
|
|
428
|
-
|
|
429
|
-
local
|
|
425
|
+
# --statut: publishes the result on the HEAD commit of the current repository, through
|
|
426
|
+
# the GitHub API of gh (maintainer token). Clear refusal if gh is not logged in.
|
|
427
|
+
publish_status() {
|
|
428
|
+
local repo sha state description
|
|
430
429
|
if ! gh auth status >/dev/null 2>&1; then
|
|
431
|
-
echo "devzone test-gitlab : gh
|
|
430
|
+
echo "devzone test-gitlab : gh not logged in, gitlab-integration status not published (gh auth login -s workflow)" >&2
|
|
432
431
|
return 1
|
|
433
432
|
fi
|
|
434
|
-
|
|
435
|
-
if [ -z "$
|
|
436
|
-
echo "devzone test-gitlab :
|
|
433
|
+
repo="$(gh repo view --json nameWithOwner -q .nameWithOwner 2>/dev/null || true)"
|
|
434
|
+
if [ -z "$repo" ]; then
|
|
435
|
+
echo "devzone test-gitlab : current GitHub repository not found, status not published" >&2
|
|
437
436
|
return 1
|
|
438
437
|
fi
|
|
439
438
|
sha="$(git rev-parse HEAD 2>/dev/null || true)"
|
|
440
439
|
if [ -z "$sha" ]; then
|
|
441
|
-
echo "devzone test-gitlab : commit
|
|
440
|
+
echo "devzone test-gitlab : HEAD commit not found, status not published" >&2
|
|
442
441
|
return 1
|
|
443
442
|
fi
|
|
444
|
-
if [ "$
|
|
445
|
-
description="$(
|
|
446
|
-
if ! gh api -X POST "repos/$
|
|
447
|
-
-f state="$
|
|
448
|
-
echo "devzone test-gitlab :
|
|
443
|
+
if [ "$FAILED" -eq 0 ]; then state=success; else state=failure; fi
|
|
444
|
+
description="$(short_summary)"
|
|
445
|
+
if ! gh api -X POST "repos/$repo/statuses/$sha" \
|
|
446
|
+
-f state="$state" -f context=gitlab-integration -f description="$description" >/dev/null; then
|
|
447
|
+
echo "devzone test-gitlab : publishing the gitlab-integration status impossible" >&2
|
|
449
448
|
return 1
|
|
450
449
|
fi
|
|
451
|
-
echo "devzone test-gitlab :
|
|
450
|
+
echo "devzone test-gitlab : gitlab-integration status ($state) published on $repo@$sha"
|
|
452
451
|
}
|
|
453
452
|
|
|
454
|
-
# ---- Options
|
|
453
|
+
# ---- Options and run ----
|
|
455
454
|
|
|
456
455
|
for arg in "$@"; do
|
|
457
456
|
case "$arg" in
|
|
458
|
-
--complet)
|
|
459
|
-
--statut)
|
|
457
|
+
--complet) FULL=1 ;;
|
|
458
|
+
--statut) PUBLISH=1 ;;
|
|
460
459
|
-h | --help) usage; exit 0 ;;
|
|
461
460
|
*)
|
|
462
|
-
echo "devzone test-gitlab : option
|
|
461
|
+
echo "devzone test-gitlab : unknown option: $arg" >&2
|
|
463
462
|
usage >&2
|
|
464
463
|
exit 2
|
|
465
464
|
;;
|
|
466
465
|
esac
|
|
467
466
|
done
|
|
468
467
|
|
|
469
|
-
|
|
468
|
+
START_TIME="$(date +%s)"
|
|
470
469
|
|
|
471
|
-
if [ "$
|
|
472
|
-
|
|
470
|
+
if [ "$FULL" = 1 ]; then
|
|
471
|
+
run_step "8. full: disable" step_full
|
|
473
472
|
fi
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
473
|
+
run_step "1. module" step_module
|
|
474
|
+
run_step "2. state" step_state
|
|
475
|
+
run_step "3. host name" step_name
|
|
476
|
+
run_step "4. pipeline" step_pipeline
|
|
477
|
+
run_step "5. HTTP and SSH clones" step_clones
|
|
478
|
+
run_step "6. platform" step_platform
|
|
479
|
+
run_step "7. repowarden integration" step_repowarden
|
|
481
480
|
|
|
482
|
-
TOTAL=$(( $(date +%s) -
|
|
483
|
-
|
|
481
|
+
TOTAL=$(( $(date +%s) - START_TIME ))
|
|
482
|
+
summary
|
|
484
483
|
|
|
485
484
|
CODE=0
|
|
486
|
-
[ "$
|
|
487
|
-
if [ "$
|
|
488
|
-
|
|
485
|
+
[ "$FAILED" -eq 0 ] || CODE=1
|
|
486
|
+
if [ "$PUBLISH" = 1 ]; then
|
|
487
|
+
publish_status || CODE=1
|
|
489
488
|
fi
|
|
490
489
|
exit "$CODE"
|