#Requires -Version 7 <# .SYNOPSIS Prepares a deployment package for LinkSyncServer. .DESCRIPTION Copies only the files needed for production deployment to a target folder, excludes development artifacts, and creates a starter .env file. After running, the user should edit the .env file with production secrets and run docker-compose up -d --build in the target folder. .PARAMETER DeployPath Path to the deployment folder. Will be created if it does not exist. .EXAMPLE .\deploy.ps1 -DeployPath "..\linksync-deploy" .\deploy.ps1 ..\linksync-deploy #> param( [Parameter(Mandatory = $true, Position = 0)] [string]$DeployPath ) $ErrorActionPreference = "Stop" $SourceDir = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path } # Patterns excluded from deployment Write-Host "LinkSyncServer - Deploy Script" -ForegroundColor Cyan Write-Host " Source: $SourceDir" -ForegroundColor Gray Write-Host " Deploy to: $DeployPath" -ForegroundColor Gray Write-Host "" # Resolve to absolute path if (Test-Path $DeployPath) { $DeployPath = (Get-Item $DeployPath).FullName } else { $DeployPath = (New-Item -ItemType Directory -Force -Path $DeployPath).FullName } # Clean target folder if it exists and has content if (Test-Path $DeployPath) { $existing = Get-ChildItem -Path $DeployPath -Force -ErrorAction SilentlyContinue if ($existing) { $confirm = Read-Host "Target folder already exists. Clear it? (y/N)" if ($confirm -ne "y") { Write-Host "Aborted." -ForegroundColor Yellow exit 1 } Remove-Item -Path "$DeployPath\*" -Recurse -Force } } else { New-Item -ItemType Directory -Force -Path $DeployPath | Out-Null } Write-Host "Copying files..." -ForegroundColor Gray # Build robocopy arguments $robocopyArgs = @( $SourceDir, $DeployPath, "/E", "/NFL", "/NDL", "/NJH", "/NJS", "/NC", "/NS", "/NP", "/XD", "__pycache__", ".pytest_cache", ".git", ".vscode", ".idea", ".mypy_cache", ".ruff_cache", "node_modules", "dist", "build", "tests", "/XF", "*.pyc", "*.pyo", "*.pyd", "*.db", "*.sqlite3", "*.egg-info", "deploy.ps1", "deploy.sh" ) $result = & robocopy @robocopyArgs # robocopy exit codes: 0-7 are success, 8+ are errors $exitCode = $LASTEXITCODE if ($exitCode -ge 8) { Write-Host "Error during file copy (robocexit code: $exitCode)" -ForegroundColor Red exit 1 } # Copy .env.example as .env if (Test-Path "$SourceDir\.env.example") { Copy-Item "$SourceDir\.env.example" "$DeployPath\.env" Write-Host " Created .env from .env.example" -ForegroundColor Green } Write-Host "" Write-Host "Deployment package prepared at: $DeployPath" -ForegroundColor Cyan Write-Host "" Write-Host "Next steps:" -ForegroundColor Yellow Write-Host " 1. Edit $DeployPath\.env with production secrets" -ForegroundColor Gray Write-Host " - Set DATABASE_URL (PostgreSQL connection string)" -ForegroundColor Gray Write-Host " - Set SECRET_KEY (generate: openssl rand -base64 32)" -ForegroundColor Gray Write-Host " - Set ADMIN_PASSWORD (strong password)" -ForegroundColor Gray Write-Host " 2. Run: cd $DeployPath" -ForegroundColor Gray Write-Host " 3. Run: docker-compose up -d --build" -ForegroundColor Gray Write-Host ""