Files
BigDataTool/Makefile
2025-08-11 09:34:45 +08:00

148 lines
3.9 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# BigDataTool Docker 管理 Makefile
.PHONY: help build run stop clean logs shell health
# 默认目标
help:
@echo "BigDataTool Docker 管理命令:"
@echo ""
@echo " build 构建Docker镜像"
@echo " run 启动服务(简化版本)"
@echo " run-full 启动完整服务(包含缓存和监控)"
@echo " stop 停止服务"
@echo " restart 重启服务"
@echo " clean 清理容器和镜像"
@echo " logs 查看服务日志"
@echo " shell 进入容器shell"
@echo " health 检查服务健康状态"
@echo " ps 查看运行状态"
@echo ""
@echo "环境变量设置:"
@echo " export SECRET_KEY=your-secret-key"
@echo " export FLASK_ENV=production"
@echo ""
# 构建镜像
build:
@echo "构建BigDataTool Docker镜像..."
docker build -t bigdatatool:latest .
# 快速运行(简化版本)
run:
@echo "启动BigDataTool服务(简化版本)..."
docker-compose -f docker-compose.simple.yml up -d
@echo "服务启动中请等待30秒后访问 http://localhost:5000"
# 完整运行(包含缓存和监控)
run-full:
@echo "启动BigDataTool完整服务..."
docker-compose up -d
@echo "服务启动中请等待30秒后访问:"
@echo " - 主应用: http://localhost:5000"
@echo " - Redis缓存: localhost:6379"
# 生产环境运行(包含Nginx)
run-prod:
@echo "启动生产环境服务..."
docker-compose --profile production up -d
@echo "生产环境服务启动,访问地址:"
@echo " - HTTP: http://localhost"
@echo " - HTTPS: https://localhost (需要SSL证书)"
# 监控环境运行
run-monitor:
@echo "启动监控环境..."
docker-compose --profile monitoring up -d
@echo "监控服务启动,访问地址:"
@echo " - 主应用: http://localhost:5000"
@echo " - Prometheus: http://localhost:9090"
# 停止服务
stop:
@echo "停止所有服务..."
docker-compose down
docker-compose -f docker-compose.simple.yml down
# 重启服务
restart: stop run
# 查看日志
logs:
@echo "查看服务日志..."
docker-compose logs -f bigdatatool
# 查看特定服务日志
logs-app:
docker-compose logs -f bigdatatool
logs-redis:
docker-compose logs -f redis-cache
logs-nginx:
docker-compose logs -f nginx
# 进入容器shell
shell:
@echo "进入BigDataTool容器..."
docker-compose exec bigdatatool /bin/bash
# 健康检查
health:
@echo "检查服务健康状态..."
@docker-compose ps
@echo ""
@echo "应用健康检查:"
@curl -s http://localhost:5000/api/health | python -m json.tool || echo "服务未响应"
# 查看运行状态
ps:
@echo "容器运行状态:"
@docker-compose ps
# 清理资源
clean:
@echo "清理Docker资源..."
docker-compose down -v --remove-orphans
docker-compose -f docker-compose.simple.yml down -v --remove-orphans
docker system prune -f
@echo "清理完成"
# 强制清理(包括镜像)
clean-all: clean
@echo "强制清理所有资源..."
docker rmi bigdatatool:latest || true
docker volume prune -f
docker network prune -f
# 更新镜像
update: clean build run
# 查看资源使用
stats:
@echo "Docker资源使用情况:"
@docker stats --no-stream
# 备份数据
backup:
@echo "备份数据库和配置..."
@mkdir -p backups/$(shell date +%Y%m%d_%H%M%S)
@docker cp bigdatatool:/app/config_groups.db backups/$(shell date +%Y%m%d_%H%M%S)/
@echo "备份完成: backups/$(shell date +%Y%m%d_%H%M%S)/"
# 开发模式运行
dev:
@echo "开发模式运行..."
@docker run --rm -it \
-p 5000:5000 \
-v $(PWD):/app \
-e FLASK_ENV=development \
-e FLASK_DEBUG=True \
bigdatatool:latest
# 构建并推送到仓库(需要先登录Docker Hub)
publish: build
@echo "推送镜像到Docker Hub..."
@read -p "请输入Docker Hub用户名: " username && \
docker tag bigdatatool:latest $$username/bigdatatool:latest && \
docker tag bigdatatool:latest $$username/bigdatatool:2.0 && \
docker push $$username/bigdatatool:latest && \
docker push $$username/bigdatatool:2.0