59 lines
2.4 KiB
PowerShell
59 lines
2.4 KiB
PowerShell
# 确保在项目根目录下执行此脚本
|
|
|
|
# 7-Zip路径 - 请根据实际安装位置修改
|
|
$7zipPath = "D:\7zip\7-Zip\7z.exe" # 原始路径
|
|
# $7zipPath = "C:\Program Files\7-Zip\7z.exe" # 修改后的路径
|
|
|
|
# 创建临时部署目录
|
|
New-Item -Path "deploy_temp" -ItemType Directory -Force
|
|
|
|
# 复制整个项目目录到临时目录
|
|
Copy-Item -Path "role_based_system" -Destination "deploy_temp\" -Recurse -Force
|
|
Copy-Item -Path "user_management" -Destination "deploy_temp\" -Recurse -Force
|
|
Copy-Item -Path "manage.py" -Destination "deploy_temp\" -Force
|
|
Copy-Item -Path "requirements.txt" -Destination "deploy_temp\" -Force
|
|
Copy-Item -Path "*.md" -Destination "deploy_temp\" -Force -ErrorAction SilentlyContinue
|
|
|
|
# 移除不需要的文件和目录
|
|
Get-ChildItem -Path "deploy_temp" -Recurse -Filter "__pycache__" -Directory | Remove-Item -Recurse -Force
|
|
Get-ChildItem -Path "deploy_temp" -Recurse -Filter "*.pyc" | Remove-Item -Force
|
|
|
|
# 特别排除不需要的目录
|
|
$excludeDirs = @(
|
|
".git", ".idea", ".vscode",
|
|
"venv", ".venv", "env", "__pycache__", "migrations"
|
|
)
|
|
|
|
foreach ($dir in $excludeDirs) {
|
|
Get-ChildItem -Path "deploy_temp" -Recurse -Directory -Filter $dir |
|
|
Where-Object { $_.FullName -notmatch "\\migrations\\__pycache__" } |
|
|
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# 保留migrations目录但删除其中的pyc文件
|
|
if (Test-Path "deploy_temp\user_management\migrations") {
|
|
Get-ChildItem -Path "deploy_temp\user_management\migrations" -Filter "*.pyc" | Remove-Item -Force
|
|
Get-ChildItem -Path "deploy_temp\user_management\migrations" -Directory -Filter "__pycache__" | Remove-Item -Recurse -Force
|
|
}
|
|
|
|
# 排除不需要的文件
|
|
$excludeFiles = @(
|
|
"*.pyc", "*.pyo", "*.pyd", "*.so", "*.dll",
|
|
"*.db", "*.sqlite3", "*.log", "*.zip", "*.tar.gz",
|
|
"local_settings.py", "*.bak"
|
|
)
|
|
|
|
foreach ($pattern in $excludeFiles) {
|
|
Get-ChildItem -Path "deploy_temp" -Recurse -Filter $pattern | Remove-Item -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
|
|
# 使用7-Zip打包
|
|
& $7zipPath a -ttar knowledge_system.tar ".\deploy_temp\*"
|
|
& $7zipPath a -tgzip knowledge_system.tar.gz knowledge_system.tar
|
|
|
|
# 清理临时文件
|
|
Remove-Item -Path "knowledge_system.tar" -Force
|
|
Remove-Item -Path "deploy_temp" -Recurse -Force
|
|
|
|
Write-Host "部署包已创建: knowledge_system.tar.gz" -ForegroundColor Green |