devzone 7.5.5 → 7.6.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.
- package/.devcontainer/devzone +1 -60
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/manage/devzone +7 -16
- package/package.json +1 -1
- package/.devcontainer/argocd/application.sh +0 -69
- package/.devcontainer/argocd/conf.sh +0 -141
- package/.devcontainer/argocd/gitops.sh +0 -247
- package/.devcontainer/devzone-modules.sh +0 -125
- package/.devcontainer/devzone-platform.sh +0 -189
- package/.devcontainer/devzone-services.sh +0 -242
- package/manage/scripts/uninstall.sh +0 -234
package/.devcontainer/devzone
CHANGED
|
@@ -55,14 +55,6 @@ export DEVZONE_STATE="$ETAT"
|
|
|
55
55
|
MODULES=(ai kubernetes gitlab postgres argocd mysql)
|
|
56
56
|
INSTANCE_SUFFIX=""
|
|
57
57
|
[ "${DEVZONE_INSTANCE:-devzone}" = devzone ] || INSTANCE_SUFFIX="-${DEVZONE_INSTANCE}"
|
|
58
|
-
# .argocd.conf of the instance: the GitOps repository designation (#539)
|
|
59
|
-
# shellcheck source=SCRIPTDIR/argocd/conf.sh
|
|
60
|
-
# shellcheck disable=SC1091
|
|
61
|
-
# shellcheck disable=SC2034 # read by conf.sh
|
|
62
|
-
if [ -f "$ICI/argocd/conf.sh" ]; then
|
|
63
|
-
ARGOCD_CONF="$RACINE/.argocd.conf"
|
|
64
|
-
. "$ICI/argocd/conf.sh"
|
|
65
|
-
fi
|
|
66
58
|
# GitOps repository line in the Kubernetes workspace pod (#639)
|
|
67
59
|
# Host models and assistants are handled by the Go command of the pod (#882).
|
|
68
60
|
|
|
@@ -77,29 +69,7 @@ IA_OPENCODE=opencode-ai@1.19.6
|
|
|
77
69
|
IA_PAQUETS=("$IA_CLAUDE" "$IA_OPENCODE")
|
|
78
70
|
IA_NOMS=("${IA_CLAUDE%@*}" "${IA_OPENCODE%@*}")
|
|
79
71
|
|
|
80
|
-
# glab (GitLab CLI), installed only when the gitlab platform is chosen: binary
|
|
81
|
-
# of the official release (gitlab.com/gitlab-org/cli) in ~/.local/bin, SHA-256
|
|
82
|
-
# sum of its archive checked; removed when going back to github. All its calls
|
|
83
|
-
# go through this path (never PATH: ~/.local/bin is not necessarily in it); the
|
|
84
|
-
# state and the login too.
|
|
85
|
-
GLAB="$HOME/.local/bin/glab"
|
|
86
|
-
GLAB_VERSION=v1.126.0
|
|
87
|
-
GLAB_SOMME_ARM64=de5e92c9c8b306eeebb19daa854d48101b78328850e7b9cd677ecd6f98cd4391
|
|
88
|
-
GLAB_SOMME_AMD64=f386519ba83e9482979992ee7f60eeebee4d95b950f95f4fe7289e0a1b1ea74c
|
|
89
|
-
# gitlab module instance: its default URL and the root token of its seed
|
|
90
|
-
GITLAB_URL_MODULE=http://gitlab.localhost:8929
|
|
91
72
|
|
|
92
|
-
# Functions of devzone, by topic (sourced here, defined before any command runs)
|
|
93
|
-
# shellcheck source=SCRIPTDIR/devzone-modules.sh
|
|
94
|
-
# shellcheck disable=SC1091
|
|
95
|
-
. "$ICI/devzone-modules.sh"
|
|
96
|
-
# The AI module and its guard are handled by the Go command of the pod (#882).
|
|
97
|
-
# shellcheck source=SCRIPTDIR/devzone-services.sh
|
|
98
|
-
# shellcheck disable=SC1091
|
|
99
|
-
. "$ICI/devzone-services.sh"
|
|
100
|
-
# shellcheck source=SCRIPTDIR/devzone-platform.sh
|
|
101
|
-
# shellcheck disable=SC1091
|
|
102
|
-
. "$ICI/devzone-platform.sh"
|
|
103
73
|
|
|
104
74
|
case "${1:-}" in
|
|
105
75
|
"" | status | modules)
|
|
@@ -128,34 +98,12 @@ case "${1:-}" in
|
|
|
128
98
|
exit 127
|
|
129
99
|
fi
|
|
130
100
|
;;
|
|
131
|
-
enable) change_module on "${2:-}" "${@:3}" ;;
|
|
132
|
-
disable) change_module off "${2:-}" "${@:3}" ;;
|
|
133
|
-
apply)
|
|
134
|
-
migrate_llm
|
|
135
|
-
# The user confirms the current state (#417, step 4): the watchers
|
|
136
|
-
# may uninstall again
|
|
137
|
-
DEVZONE_STATE="$ETAT" bash "$ICI/devzone" state recovery-confirm
|
|
138
|
-
"${DEVZONE_HOST_BIN:?devzone: Go pod binary unavailable}" apply-repowarden
|
|
139
|
-
[ "$(value_of ai)" = off ] || DEVZONE_STATE="$ETAT" "$ICI/devzone" ai apply on
|
|
140
|
-
# gitlab, postgres, argocd: installed from the workstation in the
|
|
141
|
-
# Kubernetes workspace pod (#528), by their installer elsewhere
|
|
142
|
-
[ "$(value_of gitlab)" = off ] || apply_service gitlab
|
|
143
|
-
[ "$(value_of postgres)" = off ] || apply_service postgres
|
|
144
|
-
[ "$(value_of mysql)" = off ] || apply_mysql on
|
|
145
|
-
[ "$(value_of argocd)" = off ] || apply_service argocd
|
|
146
|
-
;;
|
|
147
|
-
is-enabled)
|
|
148
|
-
is_known "${2:-}" || { echo "devzone : unknown module : ${2:-(none)}" >&2; exit 2; }
|
|
149
|
-
# Silent test: code 0 if the module is active, 1 otherwise, without
|
|
150
|
-
# writing anything
|
|
151
|
-
[ "$(value_of "$2")" = on ]
|
|
152
|
-
;;
|
|
153
101
|
build)
|
|
154
102
|
bash "$ICI/workspace-build.sh" "${@:2}"
|
|
155
103
|
;;
|
|
156
104
|
# Go only: reached when the binary did not take the call. Never call
|
|
157
105
|
# "devzone" again from here, it would loop forever, see #864
|
|
158
|
-
-h | --help | help | repair | apply-repowarden | cluster | clusters | metrics | use | kube | ai | agent | postgres | mysql | gitlab | test-gitlab | catalog | catalog-watcher)
|
|
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)
|
|
159
107
|
echo "devzone $1: Go binary of the pod unavailable (.devcontainer/bin)" >&2
|
|
160
108
|
exit 1
|
|
161
109
|
;;
|
|
@@ -176,13 +124,6 @@ case "${1:-}" in
|
|
|
176
124
|
exit 1
|
|
177
125
|
;;
|
|
178
126
|
test-bash32) bash "$RACINE/manage/test/bash32.sh" ;;
|
|
179
|
-
platform)
|
|
180
|
-
if [ -n "${2:-}" ]; then
|
|
181
|
-
change_platform "${@:2}"
|
|
182
|
-
else
|
|
183
|
-
platform_summary
|
|
184
|
-
fi
|
|
185
|
-
;;
|
|
186
127
|
*)
|
|
187
128
|
echo "devzone : unknown command : $1 (devzone --help)" >&2
|
|
188
129
|
exit 1
|
package/bin/SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
package/bin/devzone-darwin-amd64
CHANGED
|
Binary file
|
package/bin/devzone-darwin-arm64
CHANGED
|
Binary file
|
package/bin/devzone-linux-amd64
CHANGED
|
Binary file
|
package/bin/devzone-linux-arm64
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/manage/devzone
CHANGED
|
@@ -171,9 +171,10 @@ devzone $(version): development workspace in a Kubernetes cluster
|
|
|
171
171
|
the installed package, after backing up the replaced files in
|
|
172
172
|
.devzone.backup/ (the new image is used at the next workspace start)
|
|
173
173
|
devzone uninstall [--yes]
|
|
174
|
-
in a devzone folder: removes
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
in a devzone folder: removes what this devzone instance created on
|
|
175
|
+
the host (containers, images, volumes, kind clusters, metrics-server)
|
|
176
|
+
and in the cluster (namespaces, Argo CD Applications, temporary
|
|
177
|
+
accounts); workspace/ is kept; asks for confirmation
|
|
177
178
|
devzone ai [check|rapport|guard] host models, update report or tool-call guard
|
|
178
179
|
devzone workspace start|stop|status|shell|update|deploy
|
|
179
180
|
devzone workspace vscode|copy-to|copy-from|clone
|
|
@@ -212,19 +213,9 @@ case "${1:-}" in
|
|
|
212
213
|
DEVZONE_BASH_ENTRY="$PAQUET/manage/devzone" "${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" update "${@:2}"
|
|
213
214
|
;;
|
|
214
215
|
uninstall)
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
|
|
218
|
-
if [ -d .devcontainer ]; then
|
|
219
|
-
for f in manage/scripts/uninstall.sh core/scripts/uninstall.sh scripts/uninstall.sh uninstall.sh; do
|
|
220
|
-
if [ -f "$f" ]; then uninstaller="$f" && break; fi
|
|
221
|
-
done
|
|
222
|
-
fi
|
|
223
|
-
if [ -z "$uninstaller" ]; then
|
|
224
|
-
echo "✖ Run this in a devzone folder (uninstall.sh not found here)." >&2
|
|
225
|
-
exit 1
|
|
226
|
-
fi
|
|
227
|
-
DEVZONE_COMMAND="devzone uninstall" bash "$uninstaller"
|
|
216
|
+
# The uninstall is the Go program's (#884), as update is: an older devzone
|
|
217
|
+
# keeps its own uninstall.sh, which the Go command runs from its folder
|
|
218
|
+
"${DEVZONE_HOST_BIN:?devzone: Go program not found (DEVZONE_HOST_BIN), run it through manage/devzone}" uninstall "${@:2}"
|
|
228
219
|
;;
|
|
229
220
|
workspace)
|
|
230
221
|
bash "$PAQUET/manage/workspace.sh" "${@:2}"
|
package/package.json
CHANGED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Argo CD Application manifest of devzone (#516), printed on stdout:
|
|
3
|
-
# application.sh <name> <kind> <destination namespace> <repo url> <revision> <path> [key=value ...]
|
|
4
|
-
# kind: workspace | service | project | root (label devzone.io/kind). Each key=value
|
|
5
|
-
# is a Helm parameter of the source. Automated sync with prune and selfHeal,
|
|
6
|
-
# the destination namespace created, the resources deleted with the
|
|
7
|
-
# Application (finalizer). The Application lives in devzone-argocd.
|
|
8
|
-
# bash 3.2 (macOS): used by the workstation and by the container.
|
|
9
|
-
set -euo pipefail
|
|
10
|
-
|
|
11
|
-
usage() {
|
|
12
|
-
echo "usage: application.sh <name> <kind> <destination namespace> <repo url> <revision> <path> [key=value ...]" >&2
|
|
13
|
-
exit 2
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
[ "$#" -ge 6 ] || usage
|
|
17
|
-
name="$1" kind="$2" namespace="$3" repo="$4" revision="$5" path="$6"
|
|
18
|
-
shift 6
|
|
19
|
-
case "$kind" in
|
|
20
|
-
workspace | service | project | root) ;;
|
|
21
|
-
*) echo "application.sh: unknown kind: $kind (workspace, service, project, root)" >&2; exit 2 ;;
|
|
22
|
-
esac
|
|
23
|
-
case "$name" in
|
|
24
|
-
'' | *[!a-z0-9-]* | -*) echo "application.sh: invalid name: ${name:-(none)} (lowercase letters, digits, dashes)" >&2; exit 2 ;;
|
|
25
|
-
esac
|
|
26
|
-
if [ -z "$namespace" ] || [ -z "$repo" ] || [ -z "$revision" ] || [ -z "$path" ]; then
|
|
27
|
-
usage
|
|
28
|
-
fi
|
|
29
|
-
|
|
30
|
-
cat <<EOF
|
|
31
|
-
apiVersion: argoproj.io/v1alpha1
|
|
32
|
-
kind: Application
|
|
33
|
-
metadata:
|
|
34
|
-
name: $name
|
|
35
|
-
namespace: devzone-argocd
|
|
36
|
-
labels:
|
|
37
|
-
app.kubernetes.io/managed-by: devzone
|
|
38
|
-
devzone.io/kind: $kind
|
|
39
|
-
finalizers:
|
|
40
|
-
- resources-finalizer.argocd.argoproj.io
|
|
41
|
-
spec:
|
|
42
|
-
project: default
|
|
43
|
-
source:
|
|
44
|
-
repoURL: $repo
|
|
45
|
-
targetRevision: $revision
|
|
46
|
-
path: $path
|
|
47
|
-
EOF
|
|
48
|
-
if [ "$#" -gt 0 ]; then
|
|
49
|
-
echo " helm:"
|
|
50
|
-
echo " parameters:"
|
|
51
|
-
for kv in "$@"; do
|
|
52
|
-
case "$kv" in
|
|
53
|
-
*=*) ;;
|
|
54
|
-
*) echo "application.sh: Helm parameter without value: $kv" >&2; exit 2 ;;
|
|
55
|
-
esac
|
|
56
|
-
printf ' - name: %s\n value: "%s"\n' "${kv%%=*}" "${kv#*=}"
|
|
57
|
-
done
|
|
58
|
-
fi
|
|
59
|
-
cat <<EOF
|
|
60
|
-
destination:
|
|
61
|
-
server: https://kubernetes.default.svc
|
|
62
|
-
namespace: $namespace
|
|
63
|
-
syncPolicy:
|
|
64
|
-
automated:
|
|
65
|
-
prune: true
|
|
66
|
-
selfHeal: true
|
|
67
|
-
syncOptions:
|
|
68
|
-
- CreateNamespace=true
|
|
69
|
-
EOF
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Configuration file of the Argo CD of devzone (#516): .argocd.conf at the
|
|
3
|
-
# root of the devzone folder, the same shape as .repowarden.conf:
|
|
4
|
-
# [argocd]
|
|
5
|
-
# repo = https://github.com/<login>/devzone-argocd.git # none: direct apply
|
|
6
|
-
# [app demo]
|
|
7
|
-
# repo = https://github.com/argoproj/argocd-example-apps
|
|
8
|
-
# path = guestbook
|
|
9
|
-
# revision = HEAD
|
|
10
|
-
# namespace = devzone-app-demo
|
|
11
|
-
# username = root # private repositories
|
|
12
|
-
# token-file = workspace/.gitlab/root-token
|
|
13
|
-
# The file is the declaration, versioned with the devzone folder: devzone
|
|
14
|
-
# writes it (argocd init, app add, app remove) and applies it (workspace
|
|
15
|
-
# start, argocd apply). Tokens never go in it, only paths to them. The
|
|
16
|
-
# includer defines ARGOCD_CONF (the path of the file).
|
|
17
|
-
# conf_get <section> <key> value, empty when absent
|
|
18
|
-
# conf_sections <prefix> names of the sections "[<prefix> <name>]"
|
|
19
|
-
# conf_set <section> key=value... section replaced (or added at the end)
|
|
20
|
-
# conf_remove <section>
|
|
21
|
-
# bash 3.2 (macOS): no associative array, one pass per call.
|
|
22
|
-
|
|
23
|
-
conf_trim() {
|
|
24
|
-
local s="$1"
|
|
25
|
-
s="${s#"${s%%[![:space:]]*}"}"
|
|
26
|
-
s="${s%"${s##*[![:space:]]}"}"
|
|
27
|
-
printf '%s' "$s"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
# Section name of a "[...]" line, trimmed
|
|
31
|
-
conf_section_of() {
|
|
32
|
-
local s="$1"
|
|
33
|
-
s="${s#\[}"
|
|
34
|
-
s="${s%\]}"
|
|
35
|
-
conf_trim "$s"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# Lines of the file as "section<TAB>key<TAB>value"; comments and blanks dropped
|
|
39
|
-
conf_entries() {
|
|
40
|
-
local line section="" key value
|
|
41
|
-
[ -f "$ARGOCD_CONF" ] || return 0
|
|
42
|
-
while IFS= read -r line || [ -n "$line" ]; do
|
|
43
|
-
line="$(conf_trim "$line")"
|
|
44
|
-
case "$line" in
|
|
45
|
-
'' | '#'*) continue ;;
|
|
46
|
-
'['*']') section="$(conf_section_of "$line")"; continue ;;
|
|
47
|
-
esac
|
|
48
|
-
case "$line" in *=*) ;; *) continue ;; esac
|
|
49
|
-
key="$(conf_trim "${line%%=*}")"
|
|
50
|
-
value="${line#*=}"
|
|
51
|
-
value="${value%%#*}"
|
|
52
|
-
value="$(conf_trim "$value")"
|
|
53
|
-
printf '%s\t%s\t%s\n' "$section" "$key" "$value"
|
|
54
|
-
done <"$ARGOCD_CONF"
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
conf_get() {
|
|
58
|
-
local s k v
|
|
59
|
-
while IFS="$(printf '\t')" read -r s k v; do
|
|
60
|
-
if [ "$s" = "$1" ] && [ "$k" = "$2" ]; then
|
|
61
|
-
printf '%s' "$v"
|
|
62
|
-
return 0
|
|
63
|
-
fi
|
|
64
|
-
done <<<"$(conf_entries)"
|
|
65
|
-
return 0
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
conf_sections() {
|
|
69
|
-
local line t n
|
|
70
|
-
[ -f "$ARGOCD_CONF" ] || return 0
|
|
71
|
-
while IFS= read -r line || [ -n "$line" ]; do
|
|
72
|
-
t="$(conf_trim "$line")"
|
|
73
|
-
case "$t" in
|
|
74
|
-
'['*']')
|
|
75
|
-
n="$(conf_section_of "$t")"
|
|
76
|
-
case "$n" in
|
|
77
|
-
"$1 "*)
|
|
78
|
-
n="$(conf_trim "${n#"$1"}")"
|
|
79
|
-
[ -z "$n" ] || printf '%s\n' "$n"
|
|
80
|
-
;;
|
|
81
|
-
esac
|
|
82
|
-
;;
|
|
83
|
-
esac
|
|
84
|
-
done <"$ARGOCD_CONF"
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
# The file without the section $1 (its header and its keys)
|
|
88
|
-
conf_without() {
|
|
89
|
-
local line t skip=0
|
|
90
|
-
[ -f "$ARGOCD_CONF" ] || return 0
|
|
91
|
-
while IFS= read -r line || [ -n "$line" ]; do
|
|
92
|
-
t="$(conf_trim "$line")"
|
|
93
|
-
case "$t" in
|
|
94
|
-
'['*']')
|
|
95
|
-
if [ "$(conf_section_of "$t")" = "$1" ]; then skip=1; continue; fi
|
|
96
|
-
skip=0
|
|
97
|
-
;;
|
|
98
|
-
esac
|
|
99
|
-
[ "$skip" = 1 ] && continue
|
|
100
|
-
printf '%s\n' "$line"
|
|
101
|
-
done <"$ARGOCD_CONF"
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
conf_header() {
|
|
105
|
-
cat <<'EOF'
|
|
106
|
-
# Argo CD of devzone (#516): what devzone declares in its GitOps repository.
|
|
107
|
-
# Written by devzone (argocd init, app add, app remove), applied by
|
|
108
|
-
# devzone workspace argocd apply and by workspace start. Tokens never go
|
|
109
|
-
# here, only paths to them (token-file).
|
|
110
|
-
EOF
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
# Section $1 replaced by the key=value pairs that follow (added at the end
|
|
114
|
-
# when absent); blank lines squeezed
|
|
115
|
-
conf_set() {
|
|
116
|
-
local section="$1" tmp kv
|
|
117
|
-
shift
|
|
118
|
-
tmp="$(mktemp)"
|
|
119
|
-
if [ -f "$ARGOCD_CONF" ]; then
|
|
120
|
-
conf_without "$section" >"$tmp"
|
|
121
|
-
else
|
|
122
|
-
conf_header >"$tmp"
|
|
123
|
-
fi
|
|
124
|
-
{
|
|
125
|
-
echo
|
|
126
|
-
echo "[$section]"
|
|
127
|
-
for kv in "$@"; do
|
|
128
|
-
printf ' %s = %s\n' "${kv%%=*}" "${kv#*=}"
|
|
129
|
-
done
|
|
130
|
-
} >>"$tmp"
|
|
131
|
-
cat -s "$tmp" >"$ARGOCD_CONF"
|
|
132
|
-
rm -f "$tmp"
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
conf_remove() {
|
|
136
|
-
local tmp
|
|
137
|
-
[ -f "$ARGOCD_CONF" ] || return 0
|
|
138
|
-
tmp="$(mktemp)"
|
|
139
|
-
conf_without "$1" | cat -s >"$tmp"
|
|
140
|
-
mv "$tmp" "$ARGOCD_CONF"
|
|
141
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# GitOps repository of the user for the Argo CD of devzone (#516):
|
|
3
|
-
# <login>/devzone-argocd on GitHub, private, written through the GitHub API
|
|
4
|
-
# (gh: no clone, no local commit). A root Application "devzone" follows its
|
|
5
|
-
# apps/ folder: every Application devzone declares (workspace, services,
|
|
6
|
-
# projects) is a file apps/<name>.yaml there, so the cluster is rebuilt from
|
|
7
|
-
# Git. Without a repository (gh not logged in, or argocd_repo=none in the
|
|
8
|
-
# state), the Applications are applied directly, as before.
|
|
9
|
-
# gitops_init [--repo <url>] [--none] creates or designates the repository
|
|
10
|
-
# gitops_enabled a repository is designated
|
|
11
|
-
# gitops_root repository Secret and root Application
|
|
12
|
-
# gitops_apply_application <generator args> file in Git (or direct apply)
|
|
13
|
-
# gitops_delete_application <name> [keep] file removed and Application deleted
|
|
14
|
-
# gitops_direct_delete_application <name> [keep] cluster only, the file stays
|
|
15
|
-
# The includer defines argocd_kubectl, APPS_GENERATOR, GITOPS_CMD (how init
|
|
16
|
-
# is spelled there) and ARGOCD_CONF (conf.sh): the repository is the key repo
|
|
17
|
-
# of the section [argocd] of .argocd.conf.
|
|
18
|
-
# Argo CD reads the repository with the gh token of the user
|
|
19
|
-
# (DEVZONE_GITOPS_TOKEN for another one). GitLab as the GitOps repository:
|
|
20
|
-
# lot B. bash 3.2 (macOS).
|
|
21
|
-
|
|
22
|
-
GITOPS_NS="devzone-argocd"
|
|
23
|
-
GITOPS_ROOT_APP="devzone"
|
|
24
|
-
GITOPS_REPO_NAME="${DEVZONE_GITOPS_REPO_NAME:-devzone-argocd}"
|
|
25
|
-
: "${GITOPS_CMD:=devzone argocd init}"
|
|
26
|
-
# shellcheck source=SCRIPTDIR/gitops-gitlab.sh
|
|
27
|
-
# shellcheck disable=SC1091
|
|
28
|
-
. "$(dirname "${BASH_SOURCE[0]}")/gitops-gitlab.sh"
|
|
29
|
-
|
|
30
|
-
gitops_repo() { conf_get argocd repo; }
|
|
31
|
-
gitops_repo_note() { conf_set argocd "repo=$1"; }
|
|
32
|
-
# GitLab designated (provider = gitlab, #559): the files go through its API
|
|
33
|
-
gitops_is_gitlab() { [ "$(conf_get argocd provider)" = gitlab ]; }
|
|
34
|
-
|
|
35
|
-
gitops_enabled() {
|
|
36
|
-
local r
|
|
37
|
-
r="$(gitops_repo)"
|
|
38
|
-
[ -n "$r" ] && [ "$r" != none ]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# owner/name of the GitHub repository
|
|
42
|
-
gitops_slug() {
|
|
43
|
-
local r
|
|
44
|
-
r="$(gitops_repo)"
|
|
45
|
-
r="${r#https://github.com/}"
|
|
46
|
-
printf '%s' "${r%.git}"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# Creates <login>/devzone-argocd when missing (private) and notes its URL;
|
|
50
|
-
# --repo: an existing GitHub repository; --none: no GitOps repository,
|
|
51
|
-
# Applications applied directly. Without gh logged in: a notice, state kept
|
|
52
|
-
gitops_init() {
|
|
53
|
-
local repo="" expect="" arg login slug
|
|
54
|
-
for arg in "$@"; do
|
|
55
|
-
if [ "$expect" = repo ]; then repo="$arg"; expect=""; continue; fi
|
|
56
|
-
case "$arg" in
|
|
57
|
-
--gitlab) gitlab_gitops_init; return ;;
|
|
58
|
-
--none)
|
|
59
|
-
gitops_repo_note none
|
|
60
|
-
echo "✔ no GitOps repository: the Applications are applied directly ($GITOPS_CMD to change)"
|
|
61
|
-
return 0
|
|
62
|
-
;;
|
|
63
|
-
--repo) expect=repo ;;
|
|
64
|
-
*) echo "✖ $GITOPS_CMD [--repo https://github.com/<owner>/<name>.git] [--none]" >&2; return 2 ;;
|
|
65
|
-
esac
|
|
66
|
-
done
|
|
67
|
-
if [ -n "$expect" ]; then
|
|
68
|
-
echo "✖ --repo needs a URL" >&2
|
|
69
|
-
return 2
|
|
70
|
-
fi
|
|
71
|
-
if [ -n "$repo" ]; then
|
|
72
|
-
case "$repo" in
|
|
73
|
-
https://github.com/*/*) ;;
|
|
74
|
-
*) echo "✖ GitHub repository URL expected (https://github.com/<owner>/<name>.git): $repo" >&2; return 2 ;;
|
|
75
|
-
esac
|
|
76
|
-
slug="${repo#https://github.com/}"
|
|
77
|
-
slug="${slug%.git}"
|
|
78
|
-
if gh auth status >/dev/null 2>&1 && ! gh repo view "$slug" --json name >/dev/null 2>&1; then
|
|
79
|
-
# The designated GitHub repository does not exist yet: create it,
|
|
80
|
-
# then write the files of a creation
|
|
81
|
-
if ! gh repo create "$slug" --private --description "GitOps repository of devzone: the Applications Argo CD holds (workspace, services, projects)" >/dev/null; then
|
|
82
|
-
echo "✖ cannot create the GitOps repository $slug" >&2
|
|
83
|
-
return 1
|
|
84
|
-
fi
|
|
85
|
-
echo "✔ GitOps repository created: https://github.com/$slug (private)"
|
|
86
|
-
gitops_repo_note "$repo"
|
|
87
|
-
gitops_put_text README.md "# devzone-argocd
|
|
88
|
-
|
|
89
|
-
GitOps repository of devzone, written by the devzone commands (never by hand): the Argo CD of devzone follows the apps/ folder, one Application per file (the workspace, the services, the projects added with argocd app add). Removing a file removes the Application and its resources.
|
|
90
|
-
" "devzone: GitOps repository"
|
|
91
|
-
gitops_put_text apps/.gitkeep "" "devzone: apps folder"
|
|
92
|
-
return 0
|
|
93
|
-
fi
|
|
94
|
-
gitops_repo_note "$repo"
|
|
95
|
-
echo "✔ GitOps repository: $repo ($ARGOCD_CONF)"
|
|
96
|
-
return 0
|
|
97
|
-
fi
|
|
98
|
-
if gitops_enabled; then
|
|
99
|
-
return 0
|
|
100
|
-
fi
|
|
101
|
-
if ! gh auth status >/dev/null 2>&1; then
|
|
102
|
-
echo "ℹ GitHub not connected (gh auth login): no GitOps repository, the Applications are applied directly; $GITOPS_CMD --none to stop this notice"
|
|
103
|
-
return 0
|
|
104
|
-
fi
|
|
105
|
-
login="$(gh api user --jq .login 2>/dev/null)" || login=""
|
|
106
|
-
if [ -z "$login" ]; then
|
|
107
|
-
echo "⚠ GitHub login unreadable (gh api user): Applications applied directly" >&2
|
|
108
|
-
return 0
|
|
109
|
-
fi
|
|
110
|
-
slug="$login/$GITOPS_REPO_NAME"
|
|
111
|
-
if ! gh repo view "$slug" --json name >/dev/null 2>&1; then
|
|
112
|
-
if ! gh repo create "$slug" --private --description "GitOps repository of devzone: the Applications Argo CD holds (workspace, services, projects)" >/dev/null; then
|
|
113
|
-
echo "✖ cannot create the GitOps repository $slug" >&2
|
|
114
|
-
return 1
|
|
115
|
-
fi
|
|
116
|
-
echo "✔ GitOps repository created: https://github.com/$slug (private)"
|
|
117
|
-
fi
|
|
118
|
-
gitops_repo_note "https://github.com/$slug.git"
|
|
119
|
-
gitops_put_text README.md "# devzone-argocd
|
|
120
|
-
|
|
121
|
-
GitOps repository of devzone, written by the devzone commands (never by hand): the Argo CD of devzone follows the apps/ folder, one Application per file (the workspace, the services, the projects added with argocd app add). Removing a file removes the Application and its resources.
|
|
122
|
-
" "devzone: GitOps repository"
|
|
123
|
-
gitops_put_text apps/.gitkeep "" "devzone: apps folder"
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
# Blob sha of a file (git), to skip a write that changes nothing
|
|
127
|
-
gitops_blob() { git hash-object "$1" 2>/dev/null || true; }
|
|
128
|
-
|
|
129
|
-
gitops_sha() {
|
|
130
|
-
local out
|
|
131
|
-
if gitops_is_gitlab; then gitlab_gitops_sha "$@"; return; fi
|
|
132
|
-
# A missing file answers 404 with its error body on stdout: never taken
|
|
133
|
-
# for a sha, or a removal would DELETE what is not there (#625)
|
|
134
|
-
out="$(gh api "repos/$(gitops_slug)/contents/$1" --jq .sha 2>/dev/null)" || out=""
|
|
135
|
-
case "$out" in '' | *[!0-9a-f]*) out="" ;; esac
|
|
136
|
-
printf '%s' "$out"
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
# Writes <file> at <path> of the repository (create or update), <message>
|
|
140
|
-
gitops_put() {
|
|
141
|
-
local path="$1" file="$2" message="$3" slug sha content
|
|
142
|
-
if gitops_is_gitlab; then gitlab_gitops_put "$@"; return; fi
|
|
143
|
-
slug="$(gitops_slug)"
|
|
144
|
-
sha="$(gitops_sha "$path")"
|
|
145
|
-
if [ -n "$sha" ] && [ "$sha" = "$(gitops_blob "$file")" ]; then
|
|
146
|
-
return 0
|
|
147
|
-
fi
|
|
148
|
-
content="$(base64 <"$file" | tr -d '\n')"
|
|
149
|
-
if [ -n "$sha" ]; then
|
|
150
|
-
gh api -X PUT "repos/$slug/contents/$path" -f message="$message" -f content="$content" -f sha="$sha" >/dev/null
|
|
151
|
-
else
|
|
152
|
-
gh api -X PUT "repos/$slug/contents/$path" -f message="$message" -f content="$content" >/dev/null
|
|
153
|
-
fi
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
gitops_put_text() {
|
|
157
|
-
local tmp
|
|
158
|
-
tmp="$(mktemp)"
|
|
159
|
-
printf '%s' "$2" >"$tmp"
|
|
160
|
-
gitops_put "$1" "$tmp" "$3"
|
|
161
|
-
rm -f "$tmp"
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
gitops_delete() {
|
|
165
|
-
local path="$1" message="$2" sha
|
|
166
|
-
if gitops_is_gitlab; then gitlab_gitops_delete "$@"; return; fi
|
|
167
|
-
sha="$(gitops_sha "$path")"
|
|
168
|
-
[ -n "$sha" ] || return 0
|
|
169
|
-
gh api -X DELETE "repos/$(gitops_slug)/contents/$path" -f message="$message" -f sha="$sha" >/dev/null
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
# Repository Secret (token of gh) and root Application "devzone" on apps/
|
|
173
|
-
gitops_root() {
|
|
174
|
-
local url token user=devzone
|
|
175
|
-
gitops_enabled || return 0
|
|
176
|
-
url="$(gitops_repo)"
|
|
177
|
-
token="${DEVZONE_GITOPS_TOKEN:-$(gh auth token 2>/dev/null || true)}"
|
|
178
|
-
if gitops_is_gitlab; then user=oauth2; token="$(gitlab_gitops_root_token 2>/dev/null || true)"; fi
|
|
179
|
-
if [ -n "$token" ]; then
|
|
180
|
-
argocd_kubectl -n "$GITOPS_NS" apply -f - >/dev/null <<EOF
|
|
181
|
-
apiVersion: v1
|
|
182
|
-
kind: Secret
|
|
183
|
-
metadata:
|
|
184
|
-
name: repo-$GITOPS_REPO_NAME
|
|
185
|
-
namespace: $GITOPS_NS
|
|
186
|
-
labels:
|
|
187
|
-
argocd.argoproj.io/secret-type: repository
|
|
188
|
-
app.kubernetes.io/managed-by: devzone
|
|
189
|
-
type: Opaque
|
|
190
|
-
stringData:
|
|
191
|
-
type: git
|
|
192
|
-
url: $url
|
|
193
|
-
username: $user
|
|
194
|
-
password: $token
|
|
195
|
-
EOF
|
|
196
|
-
else
|
|
197
|
-
echo "⚠ no GitHub token for Argo CD (gh auth token): a private repository will not sync; DEVZONE_GITOPS_TOKEN=<token>" >&2
|
|
198
|
-
fi
|
|
199
|
-
bash "$APPS_GENERATOR" "$GITOPS_ROOT_APP" root "$GITOPS_NS" "$url" HEAD apps |
|
|
200
|
-
argocd_kubectl apply -f - >/dev/null
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
# Argo CD reads Git every 3 min: a refresh of the root Application right away
|
|
204
|
-
gitops_refresh() {
|
|
205
|
-
argocd_kubectl -n "$GITOPS_NS" annotate application.argoproj.io "$GITOPS_ROOT_APP" \
|
|
206
|
-
argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
gitops_apply_application() {
|
|
210
|
-
local name="$1" tmp
|
|
211
|
-
if ! gitops_enabled; then
|
|
212
|
-
bash "$APPS_GENERATOR" "$@" | argocd_kubectl apply -f - >/dev/null
|
|
213
|
-
return
|
|
214
|
-
fi
|
|
215
|
-
tmp="$(mktemp)"
|
|
216
|
-
if ! bash "$APPS_GENERATOR" "$@" >"$tmp"; then
|
|
217
|
-
rm -f "$tmp"
|
|
218
|
-
return 1
|
|
219
|
-
fi
|
|
220
|
-
if ! gitops_put "apps/$name.yaml" "$tmp" "devzone: application $name"; then
|
|
221
|
-
rm -f "$tmp"
|
|
222
|
-
return 1
|
|
223
|
-
fi
|
|
224
|
-
rm -f "$tmp"
|
|
225
|
-
gitops_refresh
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
# keep: finalizer dropped first, the resources stay
|
|
229
|
-
gitops_direct_delete_application() {
|
|
230
|
-
local name="$1" mode="${2:-cascade}"
|
|
231
|
-
if [ "$mode" = keep ]; then
|
|
232
|
-
argocd_kubectl -n "$GITOPS_NS" patch application.argoproj.io "$name" --type merge \
|
|
233
|
-
-p '{"metadata":{"finalizers":null}}' >/dev/null 2>&1 || true
|
|
234
|
-
fi
|
|
235
|
-
argocd_kubectl -n "$GITOPS_NS" delete application.argoproj.io "$name" --ignore-not-found --wait=true >/dev/null
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
# The file leaves Git first (so that the root Application never recreates
|
|
239
|
-
# the child), then the Application is deleted right away
|
|
240
|
-
gitops_delete_application() {
|
|
241
|
-
local name="$1" mode="${2:-cascade}"
|
|
242
|
-
if gitops_enabled; then
|
|
243
|
-
gitops_delete "apps/$name.yaml" "devzone: application $name removed" || return 1
|
|
244
|
-
gitops_refresh
|
|
245
|
-
fi
|
|
246
|
-
gitops_direct_delete_application "$name" "$mode"
|
|
247
|
-
}
|