ЛР 2: PostgreSQL, сессии и Valkey — на 4
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Set-Location (Join-Path $PSScriptRoot '..')
|
||||
$encoding = New-Object System.Text.UTF8Encoding($false)
|
||||
New-Item -ItemType Directory -Force secrets | Out-Null
|
||||
if (-not (Test-Path secrets/postgres_password)) {
|
||||
$bytes = New-Object byte[] 32
|
||||
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
|
||||
$rng.GetBytes($bytes)
|
||||
$rng.Dispose()
|
||||
$password = [BitConverter]::ToString($bytes).Replace('-', '').ToLowerInvariant()
|
||||
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/postgres_password'), $password, $encoding)
|
||||
}
|
||||
$password = [IO.File]::ReadAllText((Join-Path $PWD 'secrets/postgres_password')).Trim()
|
||||
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/database_url'), "postgresql://messenger:${password}@postgres:5432/messenger", $encoding)
|
||||
[IO.File]::WriteAllText((Join-Path $PWD 'secrets/cache_url'), 'redis://valkey:6379/0', $encoding)
|
||||
if (-not (Test-Path .env)) { Copy-Item .env.example .env }
|
||||
Write-Output 'Local configuration ready; secrets were not printed.'
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p secrets
|
||||
chmod 700 secrets
|
||||
umask 077
|
||||
if [ ! -f secrets/postgres_password ]; then
|
||||
od -An -N32 -tx1 /dev/urandom | tr -d ' \n' > secrets/postgres_password
|
||||
fi
|
||||
password=$(cat secrets/postgres_password)
|
||||
for file in secrets/database_url secrets/cache_url; do
|
||||
[ ! -f "$file" ] || chmod u+w "$file"
|
||||
done
|
||||
printf 'postgresql://messenger:%s@postgres:5432/messenger' "$password" > secrets/database_url
|
||||
printf 'redis://valkey:6379/0' > secrets/cache_url
|
||||
# The parent directory protects host access; bind-mounted files must be readable
|
||||
# by the non-root API user inside its container (Compose file secrets preserve modes).
|
||||
chmod 444 secrets/postgres_password secrets/database_url secrets/cache_url
|
||||
[ -f .env ] || cp .env.example .env
|
||||
printf '%s\n' 'Local configuration ready; secrets were not printed.'
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
# Stage this script with Git mode 100755; filesystem chmod alone is insufficient on Windows.
|
||||
# All three application dependencies are restarted; volumes are preserved.
|
||||
docker compose --env-file .env restart api postgres valkey
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p evidence
|
||||
# Run from host: docker compose --profile test run --rm tools sh scripts/run-checks.sh
|
||||
# Container has the workspace and Docker socket; it is a trusted operator tool only.
|
||||
make check validate > evidence/checks.txt 2>&1
|
||||
make test BASE_URL=http://api:8080 > evidence/smoke.txt 2>&1
|
||||
python student-tests/grade4.py core > evidence/student.txt 2>&1
|
||||
python student-tests/grade4.py expiry --base-url http://api-expiry:8080 > evidence/expiry.txt 2>&1
|
||||
python student-tests/grade4.py migrations > evidence/migrations.txt 2>&1
|
||||
python student-tests/grade4.py explain > evidence/explain.txt 2>&1
|
||||
python student-tests/grade4.py failures > evidence/failures.txt 2>&1
|
||||
docker compose ps -q api postgres valkey | xargs docker inspect --format '{{.Name}} {{.State.StartedAt}} {{.Image}}' > evidence/persistence.txt
|
||||
chmod +x scripts/restart.sh
|
||||
make test-persistence BASE_URL=http://api:8080 ACTION_SCRIPT=scripts/restart.sh >> evidence/persistence.txt 2>&1
|
||||
docker compose ps -q api postgres valkey | xargs docker inspect --format '{{.Name}} {{.State.StartedAt}} {{.Image}}' >> evidence/persistence.txt
|
||||
python student-tests/grade4.py persistence_meta > evidence/session-persistence.txt 2>&1
|
||||
printf '%s\n' 'PASS: all grade 3/4 checks completed; inspect evidence/*.txt'
|
||||
Reference in New Issue
Block a user