forked from mtusi2026/mtusi2026lab2
ЛР2: PostgreSQL, сессии (Basic + Bearer), Compose, миграции
This commit is contained in:
@@ -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' }
|
||||
Executable
+18
@@ -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"; }
|
||||
@@ -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}}"
|
||||
Executable
+9
@@ -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}}'
|
||||
Reference in New Issue
Block a user