129 lines
4.6 KiB
PowerShell
129 lines
4.6 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Exports all required Finlytic Docker images to .tar archives and saves/transfers them directly to the network share.
|
|
.DESCRIPTION
|
|
Checks all 9 Finlytic microservice images, verifies network path availability,
|
|
exports each image directly (or with copy) to \\SONA\appdata\finlytic\images,
|
|
and displays progress and total transferred size.
|
|
#>
|
|
|
|
param (
|
|
[string]$DestinationPath = "\\SONA\appdata\finlytic\images",
|
|
[switch]$BuildFirst = $false
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$images = @(
|
|
"finlyticassets",
|
|
"finlyticnews",
|
|
"finlyticfundamentals",
|
|
"finlyticsentiment",
|
|
"finlytictechnicals",
|
|
"finlyticengine",
|
|
"finlyticsimulation",
|
|
"finlyticbot",
|
|
"finlyticnotify",
|
|
"finlyticbackend"
|
|
)
|
|
|
|
Write-Host "============================================================" -ForegroundColor Cyan
|
|
Write-Host " Finlytic Docker Images Export & Server Transfer" -ForegroundColor Cyan
|
|
Write-Host "============================================================" -ForegroundColor Cyan
|
|
Write-Host "Target Server Share : $DestinationPath" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# 1. Check destination share connectivity
|
|
if (-not (Test-Path -Path $DestinationPath)) {
|
|
Write-Host "[INFO] Target directory does not exist. Attempting to create it..." -ForegroundColor Gray
|
|
try {
|
|
New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
|
|
Write-Host "[OK] Destination folder successfully created." -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Host "[ERROR] Could not access or create network share: $DestinationPath" -ForegroundColor Red
|
|
Write-Host "Please make sure \\SONA is online and credentials/permissions are valid." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
} else {
|
|
Write-Host "[OK] Target server share is accessible." -ForegroundColor Green
|
|
}
|
|
|
|
# 2. Optional: Build images first
|
|
if ($BuildFirst) {
|
|
Write-Host ""
|
|
Write-Host "[BUILD] Building all Docker images from compose.yaml..." -ForegroundColor Cyan
|
|
docker compose -f (Join-Path $PSScriptRoot "..\compose.yaml") build
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "[ERROR] Docker build failed. Aborting export." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Starting export of $($images.Count) service images..." -ForegroundColor Cyan
|
|
Write-Host "------------------------------------------------------------" -ForegroundColor Gray
|
|
|
|
$exported = 0
|
|
$failed = @()
|
|
$missing = @()
|
|
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
|
|
|
|
foreach ($img in $images) {
|
|
$ref = "$img`:latest"
|
|
$targetTar = Join-Path $DestinationPath "$img.tar"
|
|
|
|
# Verify if image exists locally in Docker
|
|
docker image inspect $ref *> $null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "[SKIP] Image '$ref' not found locally in Docker." -ForegroundColor Yellow
|
|
$missing += $img
|
|
continue
|
|
}
|
|
|
|
$imgWatch = [System.Diagnostics.Stopwatch]::StartNew()
|
|
Write-Host "[EXPORT] Saving $ref -> $targetTar ... " -NoNewline -ForegroundColor White
|
|
|
|
try {
|
|
# Export directly to network share
|
|
docker save -o $targetTar $ref
|
|
$imgWatch.Stop()
|
|
|
|
if ($LASTEXITCODE -eq 0 -and (Test-Path $targetTar)) {
|
|
$fileSizeMB = [math]::Round((Get-Item $targetTar).Length / 1MB, 2)
|
|
Write-Host "DONE! ($fileSizeMB MB in $($imgWatch.Elapsed.ToString('mm\:ss')))" -ForegroundColor Green
|
|
$exported++
|
|
} else {
|
|
Write-Host "FAILED!" -ForegroundColor Red
|
|
$failed += $img
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host "ERROR: $_" -ForegroundColor Red
|
|
$failed += $img
|
|
}
|
|
}
|
|
|
|
$stopwatch.Stop()
|
|
|
|
Write-Host "------------------------------------------------------------" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "======================= SUMMARY ============================" -ForegroundColor Cyan
|
|
Write-Host "Successfully Exported : $exported / $($images.Count)" -ForegroundColor Green
|
|
|
|
if ($missing.Count -gt 0) {
|
|
Write-Host "Missing locally : $($missing -join ', ')" -ForegroundColor Yellow
|
|
Write-Host " -> Tip: Run 'docker compose build' to build all images." -ForegroundColor DarkGray
|
|
}
|
|
|
|
if ($failed.Count -gt 0) {
|
|
Write-Host "Failed to Export : $($failed -join ', ')" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "Total Duration : $($stopwatch.Elapsed.ToString('mm\:ss'))" -ForegroundColor Cyan
|
|
Write-Host "============================================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "To load these images on your server, run on the server:" -ForegroundColor White
|
|
Write-Host ' for f in /pfad/zu/appdata/finlytic/images/*.tar; do docker load -i "$f"; done' -ForegroundColor Yellow
|
|
Write-Host ""
|