devzone 0.36.7 → 0.38.0
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/.dockerignore +1 -1
- package/.devcontainer/argocd/application.sh +69 -0
- package/.devcontainer/argocd/apps.sh +262 -0
- package/.devcontainer/argocd/argocd.sh +52 -8
- package/.devcontainer/argocd/catalogue-argocd.sh +114 -0
- package/.devcontainer/argocd/conf.sh +141 -0
- package/.devcontainer/argocd/gitops.sh +214 -0
- package/.devcontainer/argocd/services.sh +138 -0
- package/.devcontainer/catalogue/app.sh +58 -17
- package/.devcontainer/catalogue/mysql/installer.sh +31 -0
- package/.devcontainer/catalogue/mysql/mysql.sh +12 -0
- package/.devcontainer/devzone +2 -1
- package/.devcontainer/password.sh +8 -0
- package/README.md +2 -2
- package/charts/devzone-argocd/Chart.lock +6 -0
- package/charts/devzone-argocd/Chart.yaml +13 -0
- package/charts/devzone-argocd/values.yaml +28 -0
- package/charts/devzone-mysql/Chart.yaml +6 -0
- package/charts/devzone-mysql/templates/service.yaml +15 -0
- package/charts/devzone-mysql/templates/statefulset.yaml +55 -0
- package/charts/devzone-mysql/values.yaml +19 -0
- package/charts/devzone-postgres/Chart.yaml +6 -0
- package/charts/devzone-postgres/templates/service.yaml +15 -0
- package/charts/devzone-postgres/templates/statefulset.yaml +56 -0
- package/charts/devzone-postgres/values.yaml +11 -0
- package/manage/devzone +4 -1
- package/manage/scripts/argocd-services-svc.sh +110 -0
- package/manage/scripts/argocd-services.sh +179 -0
- package/manage/scripts/argocd-workspace.sh +221 -0
- package/manage/scripts/ci-dns.sh +10 -10
- package/manage/scripts/desinstaller.sh +137 -135
- package/manage/scripts/docker.sh +26 -22
- package/manage/scripts/lancer.sh +103 -103
- package/manage/scripts/migrer-retour.sh +37 -34
- package/manage/scripts/migrer.sh +154 -138
- package/manage/scripts/ports-workspace.sh +94 -82
- package/manage/scripts/poste.sh +48 -49
- package/manage/scripts/services-workspace.sh +22 -5
- package/manage/scripts/versions.sh +88 -88
- package/manage/scripts/workspace-aliases.sh +47 -0
- package/manage/scripts/workspace-wait.sh +27 -24
- package/manage/workspace.sh +134 -105
- package/package.json +1 -1
- package/.devcontainer/argocd/values.yaml +0 -21
|
@@ -0,0 +1,69 @@
|
|
|
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
|
|
@@ -0,0 +1,262 @@
|
|
|
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/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 autoriser
|
|
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 autoriser $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,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Module argocd (#411) : Argo CD dans le cluster des services de devzone.
|
|
3
3
|
# argocd.sh installer | desinstaller | etat | relais-lancer | relais-arreter
|
|
4
|
+
# argocd.sh app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>
|
|
4
5
|
# Namespace devzone-argocd isolé, relais 127.0.0.1:8443 dans le conteneur.
|
|
5
6
|
# Mot de passe admin dans workspace/.argocd/admin.env (600), repris dans
|
|
6
7
|
# .password ; jamais affiché.
|
|
@@ -138,15 +139,14 @@ installer() {
|
|
|
138
139
|
echo "▶ Vérification de la mémoire allouable du cluster des services…"
|
|
139
140
|
verifier_memoire || return 2
|
|
140
141
|
preparer_namespace
|
|
141
|
-
echo "▶
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
compte_helm "$(compte_ctx)" upgrade --install argocd
|
|
146
|
-
|
|
142
|
+
echo "▶ Installation d'Argo CD $ARGOCD_VERSION dans $NS (chart charts/devzone-argocd)…"
|
|
143
|
+
# Wrapper chart: the dependency argo-cd (pinned in Chart.yaml) is built
|
|
144
|
+
# first, then installed from the local chart (#538)
|
|
145
|
+
helm dependency build "$RACINE/charts/devzone-argocd" >/dev/null
|
|
146
|
+
compte_helm "$(compte_ctx)" upgrade --install argocd \
|
|
147
|
+
"$RACINE/charts/devzone-argocd" \
|
|
147
148
|
--namespace "$NS" \
|
|
148
149
|
--create-namespace \
|
|
149
|
-
-f "$ICI/values.yaml" \
|
|
150
150
|
--timeout "${ARGOCD_ATTENTE}s" \
|
|
151
151
|
--wait
|
|
152
152
|
enregistrer_admin
|
|
@@ -195,14 +195,58 @@ relais() {
|
|
|
195
195
|
fi
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
# Applications of the projects (#516): shared with the workstation (apps.sh),
|
|
199
|
+
# here with the limited devzone context (aggregate roles of the chart)
|
|
200
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
201
|
+
APPS_CMD="devzone argocd app"
|
|
202
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
203
|
+
APPS_GENERATOR="$ICI/application.sh"
|
|
204
|
+
# shellcheck disable=SC2034 # read by apps.sh: GitLab namespace of this instance
|
|
205
|
+
APPS_GITLAB_NS="devzone-gitlab${INSTANCE_SUFFIX}"
|
|
206
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
207
|
+
APPS_GITLAB_TOKEN_FILE="$RACINE/workspace/.gitlab/root-token"
|
|
208
|
+
# shellcheck disable=SC2034 # read by gitops.sh
|
|
209
|
+
GITOPS_CMD="devzone argocd init"
|
|
210
|
+
# shellcheck disable=SC2034 # read by conf.sh and apps.sh: .argocd.conf of the instance
|
|
211
|
+
ARGOCD_CONF_DIR="$RACINE"
|
|
212
|
+
# shellcheck disable=SC2034
|
|
213
|
+
ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
|
|
214
|
+
# shellcheck source=SCRIPTDIR/conf.sh
|
|
215
|
+
# shellcheck disable=SC1091
|
|
216
|
+
. "$ICI/conf.sh"
|
|
217
|
+
# shellcheck source=SCRIPTDIR/gitops.sh
|
|
218
|
+
# shellcheck disable=SC1091
|
|
219
|
+
. "$ICI/gitops.sh"
|
|
220
|
+
# shellcheck source=SCRIPTDIR/apps.sh
|
|
221
|
+
# shellcheck disable=SC1091
|
|
222
|
+
. "$ICI/apps.sh"
|
|
223
|
+
argocd_kubectl() { kubectl --context devzone "$@"; }
|
|
224
|
+
|
|
198
225
|
case "${1:-}" in
|
|
199
226
|
installer) installer ;;
|
|
200
227
|
desinstaller) desinstaller ;;
|
|
201
228
|
etat) etat ;;
|
|
202
229
|
relais-lancer) relais ;;
|
|
203
230
|
relais-arreter) relais_arreter argocd ;;
|
|
231
|
+
init)
|
|
232
|
+
# GitOps repository of the user (#516): created or designated, then
|
|
233
|
+
# the root Application when the module is installed
|
|
234
|
+
gitops_init "${@:2}" || exit $?
|
|
235
|
+
if installe; then gitops_root; fi
|
|
236
|
+
;;
|
|
237
|
+
apply)
|
|
238
|
+
installe || refuse "module off: devzone enable argocd"
|
|
239
|
+
gitops_init && gitops_root && apps_reconcile
|
|
240
|
+
;;
|
|
241
|
+
app)
|
|
242
|
+
if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
|
|
243
|
+
refuse "in the workspace pod, on the workstation: devzone workspace argocd app ${*:2}"
|
|
244
|
+
fi
|
|
245
|
+
installe || refuse "module off: devzone enable argocd"
|
|
246
|
+
argocd_app "${@:2}"
|
|
247
|
+
;;
|
|
204
248
|
*)
|
|
205
|
-
echo "devzone argocd : installer | desinstaller | etat" >&2
|
|
249
|
+
echo "devzone argocd : installer | desinstaller | etat | init [--repo <url>|--none] | apply | app add|list|remove" >&2
|
|
206
250
|
exit 1
|
|
207
251
|
;;
|
|
208
252
|
esac
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Argo CD for the catalogue applications in the container (#538): the module
|
|
3
|
+
# mysql and the catalogue install their application as the Application
|
|
4
|
+
# devzone-<app> (services.sh) when the module argocd is active, instead of
|
|
5
|
+
# the manifest applied by hand. The namespace (compte_namespace of
|
|
6
|
+
# cluster.sh, isolement.sh) and the secret <app>-admin (mirror
|
|
7
|
+
# workspace/.<app>/) stay created apart, out of Git; Argo CD holds the chart
|
|
8
|
+
# charts/devzone-<app> of the devzone repository at the revision.
|
|
9
|
+
# catalogue_argocd_active <app> on, installed, chart and revision
|
|
10
|
+
# catalogue_argocd_apply <app> <ns> ... the Application, then refreshed
|
|
11
|
+
# catalogue_argocd_application_exists <app>
|
|
12
|
+
# catalogue_argocd_delete <app> Application deleted (namespace
|
|
13
|
+
# and volumes stay)
|
|
14
|
+
# argocd_revision: DEVZONE_ARGOCD_REVISION, else v<package.json version>;
|
|
15
|
+
# empty on a development clone (0.0.0): the local chart is not in Git, the
|
|
16
|
+
# manifest path keeps serving. The includer defines RACINE and ETAT (the
|
|
17
|
+
# devzone modules file), and the secret hook services_secret_<app> (mirrored,
|
|
18
|
+
# never printed). bash 3.2 (macOS).
|
|
19
|
+
|
|
20
|
+
CATALOGUE_ARGOCD_WIRED="${CATALOGUE_ARGOCD_WIRED:-}"
|
|
21
|
+
|
|
22
|
+
# Line argocd=on of .devzone.modules of the container
|
|
23
|
+
catalogue_argocd_module_on() {
|
|
24
|
+
grep -E '^argocd=' "${ETAT:-}" 2>/dev/null | tail -1 | cut -d= -f2- | grep -qx on
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# Git revision for the Applications: DEVZONE_ARGOCD_REVISION, else the tag of
|
|
28
|
+
# the package version of the image; empty on a development clone
|
|
29
|
+
argocd_revision() {
|
|
30
|
+
local version
|
|
31
|
+
if [ -n "${DEVZONE_ARGOCD_REVISION:-}" ]; then
|
|
32
|
+
printf '%s' "$DEVZONE_ARGOCD_REVISION"
|
|
33
|
+
return 0
|
|
34
|
+
fi
|
|
35
|
+
version="$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$RACINE/package.json" | head -1)"
|
|
36
|
+
case "$version" in
|
|
37
|
+
'' | 0.0.0) ;;
|
|
38
|
+
*) printf 'v%s' "$version" ;;
|
|
39
|
+
esac
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Sources the shared pieces once: conf.sh and gitops.sh with the
|
|
43
|
+
# .argocd.conf of the devzone folder, services.sh with the hooks of the
|
|
44
|
+
# container (limited devzone context)
|
|
45
|
+
catalogue_argocd_load() {
|
|
46
|
+
[ -n "$CATALOGUE_ARGOCD_WIRED" ] && return 0
|
|
47
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
48
|
+
APPS_CMD="devzone argocd app"
|
|
49
|
+
# shellcheck disable=SC2034 # read by apps.sh and services.sh
|
|
50
|
+
APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
|
|
51
|
+
# shellcheck disable=SC2034 # read by gitops.sh
|
|
52
|
+
GITOPS_CMD="devzone argocd init"
|
|
53
|
+
# shellcheck disable=SC2034 # read by conf.sh and apps.sh
|
|
54
|
+
ARGOCD_CONF_DIR="$RACINE"
|
|
55
|
+
# shellcheck disable=SC2034
|
|
56
|
+
ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
|
|
57
|
+
# shellcheck source=SCRIPTDIR/conf.sh
|
|
58
|
+
# shellcheck disable=SC1091
|
|
59
|
+
. "$RACINE/.devcontainer/argocd/conf.sh"
|
|
60
|
+
# shellcheck source=SCRIPTDIR/gitops.sh
|
|
61
|
+
# shellcheck disable=SC1091
|
|
62
|
+
. "$RACINE/.devcontainer/argocd/gitops.sh"
|
|
63
|
+
# shellcheck source=SCRIPTDIR/services.sh
|
|
64
|
+
# shellcheck disable=SC1091
|
|
65
|
+
. "$RACINE/.devcontainer/argocd/services.sh"
|
|
66
|
+
# shellcheck disable=SC2034 # read by services.sh
|
|
67
|
+
DEVZONE_REPO_URL="${DEVZONE_REPO_URL:-https://github.com/SimBienvenueHoulBoumi/devzone.git}"
|
|
68
|
+
CATALOGUE_ARGOCD_WIRED=1
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# The catalogue application <app> can be an Argo CD Application: the module
|
|
72
|
+
# argocd is on and installed, the chart exists in charts/, the revision is
|
|
73
|
+
# known (a development clone keeps the manifest path)
|
|
74
|
+
catalogue_argocd_active() {
|
|
75
|
+
local app="$1"
|
|
76
|
+
catalogue_argocd_module_on || return 1
|
|
77
|
+
[ -d "$RACINE/charts/devzone-$app" ] || return 1
|
|
78
|
+
compte_admin "$(compte_ctx)" get namespace devzone-argocd >/dev/null 2>&1 || return 1
|
|
79
|
+
catalogue_argocd_load
|
|
80
|
+
[ -n "$(argocd_revision)" ]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# Applies the Application devzone-<app> (kind service) with the chart
|
|
84
|
+
# charts/devzone-<app> at the revision; image, port, memory and size are the
|
|
85
|
+
# values of app.conf passed as helm parameters, <extra> holds the ones of the
|
|
86
|
+
# application itself (claim). In the GitOps repository when one is designated
|
|
87
|
+
# (.argocd.conf), applied directly otherwise (gitops.sh)
|
|
88
|
+
catalogue_argocd_apply() {
|
|
89
|
+
local app="$1" ns="$2" image="$3" port="$4" memory="$5" size="$6" params extra="${7:-}"
|
|
90
|
+
catalogue_argocd_load
|
|
91
|
+
params="image=$image port=$port memory=$memory size=$size"
|
|
92
|
+
[ -n "$extra" ] && params="$params $extra"
|
|
93
|
+
# shellcheck disable=SC2086
|
|
94
|
+
gitops_apply_application "devzone-$app" service "$ns" "$DEVZONE_REPO_URL" \
|
|
95
|
+
"$(argocd_revision)" "charts/devzone-$app" $params || return 1
|
|
96
|
+
# Argo CD reads Git every 3 min: an immediate refresh of the Application
|
|
97
|
+
kubectl --context devzone -n devzone-argocd annotate application.argoproj.io \
|
|
98
|
+
"devzone-$app" argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# The Application devzone-<app> exists in devzone-argocd
|
|
102
|
+
catalogue_argocd_application_exists() {
|
|
103
|
+
catalogue_argocd_module_on || return 1
|
|
104
|
+
kubectl --context devzone -n devzone-argocd get application.argoproj.io "devzone-$1" >/dev/null 2>&1
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# Deletes the Application devzone-<app>: its resources go with it, the
|
|
108
|
+
# namespace and the volumes stay (the explicit removal of the data keeps its
|
|
109
|
+
# own command); nothing to delete when the Application is absent
|
|
110
|
+
catalogue_argocd_delete() {
|
|
111
|
+
catalogue_argocd_application_exists "$1" || return 0
|
|
112
|
+
catalogue_argocd_load
|
|
113
|
+
gitops_delete_application "devzone-$1"
|
|
114
|
+
}
|