forked from mtusi2026/mtusi2026lab4
Implement lab4 attachments on RustFS for grade 4.
Carry over lab3 HA stack and add private S3 storage, Attachment API, orphan compensation/reaper, own tests, and evidence for smoke/persistence/failover.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Creates local synthetic secrets for compose (never commit secrets/).
|
||||
$ErrorActionPreference = "Stop"
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
$secrets = Join-Path $root "secrets"
|
||||
New-Item -ItemType Directory -Force -Path $secrets | Out-Null
|
||||
|
||||
$password = "lab2-pg-pass-" + [guid]::NewGuid().ToString("N").Substring(0, 12)
|
||||
Set-Content -Path (Join-Path $secrets "postgres_password") -Value $password -NoNewline
|
||||
$dbUrl = "postgresql://messenger:${password}@postgres:5432/messenger"
|
||||
Set-Content -Path (Join-Path $secrets "database_url") -Value $dbUrl -NoNewline
|
||||
Set-Content -Path (Join-Path $secrets "cache_url") -Value "redis://redis:6379/0" -NoNewline
|
||||
|
||||
# Dedicated non-default S3 credentials for API (not built-in rustfs defaults).
|
||||
$apiKey = "messengerapi" + [guid]::NewGuid().ToString("N").Substring(0, 8)
|
||||
$apiSecret = "s3-api-" + [guid]::NewGuid().ToString("N")
|
||||
Set-Content -Path (Join-Path $secrets "s3_access_key_id") -Value $apiKey -NoNewline
|
||||
Set-Content -Path (Join-Path $secrets "s3_secret_access_key") -Value $apiSecret -NoNewline
|
||||
|
||||
Write-Host "Wrote secrets/postgres_password, secrets/database_url, secrets/cache_url, secrets/s3_*"
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
||||
mkdir -p "$ROOT/secrets"
|
||||
PASSWORD="lab2-pg-pass-$(openssl rand -hex 6)"
|
||||
printf '%s' "$PASSWORD" > "$ROOT/secrets/postgres_password"
|
||||
printf '%s' "postgresql://messenger:${PASSWORD}@postgres:5432/messenger" > "$ROOT/secrets/database_url"
|
||||
printf '%s' "redis://redis:6379/0" > "$ROOT/secrets/cache_url"
|
||||
printf '%s' "messengerapi$(openssl rand -hex 4)" > "$ROOT/secrets/s3_access_key_id"
|
||||
printf '%s' "s3-api-$(openssl rand -hex 16)" > "$ROOT/secrets/s3_secret_access_key"
|
||||
echo "Wrote secrets/postgres_password, secrets/database_url, secrets/cache_url, secrets/s3_*"
|
||||
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
cd /d "%~dp0.."
|
||||
docker compose --env-file .env restart
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Restart LB, API replicas and state stores without removing volumes.
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose --env-file .env restart
|
||||
exit 0
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
REM Start any stopped API containers after failover demo.
|
||||
cd /d "%~dp0.."
|
||||
docker compose --env-file .env start api
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -0,0 +1,17 @@
|
||||
@echo off
|
||||
setlocal
|
||||
cd /d "%~dp0.."
|
||||
if "%TARGET_INSTANCE_ID%"=="" (
|
||||
echo TARGET_INSTANCE_ID required 1>&2
|
||||
exit /b 1
|
||||
)
|
||||
for /f %%i in ('docker compose --env-file .env ps -q api') do (
|
||||
for /f %%h in ('docker inspect -f "{{.Config.Hostname}}" %%i') do (
|
||||
if "%%h"=="%TARGET_INSTANCE_ID%" (
|
||||
docker stop %%i >nul
|
||||
exit /b 0
|
||||
)
|
||||
)
|
||||
)
|
||||
echo API replica not found for TARGET_INSTANCE_ID 1>&2
|
||||
exit /b 1
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Stop ONE API replica matching TARGET_INSTANCE_ID (= X-Instance-Id = container hostname).
|
||||
# Leave it stopped; do not touch DB/LB/volumes. Return quickly.
|
||||
cd "$(dirname "$0")/.."
|
||||
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID required}"
|
||||
|
||||
for id in $(docker compose --env-file .env ps -q api); do
|
||||
[ -n "$id" ] || continue
|
||||
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
|
||||
if [ "$host" = "$TARGET_INSTANCE_ID" ]; then
|
||||
docker stop "$id" >/dev/null
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
printf '%s\n' "API replica not found for TARGET_INSTANCE_ID" >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user