ЛР2: PostgreSQL, сессии (Basic + Bearer), Compose, миграции

This commit is contained in:
2026-10-16 11:11:00 +03:00
parent 65003b6119
commit 4937d6d4e8
56 changed files with 1969 additions and 26 deletions
+19
View File
@@ -0,0 +1,19 @@
# Windows twin of scripts/init-secrets.sh. Existing files are kept.
$ErrorActionPreference = 'Stop'
Set-Location (Join-Path $PSScriptRoot '..')
New-Item -ItemType Directory -Force secrets | Out-Null
function New-Secret($name, $bytes) {
$path = Join-Path 'secrets' $name
if ((Test-Path $path) -and (Get-Item $path).Length -gt 0) { "kept secrets/$name"; return }
$buffer = New-Object byte[] $bytes
[Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($buffer)
$value = [Convert]::ToBase64String($buffer) -replace '[+/=]', ''
# ASCII, no BOM, no trailing newline.
[IO.File]::WriteAllText((Join-Path (Get-Location) $path), $value, [Text.Encoding]::ASCII)
"created secrets/$name"
}
New-Secret 'postgres_password' 32
New-Secret 'jwt_secret' 64
if (-not (Test-Path .env)) { Copy-Item .env.example .env; 'created .env' }
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# Создать локальные секреты после clone. Существующие файлы не перезаписываются.
set -eu
cd "$(dirname "$0")/.."
mkdir -p secrets
make_secret() {
if [ ! -s "secrets/$1" ]; then
head -c "$2" /dev/urandom | base64 | tr -d '\n+/=' > "secrets/$1"
echo "created secrets/$1"
else
echo "kept secrets/$1"
fi
}
make_secret postgres_password 32
make_secret jwt_secret 64
[ -f .env ] || { cp .env.example .env; echo "created .env"; }
+8
View File
@@ -0,0 +1,8 @@
@echo off
rem Windows twin of scripts/restart.sh: the test cannot execute .sh on Windows.
setlocal
cd /d "%~dp0.."
docker compose stop api postgres || exit /b 1
docker compose up -d --wait || exit /b 1
docker compose ps --format "{{.Name}} {{.Status}}"
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# Hook для make test-persistence: перезапуск API и PostgreSQL с сохранением volumes.
set -eu
cd "$(dirname "$0")/.."
docker compose stop api postgres
# Порядок: postgres (healthy) -> migrate (exit 0) -> api (healthy).
docker compose up -d --wait
docker compose ps --format '{{.Name}} {{.Status}}'