Repository navigation
Expand file tree
/
Copy pathstart-VC-solution.ps1
More file actions
135 lines (119 loc) · 4.84 KB
/
Copy pathstart-VC-solution.ps1
File metadata and controls
135 lines (119 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
param (
[string]$solutionFolder = "VirtoLocal",
[bool]$skipSampleData = $true
)
function Test-PortInUse {
param([int]$Port)
if ($IsWindows) {
# Windows: use netstat
$listeningPorts = netstat -an | Where-Object { $_ -match "LISTENING" }
return $listeningPorts | Where-Object { $_ -match ":$Port\s" }
}
else {
# Linux/macOS: use ss command (modern replacement for netstat)
try {
$ssOutput = ss -tuln | Where-Object { $_ -match "LISTEN" }
return $ssOutput | Where-Object { $_ -match ":$Port\s" }
}
catch {
# Fallback: try lsof if ss is not available
try {
$lsofOutput = lsof -i :$Port 2>$null
return $lsofOutput | Where-Object { $_ -match "LISTEN" }
}
catch {
Write-Warning "Could not check port $Port - port checking tools not available"
return $null
}
}
}
}
$scriptsDir = Join-Path $solutionFolder "scripts"
$dockerComposePath = "$solutionFolder/docker-compose.yml"
if (-not (Test-Path -Path $dockerComposePath)) {
Write-Host "Error: Docker compose file not found: $dockerComposePath" -ForegroundColor Red
exit 1
}
. "$scriptsDir/docker-compose-helper.ps1"
# Read DB_PROVIDER from .env
$envFile = Join-Path $solutionFolder ".env"
if (-not (Test-Path -Path $envFile)) {
Write-Host "Error: .env file not found: $envFile" -ForegroundColor Red
exit 1
}
$dbProviderLine = Get-Content $envFile | Select-String -Pattern "^DB_PROVIDER=" | Select-Object -First 1
if (-not $dbProviderLine) {
Write-Host "Error: DB_PROVIDER is not set in $envFile" -ForegroundColor Red
exit 1
}
$dbProvider = $dbProviderLine.Line.Split('=', 2)[1].Trim().ToLower()
$validProviders = @("postgres", "mysql", "sqlserver")
if ($dbProvider -notin $validProviders) {
Write-Host "Error: Invalid DB_PROVIDER '$dbProvider' in .env file. Must be one of: $($validProviders -join ', ')" -ForegroundColor Red
exit 1
}
$dbOverridePath = "$solutionFolder/docker-compose.$dbProvider.yml"
if (-not (Test-Path -Path $dbOverridePath)) {
Write-Host "Error: Docker compose override file not found: $dbOverridePath" -ForegroundColor Red
exit 1
}
Write-Host "Using database provider: $dbProvider" -ForegroundColor Cyan
# Determine which DB port to check based on provider
$dbPortVarMap = @{
"postgres" = "PGSQL_PORT"
"mysql" = "MYSQL_PORT"
"sqlserver" = "MSSQL_PORT"
}
$dbPortVar = $dbPortVarMap[$dbProvider]
Write-Host "Checking required ports..." -ForegroundColor Yellow
$envContent = Get-Content $envFile
# Parse .env into a hashtable once — reused for port checks and URL building.
$envValues = @{}
foreach ($envLine in $envContent) {
if ($envLine -match '^\s*([^#=\s][^=]*)=(.*)$') {
$envValues[$matches[1].Trim()] = $matches[2].Trim()
}
}
# Collect shared ports (non-DB) + the active DB port
$sharedPortVars = @("PLATFORM_PORT", "ES_PORT", "KIBANA_PORT", "REDIS_PORT", "FRONTEND_PORT")
$allPortVars = $sharedPortVars + @($dbPortVar)
$requiredPorts = @()
foreach ($varName in $allPortVars) {
if ($envValues.ContainsKey($varName)) {
$requiredPorts += $envValues[$varName]
}
}
foreach ($port in $requiredPorts) {
Write-Host "Checking port '$port'..."
$portInUse = Test-PortInUse -Port $port
if ($portInUse) {
Write-Host "Local TCP port $port is busy, please review ports configuration in '.env' file" -ForegroundColor Red
exit 1
}
else {
Write-Host "... port '$port' is free"
}
}
Write-Host "Ports check completed" -ForegroundColor Green
$platformPort = if ($envValues.ContainsKey("PLATFORM_PORT")) { $envValues["PLATFORM_PORT"] } else { "8090" }
$platformApiUrl = "http://localhost:$platformPort"
Write-Host "Starting VC solution..." -ForegroundColor Yellow
Invoke-DockerCompose -f $dockerComposePath -f $dbOverridePath up -d
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to start VC solution" -ForegroundColor Red
Write-Host "docker compose command failed with exit code: $LASTEXITCODE" -ForegroundColor Red
exit 1
}
Write-Host "... VC solution started" -ForegroundColor Green
Write-Host "Checking installed modules..." -ForegroundColor Yellow
$solutionFolderLower = $solutionFolder.ToLower()
Invoke-Expression "./$scriptsDir/check-installed-modules.ps1 -ApiUrl $platformApiUrl -ContainerId '$solutionFolderLower-vc-platform-web-1' -watchUrlScriptPath $scriptsDir/watch-url-up.ps1"
Write-Host "... Installed modules checked" -ForegroundColor Green
if ($skipSampleData) {
Write-Host "Skipping sampledata setup (--skipSampleData)" -ForegroundColor Yellow
}
else {
Write-Host "Setting up sampledata..." -ForegroundColor Yellow
Invoke-Expression "./$scriptsDir/setup-sampledata.ps1 -ApiUrl $platformApiUrl -Verbose -Debug"
Write-Host "... Sampledata set up" -ForegroundColor Green
}