devzone 0.36.7 → 0.37.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/argocd/application.sh +69 -0
- package/.devcontainer/argocd/apps.sh +262 -0
- package/.devcontainer/argocd/argocd.sh +46 -1
- package/.devcontainer/argocd/conf.sh +141 -0
- package/.devcontainer/argocd/gitops.sh +214 -0
- package/.devcontainer/argocd/values.yaml +4 -0
- package/.devcontainer/devzone +1 -0
- package/README.md +1 -1
- 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 +2 -0
- package/manage/scripts/argocd-services.sh +243 -0
- package/manage/scripts/argocd-workspace.sh +219 -0
- package/manage/scripts/ports-workspace.sh +17 -10
- package/manage/scripts/services-workspace.sh +13 -1
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +23 -7
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
# L'accès passe par le relais kubectl port-forward du conteneur (8443:443).
|
|
4
4
|
global:
|
|
5
5
|
domain: ""
|
|
6
|
+
# Aggregate ClusterRoles (#516): the Application resources join the edit role,
|
|
7
|
+
# so the limited devzone account (#430) manages the Applications of the
|
|
8
|
+
# projects in devzone-argocd (devzone argocd app …)
|
|
9
|
+
createAggregateRoles: true
|
|
6
10
|
dex:
|
|
7
11
|
enabled: false
|
|
8
12
|
notifications:
|
package/.devcontainer/devzone
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
# devzone gitlab nouveau-mdp [root|dev] mot de passe aléatoire (root ou dev) régénéré
|
|
24
24
|
# devzone activer argocd Argo CD dans le cluster des services, accès https://127.0.0.1:8443
|
|
25
25
|
# devzone argocd etat|relais-lancer|relais-arreter Argo CD (module argocd)
|
|
26
|
+
# devzone argocd app add <repo url> [path]|list|remove <N> projets déployés par Argo CD (#516)
|
|
26
27
|
# devzone cluster [CTX] [--oui] [--confirmer CTX] cluster des services de devzone, ou en changer
|
|
27
28
|
# devzone port [<n>|--fermer <n>] relais d'un port du conteneur vers le poste
|
|
28
29
|
# devzone mots-de-passe régénère .password et affiche son chemin
|
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ La liste vit dans .devzone.paquets a la racine du dossier devzone, hors du depot
|
|
|
152
152
|
| État | — | `make status` | — |
|
|
153
153
|
| **Désinstaller** (tout ce que devzone a créé, après confirmation) | — | `make desinstaller` | `npx devzone uninstall` |
|
|
154
154
|
|
|
155
|
-
Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)).
|
|
155
|
+
Après `devzone workspace migrate`, `make up`, `make shell` et `make stop` pilotent le workspace Kubernetes ; `devzone workspace revert` rend le poste Docker. Les services GitLab, PostgreSQL et Argo CD s'y installent depuis le poste : `devzone workspace services enable postgres` (voir [la référence](manage/docs/reference.md#services-de-devzone-dans-le-workspace-kubernetes)). Argo CD y est installé d'office et tient les déploiements : interface sur https://localhost:8443 (mot de passe `admin` dans `.password`), dépôt GitOps `<login>/devzone-argocd` créé sur ton GitHub, projets déclarés dans `.argocd.conf` (`devzone workspace argocd app add <dépôt>`) ; voir [Argo CD dans le workspace Kubernetes](manage/docs/reference.md#argo-cd-dans-le-workspace-kubernetes).
|
|
156
156
|
|
|
157
157
|
### Mettre à jour devzone
|
|
158
158
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
apiVersion: v1
|
|
2
|
+
kind: Service
|
|
3
|
+
metadata:
|
|
4
|
+
name: postgres
|
|
5
|
+
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app: postgres
|
|
8
|
+
app.kubernetes.io/managed-by: devzone
|
|
9
|
+
spec:
|
|
10
|
+
selector:
|
|
11
|
+
app: postgres
|
|
12
|
+
ports:
|
|
13
|
+
- name: postgres
|
|
14
|
+
port: 5432
|
|
15
|
+
targetPort: 5432
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
apiVersion: apps/v1
|
|
2
|
+
kind: StatefulSet
|
|
3
|
+
metadata:
|
|
4
|
+
name: postgres
|
|
5
|
+
namespace: {{ .Release.Namespace }}
|
|
6
|
+
labels:
|
|
7
|
+
app: postgres
|
|
8
|
+
app.kubernetes.io/managed-by: devzone
|
|
9
|
+
spec:
|
|
10
|
+
serviceName: postgres
|
|
11
|
+
replicas: 1
|
|
12
|
+
selector:
|
|
13
|
+
matchLabels:
|
|
14
|
+
app: postgres
|
|
15
|
+
template:
|
|
16
|
+
metadata:
|
|
17
|
+
labels:
|
|
18
|
+
app: postgres
|
|
19
|
+
app.kubernetes.io/managed-by: devzone
|
|
20
|
+
spec:
|
|
21
|
+
containers:
|
|
22
|
+
- name: postgres
|
|
23
|
+
image: {{ .Values.image }}
|
|
24
|
+
env:
|
|
25
|
+
- name: POSTGRES_PASSWORD
|
|
26
|
+
valueFrom:
|
|
27
|
+
secretKeyRef:
|
|
28
|
+
name: postgres-admin
|
|
29
|
+
key: password
|
|
30
|
+
- name: PGDATA
|
|
31
|
+
value: /var/lib/postgresql/data/pgdata
|
|
32
|
+
ports:
|
|
33
|
+
- containerPort: 5432
|
|
34
|
+
name: postgres
|
|
35
|
+
readinessProbe:
|
|
36
|
+
exec:
|
|
37
|
+
command: ["pg_isready", "-U", "postgres"]
|
|
38
|
+
initialDelaySeconds: 5
|
|
39
|
+
periodSeconds: 5
|
|
40
|
+
resources:
|
|
41
|
+
requests:
|
|
42
|
+
cpu: {{ .Values.resources.requests.cpu }}
|
|
43
|
+
memory: {{ .Values.resources.requests.memory }}
|
|
44
|
+
volumeMounts:
|
|
45
|
+
- name: donnees
|
|
46
|
+
mountPath: /var/lib/postgresql/data
|
|
47
|
+
volumeClaimTemplates:
|
|
48
|
+
- metadata:
|
|
49
|
+
name: donnees
|
|
50
|
+
labels:
|
|
51
|
+
app.kubernetes.io/managed-by: devzone
|
|
52
|
+
spec:
|
|
53
|
+
accessModes: ["ReadWriteOnce"]
|
|
54
|
+
resources:
|
|
55
|
+
requests:
|
|
56
|
+
storage: {{ .Values.size }}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Same objects as .devcontainer/postgres/postgres.yaml, the helm-direct path:
|
|
2
|
+
# manage/test/chart-postgres.bats checks that both renderings agree. The
|
|
3
|
+
# secret postgres-admin (superuser password) is created apart by devzone,
|
|
4
|
+
# never by the chart (#516: secrets out of Git).
|
|
5
|
+
image: postgres:16.15-alpine
|
|
6
|
+
# Size of the data volume (POSTGRES_TAILLE of the helm-direct path)
|
|
7
|
+
size: 5Gi
|
|
8
|
+
resources:
|
|
9
|
+
requests:
|
|
10
|
+
cpu: 100m
|
|
11
|
+
memory: 256Mi
|
package/manage/devzone
CHANGED
|
@@ -431,6 +431,8 @@ devzone $(version) : environnement de développement conteneurisé
|
|
|
431
431
|
poste Kubernetes : pilote le chart devzone-workspace
|
|
432
432
|
devzone workspace services enable|disable <service>|status
|
|
433
433
|
services (gitlab, postgres, argocd) du workspace Kubernetes
|
|
434
|
+
devzone workspace argocd status|init|apply|app add|list|remove
|
|
435
|
+
Argo CD du workspace : dépôt GitOps, .argocd.conf, projets
|
|
434
436
|
(anciens noms français acceptés : mettre-a-jour, desinstaller, demarrer…)
|
|
435
437
|
devzone --version
|
|
436
438
|
EOF
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Deployments held by Argo CD in the Kubernetes workspace (#516), sourced by
|
|
3
|
+
# manage/workspace.sh after argocd-workspace.sh: the workspace itself, the
|
|
4
|
+
# postgres service, the argocd services switch and devzone workspace argocd.
|
|
5
|
+
# workspace_deploy <repository> <tag> <with-image> start: Application, else helm direct
|
|
6
|
+
# workspace_undeploy stop: Application, else helm uninstall
|
|
7
|
+
# argocd_toggle enable|disable devzone workspace services … argocd
|
|
8
|
+
# postgres_argocd enable|disable [--yes] postgres as an Application
|
|
9
|
+
# argocd_cmd status | init | apply | app add|list|remove devzone workspace argocd …
|
|
10
|
+
# Secrets stay out of Git: created here, only referenced by the charts.
|
|
11
|
+
# bash 3.2 (macOS).
|
|
12
|
+
|
|
13
|
+
WORKSPACE_APP="devzone-workspace"
|
|
14
|
+
POSTGRES_APP="devzone-postgres"
|
|
15
|
+
POSTGRES_NS="devzone-postgres"
|
|
16
|
+
|
|
17
|
+
# The only option of a removal: --yes (--oui still accepted); prints 1 or 0
|
|
18
|
+
yes_flag() {
|
|
19
|
+
local usage="$1" arg found=0
|
|
20
|
+
shift
|
|
21
|
+
for arg in "$@"; do
|
|
22
|
+
case "$arg" in
|
|
23
|
+
--yes | --oui) found=1 ;;
|
|
24
|
+
*) echo "✖ unknown option: $arg (devzone workspace $usage)" >&2; return 1 ;;
|
|
25
|
+
esac
|
|
26
|
+
done
|
|
27
|
+
echo "$found"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# [y/N] in a terminal; without one, --yes is required
|
|
31
|
+
confirm_removal() {
|
|
32
|
+
local answer=""
|
|
33
|
+
[ "${2:-0}" = 1 ] && return 0
|
|
34
|
+
if [ ! -t 0 ]; then
|
|
35
|
+
echo "✖ no terminal: confirmation impossible, run again with --yes" >&2
|
|
36
|
+
return 1
|
|
37
|
+
fi
|
|
38
|
+
read -r -p "$1 [y/N] " answer || true
|
|
39
|
+
case "$answer" in y | Y | yes | YES | o | O | oui) return 0 ;; esac
|
|
40
|
+
echo "✖ cancelled, nothing changed" >&2
|
|
41
|
+
return 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
45
|
+
APPS_CMD="devzone workspace argocd app"
|
|
46
|
+
# shellcheck disable=SC2034 # read by apps.sh
|
|
47
|
+
APPS_GENERATOR="$RACINE/.devcontainer/argocd/application.sh"
|
|
48
|
+
# shellcheck disable=SC2034 # read by gitops.sh
|
|
49
|
+
GITOPS_CMD="devzone workspace argocd init"
|
|
50
|
+
# .argocd.conf of the devzone folder of the workstation (conf.sh)
|
|
51
|
+
# shellcheck disable=SC2034 # read by conf.sh and apps.sh
|
|
52
|
+
ARGOCD_CONF_DIR="$PWD"
|
|
53
|
+
# shellcheck disable=SC2034
|
|
54
|
+
ARGOCD_CONF="$PWD/.argocd.conf"
|
|
55
|
+
# shellcheck source=../../.devcontainer/argocd/conf.sh
|
|
56
|
+
# shellcheck disable=SC1091
|
|
57
|
+
. "$RACINE/.devcontainer/argocd/conf.sh"
|
|
58
|
+
# shellcheck source=../../.devcontainer/argocd/gitops.sh
|
|
59
|
+
# shellcheck disable=SC1091
|
|
60
|
+
. "$RACINE/.devcontainer/argocd/gitops.sh"
|
|
61
|
+
# shellcheck source=../../.devcontainer/argocd/apps.sh
|
|
62
|
+
# shellcheck disable=SC1091
|
|
63
|
+
. "$RACINE/.devcontainer/argocd/apps.sh"
|
|
64
|
+
argocd_kubectl() { ak "$@"; }
|
|
65
|
+
|
|
66
|
+
# workspace start and argocd apply: the declarations of .argocd.conf held
|
|
67
|
+
argocd_reconcile() {
|
|
68
|
+
argocd_installed || return 0
|
|
69
|
+
gitops_init || return 1
|
|
70
|
+
gitops_root || return 1
|
|
71
|
+
apps_reconcile
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Root token of the devzone GitLab for app add: the file of the workstation,
|
|
75
|
+
# else the one of the pod (the module was installed there, #528); never printed
|
|
76
|
+
apps_gitlab_token() {
|
|
77
|
+
if [ -s "$PWD/workspace/.gitlab/root-token" ]; then
|
|
78
|
+
cat "$PWD/workspace/.gitlab/root-token"
|
|
79
|
+
else
|
|
80
|
+
ak -n "$NAMESPACE" exec "$POD" -c workspace -- cat "$DOSSIER_PROJETS/workspace/.gitlab/root-token" 2>/dev/null || true
|
|
81
|
+
fi
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Argo CD holds the devzone charts only with a Git revision (release tag or
|
|
85
|
+
# DEVZONE_ARGOCD_REVISION): a development clone stays on helm direct
|
|
86
|
+
argocd_holds_charts() {
|
|
87
|
+
argocd_active && [ -n "$(argocd_revision)" ]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
argocd_clone_notice() {
|
|
91
|
+
if argocd_active && [ -z "$(argocd_revision)" ]; then
|
|
92
|
+
echo "ℹ development clone (version 0.0.0): helm direct; DEVZONE_ARGOCD_REVISION=<branch> to go through Argo CD"
|
|
93
|
+
fi
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# Release secrets of a release deployed with helm before: deleted, so that
|
|
97
|
+
# Argo CD adopts the live resources without any helm uninstall (no downtime)
|
|
98
|
+
helm_release_forget() {
|
|
99
|
+
ak -n "$2" delete secret -l "owner=helm,name=$1" --ignore-not-found >/dev/null 2>&1 || true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
workspace_deploy() {
|
|
103
|
+
local repository="$1" tag="$2" with_image="$3" params
|
|
104
|
+
if ! argocd_holds_charts; then
|
|
105
|
+
argocd_clone_notice
|
|
106
|
+
workspace_helm_deploy "$repository" "$tag" "$with_image"
|
|
107
|
+
return
|
|
108
|
+
fi
|
|
109
|
+
params="image.tag=$tag"
|
|
110
|
+
[ -z "$with_image" ] || params="$params image.repository=$repository"
|
|
111
|
+
[ "$tag" != latest ] || params="$params image.pullPolicy=Always"
|
|
112
|
+
# GitOps repository created or designated first, with its root Application
|
|
113
|
+
gitops_init || return 1
|
|
114
|
+
gitops_root || return 1
|
|
115
|
+
echo "▶ Application $WORKSPACE_APP (Argo CD, charts/devzone-workspace at $(argocd_revision))…"
|
|
116
|
+
helm_release_forget devzone-workspace devzone-workspace
|
|
117
|
+
# shellcheck disable=SC2086
|
|
118
|
+
argocd_apply_application "$WORKSPACE_APP" workspace devzone-workspace \
|
|
119
|
+
"$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-workspace $params
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
workspace_undeploy() {
|
|
123
|
+
if argocd_installed && argocd_application_exists "$WORKSPACE_APP"; then
|
|
124
|
+
echo "▶ Application $WORKSPACE_APP deleted (Argo CD removes the pod, the volumes stay)…"
|
|
125
|
+
argocd_delete_application "$WORKSPACE_APP"
|
|
126
|
+
else
|
|
127
|
+
# shellcheck disable=SC2046
|
|
128
|
+
helm $(drapeau_helm) uninstall devzone-workspace --namespace devzone-workspace
|
|
129
|
+
fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# devzone workspace services enable|disable argocd: the workstation installs
|
|
133
|
+
# or removes it itself; the state line follows what succeeded
|
|
134
|
+
argocd_toggle() {
|
|
135
|
+
local action="$1"
|
|
136
|
+
shift
|
|
137
|
+
if [ "$#" -ne 0 ]; then
|
|
138
|
+
echo "✖ services $action argocd takes no option (got: $*)" >&2
|
|
139
|
+
return 1
|
|
140
|
+
fi
|
|
141
|
+
case "$action" in
|
|
142
|
+
enable) argocd_install && state_note argocd on && gitops_init && gitops_root ;;
|
|
143
|
+
disable) argocd_uninstall && state_note argocd off ;;
|
|
144
|
+
esac
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Namespace of the service: labelled, isolated like the other devzone-*
|
|
148
|
+
postgres_namespace_prepare() {
|
|
149
|
+
ak create namespace "$POSTGRES_NS" --dry-run=client -o yaml | ak apply -f - >/dev/null
|
|
150
|
+
ak label namespace "$POSTGRES_NS" app.kubernetes.io/managed-by=devzone --overwrite >/dev/null
|
|
151
|
+
ak -n "$POSTGRES_NS" apply -f - >/dev/null <<EOF
|
|
152
|
+
apiVersion: networking.k8s.io/v1
|
|
153
|
+
kind: NetworkPolicy
|
|
154
|
+
metadata:
|
|
155
|
+
name: devzone-meme-namespace
|
|
156
|
+
labels:
|
|
157
|
+
app.kubernetes.io/managed-by: devzone
|
|
158
|
+
spec:
|
|
159
|
+
podSelector: {}
|
|
160
|
+
ingress:
|
|
161
|
+
- from:
|
|
162
|
+
- podSelector: {}
|
|
163
|
+
EOF
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Superuser secret postgres-admin, created apart: an existing secret is kept
|
|
167
|
+
# and mirrored; otherwise a password generated on the workstation. Mirror
|
|
168
|
+
# workspace/.postgres/admin-password (600) and .password; never printed
|
|
169
|
+
postgres_secret_ensure() {
|
|
170
|
+
local dir="$PWD/workspace/.postgres" file password
|
|
171
|
+
file="$dir/admin-password"
|
|
172
|
+
mkdir -p "$dir"
|
|
173
|
+
chmod 700 "$dir"
|
|
174
|
+
password="$(ak -n "$POSTGRES_NS" get secret postgres-admin \
|
|
175
|
+
-o go-template='{{.data.password | base64decode}}' 2>/dev/null)" || password=""
|
|
176
|
+
if [ -n "$password" ]; then
|
|
177
|
+
(umask 077 && printf '%s' "$password" >"$file")
|
|
178
|
+
else
|
|
179
|
+
if [ ! -s "$file" ]; then
|
|
180
|
+
(umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
|
|
181
|
+
fi
|
|
182
|
+
ak -n "$POSTGRES_NS" create secret generic postgres-admin --from-file=password="$file" >/dev/null
|
|
183
|
+
fi
|
|
184
|
+
chmod 600 "$file"
|
|
185
|
+
argocd_passwords_refresh
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
postgres_argocd() {
|
|
189
|
+
local action="$1" yes
|
|
190
|
+
shift
|
|
191
|
+
case "$action" in
|
|
192
|
+
enable)
|
|
193
|
+
if [ "$#" -ne 0 ]; then
|
|
194
|
+
echo "✖ postgres through Argo CD takes no option (got: $*)" >&2
|
|
195
|
+
return 1
|
|
196
|
+
fi
|
|
197
|
+
echo "▶ postgres as an Argo CD Application (charts/devzone-postgres at $(argocd_revision))…"
|
|
198
|
+
postgres_namespace_prepare
|
|
199
|
+
postgres_secret_ensure
|
|
200
|
+
argocd_apply_application "$POSTGRES_APP" service "$POSTGRES_NS" \
|
|
201
|
+
"$DEVZONE_REPO_URL" "$(argocd_revision)" charts/devzone-postgres
|
|
202
|
+
echo "✔ Application $POSTGRES_APP declared; status: devzone workspace argocd status; local access: devzone workspace ports"
|
|
203
|
+
;;
|
|
204
|
+
disable)
|
|
205
|
+
yes="$(yes_flag "services disable postgres [--yes]" "$@")" || return 1
|
|
206
|
+
confirm_removal "Remove PostgreSQL and ALL its databases (Application and namespace $POSTGRES_NS)?" "$yes" || return 1
|
|
207
|
+
argocd_delete_application "$POSTGRES_APP"
|
|
208
|
+
ak delete namespace "$POSTGRES_NS" --wait=true --ignore-not-found >/dev/null
|
|
209
|
+
rm -rf "$PWD/workspace/.postgres"
|
|
210
|
+
argocd_passwords_refresh
|
|
211
|
+
echo "✔ postgres removed: Application, namespace $POSTGRES_NS and databases"
|
|
212
|
+
;;
|
|
213
|
+
esac
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
# devzone workspace argocd status | app …
|
|
217
|
+
argocd_cmd() {
|
|
218
|
+
case "${1:-status}" in
|
|
219
|
+
status | etat) argocd_status ;;
|
|
220
|
+
init)
|
|
221
|
+
gitops_init "${@:2}" || return $?
|
|
222
|
+
if argocd_installed; then gitops_root; fi
|
|
223
|
+
;;
|
|
224
|
+
apply)
|
|
225
|
+
if ! argocd_installed; then
|
|
226
|
+
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
227
|
+
return 1
|
|
228
|
+
fi
|
|
229
|
+
argocd_reconcile
|
|
230
|
+
;;
|
|
231
|
+
app)
|
|
232
|
+
if ! argocd_installed; then
|
|
233
|
+
echo "✖ Argo CD not installed: devzone workspace services enable argocd" >&2
|
|
234
|
+
return 1
|
|
235
|
+
fi
|
|
236
|
+
argocd_app "${@:2}"
|
|
237
|
+
;;
|
|
238
|
+
*)
|
|
239
|
+
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
|
|
240
|
+
return 1
|
|
241
|
+
;;
|
|
242
|
+
esac
|
|
243
|
+
}
|