초기 관제 시스템 뼈대 구성
This commit is contained in:
24
scripts/backup-runtime-data.ps1
Normal file
24
scripts/backup-runtime-data.ps1
Normal file
@@ -0,0 +1,24 @@
|
||||
param(
|
||||
[string]$DataDir = "runtime-data",
|
||||
[string]$BackupDir = "backups"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$root = (Resolve-Path ".").Path
|
||||
$resolvedDataDir = Resolve-Path $DataDir
|
||||
|
||||
if (-not $resolvedDataDir.Path.StartsWith($root)) {
|
||||
throw "Refusing to back up a path outside the repository: $($resolvedDataDir.Path)"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$archivePath = Join-Path $BackupDir "cargoradar-runtime-$timestamp.zip"
|
||||
|
||||
Compress-Archive -Path (Join-Path $resolvedDataDir.Path "*") -DestinationPath $archivePath -Force
|
||||
|
||||
[pscustomobject]@{
|
||||
Backup = (Resolve-Path $archivePath).Path
|
||||
} | Format-List
|
||||
32
scripts/health-check.ps1
Normal file
32
scripts/health-check.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
param(
|
||||
[string]$BaseUrl = "http://127.0.0.1:8080",
|
||||
[string]$AdminToken = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Invoke-CargoRadarJson {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
$headers = @{}
|
||||
if ($AdminToken) {
|
||||
$headers["X-Admin-Token"] = $AdminToken
|
||||
}
|
||||
|
||||
Invoke-RestMethod -Uri "$BaseUrl$Path" -Method Get -Headers $headers
|
||||
}
|
||||
|
||||
$health = Invoke-CargoRadarJson -Path "/health"
|
||||
$drivers = Invoke-CargoRadarJson -Path "/api/v1/drivers"
|
||||
$latest = Invoke-CargoRadarJson -Path "/api/v1/locations/latest"
|
||||
|
||||
[pscustomobject]@{
|
||||
BaseUrl = $BaseUrl
|
||||
Health = $health.status
|
||||
ServerTime = $health.time
|
||||
DriverCount = $drivers.drivers.Count
|
||||
LatestLocationCount = $latest.locations.Count
|
||||
} | Format-List
|
||||
76
scripts/package-nas-deploy.ps1
Normal file
76
scripts/package-nas-deploy.ps1
Normal file
@@ -0,0 +1,76 @@
|
||||
param(
|
||||
[string]$OutputDir = "dist"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$root = (Resolve-Path ".").Path
|
||||
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$archivePath = Join-Path $OutputDir "cargoradar-nas-$timestamp.zip"
|
||||
$staging = Join-Path $OutputDir "cargoradar-nas-stage"
|
||||
|
||||
if (Test-Path $staging) {
|
||||
$resolvedStaging = (Resolve-Path $staging).Path
|
||||
if (-not $resolvedStaging.StartsWith($root)) {
|
||||
throw "Refusing to remove outside the repository: $resolvedStaging"
|
||||
}
|
||||
Remove-Item -LiteralPath $resolvedStaging -Recurse -Force
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $staging | Out-Null
|
||||
$stagingPath = (Resolve-Path $staging).Path
|
||||
|
||||
$items = @(
|
||||
".dockerignore",
|
||||
".env.example",
|
||||
".env.nas.example",
|
||||
"Dockerfile",
|
||||
"docker-compose.yml",
|
||||
"README.md",
|
||||
"apps",
|
||||
"docs",
|
||||
"scripts"
|
||||
)
|
||||
|
||||
foreach ($item in $items) {
|
||||
$source = Join-Path $root $item
|
||||
if (-not (Test-Path $source)) {
|
||||
throw "Missing deploy item: $item"
|
||||
}
|
||||
|
||||
Copy-Item -Path $source -Destination $stagingPath -Recurse -Force
|
||||
}
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
|
||||
if (Test-Path $archivePath) {
|
||||
Remove-Item -LiteralPath $archivePath -Force
|
||||
}
|
||||
|
||||
$zip = [System.IO.Compression.ZipFile]::Open($archivePath, [System.IO.Compression.ZipArchiveMode]::Create)
|
||||
try {
|
||||
$files = Get-ChildItem -Path $stagingPath -Recurse -File -Force
|
||||
foreach ($file in $files) {
|
||||
$relativePath = $file.FullName.Substring($stagingPath.Length)
|
||||
$relativePath = $relativePath -replace "^[\\/]+", ""
|
||||
$entryName = $relativePath -replace "\\", "/"
|
||||
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
|
||||
$zip,
|
||||
$file.FullName,
|
||||
$entryName,
|
||||
[System.IO.Compression.CompressionLevel]::Optimal
|
||||
) | Out-Null
|
||||
}
|
||||
}
|
||||
finally {
|
||||
$zip.Dispose()
|
||||
}
|
||||
|
||||
Remove-Item -LiteralPath $stagingPath -Recurse -Force
|
||||
|
||||
[pscustomobject]@{
|
||||
Archive = (Resolve-Path $archivePath).Path
|
||||
} | Format-List
|
||||
29
scripts/post-demo-location.ps1
Normal file
29
scripts/post-demo-location.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
param(
|
||||
[string]$BaseUrl = "http://127.0.0.1:8080",
|
||||
[string]$DeviceToken = "demo-token",
|
||||
[string]$DriverId = "demo-driver",
|
||||
[string]$VehicleNo = "SEOUL-12-3456",
|
||||
[double]$Latitude = 37.5665,
|
||||
[double]$Longitude = 126.9780
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$body = @{
|
||||
driverId = $DriverId
|
||||
vehicleNo = $VehicleNo
|
||||
latitude = $Latitude
|
||||
longitude = $Longitude
|
||||
accuracy = 12
|
||||
speed = 42
|
||||
heading = 90
|
||||
provider = "script"
|
||||
recordedAt = (Get-Date).ToUniversalTime().ToString("o")
|
||||
} | ConvertTo-Json
|
||||
|
||||
Invoke-RestMethod `
|
||||
-Uri "$BaseUrl/api/v1/locations" `
|
||||
-Method Post `
|
||||
-Headers @{ "X-Device-Token" = $DeviceToken } `
|
||||
-ContentType "application/json" `
|
||||
-Body $body
|
||||
Reference in New Issue
Block a user