157 lines
5.4 KiB
PowerShell
157 lines
5.4 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[string] $DestinationPath = (
|
|
Join-Path $PSScriptRoot (
|
|
"artifacts\WebAccess.MCP-deployment-{0}\WebAccess.MCP" -f
|
|
(Get-Date -Format "yyyyMMdd-HHmmss"))),
|
|
[switch] $SkipBuild,
|
|
[switch] $NoArchive
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$repositoryRoot = $PSScriptRoot
|
|
$destinationRoot = [System.IO.Path]::GetFullPath($DestinationPath)
|
|
$archivePath = "$destinationRoot.zip"
|
|
|
|
function Copy-DirectoryFiles {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string] $Source,
|
|
|
|
[Parameter(Mandatory)]
|
|
[string] $Destination,
|
|
|
|
[string[]] $ExcludedDirectoryNames = @(),
|
|
|
|
[string[]] $ExcludedFileNames = @()
|
|
)
|
|
|
|
$sourceRoot = [System.IO.Path]::GetFullPath($Source).TrimEnd("\")
|
|
|
|
Get-ChildItem -LiteralPath $sourceRoot -File -Recurse |
|
|
Where-Object {
|
|
$relativePath = $_.FullName.Substring($sourceRoot.Length).TrimStart("\")
|
|
$directoryNames = $relativePath.Split("\")
|
|
$_.Name -notin $ExcludedFileNames -and
|
|
-not ($directoryNames | Where-Object { $_ -in $ExcludedDirectoryNames })
|
|
} |
|
|
ForEach-Object {
|
|
$relativePath = $_.FullName.Substring($sourceRoot.Length).TrimStart("\")
|
|
$targetPath = Join-Path $Destination $relativePath
|
|
$targetDirectory = Split-Path -Parent $targetPath
|
|
|
|
if (-not (Test-Path -LiteralPath $targetDirectory -PathType Container)) {
|
|
New-Item -ItemType Directory -Path $targetDirectory -Force | Out-Null
|
|
}
|
|
|
|
Copy-Item -LiteralPath $_.FullName -Destination $targetPath
|
|
}
|
|
}
|
|
|
|
if (Test-Path -LiteralPath $destinationRoot) {
|
|
throw "Destination already exists: $destinationRoot"
|
|
}
|
|
|
|
if (-not $NoArchive -and (Test-Path -LiteralPath $archivePath)) {
|
|
throw "Archive already exists: $archivePath"
|
|
}
|
|
|
|
$requiredPaths = @(
|
|
(Join-Path $repositoryRoot ".dockerignore"),
|
|
(Join-Path $repositoryRoot "Containerfile"),
|
|
(Join-Path $repositoryRoot "QUICKSTART.md"),
|
|
(Join-Path $repositoryRoot "Readme.md"),
|
|
(Join-Path $repositoryRoot "Start-WebAccessMcp.cmd"),
|
|
(Join-Path $repositoryRoot "deploy\compose.yml"),
|
|
(Join-Path $repositoryRoot "deploy\Start-WebAccessStack.ps1"),
|
|
(Join-Path $repositoryRoot "deploy\searxng\settings.yml"),
|
|
(Join-Path $repositoryRoot "src\WebAccess.MCP\WebAccess.MCP.csproj")
|
|
)
|
|
|
|
foreach ($requiredPath in $requiredPaths) {
|
|
if (-not (Test-Path -LiteralPath $requiredPath -PathType Leaf)) {
|
|
throw "Required deployment file is missing: $requiredPath"
|
|
}
|
|
}
|
|
|
|
if (-not $SkipBuild) {
|
|
if (-not (Get-Command "podman" -ErrorAction SilentlyContinue)) {
|
|
throw "Podman is not installed or is not available in PATH. Install or start Podman, or use -SkipBuild to create the bundle without validating the image build."
|
|
}
|
|
|
|
& podman info *> $null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Podman is not running. Start the Podman machine, or use -SkipBuild to create the bundle without validating the image build."
|
|
}
|
|
|
|
Write-Host "Building the WebAccess.MCP container image..."
|
|
& podman build `
|
|
--file (Join-Path $repositoryRoot "Containerfile") `
|
|
--tag "localhost/webaccess-mcp:compose" `
|
|
$repositoryRoot
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "The WebAccess.MCP container image build failed with exit code $LASTEXITCODE."
|
|
}
|
|
}
|
|
|
|
Write-Host "Creating deployment bundle at $destinationRoot..."
|
|
New-Item -ItemType Directory -Path $destinationRoot -Force | Out-Null
|
|
|
|
Copy-Item `
|
|
-LiteralPath (Join-Path $repositoryRoot ".dockerignore") `
|
|
-Destination (Join-Path $destinationRoot ".dockerignore")
|
|
|
|
Copy-Item `
|
|
-LiteralPath (Join-Path $repositoryRoot "Containerfile") `
|
|
-Destination (Join-Path $destinationRoot "Containerfile")
|
|
|
|
Copy-Item `
|
|
-LiteralPath (Join-Path $repositoryRoot "QUICKSTART.md") `
|
|
-Destination (Join-Path $destinationRoot "QUICKSTART.md")
|
|
|
|
Copy-Item `
|
|
-LiteralPath (Join-Path $repositoryRoot "Readme.md") `
|
|
-Destination (Join-Path $destinationRoot "Readme.md")
|
|
|
|
Copy-Item `
|
|
-LiteralPath (Join-Path $repositoryRoot "Start-WebAccessMcp.cmd") `
|
|
-Destination (Join-Path $destinationRoot "Start-WebAccessMcp.cmd")
|
|
|
|
Copy-DirectoryFiles `
|
|
-Source (Join-Path $repositoryRoot "deploy") `
|
|
-Destination (Join-Path $destinationRoot "deploy") `
|
|
-ExcludedDirectoryNames @("bin", "obj") `
|
|
-ExcludedFileNames @(".env")
|
|
|
|
Copy-DirectoryFiles `
|
|
-Source (Join-Path $repositoryRoot "src\WebAccess.MCP") `
|
|
-Destination (Join-Path $destinationRoot "src\WebAccess.MCP") `
|
|
-ExcludedDirectoryNames @("bin", "obj")
|
|
|
|
Copy-DirectoryFiles `
|
|
-Source (Join-Path $repositoryRoot "docs") `
|
|
-Destination (Join-Path $destinationRoot "docs")
|
|
|
|
$environmentPath = Join-Path $destinationRoot "deploy\.env"
|
|
if (Test-Path -LiteralPath $environmentPath) {
|
|
throw "The deployment bundle unexpectedly contains deploy\.env. Remove the bundle and investigate before distributing it."
|
|
}
|
|
|
|
if (-not $NoArchive) {
|
|
Write-Host "Creating archive at $archivePath..."
|
|
Compress-Archive -LiteralPath $destinationRoot -DestinationPath $archivePath
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Deployment bundle created:"
|
|
Write-Host " Folder: $destinationRoot"
|
|
|
|
if (-not $NoArchive) {
|
|
Write-Host " Archive: $archivePath"
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "The recipient can extract/copy the WebAccess.MCP folder, open it, and run:"
|
|
Write-Host " .\Start-WebAccessMcp.cmd"
|