devzone 7.0.3 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.devcontainer/Dockerfile +1 -8
  2. package/.devcontainer/catalog/app.sh +5 -12
  3. package/.devcontainer/cluster.sh +1 -11
  4. package/.devcontainer/devcontainer.json +1 -11
  5. package/.devcontainer/devzone +18 -10
  6. package/.devcontainer/devzone-cluster.sh +1 -1
  7. package/.devcontainer/devzone-modules.sh +7 -2
  8. package/.devcontainer/devzone-repair.sh +10 -19
  9. package/.devcontainer/devzone-services.sh +21 -20
  10. package/.devcontainer/devzone-status.sh +5 -12
  11. package/.devcontainer/help.sh +3 -4
  12. package/.devcontainer/isolation.sh +1 -1
  13. package/.devcontainer/kube-account.sh +12 -173
  14. package/.devcontainer/metrics-server.sh +1 -1
  15. package/.devcontainer/packages.sh +2 -2
  16. package/.devcontainer/ports-json.sh +0 -4
  17. package/.devcontainer/ports.sh +6 -102
  18. package/.devcontainer/state-json.sh +5 -14
  19. package/.devcontainer/versions.env +2 -2
  20. package/.devcontainer/workspace-init.sh +1 -2
  21. package/Makefile +4 -4
  22. package/README.md +13 -20
  23. package/bin/SHA256SUMS +6 -6
  24. package/bin/devzone-darwin-amd64 +0 -0
  25. package/bin/devzone-darwin-arm64 +0 -0
  26. package/bin/devzone-linux-amd64 +0 -0
  27. package/bin/devzone-linux-arm64 +0 -0
  28. package/bin/devzone-windows-amd64.exe +0 -0
  29. package/bin/devzone-windows-arm64.exe +0 -0
  30. package/manage/devzone +4 -4
  31. package/package.json +1 -1
  32. package/.devcontainer/argocd/argocd.sh +0 -222
  33. package/.devcontainer/argocd/catalog-argocd.sh +0 -119
  34. package/.devcontainer/argocd/services-hook.sh +0 -181
  35. package/.devcontainer/catalog/mysql/install.sh +0 -87
  36. package/.devcontainer/catalog/mysql/mysql.sh +0 -262
  37. package/.devcontainer/catalog/mysql/volume.sh +0 -71
  38. package/.devcontainer/git-identity.sh +0 -28
  39. package/.devcontainer/gitlab/argocd.sh +0 -54
  40. package/.devcontainer/gitlab/chart.sh +0 -39
  41. package/.devcontainer/gitlab/gitlab.sh +0 -168
  42. package/.devcontainer/gitlab/installation.sh +0 -193
  43. package/.devcontainer/gitlab/secrets.sh +0 -95
  44. package/.devcontainer/gitlab/seed.sh +0 -204
  45. package/.devcontainer/gitlab/test-gitlab-restes.sh +0 -16
  46. package/.devcontainer/gitlab/test-gitlab.sh +0 -489
  47. package/.devcontainer/kind-wrapper.sh +0 -45
  48. package/.devcontainer/kube-config.sh +0 -78
  49. package/.devcontainer/kube-reachable.sh +0 -64
  50. package/.devcontainer/ports-auto.sh +0 -247
  51. package/.devcontainer/post-create.sh +0 -91
  52. package/.devcontainer/postgres/postgres.sh +0 -309
  53. package/.devcontainer/startup.sh +0 -65
