feat: auto-tune swap and Node.js memory based on VPS RAM
Some checks failed
Docker Cloud Build / Build & Publish Image (push) Failing after 36m19s
Some checks failed
Docker Cloud Build / Build & Publish Image (push) Failing after 36m19s
install.sh: detect RAM at runner install time and create swap only when needed (<2GB → 2G swap, 2-4GB → 1G swap, >4GB → no swap). workflow: detect RAM at build time and set NODE_OPTIONS accordingly (<2GB → 768MB, 2-4GB → 1536MB, >4GB → 3072MB). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
89c9ed842f
commit
23f197aeb1
2 changed files with 33 additions and 12 deletions
12
.github/workflows/docker-publish.yml
vendored
12
.github/workflows/docker-publish.yml
vendored
|
|
@ -45,9 +45,17 @@ jobs:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
- name: Install Frontend Dependencies & Build
|
- name: Install Frontend Dependencies & Build
|
||||||
env:
|
|
||||||
NODE_OPTIONS: "--max-old-space-size=768"
|
|
||||||
run: |
|
run: |
|
||||||
|
total_ram_mb=$(awk '/MemTotal/ { printf "%d", $2/1024 }' /proc/meminfo)
|
||||||
|
if [ "$total_ram_mb" -lt 2048 ]; then
|
||||||
|
node_mem=768
|
||||||
|
elif [ "$total_ram_mb" -lt 4096 ]; then
|
||||||
|
node_mem=1536
|
||||||
|
else
|
||||||
|
node_mem=3072
|
||||||
|
fi
|
||||||
|
echo "RAM: ${total_ram_mb}MB — setting Node.js max to ${node_mem}MB"
|
||||||
|
export NODE_OPTIONS="--max-old-space-size=${node_mem}"
|
||||||
cd frontend
|
cd frontend
|
||||||
yarn install --frozen-lockfile
|
yarn install --frozen-lockfile
|
||||||
yarn locale-compile
|
yarn locale-compile
|
||||||
|
|
|
||||||
21
install.sh
21
install.sh
|
|
@ -778,18 +778,31 @@ do_forgejo_runner_install() {
|
||||||
|
|
||||||
mkdir -p "$FORGEJO_RUNNER_DIR"
|
mkdir -p "$FORGEJO_RUNNER_DIR"
|
||||||
|
|
||||||
# Ensure swap exists for low-RAM VPS (Docker image builds need ~2GB memory)
|
# Auto-configure swap based on available RAM
|
||||||
|
local total_ram_mb
|
||||||
|
total_ram_mb=$(awk '/MemTotal/ { printf "%d", $2/1024 }' /proc/meminfo)
|
||||||
|
local swap_size=""
|
||||||
|
if [ "$total_ram_mb" -lt 2048 ]; then
|
||||||
|
swap_size="2G"
|
||||||
|
elif [ "$total_ram_mb" -lt 4096 ]; then
|
||||||
|
swap_size="1G"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$swap_size" ]; then
|
||||||
if [ ! -f /swapfile ]; then
|
if [ ! -f /swapfile ]; then
|
||||||
log_step "Creating 2GB swapfile for build memory..."
|
log_step "RAM: ${total_ram_mb}MB detected — creating ${swap_size} swapfile..."
|
||||||
fallocate -l 2G /swapfile
|
fallocate -l "$swap_size" /swapfile
|
||||||
chmod 600 /swapfile
|
chmod 600 /swapfile
|
||||||
mkswap /swapfile > /dev/null
|
mkswap /swapfile > /dev/null
|
||||||
swapon /swapfile
|
swapon /swapfile
|
||||||
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
||||||
log_ok "Swapfile created and enabled (persistent across reboots)."
|
log_ok "Swapfile ${swap_size} created and enabled (persistent across reboots)."
|
||||||
else
|
else
|
||||||
log_ok "Swapfile already exists, skipping."
|
log_ok "Swapfile already exists, skipping."
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
log_ok "RAM: ${total_ram_mb}MB — sufficient, no swap needed."
|
||||||
|
fi
|
||||||
|
|
||||||
# gitea/act_runner auto-registers on first start via env vars, then starts daemon
|
# gitea/act_runner auto-registers on first start via env vars, then starts daemon
|
||||||
log_step "Starting Forgejo Runner (auto-register on first boot)..."
|
log_step "Starting Forgejo Runner (auto-register on first boot)..."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue