feat: add node env build

This commit is contained in:
engigu
2025-12-23 22:42:51 +08:00
parent e3b005a6be
commit 08f42778a6
+25 -22
View File
@@ -4,16 +4,23 @@ set -e
PYTHON_VENV_DIR="/app/envs/python" PYTHON_VENV_DIR="/app/envs/python"
NODE_ENV_DIR="/app/envs/node" NODE_ENV_DIR="/app/envs/node"
echo "[entrypoint] Starting environment initialization..."
# ============================ # ============================
# 创建基础目录 # 创建基础目录
# ============================ # ============================
mkdir -p /app/data /app/data/scripts /app/configs /app/envs mkdir -p \
/app/data \
/app/data/scripts \
/app/configs \
/app/envs \
"$NODE_ENV_DIR"
# ============================ # ============================
# Python 虚拟环境 # Python 虚拟环境
# ============================ # ============================
if [ ! -x "$PYTHON_VENV_DIR/bin/python" ]; then if [ ! -x "$PYTHON_VENV_DIR/bin/python" ]; then
echo "[entrypoint] Creating Python venv..." echo "[entrypoint] Creating Python virtual environment..."
python3 -m venv "$PYTHON_VENV_DIR" python3 -m venv "$PYTHON_VENV_DIR"
"$PYTHON_VENV_DIR/bin/pip" install --upgrade pip setuptools wheel "$PYTHON_VENV_DIR/bin/pip" install --upgrade pip setuptools wheel
"$PYTHON_VENV_DIR/bin/pip" config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple "$PYTHON_VENV_DIR/bin/pip" config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
@@ -22,41 +29,37 @@ else
fi fi
# ============================ # ============================
# Node 本地环境(npm prefix 方案) # Node 环境(npm prefix 方案,核心
# ============================ # ============================
if [ ! -d "$NODE_ENV_DIR/node_modules" ]; then echo "[entrypoint] Initializing Node npm prefix..."
echo "[entrypoint] Initializing Node environment..."
mkdir -p "$NODE_ENV_DIR"
cd "$NODE_ENV_DIR"
npm init -y >/dev/null 2>&1
else
echo "[entrypoint] Node environment exists"
fi
# ============================ # npm 全局安装目录 → /app/envs/node
# npm / Node 内存与行为控制(关键) npm config set prefix "$NODE_ENV_DIR"
# ============================
export NODE_OPTIONS="--max-old-space-size=256"
# npm 行为优化(防内存暴涨)
npm config set registry https://registry.npmmirror.com npm config set registry https://registry.npmmirror.com
npm config set audit false npm config set audit false
npm config set fund false npm config set fund false
npm config set progress false npm config set progress false
npm config set maxsockets 2 npm config set maxsockets 2
# ============================ # Node 内存限制(非常关键)
# 环境变量注入(等价于 activate) export NODE_OPTIONS="--max-old-space-size=256"
# ============================
export PATH="$PYTHON_VENV_DIR/bin:$NODE_ENV_DIR/node_modules/.bin:$PATH"
export NODE_PATH="$NODE_ENV_DIR/node_modules"
# ============================ # ============================
# 打印确认(非常建议保留 # 环境变量注入(等价 activate
# ============================
export PATH="$PYTHON_VENV_DIR/bin:$NODE_ENV_DIR/bin:$PATH"
export NODE_PATH="$NODE_ENV_DIR/lib/node_modules"
# ============================
# 打印确认(强烈建议保留)
# ============================ # ============================
echo "[entrypoint] python: $(which python)" echo "[entrypoint] python: $(which python)"
echo "[entrypoint] pip: $(which pip)" echo "[entrypoint] pip: $(which pip)"
echo "[entrypoint] node: $(which node)" echo "[entrypoint] node: $(which node)"
echo "[entrypoint] npm root: $(npm root --prefix $NODE_ENV_DIR)" echo "[entrypoint] npm prefix: $(npm config get prefix)"
echo "[entrypoint] npm root: $(npm root -g)"
# ============================ # ============================
# 启动应用 # 启动应用