@@ -1,489 +0,0 @@
1
- #!/usr/bin/env bash
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
- #
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
- #
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
- # shellcheck disable=SC2317
15
- set -uo pipefail
16
-
17
- ICI="$(cd "$(dirname "$0")" && pwd)"
18
- # Same root as gitlab.sh: DEVZONE_ROOT for the tests
19
- RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
20
- GITLAB="$ICI/gitlab.sh"
21
- SECRETS="$RACINE/workspace/.gitlab"
22
- TOKEN_FILE="$SECRETS/root-token"
23
- STATE_FILE="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
24
- HOSTS="${DEVZONE_HOSTS:-/etc/hosts}"
25
- # Instance name: DEVZONE_INSTANCE suffix computed by cluster.sh, as in
26
- # gitlab.sh (suffixed devzone-gitlab namespace).
27
- # shellcheck source=SCRIPTDIR/../cluster.sh
28
- # shellcheck disable=SC1091
29
- . "$ICI/../cluster.sh"
30
- # shellcheck source=SCRIPTDIR/test-gitlab-restes.sh
31
- # shellcheck disable=SC1091
32
- . "$ICI/test-gitlab-restes.sh"
33
- URL="${GITLAB_TEST_URL:-http://gitlab.localhost:8929}"
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
-
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
- DEVZONE_BIN="${DEVZONE_TEST_DEVZONE:-}"
44
- if [ -z "$DEVZONE_BIN" ]; then
45
- if command -v devzone >/dev/null 2>&1; then
46
- DEVZONE_BIN=devzone
47
- else
48
- DEVZONE_BIN="$RACINE/.devcontainer/devzone"
49
- fi
50
- fi
51
- # Same path as devzone: glab lives in ~/.local/bin, never in the PATH
52
- GLAB="$HOME/.local/bin/glab"
53
-
54
- FULL=0
55
- PUBLISH=0
56
- TOKEN=""
57
- KEY_ID=""
58
- FAILED=0
59
- TOTAL=0
60
- REASON=""
61
- PLATFORM_CHANGED=0
62
- TMP_DIRS=()
63
- NAMES=()
64
- SYMBOLS=()
65
- DURATIONS=()
66
- SUFFIXES=()
67
-
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
-
74
- usage() {
75
- cat <<'USAGE'
76
- devzone test-gitlab [--complet] [--statut]
77
-
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
- USAGE
82
- }
83
-
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
- api() {
87
- local method="$1" path="$2"
88
- shift 2
89
- curl -sS --fail --request "$method" --header "PRIVATE-TOKEN: ${TOKEN:-}" \
90
- "${URL}/api/v4${path}" "$@"
91
- }
92
-
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
- return 1
97
- fi
98
- TOKEN="$(cat "$TOKEN_FILE")"
99
- if [ -z "$TOKEN" ]; then
100
- REASON="root token empty ($TOKEN_FILE)"
101
- return 1
102
- fi
103
- return 0
104
- }
105
-
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
- else
113
- "$DEVZONE_BIN" platform github >/dev/null 2>&1
114
- fi
115
- }
116
-
117
- # Guaranteed cleanup: throwaway SSH key removed from GitLab, temporary folders
118
- # deleted, previous platform restored. Even when a step failed.
119
- cleanup() {
120
- local code=$? d
121
- trap - EXIT
122
- if [ -n "${KEY_ID:-}" ]; then
123
- api DELETE "/user/keys/$KEY_ID" >/dev/null 2>&1 || true
124
- fi
125
- if [ "$PLATFORM_CHANGED" = 1 ]; then
126
- restore_platform || true
127
- fi
128
- for d in ${TMP_DIRS[@]+"${TMP_DIRS[@]}"}; do
129
- [ -n "$d" ] && rm -rf "$d"
130
- done
131
- exit "$code"
132
- }
133
- trap cleanup EXIT
134
-
135
- # ---- The steps, one function per step ----
136
-
137
- # 1. Module: active, otherwise enabled (the activation also installs if needed).
138
- step_module() {
139
- if "$DEVZONE_BIN" is-enabled gitlab >/dev/null 2>&1; then
140
- return 0
141
- fi
142
- if ! "$DEVZONE_BIN" enable gitlab >/dev/null 2>&1; then
143
- REASON="devzone enable gitlab failed"
144
- return 1
145
- fi
146
- return 0
147
- }
148
-
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
- return 1
157
- fi
158
- if [[ "$state" != *"runner online"* ]]; then
159
- REASON="runner offline ($state)"
160
- return 1
161
- fi
162
- return 0
163
- }
164
-
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
- return 1
176
- fi
177
- if [ "$ip_name" != "127.0.0.1" ]; then
178
- REASON="gitlab.localhost resolves to $ip_name, expected 127.0.0.1"
179
- return 1
180
- fi
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
- return 1
184
- fi
185
- return 0
186
- }
187
-
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
- return 1
195
- }
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
- if [ -z "$id" ]; then
199
- REASON="pipeline creation response without id"
200
- return 1
201
- fi
202
- start="$(date +%s)"
203
- while :; do
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
- success) return 0 ;;
208
- failed | canceled | skipped)
209
- REASON="pipeline $state: ${web_url:-$URL/devzone/demo/-/pipelines/$id}"
210
- return 1
211
- ;;
212
- esac
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
- return 1
216
- fi
217
- sleep "$INTERVAL"
218
- done
219
- }
220
-
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
229
- d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-clones.XXXXXX")" || {
230
- REASON="temporary directory impossible"
231
- return 1
232
- }
233
- TMP_DIRS+=("$d")
234
- if ! ssh-keygen -q -t ed25519 -N '' -f "$d/id_ed25519" >/dev/null 2>&1; then
235
- REASON="ed25519 key generation impossible"
236
- return 1
237
- fi
238
- pub="$(cat "$d/id_ed25519.pub" 2>/dev/null || true)"
239
- response="$(api POST "/user/keys" --data-urlencode "title=devzone test-gitlab" \
240
- --data-urlencode "key=$pub" 2>/dev/null)" || {
241
- REASON="SSH key upload to GitLab impossible"
242
- return 1
243
- }
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"
247
- return 1
248
- fi
249
- if ! git clone -q \
250
- -c "core.sshCommand=ssh -i $d/id_ed25519 -o UserKnownHostsFile=$d/known_hosts -o StrictHostKeyChecking=accept-new" \
251
- "ssh://git@gitlab.localhost:2224/devzone/demo.git" "$d/ssh-demo" >/dev/null 2>&1; then
252
- REASON="SSH clone (ssh://git@gitlab.localhost:2224/devzone/demo.git) impossible"
253
- return 1
254
- fi
255
- if ! git -c credential.helper= \
256
- -c "credential.helper=!f() { echo username=oauth2; printf 'password='; cat \"$TOKEN_FILE\"; echo; }; f" \
257
- clone -q "$URL/devzone/demo.git" "$d/http-demo" >/dev/null 2>&1; then
258
- REASON="HTTP clone of devzone/demo impossible"
259
- return 1
260
- fi
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"
263
- return 1
264
- fi
265
- return 0
266
- }
267
-
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() {
271
- local d
272
- d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-plateforme.XXXXXX")" || {
273
- REASON="temporary directory impossible"
274
- return 1
275
- }
276
- TMP_DIRS+=("$d")
277
- PLATFORM_CHANGED=1
278
- if ! "$DEVZONE_BIN" platform gitlab >/dev/null 2>&1; then
279
- REASON="devzone platform gitlab failed"
280
- return 1
281
- fi
282
- if ! "$GLAB" repo clone devzone/demo "$d/demo" >/dev/null 2>&1; then
283
- REASON="glab repo clone devzone/demo failed"
284
- return 1
285
- fi
286
- if ! restore_platform; then
287
- REASON="return to platform $PLATFORM_BEFORE impossible"
288
- return 1
289
- fi
290
- if [ "$PLATFORM_BEFORE" = github ]; then
291
- if [ -e "$GLAB" ] || [ -e "$HOME/.config/glab-cli" ]; then
292
- REASON="glab or its configuration remains after returning to github"
293
- return 1
294
- fi
295
- fi
296
- PLATFORM_CHANGED=0
297
- return 0
298
- }
299
-
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() {
304
- local d log bats_exit bats_output
305
- read_token || return 1
306
- d="$(mktemp -d "${TMPDIR:-/tmp}/devzone-test-gitlab-repowarden.XXXXXX")" || {
307
- REASON="temporary directory impossible"
308
- return 1
309
- }
310
- TMP_DIRS+=("$d")
311
- log="${TMPDIR:-/tmp}/devzone-test-gitlab-repowarden.log"
312
- if ! git clone -q --depth 1 --branch "$REPOWARDEN_REF" \
313
- https://github.com/simdevWarden/repowarden.git "$d/repowarden" >/dev/null 2>&1; then
314
- REASON="clone of repowarden (ref $REPOWARDEN_REF) impossible"
315
- return 1
316
- fi
317
- if [ ! -d "$d/repowarden/test/gitlab" ]; then
318
- REASON="test/gitlab missing at ref $REPOWARDEN_REF"
319
- return 2
320
- fi
321
- if ! command -v bats >/dev/null 2>&1; then
322
- REASON="bats not found"
323
- return 1
324
- fi
325
- if bats_output="$(REPOWARDEN_IT_GITLAB_URL="$URL" REPOWARDEN_IT_GITLAB_TOKEN="$TOKEN" \
326
- bats "$d/repowarden/test/gitlab/" 2>&1)"; then
327
- bats_exit=0
328
- else
329
- bats_exit=$?
330
- fi
331
- printf '%s' "$bats_output" | sed "s/${TOKEN}/TOKEN_MASKED/g" > "$log"
332
- if [ "$bats_exit" -ne 0 ]; then
333
- REASON="the test/gitlab suite failed (log: $log)"
334
- return 1
335
- fi
336
- return 0
337
- }
338
-
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
344
- instance="${DEVZONE_INSTANCE:-devzone}"
345
- namespace="devzone-gitlab${INSTANCE_SUFFIX}"
346
- if ! "$DEVZONE_BIN" disable gitlab >/dev/null 2>&1; then
347
- leftovers="$leftovers disable failed;"
348
- fi
349
- if kubectl --context devzone get namespace "$namespace" >/dev/null 2>&1; then
350
- leftovers="$leftovers namespace $namespace;"
351
- fi
352
- containers="$(gitlab_restes_conteneurs "$instance")"
353
- if [ -n "$containers" ]; then
354
- leftovers="$leftovers labelled container(s) devzone.instance=$instance;"
355
- fi
356
- if [ -e "$SECRETS" ]; then
357
- leftovers="$leftovers $SECRETS;"
358
- fi
359
- if grep -q '# devzone:gitlab' "$HOSTS" 2>/dev/null; then
360
- leftovers="$leftovers /etc/hosts line;"
361
- fi
362
- if [ -n "$leftovers" ]; then
363
- REASON="remaining:$leftovers"
364
- return 1
365
- fi
366
- return 0
367
- }
368
-
369
- # ---- Common frame: times, records ✔/✖/skipped + reason ----
370
-
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"
377
- code=$?
378
- end="$(date +%s)"
379
- duration=$((end - start))
380
- case "$code" in
381
- 0) symbol="✔"; suffix="" ;;
382
- 2) symbol="–"; suffix=" — skipped: ${REASON:-no reason}" ;;
383
- *) symbol="✖"; FAILED=1; suffix=" — ${REASON:-failed}" ;;
384
- esac
385
- NAMES+=("$name")
386
- SYMBOLS+=("$symbol")
387
- DURATIONS+=("$duration")
388
- SUFFIXES+=("$suffix")
389
- printf ' %s %s (%d s)%s\n' "$symbol" "$name" "$duration" "$suffix"
390
- }
391
-
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
397
- ✔) ok=$((ok + 1)) ;;
398
- ✖) failed=$((failed + 1)); [ -n "$first_failed" ] || first_failed="${NAMES[$i]}" ;;
399
- *) skipped=$((skipped + 1)) ;;
400
- esac
401
- done
402
- if [ "$failed" -gt 0 ]; then
403
- printf '%d ✔, %d ✖ (%s), %d skipped — %d s' "$ok" "$failed" "$first_failed" "$skipped" "$TOTAL"
404
- else
405
- printf '%d ✔, %d skipped — %d s' "$ok" "$skipped" "$TOTAL"
406
- fi
407
- }
408
-
409
- summary() {
410
- local i ok=0 failed=0 skipped=0
411
- echo
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
416
- ✔) ok=$((ok + 1)) ;;
417
- ✖) failed=$((failed + 1)) ;;
418
- *) skipped=$((skipped + 1)) ;;
419
- esac
420
- done
421
- printf ' total: %d step(s), %d s, %d ✔, %d ✖, %d skipped\n' \
422
- "${#NAMES[@]}" "$TOTAL" "$ok" "$failed" "$skipped"
423
- }
424
-
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
429
- if ! gh auth status >/dev/null 2>&1; then
430
- echo "devzone test-gitlab : gh not logged in, gitlab-integration status not published (gh auth login -s workflow)" >&2
431
- return 1
432
- fi
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
436
- return 1
437
- fi
438
- sha="$(git rev-parse HEAD 2>/dev/null || true)"
439
- if [ -z "$sha" ]; then
440
- echo "devzone test-gitlab : HEAD commit not found, status not published" >&2
441
- return 1
442
- fi
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
448
- return 1
449
- fi
450
- echo "devzone test-gitlab : gitlab-integration status ($state) published on $repo@$sha"
451
- }
452
-
453
- # ---- Options and run ----
454
-
455
- for arg in "$@"; do
456
- case "$arg" in
457
- --complet) FULL=1 ;;
458
- --statut) PUBLISH=1 ;;
459
- -h | --help) usage; exit 0 ;;
460
- *)
461
- echo "devzone test-gitlab : unknown option: $arg" >&2
462
- usage >&2
463
- exit 2
464
- ;;
465
- esac
466
- done
467
-
468
- START_TIME="$(date +%s)"
469
-
470
- if [ "$FULL" = 1 ]; then
471
- run_step "8. full: disable" step_full
472
- fi
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
480
-
481
- TOTAL=$(( $(date +%s) - START_TIME ))
482
- summary
483
-
484
- CODE=0
485
- [ "$FAILED" -eq 0 ] || CODE=1
486
- if [ "$PUBLISH" = 1 ]; then
487
- publish_status || CODE=1
488
- fi
489
- exit "$CODE"
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env bash
2
- # kind wrapper (#291), installed as /usr/local/bin/kind; the real binary is
3
- # kind-reel. With the host's Docker, a cluster created by « kind create cluster »
4
- # writes server: https://127.0.0.1:<port>: unreachable from the container. After
5
- # a successful creation or kubeconfig export, the address is made reachable
6
- # (kube-reachable.sh). Everything else passes through unchanged.
7
- set -uo pipefail
8
-
9
- KIND_REEL="${DEVZONE_KIND_REAL:-/usr/local/bin/kind-reel}"
10
- ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
- if [ -f "$ICI/kube-reachable.sh" ]; then
12
- # shellcheck source=SCRIPTDIR/kube-reachable.sh
13
- . "$ICI/kube-reachable.sh"
14
- else
15
- # shellcheck source=/dev/null
16
- . /usr/local/lib/devzone/kube-reachable.sh
17
- fi
18
-
19
- "$KIND_REEL" "$@"
20
- code=$?
21
- [ "$code" -eq 0 ] || exit "$code"
22
-
23
- case "${1:-} ${2:-}" in
24
- "create cluster" | "export kubeconfig") ;;
25
- *) exit 0 ;;
26
- esac
27
-
28
- # File written by kind: --kubeconfig if given, otherwise the first of KUBECONFIG,
29
- # otherwise ~/.kube/config (same rule as kind)
30
- file=""
31
- previous=""
32
- for arg in "$@"; do
33
- case "$arg" in
34
- --kubeconfig=*) file="${arg#--kubeconfig=}" ;;
35
- esac
36
- [ "$previous" = "--kubeconfig" ] && file="$arg"
37
- previous="$arg"
38
- done
39
- if [ -z "$file" ] && [ -n "${KUBECONFIG:-}" ]; then
40
- file="${KUBECONFIG%%:*}"
41
- fi
42
- [ -n "$file" ] || file="$HOME/.kube/config"
43
-
44
- kube_reachable_from_container "$file"
45
- exit 0
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Kubernetes clusters of the container, at each startup (the port of the host
3
- # cluster can change):
4
- # - ~/.kube/hote.config: copy of the host's ~/.kube (mounted read-only) where
5
- # 127.0.0.1/localhost become host.docker.internal, the host seen from the container;
6
- # tls-server-name keeps the name expected by the certificate
7
- # - ~/.kube/config: kind clusters of the container, never touched here
8
- # KUBECONFIG (devcontainer.json) combines the two.
9
- # kubernetes module (devzone enable kubernetes): connection to the host cluster
10
- # and metrics-server only if it is enabled; the kind contexts are always restored
11
- # (a cluster created by hand stays usable).
12
- set -euo pipefail
13
-
14
- ICI="$(dirname "$0")"
15
- # shellcheck source=SCRIPTDIR/cluster.sh
16
- . "$ICI/cluster.sh"
17
- module=off
18
- bash "$ICI/devzone" is-enabled kubernetes && module=on
19
-
20
- # DEVZONE_KUBE_SOURCE: functional tests (never the host cluster)
21
- SOURCE="${DEVZONE_KUBE_SOURCE:-$HOME/.kube-host/config}"
22
- HOST_CONFIG="$HOME/.kube/hote.config"
23
-
24
- mkdir -p "$HOME/.kube"
25
- rm -f "$HOST_CONFIG"
26
- # Must exist: otherwise kind writes into hote.config, erased at the next startup
27
- [ -f "$HOME/.kube/config" ] || install -m 600 /dev/null "$HOME/.kube/config"
28
-
29
- if [ "$module" = on ] && [ -f "$SOURCE" ]; then
30
- install -m 600 "$SOURCE" "$HOST_CONFIG"
31
- kube_reachable_from_container "$HOST_CONFIG"
32
- devzone_context_set
33
- fi
34
-
35
- # Rewrite 127.0.0.1/localhost → host.docker.internal for the kind clusters, whose
36
- # API server is at 127.0.0.1:<port> but unreachable from the container. Idempotent.
37
- kube_reachable_from_container "$HOME/.kube/config"
38
-
39
- # kind clusters that survived the restart: context restored in ~/.kube/config
40
- # (the internal Docker may take a few seconds to start)
41
- for _ in 1 2 3 4 5 6 7 8 9 10; do docker info >/dev/null 2>&1 && break; sleep 1; done
42
- choice="$(KUBECONFIG="$HOME/.kube/config" kubectl config current-context 2>/dev/null || true)"
43
- for cluster in $(kind get clusters 2>/dev/null); do
44
- kind export kubeconfig --name "$cluster" --kubeconfig "$HOME/.kube/config" >/dev/null 2>&1 || true
45
- done
46
- # The kubeconfigs exported by kind carry server: https://127.0.0.1:<port>;
47
- # make them reachable from the container.
48
- kube_reachable_from_container "$HOME/.kube/config"
49
-
50
- # Active cluster: the one chosen before (kubectl config use-context), otherwise
51
- # the host's if it has one (current-context of hote.config), otherwise kind
52
- export KUBECONFIG="$HOME/.kube/config:$HOST_CONFIG"
53
- if [ -n "$choice" ] && kubectl config use-context "$choice" >/dev/null 2>&1; then
54
- :
55
- elif [ -f "$HOST_CONFIG" ] && [ -n "$(KUBECONFIG="$HOST_CONFIG" kubectl config current-context 2>/dev/null)" ]; then
56
- KUBECONFIG="$HOME/.kube/config" kubectl config unset current-context >/dev/null
57
- fi
58
-
59
- # Reachable clusters, among those of the host and those of kind
60
- reachable=0
61
- for context in $(kubectl config get-contexts -o name 2>/dev/null); do
62
- if kubectl --context "$context" --request-timeout=3s get --raw /readyz >/dev/null 2>&1; then
63
- echo "kube-config : cluster reachable : $context"
64
- reachable=$((reachable + 1))
65
- elif [[ "$context" == kind-* ]]; then
66
- echo "kube-config : kind cluster starting: $context"
67
- reachable=$((reachable + 1))
68
- fi
69
- done
70
- # Module disabled: the devzone summary reports it
71
- [ "$module" = on ] || exit 0
72
- echo "kube-config : active cluster: $(kubectl config current-context 2>/dev/null || echo none)"
73
- if [ "$reachable" -eq 0 ]; then
74
- echo "kube-config : no reachable cluster; create one in the container: kind create cluster"
75
- fi
76
-
77
- # CPU/RAM in k9s: metrics-server on the reachable clusters that do not have it
78
- bash "$ICI/metrics-server.sh" || true
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Clusters reachable from the container (#291). With the host's Docker, the API
3
- # of a kind cluster listens on 127.0.0.1 OF THE WORKSTATION: inside the
4
- # container, 127.0.0.1 is the container itself.
5
- # 1. kind node found (container publishing this port): the devzone container
6
- # joins the Docker network of the node and targets https://<node>:6443, the
7
- # address kind provides for containers (kind get kubeconfig --internal);
8
- # the node name is in the API certificate. Works under Linux as with Docker
9
- # Desktop, without exposing anything on the workstation's network.
10
- # 2. Otherwise: https://host.docker.internal:<port>, with the original name for
11
- # the TLS check (--tls-server-name); enough with Docker Desktop, where
12
- # host.docker.internal leads to the workstation's 127.0.0.1.
13
- # Sourced library (cluster.sh, kind wrapper); run directly:
14
- # kube-reachable.sh FILE
15
- # kube_reachable_from_container FILE rewrites 127.0.0.1/localhost, idempotent
16
-
17
- # kind control-plane node that publishes this port on the workstation (empty otherwise)
18
- kube_kind_node() {
19
- docker ps --filter "label=io.x-k8s.kind.role=control-plane" --filter "publish=$1" \
20
- --format '{{.Names}}' 2>/dev/null | head -1
21
- }
22
-
23
- # The devzone container joins the node's network (idempotent: already a member = nothing)
24
- kube_join_network() {
25
- local node="$1" me network
26
- me="$(hostname)"
27
- for network in $(docker inspect "$node" \
28
- --format '{{range $name, $v := .NetworkSettings.Networks}}{{$name}} {{end}}' 2>/dev/null); do
29
- docker network connect "$network" "$me" >/dev/null 2>&1 || true
30
- done
31
- }
32
-
33
- kube_reachable_from_container() {
34
- local file="${1:-}" name server host port node
35
- [ -n "$file" ] || return 0
36
- # Kubernetes workspace (#517): the pod reaches the API through the cluster service, no docker call
37
- if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then return 0; fi
38
- KUBECONFIG="$file" kubectl config view \
39
- -o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}' 2>/dev/null |
40
- while IFS=$'\t' read -r name server; do
41
- case "$server" in
42
- https://127.0.0.1:* | https://localhost:*) ;;
43
- *) continue ;;
44
- esac
45
- host="${server#https://}"
46
- host="${host%%:*}"
47
- port="${server##*:}"
48
- node="$(kube_kind_node "$port")"
49
- if [ -n "$node" ]; then
50
- kube_join_network "$node"
51
- KUBECONFIG="$file" kubectl config set-cluster "$name" \
52
- --server="https://${node}:6443" >/dev/null 2>&1 || true
53
- else
54
- KUBECONFIG="$file" kubectl config set-cluster "$name" \
55
- --server="https://host.docker.internal:${port}" \
56
- --tls-server-name="$host" >/dev/null 2>&1 || true
57
- fi
58
- done
59
- return 0
60
- }
61
-
62
- if [ "${BASH_SOURCE[0]}" = "$0" ]; then
63
- kube_reachable_from_container "${1:-}"
64
- fi