You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mail-yubao/deploy/install-bt-host-mysql-lowme...

62 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# 低内存首次部署:串行 build 1 次,web/worker 共用镜像
# 用法:bash deploy/install-bt-host-mysql-lowmem.sh
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
COMPOSE_FILE="${ROOT_DIR}/deploy/docker-compose.bt-host-mysql.yml"
ENV_FILE="${ROOT_DIR}/.env"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log() { echo -e "${GREEN}[deploy-lowmem]${NC} $*"; }
warn() { echo -e "${YELLOW}[deploy-lowmem]${NC} $*"; }
err() { echo -e "${RED}[deploy-lowmem]${NC} $*" >&2; }
if [[ ! -f "$ENV_FILE" ]]; then
err "缺少 .env,请先 cp deploy/.env.bt-host-mysql.example .env 并填写"
exit 1
fi
if command -v free >/dev/null 2>&1; then
total_kb="$(free -k | awk '/^Mem:/{print $2}')"
avail_kb="$(free -k | awk '/^Mem:/{print $7}')"
log "内存:总计约 $((total_kb / 1024))MB,可用约 $((avail_kb / 1024))MB"
if [[ -n "${avail_kb:-}" && "$avail_kb" -lt 1500000 ]]; then
warn "可用内存偏低。建议先停查价等其它 Docker 项目,或加 2G Swap 后再部署。"
fi
fi
mkdir -p "${ROOT_DIR}/data"
cd "$ROOT_DIR"
compose=(docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE")
export DOCKER_BUILDKIT=1
export BUILDKIT_MAX_PARALLELISM=1
log "停止可能半成品的容器…"
"${compose[@]}" down --remove-orphans 2>/dev/null || true
log "串行构建镜像(仅 1 次,web/worker 共用 yubao-app:latest)…"
warn "Next.js 编译峰值约 2~4GB,期间 CPU/内存会飙高,服务器变慢属正常"
"${compose[@]}" build web
log "启动 web + worker…"
"${compose[@]}" up -d
log "同步数据库结构…"
"${compose[@]}" run --rm --no-deps web pnpm exec prisma db push --skip-generate
log "同步默认账号…"
"${compose[@]}" run --rm --no-deps web pnpm db:seed || true
"${compose[@]}" ps
APP_PORT="$(grep -E '^APP_PORT=' "$ENV_FILE" | tail -1 | cut -d= -f2- | tr -d '\r' || echo 30327)"
PUBLIC_HOST="$(grep -E '^PUBLIC_HOST=' "$ENV_FILE" | tail -1 | cut -d= -f2- | tr -d '\r' || echo 127.0.0.1)"
log "完成 → http://${PUBLIC_HOST}:${APP_PORT}/login"