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.
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 +17 -9
  6. package/.devcontainer/devzone-cluster.sh +1 -1
  7. package/.devcontainer/devzone-modules.sh +7 -2
  8. package/.devcontainer/devzone-repair.sh +9 -19
  9. package/.devcontainer/devzone-services.sh +21 -20
  10. package/.devcontainer/devzone-status.sh +4 -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 +4 -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,262 +0,0 @@
1
- #!/usr/bin/env bash
2
- # MySQL of the catalog (#414): create, list, delete, status, relay-start, relay-stop, install, delete-data.
3
- set -euo pipefail
4
- ICI="$(cd "$(dirname "$0")" && pwd)"
5
- RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$(dirname "$ICI")")")}"
6
- ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
7
- # shellcheck source=SCRIPTDIR/../../cluster.sh
8
- # shellcheck disable=SC1091
9
- . "$ICI/../../cluster.sh"
10
- # shellcheck source=SCRIPTDIR/../../password.sh
11
- # shellcheck disable=SC1091
12
- . "$ICI/../../password.sh"
13
- # shellcheck source=SCRIPTDIR/../../isolation.sh
14
- # shellcheck disable=SC1091
15
- . "$ICI/../../isolation.sh"
16
- # shellcheck source=SCRIPTDIR/volume.sh
17
- # shellcheck disable=SC1091
18
- . "$ICI/volume.sh"
19
- # shellcheck source=SCRIPTDIR/install.sh
20
- # shellcheck disable=SC1091
21
- . "$ICI/install.sh"
22
- # The argocd module on: MySQL installed by an Application (#538)
23
- # shellcheck source=SCRIPTDIR/../../argocd/catalog-argocd.sh
24
- # shellcheck disable=SC1091
25
- . "$ICI/../../argocd/catalog-argocd.sh"
26
- NS=devzone-mysql
27
- SECRETS="$RACINE/workspace/.mysql"
28
- MYSQL_PORT="${MYSQL_PORT:-3306}"
29
- MYSQL_IMAGE="${MYSQL_IMAGE:-mysql:8.4}"
30
- MYSQL_MEMOIRE="${MYSQL_MEMOIRE:-1Gi}"
31
- MYSQL_TAILLE="${MYSQL_TAILLE:-5Gi}"
32
- MYSQL_ATTENTE="${MYSQL_ATTENTE:-300}"
33
- # Standard refusal with a message and code 2
34
- refuse() { echo "devzone : catalog mysql : $*" >&2; exit 2; }
35
- # Secret mysql-admin of the services.sh hook: the same as the direct installation
36
- services_secret_mysql() { mysql_secret; }
37
- # Regenerates the .password view (non-blocking failure)
38
- regenerer_identifiants() {
39
- password_regenerate ||
40
- echo "devzone : catalog mysql : grouped credentials not updated (devzone passwords)" >&2
41
- }
42
- # Shortcut for kubectl in the devzone-mysql namespace
43
- k() { kubectl --context devzone -n "$NS" "$@"; }
44
- # Does the devzone-mysql namespace exist? Administrator only (#430)
45
- installed() { account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1; }
46
- # Context of the module: the one of the devzone cluster
47
- module_context() {
48
- local c
49
- c="$(cluster_saved)"
50
- [ -n "$c" ] || refuse "no cluster chosen: devzone enable mysql"
51
- echo "$c"
52
- }
53
- # Failure marker of the module (same scheme as devzone's failure_file)
54
- failure_file() { echo "$ETAT-failed-mysql"; }
55
- # Project name: a simple SQL identifier, never escaped, not a reserved name
56
- check_project_name() {
57
- local p="${1:-}"
58
- [ -n "$p" ] || refuse "missing project name"
59
- [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "invalid project name: $p (lowercase, digits, _; starts with a letter)"
60
- case "$p" in
61
- mysql | information_schema | performance_schema | sys) refuse "reserved name: $p" ;;
62
- esac
63
- }
64
- # Random password for a new project
65
- new_password() { openssl rand -hex 24; }
66
- # Root password: from root.env of an existing installation, else admin-password
67
- root_password() {
68
- local password
69
- password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
70
- [ -z "$password" ] && [ -f "$SECRETS/admin-password" ] && password="$(cat "$SECRETS/admin-password" 2>/dev/null || true)"
71
- [ -n "$password" ] || refuse "MySQL root password not found (workspace/.mysql/root.env)"
72
- echo "$password"
73
- }
74
- # mysql as superuser in the pod; the password is never shown
75
- mysql_admin() { k exec -i mysql-0 -c mysql -- mysql -uroot -p"$(root_password)" "$@"; }
76
- # Number of databases, system databases excluded
77
- database_count() {
78
- local n
79
- n="$(mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null | grep -vE '^(information_schema|mysql|performance_schema|sys)$' | grep -c . || true)"
80
- echo "${n:-0}"
81
- }
82
- # Installs the module (the Argo CD path when the argocd module is on)
83
- install_module() {
84
- local CTX claim
85
- CTX="$(module_context)"
86
- if ! devzone_context_set "$CTX"; then
87
- echo "devzone : catalog mysql : cannot set the devzone context on $CTX" >&2
88
- return 1
89
- fi
90
- echo "▶ MySQL on cluster $CTX (namespace $NS)…"
91
- if catalogue_argocd_active mysql; then
92
- mysql_install_argocd "$CTX"
93
- return
94
- fi
95
- account_namespace "$CTX" "$NS"
96
- namespace_isolate "$NS" >/dev/null
97
- if k get statefulset mysql >/dev/null 2>&1; then
98
- echo "devzone : catalog mysql : existing installation in $NS, adopted (volume and root.env kept)"
99
- else
100
- mysql_secret
101
- claim="$(mysql_claim_choose "$NS")" || return 2
102
- mysql_apply_chart "$NS" "$claim" || return 1
103
- if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
104
- echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $NS describe pod mysql-0" >&2
105
- return 1
106
- fi
107
- fi
108
- mysql_secret
109
- relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
110
- echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
111
- regenerer_identifiants
112
- }
113
- # Deletes the namespace (so the PVCs), keeps workspace/.mysql (#441):
114
- # terminal confirmation [y/N], --yes required otherwise (refusal, code 2)
115
- delete_data() {
116
- local CTX yes="" arg answer
117
- for arg in "$@"; do
118
- case "$arg" in
119
- --yes) yes=1 ;;
120
- *) refuse "unknown argument: $arg" ;;
121
- esac
122
- done
123
- if [ -z "$yes" ]; then
124
- cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete-data --yes"
125
- printf 'Delete namespace %s and all its volumes? [y/N] ' "$NS" >&2
126
- read -r answer || answer=""
127
- case "$answer" in
128
- y | Y | yes) ;;
129
- *) echo "Aborted: nothing was deleted."; return 0 ;;
130
- esac
131
- fi
132
- CTX="$(cluster_saved)"
133
- [ -n "$CTX" ] || refuse "no cluster chosen: devzone enable mysql"
134
- installed || refuse "module disabled: devzone enable mysql"
135
- echo "▶ Deleting MySQL and its volumes on ${CTX}…"
136
- # The Application goes first (#538): otherwise Argo CD recreates the namespace
137
- catalogue_argocd_delete mysql >/dev/null 2>&1 || true
138
- # RoleBinding removed, then the namespace deleted by the administrator (#430)
139
- account_remove "$CTX" "$NS" >/dev/null 2>&1 || true
140
- account_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
141
- relay_stop mysql
142
- rm -f "$(failure_file)"
143
- echo "✔ namespace $NS and volume deleted; workspace/.mysql/root.env kept"
144
- regenerer_identifiants
145
- }
146
- # State (disabled, failed, ready, relay stopped): read by devzone, keep the words
147
- module_status() {
148
- local CTX
149
- CTX="$(cluster_saved)"
150
- if [ -z "$CTX" ] || ! installed; then
151
- echo "disabled"
152
- return 0
153
- fi
154
- if [ "$(k get statefulset mysql -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
155
- echo "failed on $CTX: devzone apply"
156
- return 0
157
- fi
158
- if ! relay_active mysql; then
159
- echo "ready on $CTX, relay stopped: devzone apply"
160
- return 0
161
- fi
162
- echo "ready on $CTX: 127.0.0.1:$MYSQL_PORT, $(database_count) database(s)"
163
- }
164
- # Creates the user and the database of a project; .env in 600, password kept
165
- create_project() {
166
- local project="${1:-}" renew="" file password arg
167
- check_project_name "$project"
168
- for arg in "${@:2}"; do
169
- case "$arg" in
170
- --new-password) renew=1 ;;
171
- *) refuse "unknown argument: $arg" ;;
172
- esac
173
- done
174
- CTX="$(module_context)"
175
- installed || refuse "module disabled: devzone enable mysql"
176
- file="$SECRETS/$project.env"
177
- if [ -z "$renew" ] && [ -s "$file" ]; then
178
- password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$file" 2>/dev/null | tail -1)"
179
- else
180
- password="$(new_password)"
181
- fi
182
- mysql_admin <<SQL
183
- CREATE USER IF NOT EXISTS '$project'@'%' IDENTIFIED BY '$password';
184
- ALTER USER '$project'@'%' IDENTIFIED BY '$password';
185
- CREATE DATABASE IF NOT EXISTS $project;
186
- GRANT ALL ON $project.* TO '$project'@'%';
187
- SQL
188
- mkdir -p "$SECRETS"
189
- chmod 700 "$SECRETS"
190
- (
191
- umask 077
192
- cat >"$file" <<ENV
193
- MYSQL_HOST=127.0.0.1
194
- MYSQL_PORT=$MYSQL_PORT
195
- MYSQL_USER=$project
196
- MYSQL_PASSWORD=$password
197
- MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$project
198
- ENV
199
- )
200
- echo "✔ database $project ready; credentials: $file"
201
- regenerer_identifiants
202
- }
203
- # Lists the databases of the server
204
- list_databases() {
205
- local CTX
206
- CTX="$(module_context)"
207
- installed || refuse "module disabled: devzone enable mysql"
208
- # grep -v exits 1 with no user database: under pipefail, the list stays at 0
209
- mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null |
210
- { grep -vE '^(information_schema|mysql|performance_schema|sys)$' || true; } |
211
- awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (no database: devzone mysql create <project>)" }'
212
- }
213
- # Deletes the database and the user of a project (confirmation without --yes)
214
- delete_project() {
215
- local project="${1:-}" yes="" arg answer
216
- check_project_name "$project"
217
- for arg in "${@:2}"; do
218
- case "$arg" in
219
- --yes) yes=1 ;;
220
- *) refuse "unknown argument: $arg" ;;
221
- esac
222
- done
223
- CTX="$(module_context)"
224
- installed || refuse "module disabled: devzone enable mysql"
225
- if [ -z "$yes" ]; then
226
- cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete $project --yes"
227
- printf 'Delete database %s and its user? [y/N] ' "$project" >&2
228
- read -r answer || answer=""
229
- case "$answer" in
230
- y | Y | yes) ;;
231
- *) echo "Aborted: nothing was deleted."; return 0 ;;
232
- esac
233
- fi
234
- mysql_admin <<SQL
235
- DROP DATABASE IF EXISTS $project;
236
- DROP USER IF EXISTS '$project'@'%';
237
- SQL
238
- rm -f "$SECRETS/$project.env"
239
- echo "✔ database $project deleted"
240
- regenerer_identifiants
241
- }
242
- # Restarts the relay 127.0.0.1:3306 if the namespace exists
243
- relay_restart() {
244
- local CTX
245
- CTX="$(cluster_saved)"
246
- [ -n "$CTX" ] && installed && relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
247
- }
248
- case "${1:-}" in
249
- install) install_module ;;
250
- delete-data) delete_data "${@:2}" ;;
251
- status) module_status ;;
252
- create) create_project "${@:2}" ;;
253
- list) list_databases ;;
254
- delete) delete_project "${@:2}" ;;
255
- volume) mysql_volume "$NS" "${@:2}" ;;
256
- relay-start) relay_restart ;;
257
- relay-stop) relay_stop mysql ;;
258
- *)
259
- echo "devzone : catalog mysql : create <project> [--new-password] | list | delete <project> [--yes] | volume [<name>] [--delete <name>] [--yes] | delete-data [--yes]" >&2
260
- exit 1
261
- ;;
262
- esac
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env bash
2
- # MySQL volumes (#440): choice, listing and deletion of the -mysql-0 PVCs.
3
-
4
- # Lists the PVCs of the namespace whose name ends with -mysql-0
5
- mysql_volumes() {
6
- local ns="$1"
7
- kubectl --context devzone -n "$ns" get pvc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null |
8
- grep -E '\-mysql-0$' || true
9
- }
10
-
11
- # Claim prefix: 1 PVC -> its prefix, 0 -> donnees, >1 -> refusal (code 2)
12
- mysql_claim_choose() {
13
- local ns="$1" list count
14
- list="$(mysql_volumes "$ns")"
15
- if [ -z "$list" ]; then echo donnees; return 0; fi
16
- count="$(printf '%s\n' "$list" | grep -c .)"
17
- if [ "$count" -eq 1 ]; then echo "${list%-mysql-0}"; return 0; fi
18
- echo "devzone : catalog mysql : several volumes found:" >&2
19
- printf '%s\n' "$list" | sed 's/^/ /' >&2
20
- echo "devzone : catalog mysql : choose one with devzone mysql volume <name>" >&2
21
- return 2
22
- }
23
-
24
- # Claim carried by the StatefulSet (empty if absent)
25
- mysql_claim_mounted() {
26
- local ns="$1"
27
- kubectl --context devzone -n "$ns" get statefulset mysql \
28
- -o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true
29
- }
30
-
31
- # volume subcommand: lists, or selects/deletes a PVC
32
- mysql_volume() {
33
- local ns="$1" name="" yes="" delete="" arg answer pvc mounted claim
34
- shift
35
- for arg in "$@"; do
36
- case "$arg" in
37
- --delete) delete=1 ;;
38
- --yes) yes=1 ;;
39
- *) name="$arg" ;;
40
- esac
41
- done
42
- if [ -n "$delete" ]; then
43
- [ -n "$name" ] || refuse "volume --delete: missing name"
44
- pvc="$name"
45
- [[ "$pvc" == *-mysql-0 ]] || pvc="$pvc-mysql-0"
46
- mounted="$(mysql_claim_mounted "$ns")"
47
- [ "${pvc%-mysql-0}" != "$mounted" ] || refuse "mounted volume, deletion refused: $name"
48
- if [ -z "$yes" ]; then
49
- cluster_interactive || refuse "confirmation needs a terminal: devzone mysql volume --delete $name --yes"
50
- printf 'Delete volume %s? [y/N] ' "$pvc" >&2
51
- read -r answer || answer=""
52
- case "$answer" in
53
- y | Y | yes) ;;
54
- *) echo "Aborted: nothing was deleted."; return 0 ;;
55
- esac
56
- fi
57
- kubectl --context devzone -n "$ns" delete pvc "$pvc" >/dev/null
58
- echo "✔ volume $pvc deleted"
59
- return 0
60
- fi
61
- if [ -z "$name" ]; then
62
- mounted="$(mysql_claim_mounted "$ns")"
63
- mysql_volumes "$ns" | awk -v m="$mounted-mysql-0" 'NF { mark = ($0 == m) ? " (mounted)" : ""; printf " %s%s\n", $0, mark; n++ } END { if (!n) print " (no volume)" }'
64
- return 0
65
- fi
66
- module_context >/dev/null
67
- installed || refuse "module disabled: devzone enable mysql"
68
- claim="$name"
69
- [[ "$claim" == *-mysql-0 ]] && claim="${claim%-mysql-0}"
70
- mysql_install_claim "$ns" "$claim"
71
- }
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Git identity, at each startup as long as it is missing: deduced from the gh
3
- # account (specific to each user, connection kept in their volume) and written
4
- # into ~/.config/git/config (devzone-git volume, survives rebuilds).
5
- # An identity already set (by hand, or copied by VS Code into ~/.gitconfig) is
6
- # never replaced. GitHub noreply email: commits are attached to the account
7
- # without exposing the personal email.
8
- set -euo pipefail
9
-
10
- CONFIG="$HOME/.config/git/config"
11
- name_git="$(git config --get user.name || true)"
12
- email_git="$(git config --get user.email || true)"
13
-
14
- [ -n "$name_git" ] && [ -n "$email_git" ] && exit 0
15
-
16
- # Without gh: nothing to deduce; the devzone summary reports it
17
- gh auth status >/dev/null 2>&1 || exit 0
18
-
19
- id="" login="" name=""
20
- IFS=$'\t' read -r id login name < <(gh api user --jq '[.id, .login, (.name // "")] | @tsv' 2>/dev/null || true)
21
- if [ -z "$id" ] || [ -z "$login" ]; then
22
- echo "git-identity : GitHub account unreadable (network?); run again: bash .devcontainer/git-identity.sh"
23
- exit 0
24
- fi
25
-
26
- [ -n "$name_git" ] || git config --file "$CONFIG" user.name "${name:-$login}"
27
- [ -n "$email_git" ] || git config --file "$CONFIG" user.email "${id}+${login}@users.noreply.github.com"
28
- echo "git-identity : $(git config --get user.name) <$(git config --get user.email)>"
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env bash
2
- # GitLab held by Argo CD (#538): with the module argocd on and installed, the
3
- # installation is the Application devzone-gitlab on the wrapper chart
4
- # charts/devzone-gitlab at the revision, instead of a helm pass (chart.sh).
5
- # The Rails secret is re-applied before it (installation.sh), the seed runs
6
- # once GitLab answers (seed.sh); the runner token goes to the Secret
7
- # gitlab-runner-secret written by the seed, out of Git.
8
- # Sourced by installation.sh (through gitlab.sh). bash 3.2 (macOS).
9
- # gitlab_argocd_active module argocd on, chart present, revision
10
- # gitlab_release_adopter helm release of before Argo CD: its release
11
- # secrets removed, the objects are adopted
12
- # gitlab_application_apply the Application devzone-gitlab
13
- # gitlab_application_retirer the Application removed (namespace kept)
14
-
15
- # The catalogue side of Argo CD (module on, chart, revision, Application)
16
- # shellcheck source=SCRIPTDIR/../argocd/catalog-argocd.sh
17
- # shellcheck disable=SC1091
18
- . "$ICI/../argocd/catalog-argocd.sh"
19
-
20
- # The module argocd is on, the namespace devzone-argocd is installed, the chart
21
- # is in the repository and the revision is known: a development clone (version
22
- # 0.0.0) keeps the helm-direct path, like the catalogue applications
23
- gitlab_argocd_active() {
24
- catalogue_argocd_active gitlab
25
- }
26
-
27
- # Argo CD takes over the objects of a helm release gitlab: the release secrets
28
- # (sh.helm.release.v1.gitlab.*) go, so that helm no longer owns the objects
29
- gitlab_release_adopter() {
30
- kubectl --context devzone -n "$GITLAB_NS" delete secret \
31
- -l owner=helm,name=gitlab --ignore-not-found >/dev/null 2>&1 || true
32
- }
33
-
34
- # The Application on charts/devzone-gitlab at the revision, in the namespace of
35
- # the instance; the internal URL of the webservice follows that namespace
36
- # (chart value not templated, passed as a helm parameter, as in chart.sh)
37
- gitlab_application_apply() {
38
- catalogue_argocd_load
39
- chart_require gitlab || return $?
40
- echo "▶ Application devzone-gitlab (Argo CD, charts/devzone-gitlab at $(argocd_revision))…"
41
- gitops_apply_application devzone-gitlab service "$GITLAB_NS" \
42
- "$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-gitlab" \
43
- "gitlab-runner.gitlabUrl=http://gitlab-webservice-default.$GITLAB_NS.svc:8181" || return 1
44
- # Argo CD reads Git every 3 min: an immediate refresh of the Application
45
- kubectl --context devzone -n devzone-argocd annotate application.argoproj.io \
46
- devzone-gitlab argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
47
- }
48
-
49
- # The Application removed when GitLab is uninstalled: its resources leave with
50
- # it; nothing to do when the module argocd is off or the Application is absent
51
- gitlab_application_retirer() {
52
- catalogue_argocd_application_exists gitlab || return 0
53
- catalogue_argocd_delete gitlab
54
- }
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env bash
2
- # GitLab installed from the wrapper chart charts/devzone-gitlab (#538): the
3
- # official gitlab 9.11.16 and gitlab-runner 0.88.2 are dependencies pinned in
4
- # the chart, its values.yaml holds the values of the GitLab of devzone
5
- # (under the gitlab and gitlab-runner keys). This file is the helm-direct
6
- # path, the Application of Argo CD is argocd.sh. Sourced by installation.sh.
7
- # gitlab_chart_depend repository HTTP gitlab added, dependency build
8
- # gitlab_helm_pass <replicas> upgrade --install of the chart, runner replicas
9
- # gitlab_runner_ancien_retirer release gitlab-runner of before #538 removed
10
- # The runner is held back (replicas 0) on the first pass: its Secret
11
- # gitlab-runner-secret is written by the seed, and a runner pod waiting for it
12
- # would hold --wait until the timeout.
13
-
14
- # The dependencies come from https://charts.gitlab.io (no OCI repository is
15
- # published): the repository is added before the build, idempotent
16
- gitlab_chart_depend() {
17
- helm repo add gitlab https://charts.gitlab.io --force-update >/dev/null 2>&1 || true
18
- helm dependency build "$RACINE/charts/devzone-gitlab" >/dev/null
19
- }
20
-
21
- # One helm pass of the wrapper chart. The webservice URL of the runner follows
22
- # the namespace of the instance: the chart value is not templated, its default
23
- # is the main instance, so it is passed here
24
- gitlab_helm_pass() {
25
- local replicas="$1"
26
- account_helm "$(account_context)" upgrade --install gitlab "$RACINE/charts/devzone-gitlab" \
27
- --namespace "$GITLAB_NS" \
28
- --create-namespace \
29
- --timeout "${GITLAB_ATTENTE}s" \
30
- --wait \
31
- --set "gitlab-runner.gitlabUrl=http://gitlab-webservice-default.$GITLAB_NS.svc:8181" \
32
- --set "gitlab-runner.replicas=$replicas"
33
- }
34
-
35
- # Release gitlab-runner of the installations before the wrapper chart (#396):
36
- # its runner now comes with the chart, the release leaves without touching data
37
- gitlab_runner_ancien_retirer() {
38
- account_helm "$(account_context)" uninstall gitlab-runner --namespace "$GITLAB_NS" >/dev/null 2>&1 || true
39
- }
@@ -1,168 +0,0 @@
1
- #!/usr/bin/env bash
2
- # GitLab module: test GitLab in the services cluster (#396).
3
- # To enable it: devzone enable gitlab
4
- # To disable it: devzone disable gitlab
5
- # set -euo pipefail so that nothing fails silently.
6
- set -euo pipefail
7
-
8
- # Root of the devzone repository (two levels above the module); DEVZONE_ROOT for the tests
9
- ICI="$(cd "$(dirname "$0")" && pwd)"
10
- RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
11
- # shellcheck source=SCRIPTDIR/../cluster.sh
12
- . "$ICI/../cluster.sh"
13
- # shellcheck source=SCRIPTDIR/../password.sh
14
- # shellcheck disable=SC1091
15
- . "$ICI/../password.sh"
16
- # Network isolation: namespace_isolate, set with the devzone-gitlab namespace
17
- # shellcheck source=SCRIPTDIR/../isolation.sh
18
- # shellcheck disable=SC1091
19
- . "$ICI/../isolation.sh"
20
-
21
- # ---- Delay variables (seconds) ----
22
- # GITLAB_ATTENTE: global wait for the installation (default 1200)
23
- GITLAB_ATTENTE="${GITLAB_ATTENTE:-1200}"
24
-
25
- # ---- Secret paths ----
26
- # Secrets stored in $RACINE/workspace/.gitlab/ (chmod 600), never shown.
27
- GITLAB_SECRETS_DIR="$RACINE/workspace/.gitlab"
28
-
29
- # Grouped view of the credentials: a failure never prevents the operation
30
- regenerer_identifiants() {
31
- password_regenerate ||
32
- echo "devzone : gitlab : grouped credentials not updated (devzone passwords)" >&2
33
- }
34
-
35
- # ---- /etc/hosts of the container ----
36
- # DEVZONE_HOSTS for the tests (never the real /etc/hosts)
37
- HOSTS="${DEVZONE_HOSTS:-/etc/hosts}"
38
- GITLAB_HOST_MARK="# devzone:gitlab"
39
-
40
- # GitLab Rails secret (#347): kept in workspace/.gitlab, applied again
41
- # before helm upgrade --install, and the password can be regenerated
42
- # shellcheck source=SCRIPTDIR/secrets.sh
43
- # shellcheck disable=SC1091
44
- . "$ICI/secrets.sh"
45
-
46
- # ---- Installation, migration and relay of the services cluster ----
47
- # New logic outside this file (#396): devzone-gitlab namespace,
48
- # allocatable memory, Helm with the devzone context, migration from kind-gitlab.
49
- # shellcheck source=SCRIPTDIR/installation.sh
50
- # shellcheck disable=SC1091
51
- . "$ICI/installation.sh"
52
- # Wrapper chart (direct helm, chart.sh), Argo CD (argocd.sh), seed (seed.sh) (#538)
53
- # shellcheck source=SCRIPTDIR/chart.sh
54
- # shellcheck disable=SC1091
55
- . "$ICI/chart.sh"
56
- # shellcheck source=SCRIPTDIR/argocd.sh
57
- # shellcheck disable=SC1091
58
- . "$ICI/argocd.sh"
59
- # shellcheck source=SCRIPTDIR/seed.sh
60
- # shellcheck disable=SC1091
61
- . "$ICI/seed.sh"
62
-
63
- # ---- host-set / host-remove: gitlab.localhost in /etc/hosts ----
64
- # Why: ssh (clone ssh://git@gitlab.localhost:2224/…), glab and getent go through
65
- # the system resolver. curl and git (libcurl) ignore /etc/hosts for the
66
- # *.localhost names (RFC 6761) and go through the TCP relay above, which
67
- # listens on 127.0.0.1. The name therefore points to 127.0.0.1 so that ssh and
68
- # glab take the same path. /etc/hosts is a Docker mount that Docker regenerates
69
- # when the container starts, hence the set again at each start (startup.sh) and
70
- # at each activation. Never sed -i nor mv: the mount cannot be renamed (in-place
71
- # write only); direct if the file is writable, otherwise sudo -n. A failure never
72
- # fails: a warning on stderr and exit code 0, so that the installation does not
73
- # fail for a host name.
74
- gitlab_host_set() {
75
- local line tmp
76
- line="$(printf '127.0.0.1\tgitlab.localhost %s' "$GITLAB_HOST_MARK")"
77
- # Already the right line, once: nothing (idempotent)
78
- if [ "$(grep -c "$GITLAB_HOST_MARK" "$HOSTS" 2>/dev/null || true)" = 1 ] &&
79
- grep -qxF "$line" "$HOSTS" 2>/dev/null; then
80
- return 0
81
- fi
82
- if grep -q "$GITLAB_HOST_MARK" "$HOSTS" 2>/dev/null; then
83
- # Line marked with another address (IPv6 of #320) or duplicate:
84
- # it is replaced by the right one, keeping the rest of the file.
85
- tmp="$(mktemp)"
86
- grep -v "$GITLAB_HOST_MARK" "$HOSTS" >"$tmp" 2>/dev/null || true
87
- printf '%s\n' "$line" >>"$tmp"
88
- if [ -w "$HOSTS" ]; then
89
- cp "$tmp" "$HOSTS" 2>/dev/null ||
90
- echo "devzone : gitlab : gitlab.localhost name not set in $HOSTS (insufficient write rights)" >&2
91
- elif ! sudo -n cp "$tmp" "$HOSTS" >/dev/null 2>&1; then
92
- echo "devzone : gitlab : gitlab.localhost name not set in $HOSTS (sudo -n unavailable or refused)" >&2
93
- fi
94
- rm -f "$tmp"
95
- return 0
96
- fi
97
- if [ -w "$HOSTS" ]; then
98
- printf '%s\n' "$line" >>"$HOSTS" 2>/dev/null ||
99
- echo "devzone : gitlab : gitlab.localhost name not set in $HOSTS (insufficient write rights)" >&2
100
- elif ! printf '%s\n' "$line" | sudo -n tee -a "$HOSTS" >/dev/null 2>&1; then
101
- echo "devzone : gitlab : gitlab.localhost name not set in $HOSTS (sudo -n unavailable or refused)" >&2
102
- fi
103
- return 0
104
- }
105
-
106
- gitlab_host_remove() {
107
- # No line found: nothing (including an unreadable file)
108
- if ! grep -q "$GITLAB_HOST_MARK" "$HOSTS" 2>/dev/null; then
109
- return 0
110
- fi
111
- local tmp
112
- tmp="$(mktemp)"
113
- grep -v "$GITLAB_HOST_MARK" "$HOSTS" >"$tmp" 2>/dev/null || true
114
- if [ -w "$HOSTS" ]; then
115
- cp "$tmp" "$HOSTS" 2>/dev/null ||
116
- echo "devzone : gitlab : gitlab.localhost line not removed from $HOSTS (insufficient write rights)" >&2
117
- elif ! sudo -n cp "$tmp" "$HOSTS" >/dev/null 2>&1; then
118
- echo "devzone : gitlab : gitlab.localhost line not removed from $HOSTS (sudo -n unavailable or refused)" >&2
119
- fi
120
- rm -f "$tmp"
121
- return 0
122
- }
123
-
124
- # ---- status: check the state of GitLab ----
125
- gitlab_status() {
126
- # Disabled if the devzone-gitlab namespace does not exist
127
- if ! gitlab_installed; then
128
- echo "disabled"
129
- return 0
130
- fi
131
-
132
- # Check that GitLab answers the readiness probe
133
- 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
134
- # Check whether the runner is online or offline
135
- local runner_status="offline"
136
- if [ -f "$GITLAB_SECRETS_DIR/root-token" ]; then
137
- local token count
138
- token="$(cat "$GITLAB_SECRETS_DIR/root-token")"
139
- count="$(curl -s --header "PRIVATE-TOKEN: $token" "http://gitlab.localhost:8929/api/v4/runners/all?status=online" 2>/dev/null | jq -r 'length' 2>/dev/null || true)"
140
- if [ "${count:-0}" -gt 0 ] 2>/dev/null; then
141
- runner_status="online"
142
- fi
143
- fi
144
- echo "ready: http://gitlab.localhost:8929, runner ${runner_status}"
145
- else
146
- echo "failed: devzone apply"
147
- fi
148
- return 0
149
- }
150
-
151
- # Subcommand dispatch
152
- case "${1:-}" in
153
- install) gitlab_install ;;
154
- uninstall) gitlab_uninstall "${@:2}" ;;
155
- migrate) shift; gitlab_migrate "$@" ;;
156
- installe) gitlab_installed ;;
157
- status) gitlab_status ;;
158
- seed) gitlab_seed_command ;;
159
- new-password) gitlab_new_password "${@:2}" ;;
160
- relay-start) gitlab_relay_start ;;
161
- relay-stop) gitlab_relay_stop ;;
162
- relay-status) gitlab_relay_status ;;
163
- hote-poser) gitlab_host_set ;;
164
- hote-retirer) gitlab_host_remove ;;
165
- *) echo "devzone : unknown command : ${1:-} (devzone gitlab --help)" >&2
166
- exit 1
167
- ;;
168
- esac