feat: 优化部署脚本

This commit is contained in:
丹尼尔
2026-03-11 09:44:17 +08:00
parent 0e8639fde1
commit 846c65b155
13 changed files with 1957 additions and 340 deletions

View File

@@ -5,6 +5,8 @@ set -e
IMAGE_NAME="wechat-admin-backend"
CONTAINER_NAME="wechat-admin-backend"
PORT="${PORT:-3000}"
# 数据目录挂载到宿主机防止容器删除后丢失SQLite 库 wechat.db 及表数据)
HOST_DATA_DIR="${HOST_DATA_DIR:-$(pwd)/data}"
echo "Building Docker image: ${IMAGE_NAME}..."
docker build -t "${IMAGE_NAME}" .
@@ -14,6 +16,9 @@ if [ "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then
docker rm -f "${CONTAINER_NAME}" >/dev/null 2>&1 || true
fi
mkdir -p "${HOST_DATA_DIR}"
echo "Data dir (host): ${HOST_DATA_DIR} -> container /app/backend/data"
ENV_FILE=".env"
if [ ! -f "${ENV_FILE}" ]; then
echo "Env file ${ENV_FILE} not found, copying from .env.example ..."
@@ -26,7 +31,9 @@ docker run -d \
--env-file "${ENV_FILE}" \
-p "${PORT}:3000" \
-p "8000:8000" \
-v "${HOST_DATA_DIR}:/app/backend/data" \
"${IMAGE_NAME}"
echo "Container started. Health check: curl http://localhost:${PORT}/health"
echo "Container started. Data persisted on host: ${HOST_DATA_DIR}"
echo "Health check: curl http://localhost:${PORT}/health"