devzone 7.6.0 → 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 +0 -8
- 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/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
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
|
|
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/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
|
-
}
|