[ci skip] openclaw: cache tools on NFS for fast restarts
- Switch /tools volume from emptyDir to NFS (/mnt/main/openclaw/tools) - Skip download of kubectl, terraform, terragrunt, pip packages if cached - Startup time: ~2.5min → ~38s on subsequent restarts
This commit is contained in:
parent
fd0c85c9cc
commit
e8ff760aff
2 changed files with 36 additions and 14 deletions
Binary file not shown.
|
|
@ -209,7 +209,7 @@ resource "kubernetes_deployment" "openclaw" {
|
||||||
spec {
|
spec {
|
||||||
service_account_name = kubernetes_service_account.openclaw.metadata[0].name
|
service_account_name = kubernetes_service_account.openclaw.metadata[0].name
|
||||||
|
|
||||||
# Init container: Download tools + clone repo (parallelized)
|
# Init container: Download tools + clone repo (parallelized, cached on NFS)
|
||||||
init_container {
|
init_container {
|
||||||
name = "setup"
|
name = "setup"
|
||||||
image = "alpine:3.20"
|
image = "alpine:3.20"
|
||||||
|
|
@ -217,9 +217,14 @@ resource "kubernetes_deployment" "openclaw" {
|
||||||
set -e
|
set -e
|
||||||
apk add --no-cache curl unzip git-crypt openssh-client git bash
|
apk add --no-cache curl unzip git-crypt openssh-client git bash
|
||||||
|
|
||||||
# Install pip and Python packages for skills
|
# Install Python packages (skip if already cached)
|
||||||
python3 -m ensurepip 2>/dev/null || apk add --no-cache py3-pip
|
if [ ! -f /tools/python-libs/.installed ]; then
|
||||||
pip3 install --break-system-packages --target=/tools/python-libs requests caldav icalendar uptime-kuma-api
|
python3 -m ensurepip 2>/dev/null || apk add --no-cache py3-pip
|
||||||
|
pip3 install --break-system-packages --target=/tools/python-libs requests caldav icalendar uptime-kuma-api
|
||||||
|
touch /tools/python-libs/.installed
|
||||||
|
else
|
||||||
|
echo "Python packages already cached, skipping pip install"
|
||||||
|
fi
|
||||||
|
|
||||||
# Copy OpenClaw config to writable home dir
|
# Copy OpenClaw config to writable home dir
|
||||||
cp /openclaw-config-src/openclaw.json /openclaw-home/openclaw.json
|
cp /openclaw-config-src/openclaw.json /openclaw-home/openclaw.json
|
||||||
|
|
@ -230,21 +235,35 @@ resource "kubernetes_deployment" "openclaw" {
|
||||||
chmod 600 /root/.ssh/id_rsa
|
chmod 600 /root/.ssh/id_rsa
|
||||||
ssh-keyscan github.com >> /root/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan github.com >> /root/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
# --- Run downloads and clone in parallel ---
|
# --- Download tools only if missing or version changed ---
|
||||||
# kubectl
|
# kubectl
|
||||||
(curl -sL --retry 3 --retry-delay 5 "https://dl.k8s.io/release/v1.34.2/bin/linux/amd64/kubectl" -o /tools/kubectl && chmod +x /tools/kubectl) &
|
if [ ! -x /tools/kubectl ]; then
|
||||||
PID_KUBECTL=$!
|
(curl -sL --retry 3 --retry-delay 5 "https://dl.k8s.io/release/v1.34.2/bin/linux/amd64/kubectl" -o /tools/kubectl && chmod +x /tools/kubectl) &
|
||||||
|
PID_KUBECTL=$!
|
||||||
|
else
|
||||||
|
echo "kubectl already cached" & PID_KUBECTL=$!
|
||||||
|
fi
|
||||||
|
|
||||||
# terraform
|
# terraform
|
||||||
(curl -sL --retry 3 --retry-delay 5 "https://releases.hashicorp.com/terraform/1.14.5/terraform_1.14.5_linux_amd64.zip" -o /tmp/tf.zip && unzip -q /tmp/tf.zip -d /tools && chmod +x /tools/terraform && rm /tmp/tf.zip) &
|
if [ ! -x /tools/terraform ]; then
|
||||||
PID_TF=$!
|
(curl -sL --retry 3 --retry-delay 5 "https://releases.hashicorp.com/terraform/1.14.5/terraform_1.14.5_linux_amd64.zip" -o /tmp/tf.zip && unzip -q /tmp/tf.zip -d /tools && chmod +x /tools/terraform && rm /tmp/tf.zip) &
|
||||||
|
PID_TF=$!
|
||||||
|
else
|
||||||
|
echo "terraform already cached" & PID_TF=$!
|
||||||
|
fi
|
||||||
|
|
||||||
# terragrunt
|
# terragrunt
|
||||||
(curl -sL --retry 3 --retry-delay 5 "https://github.com/gruntwork-io/terragrunt/releases/download/v0.99.4/terragrunt_linux_amd64" -o /tools/terragrunt && chmod +x /tools/terragrunt) &
|
if [ ! -x /tools/terragrunt ]; then
|
||||||
PID_TG=$!
|
(curl -sL --retry 3 --retry-delay 5 "https://github.com/gruntwork-io/terragrunt/releases/download/v0.99.4/terragrunt_linux_amd64" -o /tools/terragrunt && chmod +x /tools/terragrunt) &
|
||||||
|
PID_TG=$!
|
||||||
|
else
|
||||||
|
echo "terragrunt already cached" & PID_TG=$!
|
||||||
|
fi
|
||||||
|
|
||||||
# git-crypt (already installed via apk)
|
# git-crypt
|
||||||
cp /usr/bin/git-crypt /tools/git-crypt
|
if [ ! -x /tools/git-crypt ]; then
|
||||||
|
cp /usr/bin/git-crypt /tools/git-crypt
|
||||||
|
fi
|
||||||
|
|
||||||
# Clone/pull repo
|
# Clone/pull repo
|
||||||
if [ ! -d /workspace/infra/.git ]; then
|
if [ ! -d /workspace/infra/.git ]; then
|
||||||
|
|
@ -423,7 +442,10 @@ resource "kubernetes_deployment" "openclaw" {
|
||||||
|
|
||||||
volume {
|
volume {
|
||||||
name = "tools"
|
name = "tools"
|
||||||
empty_dir {}
|
nfs {
|
||||||
|
server = var.nfs_server
|
||||||
|
path = "/mnt/main/openclaw/tools"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
volume {
|
volume {
|
||||||
name = "openclaw-home"
|
name = "openclaw-home"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue