|
|
|
|
|
.PHONY: help install start stop restart logs clean dev deploy health backup restore build single test |
|
|
|
|
|
help: |
|
@echo "聊天应用管理命令:" |
|
@echo "" |
|
@echo "🚀 部署命令:" |
|
@echo " make install - 安装依赖和设置权限" |
|
@echo " make start - 启动生产环境(多容器)" |
|
@echo " make single - 启动单容器版本" |
|
@echo " make dev - 启动开发环境" |
|
@echo " make deploy - 部署到生产环境" |
|
@echo "" |
|
@echo "🔧 管理命令:" |
|
@echo " make stop - 停止所有服务" |
|
@echo " make restart - 重启所有服务" |
|
@echo " make logs - 查看服务日志" |
|
@echo " make health - 检查服务健康状态" |
|
@echo " make test - 运行功能测试" |
|
@echo "" |
|
@echo "🐳 Docker命令:" |
|
@echo " make build - 构建Docker镜像" |
|
@echo " make clean - 清理Docker资源" |
|
@echo "" |
|
@echo "💾 数据命令:" |
|
@echo " make backup - 备份数据库" |
|
@echo " make restore - 恢复数据库" |
|
@echo "" |
|
|
|
|
|
install: |
|
@echo "🔧 设置脚本权限..." |
|
chmod +x *.sh |
|
@echo "✅ 安装完成" |
|
|
|
|
|
start: |
|
@echo "🚀 启动生产环境..." |
|
./start.sh |
|
|
|
|
|
dev: |
|
@echo "🚀 启动开发环境..." |
|
./start-dev.sh |
|
|
|
|
|
single: |
|
@echo "🚀 启动单容器版本..." |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose -f docker-compose.single.yml up --build -d; \ |
|
else \ |
|
docker compose -f docker-compose.single.yml up --build -d; \ |
|
fi |
|
@echo "✅ 单容器版本启动完成" |
|
@echo "🌐 访问地址: http://localhost" |
|
|
|
|
|
build: |
|
@echo "🐳 构建Docker镜像..." |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose build --no-cache; \ |
|
else \ |
|
docker compose build --no-cache; \ |
|
fi |
|
@echo "✅ 镜像构建完成" |
|
|
|
|
|
test: |
|
@echo "🧪 运行功能测试..." |
|
./test.sh |
|
|
|
|
|
stop: |
|
@echo "🛑 停止服务..." |
|
./stop.sh |
|
|
|
|
|
restart: stop start |
|
|
|
|
|
logs: |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose logs -f; \ |
|
else \ |
|
docker compose logs -f; \ |
|
fi |
|
|
|
|
|
health: |
|
@echo "🔍 检查服务状态..." |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose ps; \ |
|
else \ |
|
docker compose ps; \ |
|
fi |
|
@echo "" |
|
@echo "🧪 测试服务连接..." |
|
@curl -f http://localhost:5000/api/health 2>/dev/null && echo "✅ 后端服务正常" || echo "❌ 后端服务异常" |
|
@curl -f http://localhost:3000 2>/dev/null && echo "✅ 前端服务正常" || echo "❌ 前端服务异常" |
|
|
|
|
|
clean: |
|
@echo "🧹 清理Docker资源..." |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose down -v --rmi all --remove-orphans; \ |
|
else \ |
|
docker compose down -v --rmi all --remove-orphans; \ |
|
fi |
|
docker system prune -f |
|
@echo "✅ 清理完成" |
|
|
|
|
|
deploy: |
|
@echo "🚀 部署到生产环境..." |
|
./deploy.sh |
|
|
|
|
|
backup: |
|
@echo "💾 备份数据库..." |
|
@mkdir -p backups |
|
@BACKUP_FILE="backups/chatapp-backup-$$(date +%Y%m%d-%H%M%S).gz"; \ |
|
docker exec chat-mongo mongodump --authenticationDatabase admin -u admin -p password123 --db chatapp --gzip --archive=$$BACKUP_FILE; \ |
|
echo "✅ 数据库已备份到: $$BACKUP_FILE" |
|
|
|
|
|
restore: |
|
@echo "📥 恢复数据库..." |
|
@if [ -z "$(FILE)" ]; then \ |
|
echo "❌ 请指定备份文件: make restore FILE=backups/backup-file.gz"; \ |
|
exit 1; \ |
|
fi |
|
@if [ ! -f "$(FILE)" ]; then \ |
|
echo "❌ 备份文件不存在: $(FILE)"; \ |
|
exit 1; \ |
|
fi |
|
docker exec chat-mongo mongorestore --authenticationDatabase admin -u admin -p password123 --db chatapp --gzip --archive=$(FILE) --drop |
|
@echo "✅ 数据库恢复完成" |
|
|
|
|
|
update: |
|
@echo "🔄 更新应用..." |
|
git pull |
|
@if command -v docker-compose >/dev/null 2>&1; then \ |
|
docker-compose pull; \ |
|
docker-compose up --build -d; \ |
|
else \ |
|
docker compose pull; \ |
|
docker compose up --build -d; \ |
|
fi |
|
@echo "✅ 更新完成" |
|
|