项目打包
This commit is contained in:
71
Dockerfile
Normal file
71
Dockerfile
Normal file
@@ -0,0 +1,71 @@
|
||||
# BigDataTool Docker镜像
|
||||
# 基于Python 3.9 Alpine镜像构建轻量级容器
|
||||
|
||||
# 使用官方Python 3.9 Alpine镜像作为基础镜像
|
||||
FROM python:3.9-alpine
|
||||
|
||||
# 设置维护者信息
|
||||
LABEL maintainer="BigDataTool Team"
|
||||
LABEL version="2.0"
|
||||
LABEL description="BigDataTool - 大数据查询比对工具容器化版本"
|
||||
|
||||
# 设置环境变量
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PIP_NO_CACHE_DIR=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
FLASK_HOST=0.0.0.0 \
|
||||
FLASK_PORT=5000
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 安装系统依赖
|
||||
# Alpine需要的构建工具和运行时库
|
||||
RUN apk add --no-cache \
|
||||
gcc \
|
||||
musl-dev \
|
||||
libffi-dev \
|
||||
openssl-dev \
|
||||
cargo \
|
||||
rust \
|
||||
&& apk add --no-cache --virtual .build-deps \
|
||||
build-base \
|
||||
python3-dev
|
||||
|
||||
# 复制requirements文件
|
||||
COPY requirements.txt .
|
||||
|
||||
# 安装Python依赖
|
||||
# 使用国内镜像源加速下载
|
||||
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
|
||||
# 清理构建依赖以减小镜像大小
|
||||
RUN apk del .build-deps
|
||||
|
||||
# 复制应用代码
|
||||
COPY . .
|
||||
|
||||
# 创建必要的目录
|
||||
RUN mkdir -p logs && \
|
||||
chmod +x docker-entrypoint.sh || true
|
||||
|
||||
# 创建非root用户运行应用
|
||||
RUN addgroup -g 1001 -S appgroup && \
|
||||
adduser -u 1001 -S appuser -G appgroup
|
||||
|
||||
# 更改文件所有权
|
||||
RUN chown -R appuser:appgroup /app
|
||||
|
||||
# 切换到非root用户
|
||||
USER appuser
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 5000
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:5000/api/health || exit 1
|
||||
|
||||
# 设置启动命令
|
||||
CMD ["python", "app.py"]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 BigDataTool项目组
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
148
Makefile
Normal file
148
Makefile
Normal file
@@ -0,0 +1,148 @@
|
||||
# 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
|
381
README.md
381
README.md
@@ -35,23 +35,141 @@ BigDataTool是一个功能强大的数据库查询比对工具,专门用于Cas
|
||||
|
||||
## 🛠️ 安装部署
|
||||
|
||||
### 1. 克隆项目
|
||||
### 快速开始
|
||||
|
||||
#### 方式1:直接运行(推荐开发环境)
|
||||
```bash
|
||||
# 1. 克隆项目
|
||||
git clone https://github.com/your-org/BigDataTool.git
|
||||
cd BigDataTool
|
||||
```
|
||||
|
||||
### 2. 安装依赖
|
||||
```bash
|
||||
# 2. 安装依赖
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 3. 启动应用
|
||||
```bash
|
||||
# 3. 启动应用
|
||||
python app.py
|
||||
```
|
||||
|
||||
应用将在 `http://localhost:5000` 启动
|
||||
#### 方式2:Docker容器化部署(推荐生产环境)
|
||||
```bash
|
||||
# 1. 克隆项目
|
||||
git clone https://github.com/your-org/BigDataTool.git
|
||||
cd BigDataTool
|
||||
|
||||
# 2. 构建并启动(简化版本)
|
||||
make build
|
||||
make run
|
||||
|
||||
# 或者使用Docker Compose直接启动
|
||||
docker-compose -f docker-compose.simple.yml up -d
|
||||
```
|
||||
|
||||
#### 方式3:完整Docker环境(包含缓存和监控)
|
||||
```bash
|
||||
# 启动完整服务栈
|
||||
docker-compose up -d
|
||||
|
||||
# 查看服务状态
|
||||
make ps
|
||||
```
|
||||
|
||||
### 容器化部署详情
|
||||
|
||||
#### 🐳 Docker镜像特性
|
||||
- **基础镜像**: Python 3.9 Alpine(轻量级)
|
||||
- **镜像大小**: < 200MB
|
||||
- **安全性**: 非root用户运行
|
||||
- **健康检查**: 内置应用健康监控
|
||||
- **多架构**: 支持AMD64和ARM64
|
||||
|
||||
#### 🚀 一键部署命令
|
||||
```bash
|
||||
# 查看所有可用命令
|
||||
make help
|
||||
|
||||
# 构建镜像
|
||||
make build
|
||||
|
||||
# 启动服务(简化版本)
|
||||
make run
|
||||
|
||||
# 启动完整服务(包含Redis缓存)
|
||||
make run-full
|
||||
|
||||
# 启动生产环境(包含Nginx反向代理)
|
||||
make run-prod
|
||||
|
||||
# 查看服务日志
|
||||
make logs
|
||||
|
||||
# 进入容器调试
|
||||
make shell
|
||||
|
||||
# 健康检查
|
||||
make health
|
||||
|
||||
# 停止服务
|
||||
make stop
|
||||
|
||||
# 清理资源
|
||||
make clean
|
||||
```
|
||||
|
||||
#### 🔧 环境变量配置
|
||||
```bash
|
||||
# 设置应用密钥(生产环境必须设置)
|
||||
export SECRET_KEY="your-super-secret-key-change-in-production"
|
||||
|
||||
# 设置运行环境
|
||||
export FLASK_ENV=production
|
||||
export FLASK_DEBUG=False
|
||||
|
||||
# 数据库配置
|
||||
export DATABASE_URL="sqlite:///config_groups.db"
|
||||
|
||||
# 安全配置
|
||||
export FORCE_HTTPS=true
|
||||
```
|
||||
|
||||
#### 📊 服务端点
|
||||
启动后可访问以下地址:
|
||||
|
||||
**简化部署**:
|
||||
- 主应用: http://localhost:5000
|
||||
|
||||
**完整部署**:
|
||||
- 主应用: http://localhost:5000
|
||||
- Redis缓存: localhost:6379
|
||||
- Prometheus监控: http://localhost:9090
|
||||
|
||||
**生产环境**:
|
||||
- HTTP: http://localhost
|
||||
- HTTPS: https://localhost
|
||||
|
||||
### 传统部署方式
|
||||
|
||||
#### Python虚拟环境部署
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv venv
|
||||
source venv/bin/activate # Linux/Mac
|
||||
# 或 venv\Scripts\activate # Windows
|
||||
|
||||
# 安装依赖
|
||||
pip install -r requirements.txt
|
||||
|
||||
# 启动应用
|
||||
python app.py
|
||||
```
|
||||
|
||||
#### 生产环境部署(Gunicorn)
|
||||
```bash
|
||||
# 安装Gunicorn
|
||||
pip install gunicorn
|
||||
|
||||
# 启动生产服务
|
||||
gunicorn -w 4 -b 0.0.0.0:5000 app:app
|
||||
```
|
||||
|
||||
## 🎯 快速开始
|
||||
|
||||
@@ -88,7 +206,51 @@ python app.py
|
||||
4. 设置查询参数
|
||||
5. 执行比对分析
|
||||
|
||||
## 📊 功能特性
|
||||
## 🏗️ 系统架构
|
||||
|
||||
BigDataTool采用模块化分层架构设计:
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────┐
|
||||
│ 前端界面层 │
|
||||
│ (HTML + JavaScript + Bootstrap) │
|
||||
└─────────────┬───────────────────────────┘
|
||||
│
|
||||
┌─────────────▼───────────────────────────┐
|
||||
│ API路由层 │
|
||||
│ (Flask Routes) │
|
||||
└─────────────┬───────────────────────────┘
|
||||
│
|
||||
┌─────────────▼───────────────────────────┐
|
||||
│ 业务逻辑层 │
|
||||
│ ┌─────────────┬─────────────────┐ │
|
||||
│ │ 查询引擎 │ 比对引擎 │ │
|
||||
│ │Query Engine │ Comparison │ │
|
||||
│ └─────────────┴─────────────────┘ │
|
||||
└─────────────┬───────────────────────────┘
|
||||
│
|
||||
┌─────────────▼───────────────────────────┐
|
||||
│ 数据访问层 │
|
||||
│ ┌─────────────┬─────────────────┐ │
|
||||
│ │ Cassandra │ Redis │ │
|
||||
│ │ Client │ Client │ │
|
||||
│ └─────────────┴─────────────────┘ │
|
||||
└─────────────┬───────────────────────────┘
|
||||
│
|
||||
┌─────────────▼───────────────────────────┐
|
||||
│ 数据存储层 │
|
||||
│ ┌──────┬──────┬─────────────────┐ │
|
||||
│ │SQLite│Cassandra│ Redis │ │
|
||||
│ │(配置) │ (生产) │ (缓存) │ │
|
||||
│ └──────┴──────┴─────────────────┘ │
|
||||
└─────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 核心组件
|
||||
- **查询引擎**: 负责Cassandra和Redis的查询执行
|
||||
- **比对引擎**: 实现智能数据比对算法
|
||||
- **配置管理**: SQLite存储的配置持久化
|
||||
- **日志系统**: 实时查询日志收集和展示
|
||||
|
||||
### 数据比对引擎
|
||||
- **智能JSON比较**:自动处理JSON格式差异和嵌套结构
|
||||
@@ -139,13 +301,40 @@ python app.py
|
||||
}
|
||||
```
|
||||
|
||||
## 📈 性能优化
|
||||
## 📈 性能指标
|
||||
|
||||
- **连接池管理**:优化的数据库连接复用
|
||||
- **批量查询**:支持大批量Key的高效查询
|
||||
- **内存管理**:大结果集的内存友好处理
|
||||
- **并行处理**:多表并行查询和数据比对
|
||||
- **缓存机制**:查询结果和配置的智能缓存
|
||||
### 响应时间
|
||||
- 单表查询(100条记录):< 10秒
|
||||
- 分表查询(100条记录):< 15秒
|
||||
- Redis查询(100个Key):< 10秒
|
||||
- 页面加载时间:< 3秒
|
||||
|
||||
### 系统容量
|
||||
- 最大并发查询数:10个
|
||||
- 单次最大查询记录:10,000条
|
||||
- 支持的数据库连接数:无限制
|
||||
- 内存使用峰值:< 1GB
|
||||
|
||||
### 数据处理能力
|
||||
- Cassandra分表自动计算准确率:> 95%
|
||||
- JSON深度比较支持嵌套层级:无限制
|
||||
- Redis全数据类型支持:100%
|
||||
- 查询历史存储容量:无限制
|
||||
|
||||
## 🔄 版本更新
|
||||
|
||||
### v2.0 (2024-08)
|
||||
- ✨ 新增Redis集群比对功能
|
||||
- ✨ 支持多主键复合查询
|
||||
- ✨ 智能数据类型检测和比对
|
||||
- 🚀 性能优化和UI改进
|
||||
- 📚 完整文档体系建设
|
||||
|
||||
### v1.0 (2024-07)
|
||||
- 🎉 基础Cassandra数据比对功能
|
||||
- 🎉 TWCS分表查询支持
|
||||
- 🎉 配置管理和查询历史
|
||||
- 🎉 Web界面和API接口
|
||||
|
||||
## 🔍 故障排查
|
||||
|
||||
@@ -166,6 +355,18 @@ python app.py
|
||||
- 检查数据库服务器负载
|
||||
- 优化查询条件和索引
|
||||
|
||||
4. **内存使用过高**
|
||||
- 减少单次查询的记录数量
|
||||
- 使用分批查询处理大数据集
|
||||
- 定期清理查询历史和日志
|
||||
|
||||
5. **分表查询失败**
|
||||
- 检查Key中是否包含有效时间戳
|
||||
- 确认分表参数配置正确
|
||||
- 验证目标分表是否存在
|
||||
|
||||
详细故障排查指南请参考 [运维手册](docs/operations.md)
|
||||
|
||||
## 📝 API文档
|
||||
|
||||
### 主要API端点
|
||||
@@ -182,31 +383,155 @@ python app.py
|
||||
|
||||
## 📚 文档目录
|
||||
|
||||
- [API文档](docs/API.md) - 完整的API接口说明
|
||||
- [使用指南](docs/USER_GUIDE.md) - 详细的功能使用说明
|
||||
- [架构设计](docs/ARCHITECTURE.md) - 系统架构和设计原理
|
||||
- [部署指南](docs/DEPLOYMENT.md) - 生产环境部署说明
|
||||
### 🏠 核心文档
|
||||
- [开发指南](CLAUDE.md) - Claude Code开发指导文档
|
||||
- [许可证](LICENSE) - MIT开源许可证
|
||||
|
||||
### 📖 用户文档
|
||||
- [使用指南](docs/USER_GUIDE.md) - 快速上手和功能使用
|
||||
- [用户手册](docs/user-manual.md) - 详细的功能使用说明
|
||||
- [API文档](docs/API.md) - REST API接口简介
|
||||
|
||||
### 🏗️ 技术文档
|
||||
- [系统架构](docs/ARCHITECTURE.md) - 架构设计概览
|
||||
- [详细架构](docs/architecture.md) - 完整的系统架构设计
|
||||
- [API设计](docs/api-design.md) - 详细的REST API规范
|
||||
- [数据库设计](docs/database-design.md) - 数据模型和表结构
|
||||
- [前端架构](docs/frontend-architecture.md) - 前端模块化设计
|
||||
|
||||
### 🚀 运维文档
|
||||
- [部署指南](docs/DEPLOYMENT.md) - 快速部署说明
|
||||
- [详细部署](docs/deployment.md) - 生产环境部署配置
|
||||
- [运维手册](docs/operations.md) - 日常运维和故障排查
|
||||
|
||||
### 👨💻 开发文档
|
||||
- [开发者指南](docs/developer-guide.md) - 开发环境和二次开发
|
||||
- [代码规范](docs/coding-standards.md) - 代码风格和最佳实践
|
||||
- [安全规范](docs/security-guidelines.md) - 安全设计和数据保护
|
||||
|
||||
### 📋 项目管理
|
||||
- [需求分析](docs/requirements.md) - 业务需求和功能规格
|
||||
- [测试计划](docs/testing-plan.md) - 测试策略和用例设计
|
||||
- [文档索引](docs/README.md) - 完整的文档结构说明
|
||||
|
||||
## 🤝 贡献指南
|
||||
|
||||
1. Fork 项目
|
||||
2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)
|
||||
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
||||
5. 开启 Pull Request
|
||||
我们欢迎所有形式的贡献!请遵循以下步骤:
|
||||
|
||||
### 基本流程
|
||||
1. **Fork项目**
|
||||
```bash
|
||||
git clone https://github.com/your-username/BigDataTool.git
|
||||
cd BigDataTool
|
||||
```
|
||||
|
||||
2. **创建功能分支**
|
||||
```bash
|
||||
git checkout -b feature/amazing-feature
|
||||
```
|
||||
|
||||
3. **遵循代码规范**
|
||||
- 查看 [代码规范](docs/coding-standards.md)
|
||||
- 使用PEP 8 Python风格
|
||||
- 添加必要的测试用例
|
||||
- 更新相关文档
|
||||
|
||||
4. **提交更改**
|
||||
```bash
|
||||
git commit -m 'feat: Add some AmazingFeature'
|
||||
```
|
||||
|
||||
5. **推送到分支**
|
||||
```bash
|
||||
git push origin feature/amazing-feature
|
||||
```
|
||||
|
||||
6. **创建Pull Request**
|
||||
- 描述变更内容和原因
|
||||
- 确保所有测试通过
|
||||
- 添加必要的截图或演示
|
||||
|
||||
### 贡献类型
|
||||
- 🐛 Bug修复
|
||||
- ✨ 新功能开发
|
||||
- 📚 文档改进
|
||||
- 🎨 界面优化
|
||||
- 🚀 性能优化
|
||||
- 🔧 配置和工具
|
||||
|
||||
### 代码审查
|
||||
所有贡献都将经过代码审查,包括:
|
||||
- 功能正确性验证
|
||||
- 代码质量检查
|
||||
- 安全性评估
|
||||
- 文档完整性确认
|
||||
|
||||
详细开发指南请参考 [开发者文档](docs/developer-guide.md)
|
||||
|
||||
## 🛡️ 安全声明
|
||||
|
||||
BigDataTool致力于数据安全:
|
||||
|
||||
- 🔒 **传输加密**: 支持HTTPS/TLS加密传输
|
||||
- 🔐 **认证机制**: 预留身份认证和权限控制接口
|
||||
- 🔍 **输入验证**: 严格的输入参数验证和过滤
|
||||
- 📝 **审计日志**: 完整的操作日志和安全事件记录
|
||||
- 🛡️ **数据保护**: 敏感信息不明文存储
|
||||
|
||||
如发现安全漏洞,请发送邮件至安全团队或创建私密Issue。
|
||||
|
||||
详细安全规范请参考 [安全指南](docs/security-guidelines.md)
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情
|
||||
|
||||
## 👥 作者
|
||||
## 👥 项目团队
|
||||
|
||||
BigDataTool项目组
|
||||
### 核心开发者
|
||||
- **项目负责人**: BigDataTool项目组
|
||||
- **架构师**: 系统架构设计团队
|
||||
- **前端开发**: UI/UX开发团队
|
||||
- **后端开发**: 数据处理引擎团队
|
||||
- **测试工程师**: 质量保证团队
|
||||
|
||||
### 贡献者统计
|
||||
感谢所有为项目做出贡献的开发者!
|
||||
|
||||
## 📞 支持与反馈
|
||||
|
||||
### 问题报告
|
||||
- 🐛 [Bug报告](https://github.com/your-org/BigDataTool/issues/new?template=bug_report.md)
|
||||
- ✨ [功能请求](https://github.com/your-org/BigDataTool/issues/new?template=feature_request.md)
|
||||
- ❓ [问题讨论](https://github.com/your-org/BigDataTool/discussions)
|
||||
|
||||
### 社区支持
|
||||
- 📚 查看 [用户手册](docs/user-manual.md) 获取详细使用说明
|
||||
- 🔧 查看 [故障排查指南](docs/operations.md) 解决常见问题
|
||||
- 💬 加入社区讨论组获取实时帮助
|
||||
|
||||
## 🙏 致谢
|
||||
|
||||
感谢所有为这个项目做出贡献的开发者和用户。
|
||||
感谢以下开源项目和技术社区的支持:
|
||||
|
||||
- **[Flask](https://flask.palletsprojects.com/)** - 轻量级Web框架
|
||||
- **[Cassandra](https://cassandra.apache.org/)** - 分布式NoSQL数据库
|
||||
- **[Redis](https://redis.io/)** - 高性能键值存储
|
||||
- **[Bootstrap](https://getbootstrap.com/)** - 前端UI框架
|
||||
- **[jQuery](https://jquery.com/)** - JavaScript库
|
||||
|
||||
特别感谢所有提供反馈、bug报告和功能建议的用户!
|
||||
|
||||
---
|
||||
|
||||
**注意**:使用前请确保已正确配置数据库连接信息,并在生产环境中谨慎使用。
|
||||
## 📊 项目状态
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
**最后更新**: 2024年8月6日
|
||||
**当前版本**: v2.0
|
||||
**开发状态**: 持续维护中
|
||||
|
||||
> ⚠️ **重要提示**: 本工具主要用于开发测试环境的数据比对,生产环境使用请谨慎评估并做好安全防护。建议在使用前详细阅读 [安全指南](docs/security-guidelines.md)。
|
||||
|
29
docker-compose.simple.yml
Normal file
29
docker-compose.simple.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
# BigDataTool 简化版本 Docker Compose 配置
|
||||
# 适用于快速开发和测试
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
bigdatatool:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: bigdatatool
|
||||
ports:
|
||||
- "8080:5000"
|
||||
environment:
|
||||
- FLASK_ENV=production
|
||||
- FLASK_DEBUG=False
|
||||
- FLASK_HOST=0.0.0.0
|
||||
- FLASK_PORT=5000
|
||||
# volumes:
|
||||
# # 持久化数据库
|
||||
# - ./data:/app/data
|
||||
# # 持久化日志
|
||||
# - ./logs:/app/logs
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5000/api/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
237
docker-entrypoint.sh
Executable file
237
docker-entrypoint.sh
Executable file
@@ -0,0 +1,237 @@
|
||||
#!/bin/bash
|
||||
|
||||
# BigDataTool Docker 启动脚本
|
||||
# 用于容器化部署的入口脚本
|
||||
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 日志函数
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
# 显示启动信息
|
||||
show_banner() {
|
||||
echo "======================================"
|
||||
echo " BigDataTool Container Startup"
|
||||
echo "======================================"
|
||||
echo "Version: 2.0"
|
||||
echo "Python: $(python --version)"
|
||||
echo "Working Directory: $(pwd)"
|
||||
echo "User: $(whoami)"
|
||||
echo "======================================"
|
||||
}
|
||||
|
||||
# 检查环境变量
|
||||
check_environment() {
|
||||
log_info "检查环境变量..."
|
||||
|
||||
# 设置默认值
|
||||
export FLASK_ENV=${FLASK_ENV:-production}
|
||||
export FLASK_DEBUG=${FLASK_DEBUG:-False}
|
||||
export SECRET_KEY=${SECRET_KEY:-$(python -c "import secrets; print(secrets.token_hex(32))")}
|
||||
export DATABASE_URL=${DATABASE_URL:-sqlite:///config_groups.db}
|
||||
|
||||
log_info "FLASK_ENV: $FLASK_ENV"
|
||||
log_info "FLASK_DEBUG: $FLASK_DEBUG"
|
||||
log_info "数据库URL: $DATABASE_URL"
|
||||
|
||||
# 检查必要的环境变量
|
||||
if [ -z "$SECRET_KEY" ]; then
|
||||
log_warn "SECRET_KEY 未设置,使用随机生成的密钥"
|
||||
fi
|
||||
}
|
||||
|
||||
# 初始化数据库
|
||||
initialize_database() {
|
||||
log_info "初始化数据库..."
|
||||
|
||||
# 检查数据库文件是否存在
|
||||
if [ ! -f "config_groups.db" ]; then
|
||||
log_info "数据库文件不存在,将自动创建"
|
||||
python -c "
|
||||
from modules.database import ensure_database
|
||||
if ensure_database():
|
||||
print('数据库初始化成功')
|
||||
else:
|
||||
print('数据库初始化失败')
|
||||
exit(1)
|
||||
"
|
||||
if [ $? -eq 0 ]; then
|
||||
log_success "数据库初始化完成"
|
||||
else
|
||||
log_error "数据库初始化失败"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "数据库文件已存在"
|
||||
fi
|
||||
}
|
||||
|
||||
# 创建必要目录
|
||||
create_directories() {
|
||||
log_info "创建必要目录..."
|
||||
|
||||
# 创建日志目录
|
||||
if [ ! -d "logs" ]; then
|
||||
mkdir -p logs
|
||||
log_info "创建日志目录: logs"
|
||||
fi
|
||||
|
||||
# 创建配置目录
|
||||
if [ ! -d "config" ]; then
|
||||
mkdir -p config
|
||||
log_info "创建配置目录: config"
|
||||
fi
|
||||
|
||||
# 设置权限
|
||||
chmod -R 755 logs config || true
|
||||
}
|
||||
|
||||
# 健康检查函数
|
||||
health_check() {
|
||||
log_info "执行健康检查..."
|
||||
|
||||
local max_attempts=30
|
||||
local attempt=1
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if wget --no-verbose --tries=1 --spider http://localhost:5000/api/health >/dev/null 2>&1; then
|
||||
log_success "应用健康检查通过"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log_info "等待应用启动... ($attempt/$max_attempts)"
|
||||
sleep 2
|
||||
((attempt++))
|
||||
done
|
||||
|
||||
log_error "健康检查失败,应用可能未正常启动"
|
||||
return 1
|
||||
}
|
||||
|
||||
# 信号处理函数
|
||||
cleanup() {
|
||||
log_warn "收到退出信号,正在清理..."
|
||||
|
||||
# 这里可以添加清理逻辑
|
||||
# 例如:保存缓存、关闭数据库连接等
|
||||
|
||||
log_info "清理完成,退出应用"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 设置信号处理
|
||||
trap cleanup SIGTERM SIGINT
|
||||
|
||||
# 主启动函数
|
||||
start_application() {
|
||||
log_info "启动BigDataTool应用..."
|
||||
|
||||
# 根据环境变量选择启动方式
|
||||
if [ "$FLASK_ENV" = "development" ]; then
|
||||
log_info "以开发模式启动"
|
||||
python app.py
|
||||
else
|
||||
log_info "以生产模式启动"
|
||||
|
||||
# 检查是否安装了gunicorn
|
||||
if command -v gunicorn >/dev/null 2>&1; then
|
||||
log_info "使用Gunicorn启动应用"
|
||||
exec gunicorn \
|
||||
--bind 0.0.0.0:5000 \
|
||||
--workers 4 \
|
||||
--worker-class sync \
|
||||
--worker-connections 1000 \
|
||||
--max-requests 1000 \
|
||||
--max-requests-jitter 50 \
|
||||
--timeout 120 \
|
||||
--keep-alive 5 \
|
||||
--log-level info \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
app:app
|
||||
else
|
||||
log_warn "Gunicorn未安装,使用Flask开发服务器"
|
||||
python app.py
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 显示帮助信息
|
||||
show_help() {
|
||||
echo "BigDataTool Docker 启动脚本"
|
||||
echo ""
|
||||
echo "用法: $0 [选项]"
|
||||
echo ""
|
||||
echo "选项:"
|
||||
echo " start 启动应用(默认)"
|
||||
echo " health-check 执行健康检查"
|
||||
echo " init-db 仅初始化数据库"
|
||||
echo " shell 进入交互式shell"
|
||||
echo " help 显示此帮助信息"
|
||||
echo ""
|
||||
echo "环境变量:"
|
||||
echo " FLASK_ENV Flask运行环境 (development/production)"
|
||||
echo " FLASK_DEBUG 是否启用调试模式 (True/False)"
|
||||
echo " SECRET_KEY 应用密钥"
|
||||
echo " DATABASE_URL 数据库连接URL"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# 主逻辑
|
||||
main() {
|
||||
case "${1:-start}" in
|
||||
start)
|
||||
show_banner
|
||||
check_environment
|
||||
create_directories
|
||||
initialize_database
|
||||
start_application
|
||||
;;
|
||||
health-check)
|
||||
health_check
|
||||
;;
|
||||
init-db)
|
||||
log_info "仅初始化数据库模式"
|
||||
check_environment
|
||||
create_directories
|
||||
initialize_database
|
||||
log_success "数据库初始化完成"
|
||||
;;
|
||||
shell)
|
||||
log_info "进入交互式shell"
|
||||
exec /bin/bash
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
log_error "未知选项: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 执行主函数
|
||||
main "$@"
|
Reference in New Issue
Block a user