devzone 7.7.0 → 7.7.2

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
- 988ed068d4e7f3845784fddb955b479f1e566f8e1872100c4ef3138324636d17 devzone-linux-amd64
2
- 525f1bb516a25c847c7e77de13655e464d9b35a9cf431ee1f5d2f43df3335a7e devzone-linux-arm64
3
- bb638ad8640ab1131d9402306d3232b8595368a649acc7a743fb7b22353acb53 devzone-darwin-amd64
4
- 820102028a8d62790240acf1f12f404976bfd389f6f196e62b738581f7c93314 devzone-darwin-arm64
5
- 6ac508ddf3f847ca6449198dcd39e0b2c053b5a9bb8f37e86c9ba100bcd2b506 devzone-windows-amd64.exe
6
- 719332e9472633e2f70b1c66970247f73080888bced4f892048efa208eca76a2 devzone-windows-arm64.exe
1
+ 3e13b6e7151158b9cf45e7afa5b8b21e9c6db13d33a11661f8344de5030d8c9e devzone-linux-amd64
2
+ 7659bfe6ff140baaefe5f0508de398204762854eb46fa01382f20e2a9533120d devzone-linux-arm64
3
+ f2145f59ce7b2373384ac3c641ce5db1988693a44b0426511fec430f534b29c2 devzone-darwin-amd64
4
+ 4d4ed6287a2cabe792b1bf3906254427d80db1bc68bc4b4df8701afea71ca4f6 devzone-darwin-arm64
5
+ 8713509ad49fea935bd3890773382ba53ca64612c210d35d9e8304ba02df13d6 devzone-windows-amd64.exe
6
+ d6b60c60ac1562bc965cc6ed9aaa50799bd55a90b2f3c5cb2730f2890e65cb69 devzone-windows-arm64.exe
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/manage/devzone CHANGED
@@ -218,7 +218,9 @@ case "${1:-}" in
218
218
  "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" uninstall "${@:2}"
219
219
  ;;
220
220
  workspace)
221
- bash "$PAQUET/manage/workspace.sh" "${@:2}"
221
+ # The workspace is Go since #934: the bash entry point only forwards to
222
+ # the Go program, as update and uninstall do, so no logic stays here.
223
+ "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace "${@:2}"
222
224
  ;;
223
225
  -*)
224
226
  echo "✖ option inconnue : $1 (devzone --help)" >&2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "7.7.0",
3
+ "version": "7.7.2",
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": {
@@ -31,7 +31,6 @@
31
31
  "manage/scripts/",
32
32
  "README.md",
33
33
  "LICENSE",
34
- "manage/workspace.sh",
35
34
  "charts/"
36
35
  ]
37
36
  }
