Files
mtusi2026lab4/scripts/bootstrap.ps1

38 lines
1.4 KiB
PowerShell

$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
Set-Location $Root
New-Item -ItemType Directory -Force -Path (Join-Path $Root "secrets") | Out-Null
function Write-Secret([string]$Name, [string]$Value) {
$path = Join-Path $Root "secrets\$Name"
if (-not (Test-Path $path)) {
[System.IO.File]::WriteAllText($path, $Value)
}
}
function Random-Text([int]$Length) {
$bytes = New-Object byte[] $Length
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
return -join ($bytes | ForEach-Object { $_.ToString("x2") })
}
$pg = Random-Text 16
Write-Secret "postgres_password" $pg
Write-Secret "database_url" "postgresql+asyncpg://messenger:${pg}@postgres:5432/messenger"
Write-Secret "host_database_url" "postgresql+asyncpg://messenger:${pg}@127.0.0.1:5433/messenger"
Write-Secret "cache_url" "redis://redis:6379/0"
Write-Secret "host_cache_url" "redis://127.0.0.1:6379/0"
Write-Secret "minio_root_user" "minioadmin"
Write-Secret "minio_root_password" (Random-Text 16)
Write-Secret "s3_access_key_id" "messengerapi"
Write-Secret "s3_secret_access_key" (Random-Text 16)
Write-Secret "host_s3_endpoint" "http://127.0.0.1:9000"
$envFile = Join-Path $Root ".env"
if (-not (Test-Path $envFile)) {
Copy-Item (Join-Path $Root ".env.example") $envFile
}
Write-Host "secrets and .env are ready"
Write-Host "next: docker compose --env-file .env up -d --build --scale api=2"