devzone 7.6.1 → 7.7.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.
@@ -98,12 +98,9 @@ case "${1:-}" in
98
98
  exit 127
99
99
  fi
100
100
  ;;
101
- build)
102
- bash "$ICI/workspace-build.sh" "${@:2}"
103
- ;;
104
101
  # Go only: reached when the binary did not take the call. Never call
105
102
  # "devzone" again from here, it would loop forever, see #864
106
- -h | --help | help | repair | apply-repowarden | cluster | clusters | metrics | use | kube | ai | agent | postgres | mysql | gitlab | test-gitlab | catalog | catalog-watcher | enable | disable | is-enabled | apply | platform)
103
+ -h | --help | help | repair | apply-repowarden | cluster | clusters | metrics | use | kube | ai | agent | build | postgres | mysql | gitlab | test-gitlab | catalog | catalog-watcher | enable | disable | is-enabled | apply | platform)
107
104
  echo "devzone $1: Go binary of the pod unavailable (.devcontainer/bin)" >&2
108
105
  exit 1
109
106
  ;;
package/bin/SHA256SUMS CHANGED
@@ -1,6 +1,6 @@
1
- ea2f9af12971226b9b91ee5f598d1804f7f433d1423a2074080b0903ee6aaeb8 devzone-linux-amd64
2
- 018d546966acdff26d2024c4120b80e12616b77b08e5fefe75658f3e9d9c9346 devzone-linux-arm64
3
- 425a9a0d32138b7e94d3ce70a6576f5e0451fee8d9a6af546d9bb80add7e8701 devzone-darwin-amd64
4
- 2d40e751b5f47c4d7986832df2032c30617c7c4ab2d0d902193cdb3462046065 devzone-darwin-arm64
5
- 50ec64b365fa0ba236c4438cd3567179df50fc4fcac102b67a1b6d4370ba4ca5 devzone-windows-amd64.exe
6
- 8116c89d1dd1998ecf7e26ff39506b5229f0e648c0b2e694da43555ba66e73d3 devzone-windows-arm64.exe
1
+ 58dee1dcd6ecaacb14501aaf29c9d636e4d92881364437a862e627c67371188c devzone-linux-amd64
2
+ 499506206fd90ae3a66e46de4c554c08afd0cac219465ab61c3aedf58470f4ef devzone-linux-arm64
3
+ d41a4bd2ed646431073aeda4cccd88e50a5e1f32fbf0a775bf37bb7005c4b734 devzone-darwin-amd64
4
+ 272f7440e3fd40869c9bc471435fc63db4b33ccd23c21822a589ea66fe4cbcd5 devzone-darwin-arm64
5
+ ed30a3cd296b1aa64f53f5f8f8ef0753daa026d5082663f01b448de226fc12fa devzone-windows-amd64.exe
6
+ c68b53c4acde7e2da3f4f8271afa79285947b0890c0b25d058c5e8c7f63af505 devzone-windows-arm64.exe
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -184,6 +184,35 @@ spec:
184
184
  value: tcp://127.0.0.1:1234
185
185
  resources:
186
186
  {{- toYaml .Values.resources | nindent 12 }}
187
+ {{- /*
188
+ Liveness probe (#982): exit 1 when pids.current is above thresholdPercent
189
+ of pids.max, so that the kubelet restarts the container. The script is
190
+ bash, passed as an argument; the threshold is its $1. Missing files or
191
+ pids.max "max" give exit 0. CGROUP_DIR overrides the cgroup directory
192
+ (the bats test uses fake files). Settings and reason: values.yaml.
193
+ Helm comment: not in the rendering.
194
+ */}}
195
+ {{- if .Values.livenessProbe.enabled }}
196
+ livenessProbe:
197
+ exec:
198
+ command:
199
+ - bash
200
+ - -c
201
+ - |
202
+ dir="${CGROUP_DIR:-/sys/fs/cgroup}"
203
+ cur="$(cat "$dir/pids.current" 2>/dev/null)" || exit 0
204
+ max="$(cat "$dir/pids.max" 2>/dev/null)" || exit 0
205
+ [[ "$cur" =~ ^[0-9]+$ && "$max" =~ ^[0-9]+$ ]] || exit 0
206
+ (( max > 0 )) || exit 0
207
+ (( cur * 100 > max * $1 )) && exit 1
208
+ exit 0
209
+ - liveness
210
+ - {{ .Values.livenessProbe.thresholdPercent | quote }}
211
+ initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
212
+ periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
213
+ timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
214
+ failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
215
+ {{- end }}
187
216
  volumeMounts:
188
217
  - name: workspace
189
218
  mountPath: /workspaces/projets
@@ -77,6 +77,23 @@ resources:
77
77
  cpu: "500m"
