Compare commits
No commits in common. "1af07892530d554f737dc70c0faf3120708cfec1" and "d0b3ed2427dfe40d4ed8eaeb95ea16e8abcc564d" have entirely different histories.
1af0789253
...
d0b3ed2427
358
README.md
358
README.md
@ -4,213 +4,325 @@
|
|||||||
|
|
||||||
## 功能特点
|
## 功能特点
|
||||||
|
|
||||||
1. **价格计算器**
|
1. 价格计算器
|
||||||
- 选择实例类型、区域、操作系统和购买选项
|
- 选择实例类型、区域、操作系统和购买选项
|
||||||
- 实时计算价格
|
- 实时计算价格
|
||||||
- 显示详细的价格信息
|
- 显示详细的价格信息
|
||||||
|
|
||||||
2. **实例搜索**
|
2. 价格对比
|
||||||
- 根据CPU、内存和其他规格查找最合适的实例
|
- 支持多个配置的价格对比
|
||||||
- 支持从AWS官方API和数据库两种数据源查询
|
- 表格和图表展示
|
||||||
- 显示完整规格和价格信息
|
- 导出对比结果
|
||||||
|
|
||||||
3. **价格比较**
|
3. 预算估算
|
||||||
- 支持多个实例配置的并排比较
|
- 支持自定义和预设使用时长
|
||||||
- 生成标准化的报价单
|
- 显示月度成本趋势
|
||||||
- 支持导出Excel格式报价单
|
- 详细的成本明细
|
||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
- **前端**:Vue.js 3 + Element Plus
|
- 前端:Vue.js 3 + Element Plus + ECharts
|
||||||
- **后端**:Python FastAPI
|
- 后端:Python FastAPI + Boto3
|
||||||
- **数据源**:AWS Pricing API + MySQL数据库
|
- 数据源:AWS API
|
||||||
|
|
||||||
## 系统要求
|
## 系统要求
|
||||||
|
|
||||||
- Python 3.9+
|
- Docker 20.10+
|
||||||
|
- Docker Compose 2.0+
|
||||||
- Node.js 14+
|
- Node.js 14+
|
||||||
- npm 6+
|
- npm 6+
|
||||||
- MySQL 5.7+
|
|
||||||
|
|
||||||
## 项目结构
|
## 快速开始
|
||||||
|
|
||||||
|
1. 克隆项目并进入项目目录:
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd calc
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 创建环境变量文件:
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
然后编辑 `.env` 文件,填入必要的环境变量。
|
||||||
|
|
||||||
|
3. 运行安装脚本:
|
||||||
|
```bash
|
||||||
|
chmod +x install.sh
|
||||||
|
./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
安装脚本会自动:
|
||||||
|
- 检查必要的命令是否已安装
|
||||||
|
- 创建必要的目录结构
|
||||||
|
- 构建前端项目
|
||||||
|
- 检查环境变量配置
|
||||||
|
- 检查 SSL 证书(如果有)
|
||||||
|
- 启动所有服务
|
||||||
|
- 检查服务状态
|
||||||
|
|
||||||
|
## 访问应用
|
||||||
|
|
||||||
|
安装完成后,可以通过以下地址访问应用:
|
||||||
|
- 前端界面:http://localhost
|
||||||
|
- 后端 API:http://localhost:8000
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
├── backend/ # 后端项目
|
├── backend/ # 后端服务
|
||||||
│ ├── app/ # 应用代码
|
├── frontend/ # 前端项目
|
||||||
│ │ ├── api/ # API路由
|
├── nginx/ # Nginx 配置
|
||||||
│ │ ├── core/ # 核心配置
|
│ ├── conf.d/ # Nginx 配置文件
|
||||||
│ │ ├── models/ # 数据模型
|
│ └── ssl/ # SSL 证书目录
|
||||||
│ │ └── services/ # 服务层
|
├── docker-compose.yml
|
||||||
│ ├── main.py # 入口文件
|
├── install.sh
|
||||||
│ └── requirements.txt # 依赖包
|
└── README.md
|
||||||
└── frontend/ # 前端项目
|
|
||||||
├── public/ # 静态资源
|
|
||||||
├── src/ # 源代码
|
|
||||||
│ ├── api/ # API调用
|
|
||||||
│ ├── assets/ # 资源文件
|
|
||||||
│ ├── components/ # 组件
|
|
||||||
│ └── views/ # 页面
|
|
||||||
└── package.json # 依赖配置
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 安装与部署
|
## 开发说明
|
||||||
|
|
||||||
### 后端部署
|
|
||||||
|
|
||||||
1. **创建并激活虚拟环境**
|
|
||||||
|
|
||||||
|
### 前端开发
|
||||||
```bash
|
```bash
|
||||||
# 创建虚拟环境
|
cd frontend
|
||||||
conda create -n calc python=3.10
|
npm install
|
||||||
conda activate calc
|
npm run serve
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **安装依赖**
|
### 后端开发
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd backend
|
cd backend
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
python manage.py runserver
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **配置环境变量**
|
## 部署说明
|
||||||
|
|
||||||
创建`.env`文件在backend目录下,添加以下内容:
|
### 使用 SSL 证书
|
||||||
|
|
||||||
|
1. 将 SSL 证书文件放在 `nginx/ssl/` 目录下:
|
||||||
|
- `cert.pem`:SSL 证书文件
|
||||||
|
- `key.pem`:SSL 私钥文件
|
||||||
|
|
||||||
|
2. 修改 `nginx/conf.d/default.conf` 中的 `server_name` 为你的域名。
|
||||||
|
|
||||||
|
### 环境变量
|
||||||
|
|
||||||
|
在 `.env` 文件中配置以下环境变量:
|
||||||
```
|
```
|
||||||
# AWS凭证
|
|
||||||
AWS_ACCESS_KEY_ID=your_access_key
|
AWS_ACCESS_KEY_ID=your_access_key
|
||||||
AWS_SECRET_ACCESS_KEY=your_secret_key
|
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||||
AWS_DEFAULT_REGION=us-east-1
|
AWS_DEFAULT_REGION=your_region
|
||||||
|
|
||||||
# MySQL数据库配置
|
|
||||||
MYSQL_HOST=localhost
|
|
||||||
MYSQL_USER=your_username
|
|
||||||
MYSQL_PASSWORD=your_password
|
|
||||||
MYSQL_DATABASE=aws_price
|
|
||||||
```
|
```
|
||||||
|
|
||||||
4. **启动开发服务器**
|
## 常见问题
|
||||||
|
|
||||||
|
1. 如果遇到权限问题,请确保使用 `sudo` 运行安装脚本:
|
||||||
```bash
|
```bash
|
||||||
# 开发环境
|
sudo ./install.sh
|
||||||
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
||||||
|
|
||||||
# 生产环境
|
|
||||||
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 前端部署
|
2. 如果服务启动失败,可以查看日志:
|
||||||
|
```bash
|
||||||
|
docker-compose logs
|
||||||
|
```
|
||||||
|
|
||||||
1. **安装依赖**
|
3. 如果需要重新构建前端:
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 维护说明
|
||||||
|
|
||||||
|
### 更新应用
|
||||||
|
```bash
|
||||||
|
git pull
|
||||||
|
./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 停止服务
|
||||||
|
```bash
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
### 查看日志
|
||||||
|
```bash
|
||||||
|
docker-compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安装说明
|
||||||
|
|
||||||
|
### 开发环境部署
|
||||||
|
|
||||||
|
#### 后端设置
|
||||||
|
|
||||||
|
1. 创建虚拟环境:
|
||||||
|
```bash
|
||||||
|
python -m venv venv
|
||||||
|
source venv/bin/activate # Linux/Mac
|
||||||
|
venv\Scripts\activate # Windows
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 安装依赖:
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 配置AWS凭证:
|
||||||
|
创建`.env`文件并添加以下内容:
|
||||||
|
```
|
||||||
|
AWS_ACCESS_KEY_ID=your_access_key
|
||||||
|
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||||
|
AWS_DEFAULT_REGION=your_region
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 运行后端服务:
|
||||||
|
```bash
|
||||||
|
cd backend
|
||||||
|
uvicorn main:app --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 前端设置
|
||||||
|
|
||||||
|
1. 安装依赖:
|
||||||
```bash
|
```bash
|
||||||
cd frontend
|
cd frontend
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **启动开发服务器**
|
2. 运行开发服务器:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run serve
|
npm run serve
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **构建生产版本**
|
### 生产环境部署
|
||||||
|
|
||||||
|
#### 后端部署
|
||||||
|
|
||||||
|
1. 安装生产环境依赖:
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
pip install -r requirements.txt
|
||||||
|
pip install gunicorn
|
||||||
```
|
```
|
||||||
|
|
||||||
4. **前端生产环境部署**
|
2. 使用 Gunicorn 启动后端服务:
|
||||||
|
```bash
|
||||||
将`frontend/dist`目录下的文件部署到Web服务器的根目录。
|
cd backend
|
||||||
|
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
|
||||||
### Nginx配置示例
|
```
|
||||||
|
|
||||||
|
3. 配置 Nginx 反向代理(可选):
|
||||||
```nginx
|
```nginx
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name your_domain.com;
|
server_name your_domain.com;
|
||||||
|
|
||||||
# 前端静态文件
|
location /api {
|
||||||
|
proxy_pass http://localhost:8000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 前端部署
|
||||||
|
|
||||||
|
1. 构建生产版本:
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 配置 Nginx 服务静态文件:
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name your_domain.com;
|
||||||
|
|
||||||
|
root /path/to/frontend/dist;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
root /path/to/frontend/dist;
|
|
||||||
index index.html;
|
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 后端API代理
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://127.0.0.1:8000;
|
proxy_pass http://localhost:8000;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## API接口说明
|
### Docker 部署
|
||||||
|
|
||||||
### 主要API端点
|
1. 构建后端镜像:
|
||||||
|
```bash
|
||||||
- `GET /api/regions` - 获取所有可用区域
|
cd backend
|
||||||
- `GET /api/instance-types` - 获取所有实例类型
|
docker build -t aws-calc-backend .
|
||||||
- `POST /api/search-instances` - 搜索符合条件的实例(AWS API方式)
|
|
||||||
- `POST /api/search-instances-v2` - 搜索符合条件的实例(数据库方式)
|
|
||||||
- `POST /api/compare-prices` - 对比多个配置的价格
|
|
||||||
|
|
||||||
### 示例请求
|
|
||||||
|
|
||||||
```json
|
|
||||||
// 搜索实例示例请求
|
|
||||||
POST /api/search-instances-v2
|
|
||||||
{
|
|
||||||
"cpu_cores": 4,
|
|
||||||
"memory_gb": 16,
|
|
||||||
"disk_gb": 100,
|
|
||||||
"region": "us-east-1",
|
|
||||||
"operating_system": "Linux"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 数据库说明
|
2. 构建前端镜像:
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
|
docker build -t aws-calc-frontend .
|
||||||
|
```
|
||||||
|
|
||||||
该应用使用MySQL数据库存储AWS实例价格数据,主要表结构如下:
|
3. 使用 Docker Compose 启动服务:
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
**aws_price表**
|
4. 查看服务状态:
|
||||||
- `id` - 唯一标识符
|
```bash
|
||||||
- `locations` - 区域类型
|
docker-compose ps
|
||||||
- `area_en` - 区域英文名称
|
```
|
||||||
- `area_cn` - 区域中文名称
|
|
||||||
- `instance_type` - 实例类型
|
|
||||||
- `price` - 小时价格
|
|
||||||
- `operating_system` - 操作系统
|
|
||||||
- `vcpu` - CPU核心数
|
|
||||||
- `memory` - 内存大小(GB)
|
|
||||||
- `updatetime` - 更新时间
|
|
||||||
|
|
||||||
## 常见问题解答
|
## 环境变量配置
|
||||||
|
|
||||||
1. **价格计算不准确?**
|
### 后端环境变量
|
||||||
- 确保已配置正确的AWS凭证
|
```env
|
||||||
- 价格可能因区域和时间而变化
|
AWS_ACCESS_KEY_ID=your_access_key
|
||||||
|
AWS_SECRET_ACCESS_KEY=your_secret_key
|
||||||
|
AWS_DEFAULT_REGION=your_region
|
||||||
|
CORS_ORIGINS=http://localhost:8080,https://your_domain.com
|
||||||
|
ENVIRONMENT=production
|
||||||
|
```
|
||||||
|
|
||||||
2. **无法连接数据库?**
|
### 前端环境变量
|
||||||
- 检查数据库连接配置
|
```env
|
||||||
- 确保MySQL服务已启动
|
VUE_APP_API_URL=http://localhost:8000
|
||||||
- 验证用户权限
|
VUE_APP_ENV=production
|
||||||
|
```
|
||||||
|
|
||||||
3. **API返回错误?**
|
## 使用说明
|
||||||
- 检查日志获取详细错误信息
|
|
||||||
- 验证请求格式是否正确
|
1. 访问 http://localhost:8080 打开应用
|
||||||
|
2. 使用导航菜单切换不同的功能页面
|
||||||
|
3. 在表单中选择所需的配置
|
||||||
|
4. 点击计算按钮查看结果
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 确保已配置有效的AWS凭证
|
||||||
|
- 后端服务默认运行在 http://localhost:8000
|
||||||
|
- 前端开发服务器默认运行在 http://localhost:8080
|
||||||
|
- 生产环境部署时请确保:
|
||||||
|
- 使用 HTTPS
|
||||||
|
- 配置适当的安全头部
|
||||||
|
- 启用 CORS 保护
|
||||||
|
- 设置适当的缓存策略
|
||||||
|
- 配置错误监控和日志记录
|
||||||
|
|
||||||
## 贡献指南
|
## 贡献指南
|
||||||
|
|
||||||
1. Fork 项目
|
1. Fork 项目
|
||||||
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
|
2. 创建特性分支
|
||||||
3. 提交更改 (`git commit -m 'Add some amazing feature'`)
|
3. 提交更改
|
||||||
4. 推送到分支 (`git push origin feature/amazing-feature`)
|
4. 推送到分支
|
||||||
5. 创建Pull Request
|
5. 创建 Pull Request
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
|
|||||||
69
docker-compose.yml
Normal file
69
docker-compose.yml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
environment:
|
||||||
|
- DATABASE_URL=postgresql://postgres:postgres@db:5432/calc
|
||||||
|
- REDIS_URL=redis://redis:6379/0
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
- redis
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
nginx:
|
||||||
|
image: nginx:stable-alpine
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
- "443:443"
|
||||||
|
volumes:
|
||||||
|
- ./frontend/dist:/usr/share/nginx/html
|
||||||
|
- ./nginx/conf.d:/etc/nginx/conf.d
|
||||||
|
- ./nginx/ssl:/etc/nginx/ssl
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "nginx", "-t"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:13-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_PASSWORD=postgres
|
||||||
|
- POSTGRES_DB=calc
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:6-alpine
|
||||||
|
volumes:
|
||||||
|
- redis_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
redis_data:
|
||||||
29
frontend/Dockerfile
Normal file
29
frontend/Dockerfile
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# 构建阶段
|
||||||
|
FROM node:16-alpine as build-stage
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制依赖文件
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# 复制源代码
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 构建应用
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# 生产阶段
|
||||||
|
FROM nginx:stable-alpine as production-stage
|
||||||
|
|
||||||
|
# 复制构建产物
|
||||||
|
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
# 复制nginx配置
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
Loading…
x
Reference in New Issue
Block a user