refactor: deploy工具适配systemd service模式-移除.env依赖

This commit is contained in:
2026-05-25 14:46:07 +08:00
parent 216dd365f6
commit 4240bb6970
2 changed files with 104 additions and 45 deletions

View File

@@ -14,7 +14,8 @@
# --tail [N] 实时跟踪日志
# --status 查看服务状态
# --post-logs 部署后显示日志
# --init-env 初始化远程 .env
# --init-env 初始化 systemd service 模板
# --deploy-service 上传 systemd service 文件到服务器
# ===========================================
set -euo pipefail
@@ -32,7 +33,7 @@ APP_ENV="production"
DRY_RUN=false; SKIP_CONFIRM=false; SKIP_TESTS=false
ROLLBACK=false; LIST_BACKUPS=false; VIEW_LOGS=false; TAIL_LOGS=false
LOG_LINES=50; VIEW_STATUS=false; POST_DEPLOY_LOGS=false; INIT_ENV=false
BACKUP_PATH=""
DEPLOY_SERVICE=false; BACKUP_PATH=""
# ---------- 选项解析 ----------
while [[ $# -gt 0 ]]; do
@@ -49,6 +50,7 @@ while [[ $# -gt 0 ]]; do
--status) VIEW_STATUS=true ;;
--post-logs) POST_DEPLOY_LOGS=true ;;
--init-env) INIT_ENV=true ;;
--deploy-service) DEPLOY_SERVICE=true ;;
--help|-h)
echo "用法: $0 [development|production] [options]"
echo "选项:"
@@ -61,7 +63,8 @@ while [[ $# -gt 0 ]]; do
echo " --tail [N] 实时跟踪日志"
echo " --status 查看服务状态"
echo " --post-logs 部署后显示日志"
echo " --init-env 初始化远程 .env"
echo " --init-env 初始化 systemd service 模板"
echo " --deploy-service 上传 systemd service 文件到服务器"
exit 0 ;;
*)
if [[ "$1" == "development" || "$1" == "production" ]]; then
@@ -98,6 +101,7 @@ ssh_connect
if [ "$LIST_BACKUPS" = true ]; then list_backups; exit 0; fi
if [ "$INIT_ENV" = true ]; then init_env; exit 0; fi
if [ "$DEPLOY_SERVICE" = true ]; then deploy_service_file; exit 0; fi
if [ "$VIEW_LOGS" = true ]; then view_logs; exit 0; fi
if [ "$TAIL_LOGS" = true ]; then tail_logs; exit 0; fi
if [ "$VIEW_STATUS" = true ]; then status; exit 0; fi
@@ -107,19 +111,20 @@ if [ "$ROLLBACK" = true ]; then rollback; exit 0; fi
show_deploy_info
confirm_deploy
check_dependencies
check_env_file
check_service_file
check_ssl_expiry
build_project
backup_old_version
cleanup_old_backups 5
upload_binary
upload_dir "配置文件" config
upload_dir "迁移文件" migrations
upload_script "测试脚本" test_deployment.sh test_deployment.sh
upload_script "清理脚本" scripts/cleanup_refresh_tokens.sh scripts/cleanup_refresh_tokens.sh
upload_script "备份脚本" scripts/backup-db.sh scripts/backup-db.sh
deploy_service_file
restart_service
run_migrations