重新整理部署脚本
This commit is contained in:
parent
8cd0bb5c06
commit
047cafa7c7
14
config.py
14
config.py
@ -3,15 +3,15 @@ import os
|
||||
class Config:
|
||||
"""配置类"""
|
||||
# 数据库配置
|
||||
MYSQL_HOST = 'localhost'
|
||||
MYSQL_USER = 'root'
|
||||
MYSQL_PASSWORD = '123456'
|
||||
MYSQL_DB = 'equipment_cost_db'
|
||||
MYSQL_HOST = os.getenv('MYSQL_HOST', 'localhost')
|
||||
MYSQL_USER = os.getenv('MYSQL_USER', 'root')
|
||||
MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD', '123456')
|
||||
MYSQL_DB = os.getenv('MYSQL_DB', 'equipment_cost_db')
|
||||
|
||||
# Flask配置
|
||||
FLASK_HOST = '0.0.0.0'
|
||||
FLASK_PORT = 5001
|
||||
FLASK_DEBUG = True
|
||||
FLASK_DEBUG = os.getenv('FLASK_DEBUG', 'True').lower() == 'true'
|
||||
|
||||
# 目录配置
|
||||
MODEL_DIR = 'models'
|
||||
@ -52,8 +52,8 @@ class Config:
|
||||
CACHE_DEFAULT_TIMEOUT = 300
|
||||
|
||||
# 安全配置
|
||||
SECRET_KEY = 'your-secret-key-here'
|
||||
JWT_SECRET_KEY = 'your-jwt-secret-key-here'
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'your-secret-key-here')
|
||||
JWT_SECRET_KEY = os.getenv('JWT_SECRET_KEY', 'your-jwt-secret-key-here')
|
||||
JWT_ACCESS_TOKEN_EXPIRES = 3600 # 1小时
|
||||
|
||||
# 跨域配置
|
||||
|
||||
30
docs/release_guide.md
Normal file
30
docs/release_guide.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Windows 发布包制作指南
|
||||
|
||||
1. 准备工作
|
||||
|
||||
1.1 安装必要软件
|
||||
|
||||
- Python 3.11.8: <https://www.python.org/downloads/>
|
||||
- Visual Studio Build Tools: <https://visualstudio.microsoft.com/visual-cpp-build-tools/>
|
||||
|
||||
1.2 下载安装程序
|
||||
|
||||
- Python 3.11.8: <https://www.python.org/ftp/python/3.11.8/python-3.11.8-amd64.exe>
|
||||
- Visual C++ Redistributable: <https://aka.ms/vs/17/release/vc_redist.x64.exe(可选,如果系统已安装则不需要)>
|
||||
|
||||
|
||||
1. 克隆项目
|
||||
|
||||
```powershell
|
||||
git clone [repository-url]
|
||||
cd cost-prediction
|
||||
```
|
||||
|
||||
2. 打包步骤
|
||||
|
||||
```powershell
|
||||
# 运行打包脚本
|
||||
.\scripts\build_win.ps1
|
||||
```
|
||||
|
||||
打包完成后会在项目根目录生成 `cost-prediction-[version]-win64.zip`。
|
||||
76
docs/windows_setup.md
Normal file
76
docs/windows_setup.md
Normal file
@ -0,0 +1,76 @@
|
||||
# Windows 开发环境设置
|
||||
|
||||
1. 安装必要软件
|
||||
- Python 3.11.8: <https://www.python.org/downloads/>
|
||||
- Git: <https://git-scm.com/download/win>
|
||||
- MySQL 8.0+: <https://dev.mysql.com/downloads/mysql/>
|
||||
- Visual Studio Build Tools: <https://visualstudio.microsoft.com/visual-cpp-build-tools/>
|
||||
- Node.js 18+ LTS: <https://nodejs.org/download/>,安装时,Chocolatey不是必需的
|
||||
- npm 9+: (随 Node.js 一起安装)
|
||||
|
||||
2. 克隆项目
|
||||
|
||||
```powershell
|
||||
git clone [repository-url]
|
||||
cd cost-prediction
|
||||
```
|
||||
|
||||
3. 设置前端环境
|
||||
|
||||
```powershell
|
||||
# 进入前端目录
|
||||
cd frontend
|
||||
|
||||
# 安装依赖
|
||||
npm install
|
||||
|
||||
# 构建生产版本
|
||||
npm run build
|
||||
|
||||
# 返回项目根目录
|
||||
cd ..
|
||||
```
|
||||
|
||||
4. 设置 Python 环境
|
||||
|
||||
```powershell
|
||||
# 创建虚拟环境
|
||||
python -m venv .venv
|
||||
|
||||
# 激活虚拟环境
|
||||
.\.venv\Scripts\Activate.ps1
|
||||
|
||||
# 安装依赖
|
||||
pip install -e .
|
||||
```
|
||||
|
||||
5. 配置数据库
|
||||
|
||||
```powershell
|
||||
# 确保 MySQL 服务已启动
|
||||
net start MySQL80
|
||||
|
||||
# 初始化数据库和导入数据
|
||||
.\scripts\init_db.ps1
|
||||
|
||||
# 运行数据库配置脚本
|
||||
.\scripts\setup_env.ps1
|
||||
```
|
||||
|
||||
6. 运行测试
|
||||
|
||||
```powershell
|
||||
python src/test_api.py
|
||||
```
|
||||
|
||||
7. 打包项目
|
||||
|
||||
```powershell
|
||||
# 先下载所有依赖
|
||||
.\scripts\download_deps.ps1
|
||||
|
||||
# 然后运行打包脚本
|
||||
.\scripts\build_win.ps1
|
||||
```
|
||||
|
||||
## 注意:如果需要制作发布包,请参考 docs/release_guide.md
|
||||
76
scripts/build_win.ps1
Normal file
76
scripts/build_win.ps1
Normal file
@ -0,0 +1,76 @@
|
||||
# Set console encoding to UTF-8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
# Ensure PowerShell stops on error
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Create virtual environment
|
||||
Write-Host "Creating virtual environment..."
|
||||
python -m venv .venv
|
||||
.\.venv\Scripts\Activate.ps1
|
||||
|
||||
# Install dependencies
|
||||
Write-Host "Installing dependencies..."
|
||||
pip install -e .
|
||||
|
||||
# Build frontend
|
||||
Write-Host "Building frontend..."
|
||||
Push-Location frontend
|
||||
npm install
|
||||
npm run build
|
||||
Pop-Location
|
||||
|
||||
# Package with PyInstaller
|
||||
Write-Host "Starting packaging..."
|
||||
# Create necessary directories
|
||||
New-Item -ItemType Directory -Force -Path "logs"
|
||||
New-Item -ItemType Directory -Force -Path "data"
|
||||
New-Item -ItemType Directory -Force -Path "models"
|
||||
|
||||
pyinstaller --clean `
|
||||
--add-data "src/loitering_munition_data.sql;data" `
|
||||
--add-data "src/rocket_artillery_data.sql;data" `
|
||||
--add-data "src/manufacturer_data.sql;data" `
|
||||
--add-data "src/schema.sql;data" `
|
||||
--add-data "config.py;." `
|
||||
--add-data "src;src" `
|
||||
--add-data "frontend;frontend" `
|
||||
--add-data "logs;logs" `
|
||||
--add-data "data;data" `
|
||||
--add-data "models;models" `
|
||||
--collect-all "xgboost" `
|
||||
--collect-all "lightgbm" `
|
||||
--collect-all "torch" `
|
||||
--collect-all "sklearn" `
|
||||
--collect-all "numpy" `
|
||||
--collect-all "pandas" `
|
||||
--collect-all "sqlalchemy" `
|
||||
--collect-all "pymysql" `
|
||||
--collect-all "cryptography" `
|
||||
--collect-all "flask" `
|
||||
--collect-all "flask_cors" `
|
||||
--hidden-import "xgboost.testing" `
|
||||
--hidden-import "torch.utils.tensorboard" `
|
||||
--hidden-import "pytest" `
|
||||
run.py
|
||||
|
||||
# Copy necessary files
|
||||
Write-Host "Copying configuration files..."
|
||||
Copy-Item "src/start.bat" -Destination "dist/run"
|
||||
|
||||
# Create release package
|
||||
Write-Host "Creating release package..."
|
||||
$version = (Get-Content pyproject.toml | Select-String 'version = "(.*?)"').Matches.Groups[1].Value
|
||||
|
||||
# Create complete offline installation package directory
|
||||
$RELEASE_DIR = "dist/release"
|
||||
New-Item -ItemType Directory -Force -Path $RELEASE_DIR
|
||||
|
||||
# Copy application files
|
||||
Copy-Item "dist/run/*" -Destination $RELEASE_DIR -Recurse
|
||||
|
||||
# Create final zip package
|
||||
Compress-Archive -Path "$RELEASE_DIR/*" -DestinationPath "cost-prediction-$version-win64.zip" -Force
|
||||
|
||||
Write-Host "Package completed: cost-prediction-$version-win64.zip"
|
||||
9
src/start.bat
Normal file
9
src/start.bat
Normal file
@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
set FLASK_DEBUG=false
|
||||
set MYSQL_HOST=localhost
|
||||
set MYSQL_USER=root
|
||||
set MYSQL_PASSWORD=123456
|
||||
set MYSQL_DB=equipment_cost_db
|
||||
echo Starting Cost Prediction System...
|
||||
start /B run.exe
|
||||
start http://localhost:5001
|
||||
Loading…
Reference in New Issue
Block a user