From ac859d56079cc29a8d705d292167826364bc97af Mon Sep 17 00:00:00 2001 From: hectorzhao Date: Tue, 7 Jul 2026 15:04:19 +0800 Subject: [PATCH] fix: install node from official tarball in bootstrap --- docs/production-deployment.md | 2 +- tools/deploy/production-bootstrap.sh | 41 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/docs/production-deployment.md b/docs/production-deployment.md index 67af10c..469d9c7 100644 --- a/docs/production-deployment.md +++ b/docs/production-deployment.md @@ -35,7 +35,7 @@ PROD_ADMIN_USERNAME=prod_admin PROD_ADMIN_PASSWORD='change-me' ``` -脚本会安装 Node.js、Go、PostgreSQL、Redis、MinIO、Nginx,创建 systemd 服务,执行 Prisma migrate,构建前端/API/Gateway,并创建平台管理员。Go 和 MinIO 下载会按服务器架构自动选择 `linux-amd64` 或 `linux-arm64`。 +脚本会安装 Node.js、Go、PostgreSQL、Redis、MinIO、Nginx,创建 systemd 服务,执行 Prisma migrate,构建前端/API/Gateway,并创建平台管理员。Node.js、Go 和 MinIO 下载会按服务器架构自动选择 x64/amd64 或 arm64。 ## 后续发布 diff --git a/tools/deploy/production-bootstrap.sh b/tools/deploy/production-bootstrap.sh index d4b675e..63e3312 100644 --- a/tools/deploy/production-bootstrap.sh +++ b/tools/deploy/production-bootstrap.sh @@ -29,35 +29,45 @@ install_packages() { log "Installing OS packages" if command -v apt-get >/dev/null 2>&1; then apt-get update - DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl gnupg git nginx redis-server postgresql postgresql-contrib build-essential tar gzip openssl - if ! command -v node >/dev/null 2>&1 || [[ "$(node -v | sed 's/^v//' | cut -d. -f1)" -lt 22 ]]; then - curl -fsSL https://deb.nodesource.com/setup_22.x | bash - - DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs - fi + DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl gnupg git nginx redis-server postgresql postgresql-contrib build-essential tar gzip xz-utils openssl elif command -v dnf >/dev/null 2>&1; then - dnf install -y ca-certificates curl git nginx redis postgresql-server postgresql-contrib gcc gcc-c++ make tar gzip openssl + dnf install -y ca-certificates curl git nginx redis postgresql-server postgresql-contrib gcc gcc-c++ make tar gzip xz openssl if [[ ! -d /var/lib/pgsql/data/base ]]; then postgresql-setup --initdb fi - if ! command -v node >/dev/null 2>&1 || [[ "$(node -v | sed 's/^v//' | cut -d. -f1)" -lt 22 ]]; then - curl -fsSL https://rpm.nodesource.com/setup_22.x | bash - - dnf install -y nodejs - fi elif command -v yum >/dev/null 2>&1; then - yum install -y ca-certificates curl git nginx redis postgresql-server postgresql-contrib gcc gcc-c++ make tar gzip openssl + yum install -y ca-certificates curl git nginx redis postgresql-server postgresql-contrib gcc gcc-c++ make tar gzip xz openssl if [[ ! -d /var/lib/pgsql/data/base ]]; then postgresql-setup initdb fi - if ! command -v node >/dev/null 2>&1 || [[ "$(node -v | sed 's/^v//' | cut -d. -f1)" -lt 22 ]]; then - curl -fsSL https://rpm.nodesource.com/setup_22.x | bash - - yum install -y nodejs - fi else echo "Unsupported Linux distribution: apt-get/dnf/yum not found." >&2 exit 1 fi } +install_node() { + local version="${NODE_VERSION:-22.21.1}" + local arch + case "$(uname -m)" in + x86_64|amd64) arch="x64" ;; + aarch64|arm64) arch="arm64" ;; + *) echo "Unsupported Node.js architecture: $(uname -m)" >&2; exit 1 ;; + esac + if command -v node >/dev/null 2>&1 && [[ "$(node -v | sed 's/^v//' | cut -d. -f1)" -ge 22 ]]; then + return + fi + log "Installing Node.js ${version} for linux-${arch}" + curl -fL "https://nodejs.org/dist/v${version}/node-v${version}-linux-${arch}.tar.xz" -o /tmp/node.tar.xz + rm -rf /usr/local/lib/nodejs + mkdir -p /usr/local/lib/nodejs + tar -C /usr/local/lib/nodejs -xJf /tmp/node.tar.xz --strip-components=1 + ln -sf /usr/local/lib/nodejs/bin/node /usr/local/bin/node + ln -sf /usr/local/lib/nodejs/bin/npm /usr/local/bin/npm + ln -sf /usr/local/lib/nodejs/bin/npx /usr/local/bin/npx + ln -sf /usr/local/lib/nodejs/bin/corepack /usr/local/bin/corepack +} + install_go() { local version="${GO_VERSION:-1.26.0}" local arch @@ -240,6 +250,7 @@ run_deploy() { } install_packages +install_node install_go install_minio start_infra