@@ -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"
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Workstation commands for the Kubernetes workspace (#398, #399): drives the
3
- # charts/devzone-workspace chart with host helm and kubectl.
4
- set -euo pipefail
5
-
6
- HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
- ROOT="$(cd "$HERE/.." && pwd)"
8
- # shellcheck disable=SC2034 # read by the argocd scripts and by .devcontainer/argocd/services.sh (shared with the pod)
9
- RACINE="$ROOT"
10
- # Pod, namespace and projects folder inside the container (#399).
11
- # shellcheck disable=SC2034 # read by the scripts sourced from scripts/workspace/
12
- POD="devzone-workspace-0"
13
- # shellcheck disable=SC2034 # read by the scripts sourced from scripts/workspace/
14
- NAMESPACE="devzone-workspace"
15
- PROJECTS_DIR="/workspaces/projets"
16
- # compatibility alias, removed with lot 4 (#509)
17
- # shellcheck disable=SC2034
18
- DOSSIER_PROJETS="$PROJECTS_DIR"
19
-
20
- # Helm flag: devzone context if it exists, otherwise current context (no flag).
21
- helm_flag() {
22
- if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
23
- printf -- '--kube-context devzone'
24
- fi
25
- }
26
-
27
- # kubectl flag: devzone context if it exists, otherwise current context (no flag).
28
- kubectl_flag() {
29
- if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
30
- printf -- '--context devzone'
31
- fi
32
- }
33
-
34
- # Chart path in the repository (or installed package).
35
- chart_path() { printf '%s/charts/devzone-workspace' "$ROOT"; }
36
-
37
- # Repository of the image published at each devzone release.
38
- IMAGE_REPO="ghcr.io/simbienvenuehoulboumi/devzone-workspace"
39
-
40
- # Why: without tag, the chart takes its appVersion (0.1.0), an image never
41
- # published; the package version is published at each release, and a
42
- # development clone (0.0.0) uses latest.
43
- default_image_tag() {
44
- local version
45
- version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$ROOT/package.json" | head -1)"
46
- if [ -z "$version" ] || [ "$version" = "0.0.0" ]; then
47
- echo "latest"
48
- else
49
- echo "$version"
50
- fi
51
- }
52
-
53
- # Installs or upgrades the workspace in the cluster; the cluster is checked first (#565): no Argo CD, helm or pod wait for a stopped one.
54
- start_workspace() {
55
- local repo tag image with_image="" args=()
56
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" kube-ready --hint >&2 || return 1
57
- repo="$IMAGE_REPO"
58
- tag="$(default_image_tag)"
59
- while [ $# -gt 0 ]; do
60
- case "$1" in
61
- --image)
62
- if [ $# -lt 2 ] || [ -z "$2" ]; then
63
- echo "✖ option --image: provide an image <repository:tag> (devzone workspace start --image <repository:tag>)" >&2
64
- return 1
65
- fi
66
- case "$2" in
67
- *:*)
68
- repo="${2%:*}"
69
- tag="${2##*:}"
70
- with_image=yes
71
- ;;
72
- *)
73
- echo "✖ option --image: image has no tag, expected <repository:tag> (devzone workspace start --image <repository:tag>)" >&2
74
- return 1
75
- ;;
76
- esac
77
- shift 2
78
- ;;
79
- *)
80
- echo "✖ unknown option: $1 (devzone workspace start [--image <repository:tag>])" >&2
81
- return 1
82
- ;;
83
- esac
84
- done
85
- image="$repo:$tag"
86
- # Argo CD first when wanted (#516): the workspace is then an Application
87
- if [ "$(grep '^argocd=' .devzone.modules 2>/dev/null | tail -1 | cut -d= -f2-)" != off ]; then
88
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace services enable argocd || echo "⚠ Argo CD not installed: the workspace is deployed with helm directly (devzone workspace services enable argocd to retry)" >&2
89
- fi
90
- rc=0
91
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace deploy "$repo" "$tag" "$with_image" || rc=$?
92
- if [ "$rc" -eq 3 ]; then
93
- workspace_helm_deploy "$repo" "$tag" "$with_image"
94
- elif [ "$rc" -ne 0 ]; then
95
- return "$rc"
96
- fi
97
- # Projects of .argocd.conf held too (#516)
98
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd reconcile || true
99
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace wait "$image" || return 1
100
- "${DEVZONE_HOST_BIN:-false}" workspace agents-guard || true
101
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports start
102
- }
103
-
104
- # helm direct: the chart of the package, image set by the options
105
- workspace_helm_deploy() {
106
- local repo="$1" tag="$2" with_image="$3" args=()
107
- args=(--namespace devzone-workspace --create-namespace)
108
- [ -z "$with_image" ] || args+=(--set "image.repository=$repo")
109
- args+=(--set "image.tag=$tag")
110
- # latest moves at every release: an image already on the node would stay
111
- # the old one with IfNotPresent (#515)
112
- [ "$tag" != latest ] || args+=(--set "image.pullPolicy=Always")
113
- # egress proxy settings (#633), replayed at each start: commas escaped for helm
114
- for p in $("${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace egress params | sed 's/,/\\,/g'); do args+=(--set "$p"); done
115
- # shellcheck disable=SC2046
116
- helm $(helm_flag) upgrade --install devzone-workspace "$(chart_path)" "${args[@]}"
117
- }
118
-
119
- # Uninstalls the workspace from the cluster (Argo CD Application or helm release).
120
- stop_workspace() {
121
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports stop || true
122
- "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace stop
123
- }
124
-
125
- # Opens a shell in the workspace container.
126
- shell_workspace() {
127
- # shellcheck disable=SC2046
128
- kubectl $(kubectl_flag) exec -it devzone-workspace-0 --namespace devzone-workspace -c workspace -- bash
129
- }
130
-
131
-
132
- case "${1:-}" in
133
- start) start_workspace "${@:2}" ;;
134
- update) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace update "${@:2}" ;;
135
- stop) stop_workspace ;;
136
- status) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace status ;;
137
- shell) shell_workspace ;;
138
- ports) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace ports "${@:2}" ;;
139
- services) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace services "${@:2}" ;;
140
- argocd)
141
- sub="${2:-status}"
142
- case "$sub" in
143
- status) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd status ;;
144
- init) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd init "${@:3}" ;;
145
- apply) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd apply ;;
146
- app) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace argocd app "${@:3}" ;;
147
- *)
148
- echo "✖ devzone workspace argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>" >&2
149
- exit 1
150
- ;;
151
- esac
152
- ;;
153
- egress) "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" workspace egress "${@:2}" ;;
154
- '' | -h | --help | help)
155
- echo "devzone workspace start|stop|status|shell|ports|services|argocd|update|egress"
156
- echo " start [--image repository:tag] install workspace (image for devzone version by default)"
157
- echo " update [--version X.Y.Z] [--yes] move to the latest stable release (or X.Y.Z); the pod is recreated"
158
- echo " ports [start|stop|status] applications and services from pod on workstation localhost"
159
- echo " services enable|disable <service> [options] | status"
160
- echo " devzone services (gitlab, postgres, argocd) of the cluster, installed from the workstation"
161
- echo " argocd status | init [--repo <url>|--none] | apply | app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>"
162
- echo " Argo CD of the workspace: .argocd.conf, GitOps repository, your projects as Applications"
163
- echo " egress observation|strict|off|status|allow <domain>|deny <domain> egress proxy of the agent sessions (--pod)"
164
- ;;
165
- *)
166
- echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|ports|services|argocd|update)" >&2
167
- exit 1
168
- ;;
169
- esac