78
78
  memory: "4Gi"
79
79
 
80
+ # Liveness probe of the workspace container (#982). It fails when pids.current
81
+ # goes past thresholdPercent of pids.max (the process limit), and the kubelet
82
+ # then restarts the container: the volumes are kept, only the processes go.
83
+ # PID 1 reaps the zombies (#967), but nothing stops another runaway (a fork loop,
84
+ # processes that never exit): the probe catches that case. The values are
85
+ # deliberately cautious, a short spike must never restart the workspace: the
86
+ # probe waits 120 s after the start, runs every 60 s and needs 5 failures in a
87
+ # row (5 minutes above the threshold at least). Unreadable or unlimited cgroup
88
+ # files count as a success. enabled: false removes the probe.
89
+ livenessProbe:
90
+ enabled: true
91
+ thresholdPercent: 85
92
+ periodSeconds: 60
93
+ failureThreshold: 5
94
+ initialDelaySeconds: 120
95
+ timeoutSeconds: 10
96
+
80
97
  persistence:
81
98
  # Identities, logins and caches, kept from one restart to the next. Each path
82
99
  # (relative to the home of vscode) is mounted from this volume at its usual
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "7.6.1",
3
+ "version": "7.7.1",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -1,262 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Applications of the user's projects in the Argo CD of devzone (#516),
3
- # declared in .argocd.conf (conf.sh) and reconciled:
4
- # argocd_app add <repo url> [path] [--name N] [--revision R] [--namespace NS] [--token T] [--username U]
5
- # argocd_app list
6
- # argocd_app remove <N>
7
- # apps_reconcile every [app N] of .argocd.conf applied, the others removed
8
- # Sourced by the container (argocd.sh: kubectl --context devzone) and by the
9
- # workstation (manage/scripts/workspace/argocd-services.sh), after conf.sh and
10
- # gitops.sh. The includer defines argocd_kubectl, APPS_GENERATOR, APPS_CMD,
11
- # ARGOCD_CONF and ARGOCD_CONF_DIR (the devzone folder: token-file paths are
12
- # relative to it), and may define apps_gitlab_token (root token of the
13
- # devzone GitLab, on stdout).
14
- # Application app-<N> in devzone-argocd, resources in devzone-app-<N>. GitHub
15
- # or any public repository: nothing else. A private one: --token (kept in
16
- # workspace/.argocd/tokens/<N>, 600, out of Git) or token-file, and username
17
- # (root by default), in a repository Secret, never in the Application. The
18
- # GitLab of devzone: its gitlab.localhost URL is rewritten to the service of
19
- # the cluster, the root token of the module is used unless a token is given,
20
- # and the NetworkPolicy of devzone-gitlab lets the devzone namespaces in.
21
- # bash 3.2 (macOS).
22
-
23
- APPS_NS="devzone-argocd"
24
- : "${APPS_CMD:=devzone argocd app}"
25
- : "${APPS_GITLAB_NS:=devzone-gitlab}"
26
-
27
- apps_usage() {
28
- echo "usage: $APPS_CMD add <repo url> [path] [--name N] [--revision R] [--namespace NS] [--token T] [--username U] | list | remove <N>" >&2
29
- return 2
30
- }
31
-
32
- apps_name_from_url() {
33
- local n="$1"
34
- n="${n%/}"
35
- n="${n##*/}"
36
- n="${n%.git}"
37
- printf '%s' "$n" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9-' '-' | sed 's/^-*//; s/-*$//'
38
- }
39
-
40
- apps_name_valid() {
41
- case "${1:-}" in
42
- '' | *[!a-z0-9-]* | -*) return 1 ;;
43
- esac
44
- [ "${#1}" -le 40 ]
45
- }
46
-
47
- apps_is_devzone_gitlab() {
48
- case "$1" in
49
- http://gitlab.localhost:8929/* | http://gitlab.localhost/* | https://gitlab.localhost/* | https://gitlab.localhost:*/*) return 0 ;;
50
- esac
51
- return 1
52
- }
53
-
54
- # Address Argo CD reaches: the webservice of the GitLab namespace
55
- apps_repo_internal() {
56
- local url="$1" path
57
- if apps_is_devzone_gitlab "$url"; then
58
- path="${url#*://gitlab.localhost}"
59
- case "$path" in :*) path="/${path#*/}" ;; esac
60
- printf 'http://gitlab-webservice-default.%s.svc:8181%s' "$APPS_GITLAB_NS" "$path"
61
- else
62
- printf '%s' "$url"
63
- fi
64
- }
65
-
66
- # Token of an app: its token-file (relative to the devzone folder), else the
67
- # root token of the devzone GitLab for a devzone GitLab repository
68
- apps_token_of() {
69
- local file="$1" repo="$2"
70
- if [ -n "$file" ]; then
71
- case "$file" in /*) cat "$file" 2>/dev/null ;; *) cat "$ARGOCD_CONF_DIR/$file" 2>/dev/null ;; esac
72
- return 0
73
- fi
74
- apps_is_devzone_gitlab "$repo" || return 0
75
- if command -v apps_gitlab_token >/dev/null 2>&1; then
76
- apps_gitlab_token
77
- else
78
- cat "$ARGOCD_CONF_DIR/workspace/.gitlab/root-token" 2>/dev/null
79
- fi
80
- }
81
-
82
- apps_repo_secret() {
83
- local name="$1" url="$2" username="$3" token="$4"
84
- argocd_kubectl -n "$APPS_NS" apply -f - >/dev/null <<EOF
85
- apiVersion: v1
86
- kind: Secret
87
- metadata:
88
- name: repo-$name
89
- namespace: $APPS_NS
90
- labels:
91
- argocd.argoproj.io/secret-type: repository
92
- app.kubernetes.io/managed-by: devzone
93
- type: Opaque
94
- stringData:
95
- type: git
96
- url: $url
97
- username: $username
98
- password: $token
99
- EOF
100
- }
101
-
102
- # Ingress of the GitLab namespace opened to the devzone namespaces (Argo CD
103
- # repo-server among them): same rule as devzone postgres authorize
104
- apps_gitlab_allow_argocd() {
105
- argocd_kubectl -n "$APPS_GITLAB_NS" patch networkpolicy devzone-meme-namespace --type merge \
106
- -p '{"spec":{"ingress":[{"from":[{"podSelector":{},"namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}' >/dev/null 2>&1 ||
107
- echo "⚠ NetworkPolicy of $APPS_GITLAB_NS not opened to Argo CD: devzone postgres authorize $APPS_NS, or the sync will fail" >&2
108
- }
109
-
110
- # One [app N] of .argocd.conf applied: Secret when a token exists, then the Application
111
- apps_apply_one() {
112
- local name="$1" repo path revision namespace username file token url
113
- repo="$(conf_get "app $name" repo)"
114
- if [ -z "$repo" ]; then
115
- echo "⚠ [app $name] without repo in $ARGOCD_CONF: skipped" >&2
116
- return 0
117
- fi
118
- path="$(conf_get "app $name" path)"; path="${path:-.}"
119
- revision="$(conf_get "app $name" revision)"; revision="${revision:-HEAD}"
120
- namespace="$(conf_get "app $name" namespace)"; namespace="${namespace:-devzone-app-$name}"
121
- username="$(conf_get "app $name" username)"; username="${username:-root}"
122
- file="$(conf_get "app $name" token-file)"
123
- url="$(apps_repo_internal "$repo")"
124
- token="$(apps_token_of "$file" "$repo")"
125
- if apps_is_devzone_gitlab "$repo"; then
126
- if [ -z "$token" ]; then
127
- echo "✖ [app $name]: token of the devzone GitLab not found (workspace/.gitlab/root-token or token-file)" >&2
128
- return 1
129
- fi
130
- apps_gitlab_allow_argocd
131
- fi
132
- if [ -n "$token" ]; then
133
- apps_repo_secret "$name" "$url" "$username" "$token" || return 1
134
- fi
135
- gitops_apply_application "app-$name" project "$namespace" "$url" "$revision" "$path" || return 1
136
- echo "✔ Application app-$name: $url ($path, $revision) → namespace $namespace${token:+; credentials in the Secret repo-$name}"
137
- }
138
-
139
- # An Application leaves the cluster with its resources, its repository
140
- # Secret and the namespace devzone created for it (never one chosen by hand)
141
- apps_purge() {
142
- local name="$1" namespace
143
- namespace="$(argocd_kubectl -n "$APPS_NS" get application.argoproj.io "app-$name" \
144
- -o jsonpath='{.spec.destination.namespace}' 2>/dev/null)" || namespace=""
145
- gitops_delete_application "app-$name" || return 1
146
- argocd_kubectl -n "$APPS_NS" delete secret "repo-$name" --ignore-not-found >/dev/null 2>&1 || true
147
- case "$namespace" in
148
- devzone-app-*) argocd_kubectl delete namespace "$namespace" --ignore-not-found --wait=true >/dev/null 2>&1 || true ;;
149
- esac
150
- echo "✔ Application app-$name removed with its resources${namespace:+ (namespace $namespace)}"
151
- }
152
-
153
- # Every [app N] applied, the project Applications absent from the file removed
154
- apps_reconcile() {
155
- local name declared=" " app code=0
156
- while IFS= read -r name; do
157
- [ -n "$name" ] || continue
158
- declared="$declared$name "
159
- apps_apply_one "$name" || code=1
160
- done <<<"$(conf_sections app)"
161
- while IFS= read -r app; do
162
- [ -n "$app" ] || continue
163
- app="${app#*/}"
164
- app="${app#app-}"
165
- case "$declared" in *" $app "*) continue ;; esac
166
- apps_purge "$app" || code=1
167
- done <<<"$(argocd_kubectl -n "$APPS_NS" get applications.argoproj.io -l devzone.io/kind=project -o name 2>/dev/null || true)"
168
- return "$code"
169
- }
170
-
171
- apps_add() {
172
- local repo="" path="" name="" revision="" namespace="" token="" username=""
173
- local arg expect="" pos=0 keys file
174
- for arg in "$@"; do
175
- if [ -n "$expect" ]; then
176
- case "$expect" in
177
- name) name="$arg" ;; revision) revision="$arg" ;; namespace) namespace="$arg" ;;
178
- token) token="$arg" ;; username) username="$arg" ;;
179
- esac
180
- expect=""
181
- continue
182
- fi
183
- case "$arg" in
184
- --name) expect=name ;;
185
- --revision) expect=revision ;;
186
- --namespace) expect=namespace ;;
187
- --token) expect=token ;;
188
- --username) expect=username ;;
189
- -*) echo "✖ $APPS_CMD add: unknown option: $arg" >&2; apps_usage; return 2 ;;
190
- *)
191
- pos=$((pos + 1))
192
- case "$pos" in
193
- 1) repo="$arg" ;;
194
- 2) path="$arg" ;;
195
- *) echo "✖ $APPS_CMD add: unexpected argument: $arg" >&2; apps_usage; return 2 ;;
196
- esac
197
- ;;
198
- esac
199
- done
200
- if [ -n "$expect" ]; then
201
- echo "✖ $APPS_CMD add: --$expect needs a value" >&2
202
- return 2
203
- fi
204
- [ -n "$repo" ] || { apps_usage; return 2; }
205
- case "$repo" in
206
- https://* | http://* | ssh://* | git@*) ;;
207
- *) echo "✖ $APPS_CMD add: repository URL expected (https://…): $repo" >&2; return 2 ;;
208
- esac
209
- [ -n "$name" ] || name="$(apps_name_from_url "$repo")"
210
- if ! apps_name_valid "$name"; then
211
- echo "✖ $APPS_CMD add: invalid name: ${name:-(empty)} (lowercase letters, digits, dashes, 40 at most: --name N)" >&2
212
- return 2
213
- fi
214
- if apps_is_devzone_gitlab "$repo" && [ -z "$token" ] && [ -z "$(apps_token_of "" "$repo")" ]; then
215
- echo "✖ $APPS_CMD add: token of the devzone GitLab not found (workspace/.gitlab/root-token): --token T" >&2
216
- return 2
217
- fi
218
- keys="repo=$repo path=${path:-.} revision=${revision:-HEAD} namespace=${namespace:-devzone-app-$name}"
219
- [ -z "$username" ] || keys="$keys username=$username"
220
- if [ -n "$token" ]; then
221
- # The token stays out of the file and out of Git: workspace/ is ignored
222
- file="workspace/.argocd/tokens/$name"
223
- mkdir -p "$ARGOCD_CONF_DIR/workspace/.argocd/tokens"
224
- chmod 700 "$ARGOCD_CONF_DIR/workspace/.argocd" "$ARGOCD_CONF_DIR/workspace/.argocd/tokens"
225
- (umask 077 && printf '%s' "$token" >"$ARGOCD_CONF_DIR/$file")
226
- keys="$keys token-file=$file"
227
- fi
228
- # shellcheck disable=SC2086
229
- conf_set "app $name" $keys
230
- apps_apply_one "$name" || return 1
231
- echo " declared in $ARGOCD_CONF; sync status: $APPS_CMD list"
232
- }
233
-
234
- apps_list() {
235
- argocd_kubectl -n "$APPS_NS" get applications.argoproj.io -l devzone.io/kind=project \
236
- -o custom-columns='APPLICATION:.metadata.name,REPOSITORY:.spec.source.repoURL,PATH:.spec.source.path,REVISION:.spec.source.targetRevision,NAMESPACE:.spec.destination.namespace,SYNC:.status.sync.status,HEALTH:.status.health.status'
237
- }
238
-
239
- apps_remove() {
240
- local name="${1:-}"
241
- if ! apps_name_valid "$name"; then
242
- echo "✖ $APPS_CMD remove <name> ($APPS_CMD list)" >&2
243
- return 2
244
- fi
245
- if ! argocd_kubectl -n "$APPS_NS" get application.argoproj.io "app-$name" >/dev/null 2>&1 &&
246
- ! conf_sections app | grep -qx -- "$name"; then
247
- echo "✖ $APPS_CMD remove: no Application app-$name ($APPS_CMD list)" >&2
248
- return 1
249
- fi
250
- conf_remove "app $name"
251
- rm -f "$ARGOCD_CONF_DIR/workspace/.argocd/tokens/$name"
252
- apps_purge "$name"
253
- }
254
-
255
- argocd_app() {
256
- case "${1:-}" in
257
- add) apps_add "${@:2}" ;;
258
- list) apps_list ;;
259
- remove) apps_remove "${@:2}" ;;
260
- *) apps_usage ;;
261
- esac
262
- }
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env bash
2
- # GitLab as the GitOps repository of Argo CD (#559, step 6): devzone/devzone-argocd
3
- # on the devzone GitLab, written through its API (files endpoint, no clone). The
4
- # repository is designated with provider = gitlab in [argocd] of .argocd.conf;
5
- # the repository URL is the internal one (Argo CD reads it in the cluster).
6
- # The root token is read from workspace/.gitlab/root-token, sent through a curl
7
- # config file (never on the command line) and never printed.
8
- # Sourced by gitops.sh, which dispatches its put, sha, delete and root functions
9
- # here when gitops_is_gitlab holds. The includer defines RACINE, conf_set and
10
- # conf_get (conf.sh). GITLAB_GITOPS_API: base URL of the API seen by this
11
- # process (the relay of the container by default). bash 3.2 (macOS).
12
- # gitlab_gitops_init project created by the API, repository designated
13
- # gitlab_gitops_sha <path> blob id of a file, empty when absent
14
- # gitlab_gitops_put <path> <file> <message> create or update, same blob skipped
15
- # gitlab_gitops_delete <path> <message> file removed
16
- # gitlab_gitops_root_token the token of the Argo CD repository Secret
17
-
18
- GITLAB_GITOPS_GROUP="${GITLAB_GITOPS_GROUP:-devzone}"
19
- GITLAB_GITOPS_PROJECT="${GITLAB_GITOPS_PROJECT:-devzone-argocd}"
20
- GITLAB_GITOPS_BRANCH="${GITLAB_GITOPS_BRANCH:-main}"
21
- GITLAB_GITOPS_API="${GITLAB_GITOPS_API:-http://gitlab.localhost:8929}"
22
- # Internal URL of the repository for Argo CD (the webservice of devzone-gitlab)
23
- GITLAB_GITOPS_URL_INTERNE="${GITLAB_GITOPS_URL_INTERNE:-http://gitlab-webservice-default.devzone-gitlab.svc:8181/$GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT.git}"
24
-
25
- # Root token of the devzone GitLab; refused when absent (devzone enable gitlab)
26
- gitlab_gitops_root_token() {
27
- local file="$RACINE/workspace/.gitlab/root-token" token=""
28
- [ -s "$file" ] && token="$(cat "$file")"
29
- if [ -z "$token" ]; then
30
- echo "✖ GitLab root token missing ($file): devzone enable gitlab" >&2
31
- return 1
32
- fi
33
- printf '%s' "$token"
34
- }
35
-
36
- # One API call: METHOD PATH [curl options]; the token goes through a config file
37
- # (mode 600, removed right after), so it never shows in the process list
38
- gitlab_gitops_api() {
39
- local method="$1" path="$2" cfg token rc=0
40
- shift 2
41
- token="$(gitlab_gitops_root_token)" || return 1
42
- cfg="$(mktemp)"
43
- chmod 600 "$cfg"
44
- printf 'header = "PRIVATE-TOKEN: %s"\n' "$token" >"$cfg" || { rm -f "$cfg"; return 1; }
45
- curl -s --config "$cfg" --request "$method" "$GITLAB_GITOPS_API/api/v4$path" "$@" || rc=$?
46
- rm -f "$cfg"
47
- return "$rc"
48
- }
49
-
50
- # The project path, URL-encoded for the API (devzone%2Fdevzone-argocd)
51
- gitlab_gitops_projet() {
52
- printf '%s' "$GITLAB_GITOPS_GROUP%2F$GITLAB_GITOPS_PROJECT"
53
- }
54
-
55
- # Numeric id of the project, empty when it does not exist
56
- gitlab_gitops_id() {
57
- gitlab_gitops_api GET "/projects/$(gitlab_gitops_projet)" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true
58
- }
59
-
60
- # A file path URL-encoded for the files endpoint (apps/x.yaml -> apps%2Fx.yaml)
61
- gitlab_gitops_chemin() {
62
- printf '%s' "$1" | jq -sRr '@uri'
63
- }
64
-
65
- # Blob id of a file on the branch (the files endpoint), empty when absent
66
- gitlab_gitops_sha() {
67
- local id
68
- id="$(gitlab_gitops_id)"
69
- [ -n "$id" ] || return 0
70
- gitlab_gitops_api GET "/projects/$id/repository/files/$(gitlab_gitops_chemin "$1")?ref=$GITLAB_GITOPS_BRANCH" 2>/dev/null |
71
- jq -r '.blob_id // empty' 2>/dev/null || true
72
- }
73
-
74
- # Creates or updates a file: PUT when the file exists, POST when it is new
75
- gitlab_gitops_put() {
76
- local path="$1" file="$2" message="$3" id sha content verb
77
- id="$(gitlab_gitops_id)"
78
- [ -n "$id" ] || { echo "✖ GitLab project $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT missing: devzone argocd init --gitlab" >&2; return 1; }
79
- sha="$(gitlab_gitops_sha "$path")"
80
- if [ -n "$sha" ] && [ "$sha" = "$(git hash-object "$file" 2>/dev/null || true)" ]; then
81
- return 0
82
- fi
83
- content="$(base64 <"$file" | tr -d '\n')"
84
- verb=POST
85
- [ -z "$sha" ] || verb=PUT
86
- gitlab_gitops_api "$verb" "/projects/$id/repository/files/$(gitlab_gitops_chemin "$path")" \
87
- --data-urlencode "branch=$GITLAB_GITOPS_BRANCH" \
88
- --data-urlencode "encoding=base64" \
89
- --data-urlencode "content=$content" \
90
- --data-urlencode "commit_message=$message" >/dev/null
91
- }
92
-
93
- # Removes a file on the branch; nothing to do when it is absent
94
- gitlab_gitops_delete() {
95
- local path="$1" message="$2" id
96
- id="$(gitlab_gitops_id)"
97
- [ -n "$id" ] || return 0
98
- [ -n "$(gitlab_gitops_sha "$path")" ] || return 0
99
- gitlab_gitops_api DELETE "/projects/$id/repository/files/$(gitlab_gitops_chemin "$path")" \
100
- --data-urlencode "branch=$GITLAB_GITOPS_BRANCH" \
101
- --data-urlencode "commit_message=$message" >/dev/null
102
- }
103
-
104
- # The group devzone (created by the seed when missing), then the project
105
- # devzone/devzone-argocd with a first commit (README) so that the files can be
106
- # written; the repository is designated in [argocd] (internal URL, provider)
107
- gitlab_gitops_init() {
108
- local group id
109
- gitlab_gitops_root_token >/dev/null || return 1
110
- group="$(gitlab_gitops_api GET "/groups/$GITLAB_GITOPS_GROUP" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
111
- if [ -z "$group" ]; then
112
- group="$(gitlab_gitops_api POST /groups --data-urlencode "name=$GITLAB_GITOPS_GROUP" \
113
- --data-urlencode "path=$GITLAB_GITOPS_GROUP" --data "visibility=private" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
114
- fi
115
- [ -n "$group" ] || { echo "✖ GitLab group $GITLAB_GITOPS_GROUP not created" >&2; return 1; }
116
- id="$(gitlab_gitops_id)"
117
- if [ -z "$id" ]; then
118
- id="$(gitlab_gitops_api POST /projects --data-urlencode "name=$GITLAB_GITOPS_PROJECT" \
119
- --data "namespace_id=$group" --data "visibility=private" --data "initialize_with_readme=true" \
120
- --data-urlencode "default_branch=$GITLAB_GITOPS_BRANCH" 2>/dev/null | jq -r '.id // empty' 2>/dev/null || true)"
121
- [ -n "$id" ] || { echo "✖ GitLab project $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT not created" >&2; return 1; }
122
- echo "✔ GitOps repository created on GitLab: $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT (private)"
123
- gitops_put_text apps/.gitkeep "" "devzone: apps folder"
124
- fi
125
- conf_set argocd "repo=$GITLAB_GITOPS_URL_INTERNE" "provider=gitlab"
126
- echo "✔ GitOps repository: GitLab $GITLAB_GITOPS_GROUP/$GITLAB_GITOPS_PROJECT (internal URL in Argo CD)"
127
- }
@@ -1,172 +0,0 @@
1
- #!/usr/bin/env bash
2
- # The services of devzone held by Argo CD (#538): postgres, mysql, gitlab,
3
- # declared in the [services] section of .argocd.conf (conf.sh):
4
- # [services]
5
- # postgres = on
6
- # mysql = off
7
- # One Application devzone-<svc> per service on: the chart charts/devzone-<svc>
8
- # of the devzone repository at the revision (gitops.sh). Before it, the
9
- # namespace devzone-<svc> (labelled, isolated by a NetworkPolicy) and the
10
- # secret of the service (superuser password generated or re-read, mirrored in
11
- # workspace/.<svc>/ and .password) are created apart, out of Git.
12
- # A service off: the Application leaves with its resources, the namespace and
13
- # the volumes stay; the data removal stays the explicit command
14
- # devzone workspace services disable <svc> --yes
15
- # The lines <svc>=on|off of .devzone.modules are read in compatibility when
16
- # the [services] section does not hold the service yet.
17
- # services_reconcile every service applied or released
18
- # services_state_of <svc> on | off | empty (not declared)
19
- # services_note <svc> on|off writes the [services] section
20
- # chart_require <svc> chart charts/devzone-<svc> named devzone-<svc>, or code 2
21
- # Sourced after conf.sh and gitops.sh by the workstation
22
- # (manage/scripts/workspace/argocd-services.sh) and by the container (argocd.sh). The
23
- # includer defines argocd_kubectl, APPS_GENERATOR, ARGOCD_CONF and
24
- # ARGOCD_CONF_DIR (the devzone folder: relative paths there), DEVZONE_REPO_URL
25
- # and argocd_revision, the secret hook of each service
26
- # services_secret_<svc> secret created apart, mirrored, never printed
27
- # and may extend SERVICES_LIST (default: postgres) and define the parameters
28
- # hook services_chart_<svc> (helm parameters on stdout). bash 3.2 (macOS).
29
-
30
- : "${SERVICES_LIST:=postgres}"
31
-
32
- # Names of the Application and of the namespace of a service
33
- services_app_of() { printf 'devzone-%s' "$1"; }
34
- #
35
- # Returns the namespace name devzone-<svc> for a given service name.
36
- # Used by services_namespace_prepare and services_application_apply.
37
- services_ns_of() { printf 'devzone-%s' "$1"; }
38
-
39
- # The chart of a service, charts/devzone-<svc> of RACINE (the package), must
40
- # exist and name itself devzone-<svc> in Chart.yaml. Otherwise a refusal, code
41
- # 2, before anything is applied (#554)
42
- chart_require() {
43
- local svc="$1" chart="$RACINE/charts/devzone-$1"
44
- if [ -f "$chart/Chart.yaml" ] && grep -qxF "name: devzone-$svc" "$chart/Chart.yaml"; then
45
- return 0
46
- fi
47
- echo "✖ $svc : chart charts/devzone-$svc missing or misnamed (manage/docs/reference.md#devzone-charts)" >&2
48
- return 2
49
- }
50
-
51
- # State of a service: [services] of .argocd.conf first, then the line
52
- # <svc>=on|off of .devzone.modules (compatibility, #538); empty when neither
53
- # holds the service
54
- services_state_of() {
55
- local svc="$1" v line
56
- v="$(conf_get services "$svc")"
57
- case "$v" in on | off) printf '%s' "$v"; return 0 ;; esac
58
- [ -f "$ARGOCD_CONF_DIR/.devzone.modules" ] || return 0
59
- while IFS= read -r line || [ -n "$line" ]; do
60
- line="$(conf_trim "$line")"
61
- case "$line" in
62
- "$svc=on" | "$svc=off") printf '%s' "${line#*=}"; return 0 ;;
63
- esac
64
- done <"$ARGOCD_CONF_DIR/.devzone.modules"
65
- return 0
66
- }
67
-
68
- # The [services] section rewritten with the new state of <svc>, the keys of
69
- # the other services kept
70
- services_note() {
71
- local svc="$1" state="$2" s k v
72
- set --
73
- while IFS="$(printf '\t')" read -r s k v; do
74
- [ "$s" = services ] || continue
75
- [ "$k" = "$svc" ] && continue
76
- set -- "$@" "$k=$v"
77
- done <<<"$(conf_entries)"
78
- set -- "$@" "$svc=$state"
79
- conf_set services "$@"
80
- }
81
-
82
- # Namespace devzone-<svc>: labelled and isolated like the other devzone-*
83
- # namespaces (same rule as the helm-direct installers)
84
- services_namespace_prepare() {
85
- local ns
86
- ns="$(services_ns_of "$1")"
87
- argocd_kubectl create namespace "$ns" --dry-run=client -o yaml | argocd_kubectl apply -f - >/dev/null
88
- argocd_kubectl label namespace "$ns" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
89
- argocd_kubectl -n "$ns" apply -f - >/dev/null <<'EOF'
90
- apiVersion: networking.k8s.io/v1
91
- kind: NetworkPolicy
92
- metadata:
93
- name: devzone-meme-namespace
94
- labels:
95
- app.kubernetes.io/managed-by: devzone
96
- spec:
97
- podSelector: {}
98
- ingress:
99
- - from:
100
- - podSelector: {}
101
- EOF
102
- }
103
-
104
- # The Application devzone-<svc>: chart charts/devzone-<svc> of the devzone
105
- # repository at the revision; the parameters hook adds helm parameters
106
- services_application_apply() {
107
- local svc="$1" extra=""
108
- chart_require "$svc" || return $?
109
- set -- "$(services_app_of "$svc")" service "$(services_ns_of "$svc")" \
110
- "$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-$svc"
111
- if command -v "services_chart_$svc" >/dev/null 2>&1; then
112
- # A failing hook (several volumes to choose from…) stops the apply
113
- extra="$("services_chart_$svc")" || return $?
114
- # shellcheck disable=SC2086
115
- set -- "$@" $extra
116
- fi
117
- gitops_apply_application "$@"
118
- }
119
-
120
- # A service off: the Application leaves with its resources, the namespace and
121
- # the volumes stay (--yes of the disable command removes the data)
122
- services_application_delete() {
123
- gitops_delete_application "$(services_app_of "$1")"
124
- }
125
-
126
- # Every service of the list applied or released: on → namespace, secret and
127
- # Application; off → Application removed (namespace and volumes kept); not
128
- # declared: untouched. One failing service does not stop the others; a step
129
- # prints its ✔ only when it succeeded and its ✖ names the service and the step
130
- services_reconcile() {
131
- local svc state code=0
132
- for svc in $SERVICES_LIST; do
133
- state="$(services_state_of "$svc")"
134
- case "$state" in
135
- on)
136
- # Before the namespace and the secret: a misnamed chart applies nothing
137
- chart_require "$svc" || { code=2; continue; }
138
- services_namespace_prepare "$svc" || {
139
- echo "✖ $svc: namespace step failed" >&2
140
- code=1
141
- continue
142
- }
143
- if command -v "services_secret_$svc" >/dev/null 2>&1; then
144
- "services_secret_$svc" || {
145
- echo "✖ $svc: secret step failed" >&2
146
- code=1
147
- continue
148
- }
149
- else
150
- echo "✖ no secret hook for $svc (services_secret_$svc): the sync will fail" >&2
151
- code=1
152
- continue
153
- fi
154
- services_application_apply "$svc" || {
155
- echo "✖ $svc: declare step failed" >&2
156
- code=1
157
- continue
158
- }
159
- echo "✔ Application $(services_app_of "$svc") declared (chart charts/devzone-$svc)"
160
- ;;
161
- off)
162
- services_application_delete "$svc" || {
163
- echo "✖ $svc: remove step failed" >&2
164
- code=1
165
- continue
166
- }
167
- echo "✔ Application $(services_app_of "$svc") removed (namespace and volumes kept)"
168
- ;;
169
- esac
170
- done
171
- return "$code"
172
- }
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Build a container image in the Kubernetes workspace pod with the BuildKit
3
- # sidecar (#514). Uses buildctl against $BUILDKIT_HOST (tcp://127.0.0.1:1234).
4
- # On the Docker workstation, use docker build instead.
5
- set -euo pipefail
6
-
7
- refuse() {
8
- echo "devzone build: $*" >&2
9
- exit 1
10
- }
11
-
12
- if [ "${DEVZONE_WORKSPACE:-}" != "kubernetes" ]; then
13
- refuse "use docker build on the Docker workstation"
14
- fi
15
-
16
- if [ "$#" -lt 1 ]; then
17
- refuse "usage: devzone build <directory> [--tag <name>]"
18
- fi
19
-
20
- dir="$1"
21
- shift
22
- tag=""
23
-
24
- while [ "$#" -gt 0 ]; do
25
- case "$1" in
26
- --tag)
27
- [ "$#" -ge 2 ] || refuse "--tag requires a name"
28
- tag="$2"
29
- shift 2
30
- ;;
31
- *)
32
- refuse "unknown argument: $1"
33
- ;;
34
- esac
35
- done
36
-
37
- [ -d "$dir" ] || refuse "directory not found: $dir"
38
- [ -f "$dir/Dockerfile" ] || refuse "Dockerfile not found in: $dir"
39
-
40
- if [ -n "$tag" ]; then
41
- output="type=image,name=${tag},push=false"
42
- else
43
- output="type=cacheonly"
44
- fi
45
-
46
- addr="${BUILDKIT_HOST:-tcp://127.0.0.1:1234}"
47
- exec buildctl --addr "$addr" build \
48
- --frontend dockerfile.v0 \
49
- --local "context=$dir" \
50
- --local "dockerfile=$dir" \
51
- --output "$output"