-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
220 lines (195 loc) · 10.3 KB
/
Copy pathsetup.ps1
File metadata and controls
220 lines (195 loc) · 10.3 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# === nur-CityScope Setup Script (Windows PowerShell) ===
# This script sets up the nur-CityScope project using Docker.
# Determine script directory
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
# Navigate to script directory
Set-Location $SCRIPT_DIR
# Create necessary migration folders
Write-Host "Creating required migration folders..." -ForegroundColor Cyan
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-io\core\external_files" | Out-Null
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-io\core\migrations" | Out-Null
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-io\backend\migrations" | Out-Null
# Create empty __init__.py files
if (-not (Test-Path "$SCRIPT_DIR\nur-io\core\migrations\__init__.py")) {
New-Item -ItemType File -Path "$SCRIPT_DIR\nur-io\core\migrations\__init__.py" | Out-Null
}
if (-not (Test-Path "$SCRIPT_DIR\nur-io\backend\migrations\__init__.py")) {
New-Item -ItemType File -Path "$SCRIPT_DIR\nur-io\backend\migrations\__init__.py" | Out-Null
}
# Copy logo to required locations
Write-Host "Ensuring logo files are in place..." -ForegroundColor Cyan
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-io\django_api\media" | Out-Null
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-front\frontend\public\media" | Out-Null
$logoSource = "$SCRIPT_DIR\nur-front\frontend\public\Nur-Logo_3x-_1_.svg"
if (Test-Path $logoSource) {
Copy-Item -Path $logoSource -Destination "$SCRIPT_DIR\nur-io\django_api\media\" -Force
Copy-Item -Path $logoSource -Destination "$SCRIPT_DIR\nur-front\frontend\public\media\" -Force
}
# Handle Docker network - remove if it exists with wrong labels, then let compose create it
Write-Host "Setting up Docker network..." -ForegroundColor Cyan
$networkExists = docker network inspect nur_core 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Removing existing network to avoid conflicts..." -ForegroundColor Yellow
docker network rm nur_core 2>$null
Start-Sleep -Seconds 2
}
# Start the services (build if needed)
Write-Host "Starting services (this may take a while on first run)..." -ForegroundColor Cyan
$env:COMPOSE_BAKE = "true"
docker-compose up -d --build
# Wait for containers to be running
Write-Host "Waiting for containers to be ready..." -ForegroundColor Cyan
$maxAttempts = 30
$attempt = 0
$containersReady = $false
while ($attempt -lt $maxAttempts -and -not $containersReady) {
Start-Sleep -Seconds 2
$apiStatus = docker ps --filter "name=nur-api" --format "{{.Status}}" 2>$null
if ($apiStatus -and $apiStatus -match "Up") {
$containersReady = $true
Write-Host "Containers are ready!" -ForegroundColor Green
} else {
$attempt++
Write-Host "Waiting for containers... ($attempt/$maxAttempts)" -ForegroundColor Gray
}
}
if (-not $containersReady) {
Write-Host "Warning: Containers may not be fully ready. Checking status..." -ForegroundColor Yellow
docker-compose ps
Write-Host "You may need to wait a bit longer or check logs with: docker-compose logs" -ForegroundColor Yellow
}
# Copy logo file into nginx container (wait a bit more for nginx)
Start-Sleep -Seconds 5
Write-Host "Ensuring logo is accessible in nginx container..." -ForegroundColor Cyan
if (Test-Path $logoSource) {
$nginxRunning = docker ps --filter "name=nginx-front" --format "{{.Status}}" 2>$null
if ($nginxRunning -and $nginxRunning -match "Up") {
docker cp "$logoSource" nginx-front:/usr/share/nginx/html/media/ 2>$null
} else {
Write-Host "Warning: nginx container not ready yet, logo copy skipped" -ForegroundColor Yellow
}
}
# Setup OTEF Interactive - process layer packs (process_layers.py)
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCmd) {
$pythonCmd = Get-Command python3 -ErrorAction SilentlyContinue
}
if ($pythonCmd) {
$venvPath = "$SCRIPT_DIR\otef-interactive\scripts\.venv"
if (-not (Test-Path $venvPath)) {
Write-Host "Creating Python virtual environment for layer processing..." -ForegroundColor Gray
& $pythonCmd.Name -m venv "$venvPath"
}
# Ensure dependencies are installed
Write-Host "Ensuring dependencies are installed..." -ForegroundColor Gray
& "$venvPath\Scripts\python" -m pip install -q -r "$SCRIPT_DIR\otef-interactive\scripts\requirements.txt"
# Fetch source layers if needed
Write-Host "Fetching source layers if needed..." -ForegroundColor Cyan
& "$venvPath\Scripts\python" "$SCRIPT_DIR\otef-interactive\scripts\fetch_data.py" --output "$SCRIPT_DIR\otef-interactive\public\source"
$dockerRunning = docker info 2>$null
if ($LASTEXITCODE -eq 0) {
$manifestPath = "$SCRIPT_DIR\otef-interactive\public\processed\layers\layers-manifest.json"
$shouldProcess = $true
if (Test-Path $manifestPath) {
$manifestTime = (Get-Item $manifestPath).LastWriteTime
$sourceDir = "$SCRIPT_DIR\otef-interactive\public\source\layers"
$newerFiles = Get-ChildItem -Path $sourceDir -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -gt $manifestTime }
if ($null -eq $newerFiles -or $newerFiles.Count -eq 0) {
Write-Host "Layer packs already processed (manifest up to date), skipping..." -ForegroundColor Gray
$shouldProcess = $false
}
}
if ($shouldProcess) {
Write-Host "Processing layer packs (process_layers.py)..." -ForegroundColor Cyan
& "$venvPath\Scripts\python" "$SCRIPT_DIR\otef-interactive\scripts\process_layers.py" `
--source "$SCRIPT_DIR\otef-interactive\public\source\layers" `
--output "$SCRIPT_DIR\otef-interactive\public\processed\layers"
}
} else {
Write-Host "Warning: Docker not running, skipping layer pack processing" -ForegroundColor Yellow
}
} else {
Write-Host "Warning: Python not found, skipping layer pack processing" -ForegroundColor Yellow
}
# Ensure OTEF frontend dependencies (for tests and dev)
Write-Host "Ensuring OTEF frontend dependencies..." -ForegroundColor Cyan
$npmCmd = Get-Command npm -ErrorAction SilentlyContinue
if ($npmCmd) {
Write-Host " Installing OTEF frontend dependencies (npm install)..." -ForegroundColor Gray
npm install --prefix "$SCRIPT_DIR\otef-interactive"
} else {
Write-Host " Warning: npm not found, skipping otef-interactive deps (run 'npm install' in otef-interactive manually)" -ForegroundColor Yellow
}
# Copy model-bounds.json if it doesn't exist in Django API directory
$modelBoundsSource = "$SCRIPT_DIR\otef-interactive\frontend\data\model-bounds.json"
$modelBoundsDest = "$SCRIPT_DIR\nur-io\django_api\public\processed\otef\model-bounds.json"
if (-not (Test-Path $modelBoundsDest) -and (Test-Path $modelBoundsSource)) {
Write-Host "Copying model-bounds.json to Django API directory..." -ForegroundColor Cyan
New-Item -ItemType Directory -Force -Path "$SCRIPT_DIR\nur-io\django_api\public\processed\otef" | Out-Null
Copy-Item -Path $modelBoundsSource -Destination $modelBoundsDest -Force
}
# Run migrations (only if container is running)
Write-Host "Running database migrations..." -ForegroundColor Cyan
$apiRunning = docker ps --filter "name=nur-api" --format "{{.Status}}" 2>$null
if ($apiRunning -and $apiRunning -match "Up") {
docker exec nur-api python manage.py migrate
if ($LASTEXITCODE -ne 0) {
Write-Host "Warning: Migrations may have failed. Check logs with: docker-compose logs nur-api" -ForegroundColor Yellow
}
} else {
Write-Host "Error: nur-api container is not running. Check logs with: docker-compose logs nur-api" -ForegroundColor Red
Write-Host "You may need to rebuild containers: docker-compose up --build -d" -ForegroundColor Yellow
exit 1
}
# Create data (loads real data from public/)
Write-Host "Creating data structure..." -ForegroundColor Cyan
docker exec nur-api python manage.py create_data
if ($LASTEXITCODE -ne 0) {
Write-Host "Warning: Data creation may have failed. Check logs with: docker-compose logs nur-api" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "All services have been successfully configured and data has been loaded." -ForegroundColor Green
Write-Host ""
# Get local IP address
$localIP = $null
try {
$networkAdapters = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue |
Where-Object {
$_.IPAddress -notlike "127.*" -and
$_.IPAddress -notlike "169.254.*" -and
$_.InterfaceAlias -notlike "*Loopback*"
} |
Sort-Object InterfaceIndex |
Select-Object -First 1
if ($networkAdapters) {
$localIP = $networkAdapters.IPAddress
}
} catch {
# Fallback method
$localIP = (Get-NetIPConfiguration -ErrorAction SilentlyContinue |
Where-Object { $_.IPv4Address.IPAddress -notlike "127.*" -and $_.IPv4Address.IPAddress -notlike "169.254.*" } |
Select-Object -First 1).IPv4Address.IPAddress
}
Write-Host "You can now access:" -ForegroundColor Green
Write-Host ""
Write-Host "Local access (localhost):" -ForegroundColor Yellow
Write-Host "- Dashboard: http://localhost/dashboard/" -ForegroundColor Cyan
Write-Host "- Projection: http://localhost/projection/" -ForegroundColor Cyan
Write-Host "- Remote Controller: http://localhost/remote/" -ForegroundColor Cyan
Write-Host "- OTEF Interactive: http://localhost/otef-interactive/" -ForegroundColor Cyan
Write-Host "- OTEF Projection: http://localhost/otef-interactive/projection.html" -ForegroundColor Cyan
Write-Host "- Admin Interface: http://localhost:9900/admin" -ForegroundColor Cyan
if ($localIP) {
Write-Host ""
Write-Host "Network access (from other devices):" -ForegroundColor Yellow
Write-Host "- Dashboard: http://$localIP/dashboard/" -ForegroundColor Cyan
Write-Host "- Projection: http://$localIP/projection/" -ForegroundColor Cyan
Write-Host "- Remote Controller: http://$localIP/remote/" -ForegroundColor Cyan
Write-Host "- OTEF Interactive: http://$localIP/otef-interactive/" -ForegroundColor Cyan
Write-Host "- OTEF Projection: http://$localIP/otef-interactive/projection.html" -ForegroundColor Cyan
Write-Host "- Admin Interface: http://$localIP:9900/admin" -ForegroundColor Cyan
} else {
Write-Host ""
Write-Host "Could not detect local IP address for network access" -ForegroundColor Yellow
}