141 lines
4.0 KiB
PowerShell
141 lines
4.0 KiB
PowerShell
# Build deployment package
|
|
param(
|
|
[switch]$SinglePort
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$DistDir = "deploy-dist"
|
|
|
|
Write-Host "=== Building deployment package ===" -ForegroundColor Green
|
|
if ($SinglePort) {
|
|
Write-Host "Mode: Single Port (8080->80)" -ForegroundColor Cyan
|
|
} else {
|
|
Write-Host "Mode: Multi Port (8888+9000-9100)" -ForegroundColor Cyan
|
|
}
|
|
|
|
# 1. Clean old directory
|
|
if (Test-Path $DistDir) {
|
|
Write-Host "Cleaning old directory..." -ForegroundColor Yellow
|
|
Remove-Item -Recurse -Force $DistDir
|
|
}
|
|
|
|
# 2. Create directory structure
|
|
Write-Host "Creating directory structure..." -ForegroundColor Yellow
|
|
New-Item -ItemType Directory -Path $DistDir -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/server" -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/client/dist" -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/data" -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/projects" -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/nginx/sites-enabled" -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$DistDir/deploy" -Force | Out-Null
|
|
|
|
# 3. Install backend dependencies
|
|
Write-Host "Installing backend dependencies..." -ForegroundColor Yellow
|
|
npm install --production
|
|
|
|
# 4. Build frontend
|
|
Write-Host "Building frontend..." -ForegroundColor Yellow
|
|
Set-Location client
|
|
npm install
|
|
npm run build
|
|
Set-Location ..
|
|
|
|
# 5. Copy files
|
|
Write-Host "Copying files..." -ForegroundColor Yellow
|
|
|
|
# Backend code
|
|
Copy-Item -Recurse -Force "server/*" "$DistDir/server/"
|
|
|
|
# Frontend build
|
|
Copy-Item -Recurse -Force "client/dist/*" "$DistDir/client/dist/"
|
|
|
|
# Config files
|
|
Copy-Item -Force "package.json" "$DistDir/"
|
|
Copy-Item -Force "package-lock.json" "$DistDir/"
|
|
Copy-Item -Force ".env.example" "$DistDir/"
|
|
|
|
# Docker files
|
|
Copy-Item -Force "deploy/start.sh" "$DistDir/deploy/"
|
|
|
|
if ($SinglePort) {
|
|
Copy-Item -Force "deploy/Dockerfile.single" "$DistDir/Dockerfile"
|
|
Copy-Item -Force "deploy/docker-compose.single.yml" "$DistDir/docker-compose.yml"
|
|
} else {
|
|
Copy-Item -Force "deploy/Dockerfile" "$DistDir/Dockerfile"
|
|
Copy-Item -Force "deploy/docker-compose.yml" "$DistDir/docker-compose.yml"
|
|
}
|
|
|
|
# 6. Create .env file
|
|
Write-Host "Creating .env file..." -ForegroundColor Yellow
|
|
if ($SinglePort) {
|
|
$envContent = @"
|
|
PORT=8888
|
|
BASE_DOMAIN=
|
|
PROJECT_PORT_START=9000
|
|
PROJECT_PORT_END=9100
|
|
PROJECT_BIND_ADDRESS=127.0.0.1
|
|
USE_NGINX=true
|
|
"@
|
|
} else {
|
|
$envContent = @"
|
|
PORT=8888
|
|
BASE_DOMAIN=
|
|
PROJECT_PORT_START=9000
|
|
PROJECT_PORT_END=9100
|
|
PROJECT_BIND_ADDRESS=0.0.0.0
|
|
USE_NGINX=false
|
|
"@
|
|
}
|
|
Set-Content -Path "$DistDir/.env" -Value $envContent -Encoding UTF8
|
|
|
|
# 7. Create README
|
|
$readmeContent = @"
|
|
# Deployment Guide
|
|
|
|
## Mode: $(if ($SinglePort) { "Single Port" } else { "Multi Port" })
|
|
|
|
## Quick Start
|
|
|
|
1. Edit .env file, set BASE_DOMAIN to your domain
|
|
|
|
2. Start container:
|
|
docker-compose up -d
|
|
|
|
3. Access admin panel:
|
|
http://your-server-ip$(if ($SinglePort) { "" } else { ":8888" })
|
|
|
|
## Default Account
|
|
|
|
- Username: admin
|
|
- Password: admin123
|
|
|
|
## Ports
|
|
|
|
$(if ($SinglePort) { "- 8080: Admin and all projects" } else { "- 8888: Admin panel`n- 9000-9009: Project ports" })
|
|
|
|
## Commands
|
|
|
|
docker-compose logs -f
|
|
docker-compose restart
|
|
docker-compose down
|
|
"@
|
|
Set-Content -Path "$DistDir/README.md" -Value $readmeContent -Encoding UTF8
|
|
|
|
# 8. Create zip
|
|
Write-Host "Creating zip file..." -ForegroundColor Yellow
|
|
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
|
$modeSuffix = if ($SinglePort) { "-single" } else { "-multi" }
|
|
$zipFile = "auto-deploy-dist$modeSuffix-$timestamp.zip"
|
|
Compress-Archive -Path "$DistDir/*" -DestinationPath $zipFile
|
|
|
|
Write-Host ""
|
|
Write-Host "=== Build Complete ===" -ForegroundColor Green
|
|
Write-Host "Mode: $(if ($SinglePort) { 'Single Port (8080->80)' } else { 'Multi Port (8888+9000-9100)' })" -ForegroundColor Cyan
|
|
Write-Host "Package: $zipFile" -ForegroundColor Cyan
|
|
Write-Host "Directory: $DistDir" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Upload to server and run:" -ForegroundColor Yellow
|
|
Write-Host " unzip $zipFile" -ForegroundColor White
|
|
Write-Host " docker-compose up -d" -ForegroundColor White
|