82 lines
3.5 KiB
Bash
Executable File
82 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
if [[ ${WSL_DISTRO_NAME:-} != WebUp-Local || $EUID != 0 ]]; then
|
|
echo 'Run as root inside the dedicated WebUp-Local WSL distribution.' >&2
|
|
exit 1
|
|
fi
|
|
project_root=$(realpath "$1")
|
|
cache="$project_root/.tools/local-cluster"
|
|
lock="$project_root/infra/local/versions.json"
|
|
if [[ $(uname -m) != x86_64 ]]; then echo 'Pinned artifacts require x86_64.' >&2; exit 1; fi
|
|
python3 - "$lock" "$cache" <<'PY'
|
|
import hashlib,json,pathlib,sys
|
|
config=json.load(open(sys.argv[1]));root=pathlib.Path(sys.argv[2])
|
|
for name,metadata in config['files'].items():
|
|
digest=hashlib.file_digest(open(root/name,'rb'),'sha256').hexdigest()
|
|
if digest!=metadata['sha256']:raise SystemExit('Checksum mismatch: '+name)
|
|
print('All official artifact checksums verified.')
|
|
PY
|
|
if [[ -e /etc/rancher/k3s/config.yaml && ! -e /etc/webup-local/environment ]]; then
|
|
echo 'An unowned K3s installation already exists; refusing to overwrite it.' >&2
|
|
exit 1
|
|
fi
|
|
install -d -m 0755 /etc/webup-local /opt/webup-local /etc/rancher/k3s
|
|
printf '%s\n' WebUp-Local > /etc/webup-local/environment
|
|
cp "$lock" /etc/webup-local/artifact-lock.json
|
|
gvisor_release=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["gvisorRelease"])' "$lock")
|
|
gvisor_dir="/opt/webup-local/$gvisor_release"
|
|
install -d -m 0755 "$gvisor_dir"
|
|
if [[ ! -e "$gvisor_dir/.complete" ]]; then
|
|
python3 - "$cache/gvisor-x86_64.tar.bz2" "$gvisor_dir" <<'PY'
|
|
import tarfile,sys
|
|
with tarfile.open(sys.argv[1]) as archive:archive.extractall(sys.argv[2],filter='data')
|
|
PY
|
|
chmod 0755 "$gvisor_dir/runsc" "$gvisor_dir/containerd-shim-runsc-v1"
|
|
touch "$gvisor_dir/.complete"
|
|
fi
|
|
ln -sfn "$gvisor_dir/runsc" /usr/local/bin/runsc
|
|
ln -sfn "$gvisor_dir/containerd-shim-runsc-v1" /usr/local/bin/containerd-shim-runsc-v1
|
|
install -m 0755 "$cache/k3s" /usr/local/bin/k3s
|
|
install -d -m 0755 /var/lib/rancher/k3s/agent/etc/containerd /var/lib/rancher/k3s/agent/etc/kubelet.conf.d /var/lib/rancher/k3s/agent/images
|
|
cat > /var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.tmpl <<'TOML'
|
|
{{ template "base" . }}
|
|
[plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runsc]
|
|
runtime_type = "io.containerd.runsc.v1"
|
|
TOML
|
|
cat > /var/lib/rancher/k3s/agent/etc/kubelet.conf.d/20-webup-pids.conf <<'YAML'
|
|
apiVersion: kubelet.config.k8s.io/v1beta1
|
|
kind: KubeletConfiguration
|
|
podPidsLimit: 512
|
|
YAML
|
|
cat > /etc/rancher/k3s/config.yaml <<'YAML'
|
|
node-name: webup-local
|
|
write-kubeconfig-mode: "0600"
|
|
disable:
|
|
- traefik
|
|
- servicelb
|
|
secrets-encryption: true
|
|
YAML
|
|
if [[ ! -e /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst ]]; then
|
|
cp "$cache/k3s-airgap-images-amd64.tar.zst" /var/lib/rancher/k3s/agent/images/
|
|
fi
|
|
version=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["k3sVersion"])' "$lock")
|
|
INSTALL_K3S_VERSION="$version" INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_SKIP_START=true sh "$cache/install-k3s.sh" server
|
|
systemctl start k3s
|
|
for attempt in $(seq 1 60); do
|
|
if k3s kubectl get node webup-local >/dev/null 2>&1; then break; fi
|
|
sleep 2
|
|
done
|
|
k3s kubectl wait --for=condition=Ready node/webup-local --timeout=120s
|
|
cat <<'YAML' | k3s kubectl apply -f -
|
|
apiVersion: node.k8s.io/v1
|
|
kind: RuntimeClass
|
|
metadata:
|
|
name: gvisor
|
|
handler: runsc
|
|
YAML
|
|
k3s kubectl apply -f "$project_root/infra/k8s/sandbox-rbac.yaml"
|
|
k3s kubectl apply -f "$project_root/infra/k8s/runtime-rbac.yaml"
|
|
k3s kubectl apply -f "$project_root/infra/k8s/review-rbac.yaml"
|
|
k3s kubectl get nodes
|
|
echo 'Local K3s installed. Isolation smoke tests are required before enabling AI execution.'
|