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

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:
xtcnet 2026-03-17 23:30:17 +07:00
parent 89c9ed842f
commit 23f197aeb1
2 changed files with 33 additions and 12 deletions

View file

@ -45,9 +45,17 @@ jobs:
node-version: 20
- name: Install Frontend Dependencies & Build
env:
NODE_OPTIONS: "--max-old-space-size=768"
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
yarn install --frozen-lockfile
yarn locale-compile

View file

@ -778,17 +778,30 @@ do_forgejo_runner_install() {
mkdir -p "$FORGEJO_RUNNER_DIR"
# Ensure swap exists for low-RAM VPS (Docker image builds need ~2GB memory)
if [ ! -f /swapfile ]; then
log_step "Creating 2GB swapfile for build memory..."
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile > /dev/null
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
log_ok "Swapfile created and enabled (persistent across reboots)."
# 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
log_step "RAM: ${total_ram_mb}MB detected — creating ${swap_size} swapfile..."
fallocate -l "$swap_size" /swapfile
chmod 600 /swapfile
mkswap /swapfile > /dev/null
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
log_ok "Swapfile ${swap_size} created and enabled (persistent across reboots)."
else
log_ok "Swapfile already exists, skipping."
fi
else
log_ok "Swapfile already exists, skipping."
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