devzone 7.5.0 → 7.5.2
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 +15 -16
- package/.devcontainer/devzone-status.sh +3 -3
- package/.devcontainer/services-admin.sh +1 -1
- package/bin/SHA256SUMS +6 -6
- package/bin/devzone-darwin-amd64 +0 -0
- package/bin/devzone-darwin-arm64 +0 -0
- package/bin/devzone-linux-amd64 +0 -0
- package/bin/devzone-linux-arm64 +0 -0
- package/bin/devzone-windows-amd64.exe +0 -0
- package/bin/devzone-windows-arm64.exe +0 -0
- package/manage/devzone +33 -13
- package/manage/scripts/workspace/argocd-services.sh +1 -1
- package/manage/scripts/workspace/argocd-workspace.sh +1 -1
- package/manage/workspace.sh +11 -27
- package/package.json +1 -1
- package/.devcontainer/devzone-repair.sh +0 -85
- package/.devcontainer/devzone-version.sh +0 -78
- package/.devcontainer/help.sh +0 -46
- package/manage/scripts/create-mode.sh +0 -103
- package/manage/scripts/devzone-create.sh +0 -110
- package/manage/scripts/devzone-update.sh +0 -237
- package/manage/scripts/kube-ready.sh +0 -75
- package/manage/scripts/workspace/ports-apps.sh +0 -156
- package/manage/scripts/workspace/ports-workspace.sh +0 -235
- package/manage/scripts/workspace/services-workspace.sh +0 -193
- package/manage/scripts/workspace/workspace-clone.sh +0 -12
- package/manage/scripts/workspace/workspace-copies.sh +0 -44
- package/manage/scripts/workspace/workspace-egress.sh +0 -184
- package/manage/scripts/workspace/workspace-update.sh +0 -106
- package/manage/scripts/workspace/workspace-wait.sh +0 -56
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Workspace mode at creation (#497): a new devzone is a Kubernetes workspace,
|
|
3
|
-
# so the cluster must answer. Without a cluster there is no fallback (#671):
|
|
4
|
-
# creation stops and lists the ways to get a cluster. The Docker workstation is
|
|
5
|
-
# retired (#735). Sourced by manage/devzone (creer): create_mode_choose runs
|
|
6
|
-
# before any file is copied (so --kubernetes without a cluster creates
|
|
7
|
-
# nothing), create_mode_write once the folder exists.
|
|
8
|
-
# Sourced only: no code at file level. Compatible with bash 3.2 (macOS).
|
|
9
|
-
# shellcheck disable=SC2034 # CREATE_MODE is read by manage/devzone (creer)
|
|
10
|
-
# shellcheck source=manage/scripts/kube-ready.sh
|
|
11
|
-
. "$(dirname "${BASH_SOURCE[0]}")/kube-ready.sh"
|
|
12
|
-
|
|
13
|
-
# Context shown to the user: devzone if declared, otherwise the current one.
|
|
14
|
-
kube_context() {
|
|
15
|
-
if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
|
|
16
|
-
echo devzone
|
|
17
|
-
else
|
|
18
|
-
kubectl config current-context 2>/dev/null || echo none
|
|
19
|
-
fi
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
# Prints, on stderr, how to get a cluster: devzone only displays the commands,
|
|
23
|
-
# it never runs them and no cloud credential goes through it.
|
|
24
|
-
create_mode_no_cluster() {
|
|
25
|
-
cat >&2 <<EOF
|
|
26
|
-
✖ Kubernetes not reachable: $1. Nothing created.
|
|
27
|
-
devzone runs in a Kubernetes cluster. Pick one, then run the same command again:
|
|
28
|
-
- a remote cluster (AWS, GCP, Azure, other): add its context to your kubeconfig, then select it
|
|
29
|
-
aws eks update-kubeconfig --name <cluster>
|
|
30
|
-
gcloud container clusters get-credentials <cluster>
|
|
31
|
-
az aks get-credentials --name <cluster> --resource-group <group>
|
|
32
|
-
kubectl config use-context <context>
|
|
33
|
-
- a local cluster: Docker Desktop (Settings > Kubernetes > Enable Kubernetes), or minikube
|
|
34
|
-
minikube start -p devzone
|
|
35
|
-
EOF
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
# Chooses the mode from the option (kubernetes or empty) and sets CREATE_MODE
|
|
39
|
-
# to kubernetes, with one line of notice. Returns 1, nothing set on disk, when
|
|
40
|
-
# the cluster does not answer.
|
|
41
|
-
create_mode_choose() {
|
|
42
|
-
local option="$1" reason
|
|
43
|
-
if reason="$(kube_ready_reason)"; then
|
|
44
|
-
CREATE_MODE=kubernetes
|
|
45
|
-
echo "✔ Kubernetes ready ($(kube_context)): workspace in the cluster"
|
|
46
|
-
create_mode_existing
|
|
47
|
-
return 0
|
|
48
|
-
fi
|
|
49
|
-
# No option, in a terminal: a menu (remote cluster, minikube) instead of a
|
|
50
|
-
# failure (#653); the choice is accepted only if the cluster then answers.
|
|
51
|
-
# The menu is the Go program's (#884), found through DEVZONE_HOST_BIN; without
|
|
52
|
-
# it no menu is offered (false), and the failure below lists the ways to get a cluster
|
|
53
|
-
if [ -z "$option" ] && "${DEVZONE_HOST_BIN:-false}" cluster-offer && reason="$(kube_ready_reason)"; then
|
|
54
|
-
CREATE_MODE=kubernetes
|
|
55
|
-
echo "✔ Kubernetes ready ($(kube_context)): workspace in the cluster"
|
|
56
|
-
create_mode_existing
|
|
57
|
-
return 0
|
|
58
|
-
fi
|
|
59
|
-
create_mode_no_cluster "$reason"
|
|
60
|
-
return 1
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
# A workspace already installed in the cluster (helm release devzone-workspace,
|
|
64
|
-
# or Argo CD Application devzone-workspace), from any folder: the new folder
|
|
65
|
-
# drives it too, and creation goes on (the start is a helm upgrade, the volumes
|
|
66
|
-
# stay). Notice only.
|
|
67
|
-
create_mode_existing() {
|
|
68
|
-
local ctx
|
|
69
|
-
ctx="$(kube_context)"
|
|
70
|
-
if helm status devzone-workspace --namespace devzone-workspace --kube-context "$ctx" >/dev/null 2>&1 ||
|
|
71
|
-
kubectl get application.argoproj.io devzone-workspace --namespace devzone-argocd --context "$ctx" >/dev/null 2>&1; then
|
|
72
|
-
echo "ℹ a devzone workspace already runs in this cluster: this folder drives it too"
|
|
73
|
-
fi
|
|
74
|
-
return 0
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
# Writes workspace=<mode> in <folder>/.devzone.modules: an earlier workspace=
|
|
78
|
-
# line is replaced, the other lines are kept.
|
|
79
|
-
create_mode_write() {
|
|
80
|
-
local folder="$1" mode="$2" f
|
|
81
|
-
f="$folder/.devzone.modules"
|
|
82
|
-
{
|
|
83
|
-
if [ -f "$f" ]; then grep -v '^workspace=' "$f" || true; fi
|
|
84
|
-
echo "workspace=$mode"
|
|
85
|
-
} >"$f.tmp" && mv "$f.tmp" "$f"
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
# Kubernetes creation: installs the workspace from the package script, run in
|
|
89
|
-
# the new folder (as devzone workspace start does). DEVZONE_WORKSPACE_SH
|
|
90
|
-
# replaces the script (tests); DEVZONE_NO_START only prints the command.
|
|
91
|
-
create_mode_start() {
|
|
92
|
-
local folder="$1" script="$2"
|
|
93
|
-
if [ -n "${DEVZONE_NO_START:-}" ]; then
|
|
94
|
-
echo "To start the workspace: cd $folder && devzone workspace start"
|
|
95
|
-
return 0
|
|
96
|
-
fi
|
|
97
|
-
echo "▶ Starting the workspace in the cluster (a few minutes the first time)…"
|
|
98
|
-
if ! (cd "$folder" && bash "${DEVZONE_WORKSPACE_SH:-$script}" start); then
|
|
99
|
-
echo "✖ Workspace not started. The folder is ready: only the start remains (cd $folder && devzone workspace start)" >&2
|
|
100
|
-
return 1
|
|
101
|
-
fi
|
|
102
|
-
echo "Next: cd $folder && devzone workspace shell (the pod)"
|
|
103
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Creation of a devzone (devzone <folder>): asks for the GitOps repository,
|
|
3
|
-
# copies the package, writes .argocd.conf and the manifest, then starts the
|
|
4
|
-
# workspace in the cluster. Sourced by manage/devzone,
|
|
5
|
-
# which defines PAQUET, PACKAGE_ITEMS and version(); devzone-manifest.sh must
|
|
6
|
-
# be sourced first.
|
|
7
|
-
# shellcheck disable=SC2154 # PAQUET, PACKAGE_ITEMS: set by manage/devzone
|
|
8
|
-
|
|
9
|
-
# GitOps repository of Argo CD for the creation (#539): github, an existing
|
|
10
|
-
# URL, or none. Asked in a terminal (default: github when gh is connected),
|
|
11
|
-
# or none with a notice without one (the --gitops option names the choice).
|
|
12
|
-
ask_gitops() {
|
|
13
|
-
local answer default=""
|
|
14
|
-
if gh auth status >/dev/null 2>&1; then
|
|
15
|
-
default="github"
|
|
16
|
-
fi
|
|
17
|
-
printf 'GitOps repository for Argo CD? [G]itHub (created under your gh account at first start) / a URL / [n]one : ' >&2
|
|
18
|
-
read -r answer || answer=""
|
|
19
|
-
answer="${answer:-$default}"
|
|
20
|
-
case "$answer" in
|
|
21
|
-
G | g | GitHub | github | y | Y | yes) echo "github" ;;
|
|
22
|
-
n | N | none | None) echo "none" ;;
|
|
23
|
-
*) echo "$answer" ;;
|
|
24
|
-
esac
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
create_workstation() {
|
|
28
|
-
local target="$1" gitops="" expect="" option="" arg value login name instance
|
|
29
|
-
shift
|
|
30
|
-
for arg in "$@"; do
|
|
31
|
-
if [ "$expect" = gitops ]; then gitops="$arg"; expect=""; continue; fi
|
|
32
|
-
case "$arg" in
|
|
33
|
-
--gitops) expect=gitops ;;
|
|
34
|
-
--gitops=*) gitops="${arg#--gitops=}" ;;
|
|
35
|
-
--kubernetes) option=kubernetes ;;
|
|
36
|
-
*) echo "✖ unknown option: $arg (devzone <folder> [--gitops github|none|<url>] [--kubernetes])" >&2; exit 1 ;;
|
|
37
|
-
esac
|
|
38
|
-
done
|
|
39
|
-
if [ -n "$expect" ]; then
|
|
40
|
-
echo "✖ --gitops expects a value (github, none or a URL)" >&2
|
|
41
|
-
exit 1
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
|
-
if [ -e "$target" ] && [ -n "$(ls -A "$target" 2>/dev/null)" ]; then
|
|
45
|
-
echo "✖ $target exists and is not empty: nothing is overwritten. Choose another folder." >&2
|
|
46
|
-
exit 1
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
# Mode before any copy: --kubernetes without a cluster creates nothing (#497)
|
|
50
|
-
# shellcheck source=SCRIPTDIR/create-mode.sh
|
|
51
|
-
. "$PAQUET/manage/scripts/create-mode.sh"
|
|
52
|
-
create_mode_choose "$option" || exit 1
|
|
53
|
-
|
|
54
|
-
if [ -z "$gitops" ]; then
|
|
55
|
-
if [ -t 0 ]; then
|
|
56
|
-
gitops="$(ask_gitops)"
|
|
57
|
-
else
|
|
58
|
-
echo "⚠ no GitOps repository for Argo CD: pass --gitops <github|none|https://github.com/<login>/<name>.git> to create a devzone without a terminal; using none" >&2
|
|
59
|
-
gitops="none"
|
|
60
|
-
fi
|
|
61
|
-
fi
|
|
62
|
-
mkdir -p "$target/workspace" "$target/manage"
|
|
63
|
-
cp -R "${PACKAGE_ITEMS[@]/#/$PAQUET/}" "$target/"
|
|
64
|
-
cp -R "$PAQUET/manage/scripts" "$target/manage/"
|
|
65
|
-
touch "$target/workspace/.gitkeep"
|
|
66
|
-
# npm never includes .gitignore: written here
|
|
67
|
-
: >"$target/.gitignore"
|
|
68
|
-
complete_gitignore "$target"
|
|
69
|
-
chmod +x "$target/manage/scripts/uninstall.sh"
|
|
70
|
-
create_mode_write "$target" "$CREATE_MODE"
|
|
71
|
-
# The GitOps repository of the new devzone (#539): github, an existing URL,
|
|
72
|
-
# or none, written in the .argocd.conf of the new devzone (conf.sh writes
|
|
73
|
-
# the header of the file when absent)
|
|
74
|
-
. "$PAQUET/.devcontainer/argocd/conf.sh"
|
|
75
|
-
# shellcheck disable=SC2034 # read by conf.sh
|
|
76
|
-
ARGOCD_CONF="$target/.argocd.conf"
|
|
77
|
-
if [ "$gitops" = github ]; then
|
|
78
|
-
if ! gh auth status >/dev/null 2>&1; then
|
|
79
|
-
echo "⚠ GitHub not connected (gh auth login): no GitOps repository, the Applications are applied directly; pass --gitops none" >&2
|
|
80
|
-
value="none"
|
|
81
|
-
else
|
|
82
|
-
login="$(gh api user --jq .login 2>/dev/null)" || login=""
|
|
83
|
-
if [ -z "$login" ]; then
|
|
84
|
-
echo "⚠ GitHub login unreadable (gh api user): no GitOps repository, the Applications are applied directly; pass --gitops none" >&2
|
|
85
|
-
value="none"
|
|
86
|
-
else
|
|
87
|
-
name="${DEVZONE_GITOPS_REPO_NAME:-devzone-argocd}"
|
|
88
|
-
instance="${DEVZONE_VOLUMES:-devzone}"
|
|
89
|
-
if [ "$instance" != "devzone" ]; then
|
|
90
|
-
name="$name-$instance"
|
|
91
|
-
fi
|
|
92
|
-
value="https://github.com/$login/$name.git"
|
|
93
|
-
fi
|
|
94
|
-
fi
|
|
95
|
-
elif [ "$gitops" = none ]; then
|
|
96
|
-
value="none"
|
|
97
|
-
else
|
|
98
|
-
value="$gitops"
|
|
99
|
-
fi
|
|
100
|
-
conf_set argocd "repo=$value"
|
|
101
|
-
case "$value" in
|
|
102
|
-
none) echo "✔ no GitOps repository: the Applications are applied directly (devzone workspace argocd init to change)" ;;
|
|
103
|
-
*) echo "✔ GitOps repository: $value ($target/.argocd.conf)" ;;
|
|
104
|
-
esac
|
|
105
|
-
target="$(cd "$target" && pwd)"
|
|
106
|
-
write_manifest "$target"
|
|
107
|
-
echo "✔ devzone $(version) created in $target"
|
|
108
|
-
# The workspace goes to the cluster (kube check done by create_mode_choose)
|
|
109
|
-
create_mode_start "$target" "$PAQUET/manage/workspace.sh"
|
|
110
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Update of a devzone (devzone update [--yes] [--no-rebuild]): replaces
|
|
3
|
-
# the files of the package, backs up the replaced or removed ones, removes the
|
|
4
|
-
# old layout, then offers the rebuild. Sourced by manage/devzone, after
|
|
5
|
-
# devzone-manifest.sh, which provides the manifest helpers.
|
|
6
|
-
# shellcheck disable=SC2154 # PAQUET: set by manage/devzone
|
|
7
|
-
|
|
8
|
-
# Starts the port watcher again when the legacy names migration stopped it: it
|
|
9
|
-
# leaves the file restart in the watcher folder, which a start or a stop by the
|
|
10
|
-
# user removes, so a watcher the user stopped is never started here. Called once
|
|
11
|
-
# the new files are in place. DEVZONE_PORTS_RESTART replaces the command (tests).
|
|
12
|
-
restart_ports_watcher() {
|
|
13
|
-
local folder="$1" marker="$1/.devzone.workspace-ports/restart"
|
|
14
|
-
[ -f "$marker" ] || return 0
|
|
15
|
-
rm -f "$marker"
|
|
16
|
-
if [ -n "${DEVZONE_PORTS_RESTART:-}" ]; then
|
|
17
|
-
(cd "$folder" && sh -c "$DEVZONE_PORTS_RESTART")
|
|
18
|
-
else
|
|
19
|
-
(cd "$folder" && bash manage/workspace.sh ports start)
|
|
20
|
-
fi || echo "devzone : port watcher not restarted: devzone workspace ports start" >&2
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
# Six steps of the update design (#349)
|
|
24
|
-
update_workstation() {
|
|
25
|
-
local assume_yes="" no_rebuild="" arg folder package installed package_list old_list
|
|
26
|
-
local missing rel current expected answer backup base n old f
|
|
27
|
-
for arg in "$@"; do
|
|
28
|
-
case "$arg" in
|
|
29
|
-
--yes) assume_yes=1 ;;
|
|
30
|
-
--no-rebuild) no_rebuild=1 ;;
|
|
31
|
-
*)
|
|
32
|
-
echo "✖ unknown option: $arg (devzone update [--yes] [--no-rebuild])" >&2
|
|
33
|
-
exit 1
|
|
34
|
-
;;
|
|
35
|
-
esac
|
|
36
|
-
done
|
|
37
|
-
if [ ! -d .devcontainer ]; then
|
|
38
|
-
echo "✖ Run this in a devzone folder (.devcontainer not found here)." >&2
|
|
39
|
-
exit 1
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
folder="$(pwd)"
|
|
43
|
-
package="$(version)"
|
|
44
|
-
installed="$(folder_version "$folder")"
|
|
45
|
-
work="$(mktemp -d)"
|
|
46
|
-
trap 'rm -rf "$work"' EXIT
|
|
47
|
-
package_list="$work/package-files"
|
|
48
|
-
old_list="$work/old-files"
|
|
49
|
-
relative_package_files >"$package_list"
|
|
50
|
-
manifest_files "$folder" | LC_ALL=C sort >"$old_list"
|
|
51
|
-
|
|
52
|
-
# 1. Versions and package files present
|
|
53
|
-
missing=""
|
|
54
|
-
while IFS= read -r rel; do
|
|
55
|
-
[ -f "$folder/$rel" ] || missing=1
|
|
56
|
-
done <"$package_list"
|
|
57
|
-
if [ "$installed" = "$package" ] && [ -z "$missing" ]; then
|
|
58
|
-
echo "✔ devzone $installed: already up to date."
|
|
59
|
-
echo "For the latest published version: npx devzone@latest update"
|
|
60
|
-
return 0
|
|
61
|
-
fi
|
|
62
|
-
echo "devzone: folder $installed, package $package"
|
|
63
|
-
|
|
64
|
-
# 2. Files modified locally (checksum different from the manifest; without
|
|
65
|
-
# a manifest, different from the one of the package)
|
|
66
|
-
: >"$work/modified"
|
|
67
|
-
: >"$work/to_save"
|
|
68
|
-
: >"$work/to_remove"
|
|
69
|
-
: >"$work/old_trees"
|
|
70
|
-
while IFS= read -r rel; do
|
|
71
|
-
[ -f "$folder/$rel" ] || continue
|
|
72
|
-
printf '%s\n' "$rel" >>"$work/to_save"
|
|
73
|
-
current="$(checksum "$folder/$rel")"
|
|
74
|
-
if expected="$(manifest_checksum "$folder" "$rel")"; then
|
|
75
|
-
:
|
|
76
|
-
else
|
|
77
|
-
expected="$(checksum "$PAQUET/$rel")"
|
|
78
|
-
fi
|
|
79
|
-
[ "$current" = "$expected" ] || printf '%s\n' "$rel" >>"$work/modified"
|
|
80
|
-
done <"$package_list"
|
|
81
|
-
while IFS= read -r rel; do
|
|
82
|
-
[ -n "$rel" ] || continue
|
|
83
|
-
if ! path_allowed "$rel"; then
|
|
84
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
85
|
-
continue
|
|
86
|
-
fi
|
|
87
|
-
in_list "$package_list" "$rel" && continue
|
|
88
|
-
is_protected "$rel" && continue
|
|
89
|
-
if ! inside_folder "$folder" "$rel"; then
|
|
90
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
91
|
-
continue
|
|
92
|
-
fi
|
|
93
|
-
printf '%s\n' "$rel" >>"$work/to_remove"
|
|
94
|
-
[ -f "$folder/$rel" ] || continue
|
|
95
|
-
printf '%s\n' "$rel" >>"$work/to_save"
|
|
96
|
-
if expected="$(manifest_checksum "$folder" "$rel")"; then
|
|
97
|
-
[ "$(checksum "$folder/$rel")" = "$expected" ] || printf '%s\n' "$rel" >>"$work/modified"
|
|
98
|
-
else
|
|
99
|
-
printf '%s\n' "$rel" >>"$work/modified"
|
|
100
|
-
fi
|
|
101
|
-
done <"$old_list"
|
|
102
|
-
for old in core scripts; do
|
|
103
|
-
[ -d "$folder/$old" ] || continue
|
|
104
|
-
old_tree "$folder" "$old" || continue
|
|
105
|
-
printf '%s\n' "$old" >>"$work/old_trees"
|
|
106
|
-
while IFS= read -r f; do
|
|
107
|
-
rel="${f#"$folder"/}"
|
|
108
|
-
if ! path_allowed "$rel"; then
|
|
109
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
110
|
-
continue
|
|
111
|
-
fi
|
|
112
|
-
is_protected "$rel" && continue
|
|
113
|
-
# A file unknown to the old package belongs to the user
|
|
114
|
-
known_old_file "$rel" || continue
|
|
115
|
-
printf '%s\n' "$rel" >>"$work/to_remove"
|
|
116
|
-
printf '%s\n' "$rel" >>"$work/to_save"
|
|
117
|
-
# Always confirmed: removing a file of the old package is a change,
|
|
118
|
-
# even with a manifest
|
|
119
|
-
printf '%s\n' "$rel" >>"$work/modified"
|
|
120
|
-
done < <(find "$folder/$old" -type f -print)
|
|
121
|
-
done
|
|
122
|
-
LC_ALL=C sort -u "$work/modified" >"$work/modified.sorted"
|
|
123
|
-
mv "$work/modified.sorted" "$work/modified"
|
|
124
|
-
LC_ALL=C sort -u "$work/to_save" >"$work/to_save.sorted"
|
|
125
|
-
mv "$work/to_save.sorted" "$work/to_save"
|
|
126
|
-
|
|
127
|
-
if [ -s "$work/modified" ]; then
|
|
128
|
-
echo "Locally modified files:"
|
|
129
|
-
while IFS= read -r rel; do
|
|
130
|
-
printf ' %s\n' "$rel"
|
|
131
|
-
done <"$work/modified"
|
|
132
|
-
if [ -z "$assume_yes" ]; then
|
|
133
|
-
if [ ! -t 0 ]; then
|
|
134
|
-
echo "✖ Locally modified files: rerun with --yes to replace them (backup in .devzone.backup/)." >&2
|
|
135
|
-
exit 1
|
|
136
|
-
fi
|
|
137
|
-
printf 'Replace these files (backup in .devzone.backup/)? [y/N] ' >&2
|
|
138
|
-
read -r answer || answer=""
|
|
139
|
-
case "$answer" in
|
|
140
|
-
y | Y | yes) ;;
|
|
141
|
-
*)
|
|
142
|
-
echo "Aborted: nothing was modified."
|
|
143
|
-
return 1
|
|
144
|
-
;;
|
|
145
|
-
esac
|
|
146
|
-
fi
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
# 3. Backup of every file replaced or removed
|
|
150
|
-
if [ -s "$work/to_save" ]; then
|
|
151
|
-
base="$folder/.devzone.backup/$(date +%Y%m%d-%H%M%S)"
|
|
152
|
-
backup="$base"
|
|
153
|
-
n=1
|
|
154
|
-
while [ -e "$backup" ]; do
|
|
155
|
-
n=$((n + 1))
|
|
156
|
-
backup="$base-$n"
|
|
157
|
-
done
|
|
158
|
-
while IFS= read -r rel; do
|
|
159
|
-
[ -f "$folder/$rel" ] || continue
|
|
160
|
-
if ! inside_folder "$folder" "$rel"; then
|
|
161
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
162
|
-
continue
|
|
163
|
-
fi
|
|
164
|
-
mkdir -p "$backup/$(dirname "$rel")"
|
|
165
|
-
# -P: a link is backed up as it is, never its target
|
|
166
|
-
cp -P -p "$folder/$rel" "$backup/$rel"
|
|
167
|
-
done <"$work/to_save"
|
|
168
|
-
echo "Sauvegarde : $backup"
|
|
169
|
-
fi
|
|
170
|
-
|
|
171
|
-
# 4. Replacement, removal of the old package and of the old layout,
|
|
172
|
-
# .gitignore completed without being overwritten
|
|
173
|
-
complete_gitignore "$folder"
|
|
174
|
-
while IFS= read -r rel; do
|
|
175
|
-
mkdir -p "$folder/$(dirname "$rel")"
|
|
176
|
-
if ! inside_folder "$folder" "$rel"; then
|
|
177
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
178
|
-
continue
|
|
179
|
-
fi
|
|
180
|
-
# Never write through a link: the link (not its target) is removed
|
|
181
|
-
if [ -L "$folder/$rel" ]; then
|
|
182
|
-
rm -f -- "$folder/$rel"
|
|
183
|
-
echo "devzone: manifest: link replaced: $rel" >&2
|
|
184
|
-
fi
|
|
185
|
-
cp -p "$PAQUET/$rel" "$folder/$rel"
|
|
186
|
-
if [ -x "$PAQUET/$rel" ]; then
|
|
187
|
-
chmod +x "$folder/$rel"
|
|
188
|
-
fi
|
|
189
|
-
done <"$package_list"
|
|
190
|
-
while IFS= read -r rel; do
|
|
191
|
-
[ -n "$rel" ] || continue
|
|
192
|
-
[ -f "$folder/$rel" ] || continue
|
|
193
|
-
if ! inside_folder "$folder" "$rel"; then
|
|
194
|
-
echo "devzone: manifest: refused path: $rel" >&2
|
|
195
|
-
continue
|
|
196
|
-
fi
|
|
197
|
-
# rm does not follow links: only the link is removed, never its target
|
|
198
|
-
rm -f -- "$folder/$rel"
|
|
199
|
-
done <"$work/to_remove"
|
|
200
|
-
while IFS= read -r old; do
|
|
201
|
-
[ -n "$old" ] || continue
|
|
202
|
-
[ -d "$folder/$old" ] || continue
|
|
203
|
-
# Only the folders that became empty are removed, never their content
|
|
204
|
-
find "$folder/$old" -depth -type d -empty -delete
|
|
205
|
-
done <"$work/old_trees"
|
|
206
|
-
|
|
207
|
-
# 6. New manifest, then rebuild offered
|
|
208
|
-
write_manifest "$folder"
|
|
209
|
-
echo "✔ devzone $package: updated."
|
|
210
|
-
restart_ports_watcher "$folder"
|
|
211
|
-
# the update never changes the workstation mode (#472)
|
|
212
|
-
if [ "$(grep -E '^workspace=' "$folder/.devzone.modules" 2>/dev/null | tail -1)" = "workspace=kubernetes" ]; then
|
|
213
|
-
return 0
|
|
214
|
-
fi
|
|
215
|
-
if [ -n "$no_rebuild" ]; then
|
|
216
|
-
echo "Rebuild not started (--no-rebuild)."
|
|
217
|
-
return 0
|
|
218
|
-
fi
|
|
219
|
-
if [ ! -t 0 ]; then
|
|
220
|
-
echo "Rebuild: make -C $folder rebuild (run in a terminal)"
|
|
221
|
-
return 0
|
|
222
|
-
fi
|
|
223
|
-
printf 'Rebuild the container now? [y/N] ' >&2
|
|
224
|
-
read -r answer || answer=""
|
|
225
|
-
case "$answer" in
|
|
226
|
-
y | Y | yes) ;;
|
|
227
|
-
*)
|
|
228
|
-
echo "Rebuild not started: make -C $folder rebuild"
|
|
229
|
-
return 0
|
|
230
|
-
;;
|
|
231
|
-
esac
|
|
232
|
-
if [ -n "${DEVZONE_REBUILD:-}" ]; then
|
|
233
|
-
sh -c "$DEVZONE_REBUILD"
|
|
234
|
-
else
|
|
235
|
-
make -C "$folder" rebuild
|
|
236
|
-
fi
|
|
237
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Shared check of the Kubernetes cluster (#497, #565), sourced by create-mode.sh,
|
|
3
|
-
# create-mode.sh (creation) and workspace.sh (workspace start). Sourced only:
|
|
4
|
-
# no code at file level. Compatible with bash 3.2 (macOS) and Linux.
|
|
5
|
-
|
|
6
|
-
# Returns 0 when kubectl and helm are present and the cluster answers within 5 s
|
|
7
|
-
# (context devzone if declared, otherwise the current context). Otherwise
|
|
8
|
-
# prints one short line on stdout (kubectl missing, helm missing, or
|
|
9
|
-
# cluster <context> unreachable (<server>)) and returns 1. With --hint, prints
|
|
10
|
-
# the message for the user instead (#565, see kube_unreachable_hint).
|
|
11
|
-
kube_ready_reason() {
|
|
12
|
-
local context server hint=no
|
|
13
|
-
[ "${1:-}" = --hint ] && hint=yes
|
|
14
|
-
command -v kubectl >/dev/null 2>&1 || {
|
|
15
|
-
kube_say "kubectl missing" "$hint"
|
|
16
|
-
return 1
|
|
17
|
-
}
|
|
18
|
-
command -v helm >/dev/null 2>&1 || {
|
|
19
|
-
kube_say "helm missing" "$hint"
|
|
20
|
-
return 1
|
|
21
|
-
}
|
|
22
|
-
if kubectl config get-contexts -o name 2>/dev/null | grep -qx 'devzone'; then
|
|
23
|
-
kubectl cluster-info --request-timeout=5s --context devzone >/dev/null 2>&1 && return 0
|
|
24
|
-
context=devzone
|
|
25
|
-
server="$(kubectl config view --minify --context devzone -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
26
|
-
else
|
|
27
|
-
kubectl cluster-info --request-timeout=5s >/dev/null 2>&1 && return 0
|
|
28
|
-
context="$(kubectl config current-context 2>/dev/null || true)"
|
|
29
|
-
server="$(kubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}' 2>/dev/null || true)"
|
|
30
|
-
fi
|
|
31
|
-
if [ "$hint" = yes ]; then
|
|
32
|
-
kube_unreachable_hint "${context:-none}" "${server:-unknown server}"
|
|
33
|
-
else
|
|
34
|
-
echo "cluster ${context:-none} unreachable (${server:-unknown server})"
|
|
35
|
-
fi
|
|
36
|
-
return 1
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
# One reason line: as is, or as a ✖ line for the user (--hint).
|
|
40
|
-
kube_say() {
|
|
41
|
-
if [ "$2" = yes ]; then
|
|
42
|
-
echo "✖ $1"
|
|
43
|
-
else
|
|
44
|
-
echo "$1"
|
|
45
|
-
fi
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
# Cluster name of a context (empty when unknown).
|
|
49
|
-
kube_context_cluster() {
|
|
50
|
-
kubectl config view --minify --context "$1" -o 'jsonpath={.clusters[0].name}' 2>/dev/null || true
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
# Message of an unreachable cluster <context> at <server> (#565). The cluster of
|
|
54
|
-
# Docker Desktop (context docker-desktop, or a local server 127.0.0.1 or
|
|
55
|
-
# localhost of a cluster named docker-desktop) runs inside Docker Desktop: when
|
|
56
|
-
# docker info fails, the cause is Docker Desktop stopped; when Docker answers,
|
|
57
|
-
# Kubernetes is disabled in it. Any other context gets the generic message.
|
|
58
|
-
kube_unreachable_hint() {
|
|
59
|
-
local context="$1" server="$2" cluster host
|
|
60
|
-
cluster="$(kube_context_cluster "$context")"
|
|
61
|
-
host="${server#*://}"
|
|
62
|
-
host="${host%%[:/]*}"
|
|
63
|
-
if [ "$context" = docker-desktop ] ||
|
|
64
|
-
{ [ "$cluster" = docker-desktop ] && { [ "$host" = 127.0.0.1 ] || [ "$host" = localhost ]; }; }; then
|
|
65
|
-
if ! docker info >/dev/null 2>&1; then
|
|
66
|
-
echo "✖ Docker Desktop is stopped: the Kubernetes cluster of this machine runs inside it. Start Docker Desktop, then: devzone workspace start"
|
|
67
|
-
echo " Tip: Settings → General → Start Docker Desktop when you sign in"
|
|
68
|
-
else
|
|
69
|
-
echo "✖ Kubernetes cluster $context unreachable ($server): enable Kubernetes in Docker Desktop (Settings → Kubernetes) or check kubectl config get-contexts"
|
|
70
|
-
fi
|
|
71
|
-
return 0
|
|
72
|
-
fi
|
|
73
|
-
echo "✖ Kubernetes cluster $context unreachable ($server)"
|
|
74
|
-
echo " Check the contexts: kubectl config get-contexts"
|
|
75
|
-
}
|