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,141 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
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
|
+
|
|
27
|
+
gitops_repo() { conf_get argocd repo; }
|
|
28
|
+
gitops_repo_note() { conf_set argocd "repo=$1"; }
|
|
29
|
+
|
|
30
|
+
gitops_enabled() {
|
|
31
|
+
local r
|
|
32
|
+
r="$(gitops_repo)"
|
|
33
|
+
[ -n "$r" ] && [ "$r" != none ]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# owner/name of the GitHub repository
|
|
37
|
+
gitops_slug() {
|
|
38
|
+
local r
|
|
39
|
+
r="$(gitops_repo)"
|
|
40
|
+
r="${r#https://github.com/}"
|
|
41
|
+
printf '%s' "${r%.git}"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Creates <login>/devzone-argocd when missing (private) and notes its URL;
|
|
45
|
+
# --repo: an existing GitHub repository; --none: no GitOps repository,
|
|
46
|
+
# Applications applied directly. Without gh logged in: a notice, state kept
|
|
47
|
+
gitops_init() {
|
|
48
|
+
local repo="" expect="" arg login slug
|
|
49
|
+
for arg in "$@"; do
|
|
50
|
+
if [ "$expect" = repo ]; then repo="$arg"; expect=""; continue; fi
|
|
51
|
+
case "$arg" in
|
|
52
|
+
--none)
|
|
53
|
+
gitops_repo_note none
|
|
54
|
+
echo "✔ no GitOps repository: the Applications are applied directly ($GITOPS_CMD to change)"
|
|
55
|
+
return 0
|
|
56
|
+
;;
|
|
57
|
+
--repo) expect=repo ;;
|
|
58
|
+
*) echo "✖ $GITOPS_CMD [--repo https://github.com/<owner>/<name>.git] [--none]" >&2; return 2 ;;
|
|
59
|
+
esac
|
|
60
|
+
done
|
|
61
|
+
if [ -n "$expect" ]; then
|
|
62
|
+
echo "✖ --repo needs a URL" >&2
|
|
63
|
+
return 2
|
|
64
|
+
fi
|
|
65
|
+
if [ -n "$repo" ]; then
|
|
66
|
+
case "$repo" in
|
|
67
|
+
https://github.com/*/*) ;;
|
|
68
|
+
*) echo "✖ GitHub repository URL expected (https://github.com/<owner>/<name>.git): $repo" >&2; return 2 ;;
|
|
69
|
+
esac
|
|
70
|
+
gitops_repo_note "$repo"
|
|
71
|
+
echo "✔ GitOps repository: $repo ($ARGOCD_CONF)"
|
|
72
|
+
return 0
|
|
73
|
+
fi
|
|
74
|
+
if gitops_enabled; then
|
|
75
|
+
return 0
|
|
76
|
+
fi
|
|
77
|
+
if ! gh auth status >/dev/null 2>&1; then
|
|
78
|
+
echo "ℹ GitHub not connected (gh auth login): no GitOps repository, the Applications are applied directly; $GITOPS_CMD --none to stop this notice"
|
|
79
|
+
return 0
|
|
80
|
+
fi
|
|
81
|
+
login="$(gh api user --jq .login 2>/dev/null)" || login=""
|
|
82
|
+
if [ -z "$login" ]; then
|
|
83
|
+
echo "⚠ GitHub login unreadable (gh api user): Applications applied directly" >&2
|
|
84
|
+
return 0
|
|
85
|
+
fi
|
|
86
|
+
slug="$login/$GITOPS_REPO_NAME"
|
|
87
|
+
if ! gh repo view "$slug" --json name >/dev/null 2>&1; then
|
|
88
|
+
if ! gh repo create "$slug" --private --description "GitOps repository of devzone: the Applications Argo CD holds (workspace, services, projects)" >/dev/null; then
|
|
89
|
+
echo "✖ cannot create the GitOps repository $slug" >&2
|
|
90
|
+
return 1
|
|
91
|
+
fi
|
|
92
|
+
echo "✔ GitOps repository created: https://github.com/$slug (private)"
|
|
93
|
+
fi
|
|
94
|
+
gitops_repo_note "https://github.com/$slug.git"
|
|
95
|
+
gitops_put_text README.md "# devzone-argocd
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
" "devzone: GitOps repository"
|
|
99
|
+
gitops_put_text apps/.gitkeep "" "devzone: apps folder"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Blob sha of a file (git), to skip a write that changes nothing
|
|
103
|
+
gitops_blob() { git hash-object "$1" 2>/dev/null || true; }
|
|
104
|
+
|
|
105
|
+
gitops_sha() {
|
|
106
|
+
gh api "repos/$(gitops_slug)/contents/$1" --jq .sha 2>/dev/null || true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Writes <file> at <path> of the repository (create or update), <message>
|
|
110
|
+
gitops_put() {
|
|
111
|
+
local path="$1" file="$2" message="$3" slug sha content
|
|
112
|
+
slug="$(gitops_slug)"
|
|
113
|
+
sha="$(gitops_sha "$path")"
|
|
114
|
+
if [ -n "$sha" ] && [ "$sha" = "$(gitops_blob "$file")" ]; then
|
|
115
|
+
return 0
|
|
116
|
+
fi
|
|
117
|
+
content="$(base64 <"$file" | tr -d '\n')"
|
|
118
|
+
if [ -n "$sha" ]; then
|
|
119
|
+
gh api -X PUT "repos/$slug/contents/$path" -f message="$message" -f content="$content" -f sha="$sha" >/dev/null
|
|
120
|
+
else
|
|
121
|
+
gh api -X PUT "repos/$slug/contents/$path" -f message="$message" -f content="$content" >/dev/null
|
|
122
|
+
fi
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
gitops_put_text() {
|
|
126
|
+
local tmp
|
|
127
|
+
tmp="$(mktemp)"
|
|
128
|
+
printf '%s' "$2" >"$tmp"
|
|
129
|
+
gitops_put "$1" "$tmp" "$3"
|
|
130
|
+
rm -f "$tmp"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
gitops_delete() {
|
|
134
|
+
local path="$1" message="$2" sha
|
|
135
|
+
sha="$(gitops_sha "$path")"
|
|
136
|
+
[ -n "$sha" ] || return 0
|
|
137
|
+
gh api -X DELETE "repos/$(gitops_slug)/contents/$path" -f message="$message" -f sha="$sha" >/dev/null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Repository Secret (token of gh) and root Application "devzone" on apps/
|
|
141
|
+
gitops_root() {
|
|
142
|
+
local url token
|
|
143
|
+
gitops_enabled || return 0
|
|
144
|
+
url="$(gitops_repo)"
|
|
145
|
+
token="${DEVZONE_GITOPS_TOKEN:-$(gh auth token 2>/dev/null || true)}"
|
|
146
|
+
if [ -n "$token" ]; then
|
|
147
|
+
argocd_kubectl -n "$GITOPS_NS" apply -f - >/dev/null <<EOF
|
|
148
|
+
apiVersion: v1
|
|
149
|
+
kind: Secret
|
|
150
|
+
metadata:
|
|
151
|
+
name: repo-$GITOPS_REPO_NAME
|
|
152
|
+
namespace: $GITOPS_NS
|
|
153
|
+
labels:
|
|
154
|
+
argocd.argoproj.io/secret-type: repository
|
|
155
|
+
app.kubernetes.io/managed-by: devzone
|
|
156
|
+
type: Opaque
|
|
157
|
+
stringData:
|
|
158
|
+
type: git
|
|
159
|
+
url: $url
|
|
160
|
+
username: devzone
|
|
161
|
+
password: $token
|
|
162
|
+
EOF
|
|
163
|
+
else
|
|
164
|
+
echo "⚠ no GitHub token for Argo CD (gh auth token): a private repository will not sync; DEVZONE_GITOPS_TOKEN=<token>" >&2
|
|
165
|
+
fi
|
|
166
|
+
bash "$APPS_GENERATOR" "$GITOPS_ROOT_APP" root "$GITOPS_NS" "$url" HEAD apps |
|
|
167
|
+
argocd_kubectl apply -f - >/dev/null
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
# Argo CD reads Git every 3 min: a refresh of the root Application right away
|
|
171
|
+
gitops_refresh() {
|
|
172
|
+
argocd_kubectl -n "$GITOPS_NS" annotate application.argoproj.io "$GITOPS_ROOT_APP" \
|
|
173
|
+
argocd.argoproj.io/refresh=normal --overwrite >/dev/null 2>&1 || true
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
gitops_apply_application() {
|
|
177
|
+
local name="$1" tmp
|
|
178
|
+
if ! gitops_enabled; then
|
|
179
|
+
bash "$APPS_GENERATOR" "$@" | argocd_kubectl apply -f - >/dev/null
|
|
180
|
+
return
|
|
181
|
+
fi
|
|
182
|
+
tmp="$(mktemp)"
|
|
183
|
+
if ! bash "$APPS_GENERATOR" "$@" >"$tmp"; then
|
|
184
|
+
rm -f "$tmp"
|
|
185
|
+
return 1
|
|
186
|
+
fi
|
|
187
|
+
if ! gitops_put "apps/$name.yaml" "$tmp" "devzone: application $name"; then
|
|
188
|
+
rm -f "$tmp"
|
|
189
|
+
return 1
|
|
190
|
+
fi
|
|
191
|
+
rm -f "$tmp"
|
|
192
|
+
gitops_refresh
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# keep: finalizer dropped first, the resources stay
|
|
196
|
+
gitops_direct_delete_application() {
|
|
197
|
+
local name="$1" mode="${2:-cascade}"
|
|
198
|
+
if [ "$mode" = keep ]; then
|
|
199
|
+
argocd_kubectl -n "$GITOPS_NS" patch application.argoproj.io "$name" --type merge \
|
|
200
|
+
-p '{"metadata":{"finalizers":null}}' >/dev/null 2>&1 || true
|
|
201
|
+
fi
|
|
202
|
+
argocd_kubectl -n "$GITOPS_NS" delete application.argoproj.io "$name" --ignore-not-found --wait=true >/dev/null
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
# The file leaves Git first (so that the root Application never recreates
|
|
206
|
+
# the child), then the Application is deleted right away
|
|
207
|
+
gitops_delete_application() {
|
|
208
|
+
local name="$1" mode="${2:-cascade}"
|
|
209
|
+
if gitops_enabled; then
|
|
210
|
+
gitops_delete "apps/$name.yaml" "devzone: application $name removed" || return 1
|
|
211
|
+
gitops_refresh
|
|
212
|
+
fi
|
|
213
|
+
gitops_direct_delete_application "$name" "$mode"
|
|
214
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
# Sourced after conf.sh and gitops.sh by the workstation
|
|
21
|
+
# (manage/scripts/argocd-services.sh) and by the container (argocd.sh). The
|
|
22
|
+
# includer defines argocd_kubectl, APPS_GENERATOR, ARGOCD_CONF and
|
|
23
|
+
# ARGOCD_CONF_DIR (the devzone folder: relative paths there), DEVZONE_REPO_URL
|
|
24
|
+
# and argocd_revision, the secret hook of each service
|
|
25
|
+
# services_secret_<svc> secret created apart, mirrored, never printed
|
|
26
|
+
# and may extend SERVICES_LIST (default: postgres) and define the parameters
|
|
27
|
+
# hook services_chart_<svc> (helm parameters on stdout). bash 3.2 (macOS).
|
|
28
|
+
|
|
29
|
+
: "${SERVICES_LIST:=postgres}"
|
|
30
|
+
|
|
31
|
+
# Names of the Application and of the namespace of a service
|
|
32
|
+
services_app_of() { printf 'devzone-%s' "$1"; }
|
|
33
|
+
#
|
|
34
|
+
# Returns the namespace name devzone-<svc> for a given service name.
|
|
35
|
+
# Used by services_namespace_prepare and services_application_apply.
|
|
36
|
+
services_ns_of() { printf 'devzone-%s' "$1"; }
|
|
37
|
+
|
|
38
|
+
# State of a service: [services] of .argocd.conf first, then the line
|
|
39
|
+
# <svc>=on|off of .devzone.modules (compatibility, #538); empty when neither
|
|
40
|
+
# holds the service
|
|
41
|
+
services_state_of() {
|
|
42
|
+
local svc="$1" v line
|
|
43
|
+
v="$(conf_get services "$svc")"
|
|
44
|
+
case "$v" in on | off) printf '%s' "$v"; return 0 ;; esac
|
|
45
|
+
[ -f "$ARGOCD_CONF_DIR/.devzone.modules" ] || return 0
|
|
46
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
47
|
+
line="$(conf_trim "$line")"
|
|
48
|
+
case "$line" in
|
|
49
|
+
"$svc=on" | "$svc=off") printf '%s' "${line#*=}"; return 0 ;;
|
|
50
|
+
esac
|
|
51
|
+
done <"$ARGOCD_CONF_DIR/.devzone.modules"
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# The [services] section rewritten with the new state of <svc>, the keys of
|
|
56
|
+
# the other services kept
|
|
57
|
+
services_note() {
|
|
58
|
+
local svc="$1" state="$2" s k v
|
|
59
|
+
set --
|
|
60
|
+
while IFS="$(printf '\t')" read -r s k v; do
|
|
61
|
+
[ "$s" = services ] || continue
|
|
62
|
+
[ "$k" = "$svc" ] && continue
|
|
63
|
+
set -- "$@" "$k=$v"
|
|
64
|
+
done <<<"$(conf_entries)"
|
|
65
|
+
set -- "$@" "$svc=$state"
|
|
66
|
+
conf_set services "$@"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# Namespace devzone-<svc>: labelled and isolated like the other devzone-*
|
|
70
|
+
# namespaces (same rule as the helm-direct installers)
|
|
71
|
+
services_namespace_prepare() {
|
|
72
|
+
local ns
|
|
73
|
+
ns="$(services_ns_of "$1")"
|
|
74
|
+
argocd_kubectl create namespace "$ns" --dry-run=client -o yaml | argocd_kubectl apply -f - >/dev/null
|
|
75
|
+
argocd_kubectl label namespace "$ns" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
76
|
+
argocd_kubectl -n "$ns" apply -f - >/dev/null <<'EOF'
|
|
77
|
+
apiVersion: networking.k8s.io/v1
|
|
78
|
+
kind: NetworkPolicy
|
|
79
|
+
metadata:
|
|
80
|
+
name: devzone-meme-namespace
|
|
81
|
+
labels:
|
|
82
|
+
app.kubernetes.io/managed-by: devzone
|
|
83
|
+
spec:
|
|
84
|
+
podSelector: {}
|
|
85
|
+
ingress:
|
|
86
|
+
- from:
|
|
87
|
+
- podSelector: {}
|
|
88
|
+
EOF
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# The Application devzone-<svc>: chart charts/devzone-<svc> of the devzone
|
|
92
|
+
# repository at the revision; the parameters hook adds helm parameters
|
|
93
|
+
services_application_apply() {
|
|
94
|
+
local svc="$1" extra=""
|
|
95
|
+
set -- "$(services_app_of "$svc")" service "$(services_ns_of "$svc")" \
|
|
96
|
+
"$DEVZONE_REPO_URL" "$(argocd_revision)" "charts/devzone-$svc"
|
|
97
|
+
if command -v "services_chart_$svc" >/dev/null 2>&1; then
|
|
98
|
+
# A failing hook (several volumes to choose from…) stops the apply
|
|
99
|
+
extra="$("services_chart_$svc")" || return $?
|
|
100
|
+
# shellcheck disable=SC2086
|
|
101
|
+
set -- "$@" $extra
|
|
102
|
+
fi
|
|
103
|
+
gitops_apply_application "$@"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# A service off: the Application leaves with its resources, the namespace and
|
|
107
|
+
# the volumes stay (--yes of the disable command removes the data)
|
|
108
|
+
services_application_delete() {
|
|
109
|
+
gitops_delete_application "$(services_app_of "$1")"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# Every service of the list applied or released: on → namespace, secret and
|
|
113
|
+
# Application; off → Application removed (namespace and volumes kept); not
|
|
114
|
+
# declared: untouched. One failing service does not stop the others
|
|
115
|
+
services_reconcile() {
|
|
116
|
+
local svc state code=0
|
|
117
|
+
for svc in $SERVICES_LIST; do
|
|
118
|
+
state="$(services_state_of "$svc")"
|
|
119
|
+
case "$state" in
|
|
120
|
+
on)
|
|
121
|
+
services_namespace_prepare "$svc" || code=1
|
|
122
|
+
if command -v "services_secret_$svc" >/dev/null 2>&1; then
|
|
123
|
+
"services_secret_$svc" || code=1
|
|
124
|
+
else
|
|
125
|
+
echo "✖ no secret hook for $svc (services_secret_$svc): the sync will fail" >&2
|
|
126
|
+
code=1
|
|
127
|
+
fi
|
|
128
|
+
services_application_apply "$svc" || code=1
|
|
129
|
+
echo "✔ Application $(services_app_of "$svc") declared (chart charts/devzone-$svc)"
|
|
130
|
+
;;
|
|
131
|
+
off)
|
|
132
|
+
services_application_delete "$svc" || code=1
|
|
133
|
+
echo "✔ Application $(services_app_of "$svc") removed (namespace and volumes kept)"
|
|
134
|
+
;;
|
|
135
|
+
esac
|
|
136
|
+
done
|
|
137
|
+
return "$code"
|
|
138
|
+
}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Opérations d'installation du catalogue (#414) : sourcé par catalogue.sh.
|
|
3
|
+
# Le module argocd actif : l'application installée est une Application Argo CD
|
|
4
|
+
# devzone-<app> (chart charts/devzone-<app> du dépôt devzone, #538) au lieu du
|
|
5
|
+
# manifeste de la voie helm direct.
|
|
3
6
|
|
|
4
7
|
ATTENTE="${DEVZONE_CATALOGUE_ATTENTE:-300}"
|
|
5
8
|
|
|
9
|
+
# shellcheck source=SCRIPTDIR/argocd/catalogue-argocd.sh
|
|
10
|
+
# shellcheck disable=SC1091
|
|
11
|
+
. "$ICI/argocd/catalogue-argocd.sh"
|
|
12
|
+
|
|
13
|
+
# Attente du StatefulSet prêt : une seule commande rollout sur la voie
|
|
14
|
+
# manifeste, sondée sur la voie Argo CD (la synchronisation est en tâche de
|
|
15
|
+
# fond)
|
|
16
|
+
app_attendre() {
|
|
17
|
+
local app="$1" ns="$2" argo="$3" fin=$((SECONDS + ATTENTE))
|
|
18
|
+
if [ "$argo" = 1 ]; then
|
|
19
|
+
while [ "$SECONDS" -lt "$fin" ]; do
|
|
20
|
+
kubectl --context devzone -n "$ns" rollout status "statefulset/$app" --timeout=10s >/dev/null 2>&1 && return 0
|
|
21
|
+
sleep 5
|
|
22
|
+
done
|
|
23
|
+
echo "devzone : catalogue : $app pas prêt après ${ATTENTE}s" >&2
|
|
24
|
+
return 1
|
|
25
|
+
fi
|
|
26
|
+
if ! kubectl --context devzone -n "$ns" rollout status "statefulset/$app" \
|
|
27
|
+
--timeout="${ATTENTE}s" >/dev/null; then
|
|
28
|
+
echo "devzone : catalogue : $app pas prêt après ${ATTENTE}s" >&2
|
|
29
|
+
return 1
|
|
30
|
+
fi
|
|
31
|
+
}
|
|
32
|
+
|
|
6
33
|
# Secret de l'application : mot de passe généré une fois, miroir local
|
|
7
34
|
# (workspace/.$app/admin-password, 600, jamais affiché). Reprise : le mot de
|
|
8
35
|
# passe déjà là (secret cluster ou root.env) est conservé, jamais régénéré.
|
|
@@ -35,10 +62,11 @@ regenerer_identifiants() {
|
|
|
35
62
|
}
|
|
36
63
|
|
|
37
64
|
# Installe une application : contexte devzone posé (#396), namespace créé et
|
|
38
|
-
# isolé (#396), secret généré,
|
|
39
|
-
# vers 127.0.0.1:<port> du
|
|
65
|
+
# isolé (#396), secret généré, puis Application Argo CD (module argocd actif,
|
|
66
|
+
# #538) ou manifeste, attente prête, relais lancé vers 127.0.0.1:<port> du
|
|
67
|
+
# conteneur ; rend non nul en échec
|
|
40
68
|
app_installer() {
|
|
41
|
-
local app="$1" ns port image CTX man
|
|
69
|
+
local app="$1" ns port image CTX man extra="" argo=0
|
|
42
70
|
ns="$(app_ns "$app")"
|
|
43
71
|
port="$(app_lire "$app" port)"
|
|
44
72
|
image="$(app_lire "$app" image)"
|
|
@@ -63,27 +91,32 @@ app_installer() {
|
|
|
63
91
|
# shellcheck disable=SC1091
|
|
64
92
|
. "$(dossier_catalogue)/mysql/volume.sh"
|
|
65
93
|
claim="$(mysql_claim_choisir "$ns")" || return 2
|
|
94
|
+
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
66
95
|
fi
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
if catalogue_argocd_active "$app"; then
|
|
97
|
+
argo=1
|
|
98
|
+
echo "▶ Application $app par Argo CD (chart charts/devzone-$app)…"
|
|
99
|
+
catalogue_argocd_apply "$app" "$ns" "$image" "$port" \
|
|
100
|
+
"$(app_lire "$app" memoire)" "$(app_lire "$app" taille)" "$extra" || return 1
|
|
101
|
+
else
|
|
102
|
+
man="$(mktemp)"
|
|
103
|
+
sed -e "s|__APP__|$app|g" -e "s|__NS__|$ns|g" -e "s|__IMAGE__|$image|g" \
|
|
104
|
+
-e "s|__PORT__|$port|g" -e "s|__MEMOIRE__|$(app_lire "$app" memoire)|g" \
|
|
105
|
+
-e "s|__TAILLE__|$(app_lire "$app" taille)|g" -e "s|__CLAIM__|$claim|g" \
|
|
106
|
+
"$(dossier_catalogue)/$app/manifeste.yaml" >"$man" &&
|
|
107
|
+
kubectl --context devzone -n "$ns" apply -f "$man" >/dev/null
|
|
108
|
+
rm -f "$man"
|
|
78
109
|
fi
|
|
110
|
+
app_attendre "$app" "$ns" "$argo" || return 1
|
|
79
111
|
relais_lancer "$app" "$CTX" "$ns" "svc/$app" "$port:$port"
|
|
80
112
|
echo "✔ $app prêt : 127.0.0.1:$port dans le conteneur"
|
|
81
113
|
regenerer_identifiants
|
|
82
114
|
}
|
|
83
115
|
|
|
84
|
-
# Désinstalle une application : relais coupé,
|
|
85
|
-
#
|
|
86
|
-
#
|
|
116
|
+
# Désinstalle une application : relais coupé, Application Argo CD retirée
|
|
117
|
+
# (module argocd actif, #538) ou manifeste, marque oubliée ; le volume (PVC)
|
|
118
|
+
# et les données restent (#441) : la suppression des données est confirmée à
|
|
119
|
+
# part (devzone mysql supprimer-donnees)
|
|
87
120
|
app_desinstaller() {
|
|
88
121
|
local app="$1" ns claim pvc CTX
|
|
89
122
|
ns="$(app_ns "$app")"
|
|
@@ -97,6 +130,14 @@ app_desinstaller() {
|
|
|
97
130
|
fi
|
|
98
131
|
claim="$(kubectl --context devzone -n "$ns" get statefulset "$app" \
|
|
99
132
|
-o jsonpath='{.spec.volumeClaimTemplates[0].metadata.name}' 2>/dev/null || true)"
|
|
133
|
+
if catalogue_argocd_application_exists "$app"; then
|
|
134
|
+
catalogue_argocd_delete "$app" >/dev/null 2>&1 || true
|
|
135
|
+
kubectl --context devzone -n "$ns" delete "secret/$app-admin" >/dev/null 2>&1 || true
|
|
136
|
+
pvc="${claim:-donnees}-$app-0"
|
|
137
|
+
echo "✔ $app retiré : Application supprimée ; volume $pvc et bases gardés : devzone $app volume"
|
|
138
|
+
regenerer_identifiants
|
|
139
|
+
return 0
|
|
140
|
+
fi
|
|
100
141
|
kubectl --context devzone -n "$ns" delete "statefulset/$app" "service/$app" \
|
|
101
142
|
"secret/$app-admin" >/dev/null 2>&1 || true
|
|
102
143
|
pvc="${claim:-donnees}-$app-0"
|
|
@@ -21,6 +21,37 @@ mysql_secret() {
|
|
|
21
21
|
fi
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
# Attente du StatefulSet posé par Argo CD (#538) : la synchronisation est en
|
|
25
|
+
# tâche de fond, le rollout est sondé jusqu'à MYSQL_ATTENTE
|
|
26
|
+
mysql_attendre() {
|
|
27
|
+
local fin=$((SECONDS + MYSQL_ATTENTE))
|
|
28
|
+
while [ "$SECONDS" -lt "$fin" ]; do
|
|
29
|
+
if k rollout status statefulset/mysql --timeout=10s >/dev/null 2>&1; then
|
|
30
|
+
return 0
|
|
31
|
+
fi
|
|
32
|
+
sleep 5
|
|
33
|
+
done
|
|
34
|
+
echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $1 -n $NS describe pod mysql-0" >&2
|
|
35
|
+
return 1
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Installation MySQL par Argo CD (#538) : Application devzone-mysql (chart
|
|
39
|
+
# charts/devzone-mysql du dépôt devzone), namespace et secret créés à part ;
|
|
40
|
+
# le claim suit les volumes existants, comme le chemin manifeste
|
|
41
|
+
mysql_installer_argocd() {
|
|
42
|
+
local CTX="$1" claim extra=""
|
|
43
|
+
mysql_secret
|
|
44
|
+
claim="$(mysql_claim_choisir "$NS")" || return 2
|
|
45
|
+
[ "$claim" = donnees ] || extra="claim=$claim"
|
|
46
|
+
catalogue_argocd_apply mysql "$NS" "$MYSQL_IMAGE" "$MYSQL_PORT" \
|
|
47
|
+
"$MYSQL_MEMOIRE" "$MYSQL_TAILLE" "$extra" || return 1
|
|
48
|
+
mysql_attendre "$CTX" || return 1
|
|
49
|
+
mysql_secret
|
|
50
|
+
relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
|
|
51
|
+
echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
|
|
52
|
+
regenerer_identifiants
|
|
53
|
+
}
|
|
54
|
+
|
|
24
55
|
# Applique le manifeste avec le préfixe de claim choisi (#440)
|
|
25
56
|
mysql_appliquer_manifeste() {
|
|
26
57
|
local ns="$1" claim="$2"
|