Выполнение lab4 на 4

This commit is contained in:
Daria0w0
2026-11-06 17:35:48 +03:00
parent 9197e151ba
commit 879463c947
89 changed files with 5551 additions and 108 deletions
+31
View File
@@ -0,0 +1,31 @@
$ErrorActionPreference = 'Stop'
Push-Location (Split-Path -Parent $PSScriptRoot)
try {
function Invoke-Compose {
Write-Output ('COMMAND: docker compose --env-file .env ' + ($args -join ' '))
& docker compose --env-file .env @args
if ($LASTEXITCODE -ne 0) { throw "Compose failed with exit code $LASTEXITCODE" }
}
./scripts/init-local.ps1
Invoke-Compose build s3 s3-bootstrap
Invoke-Compose up -d s3
Invoke-Compose run --rm s3-bootstrap
Invoke-Compose run --rm --entrypoint /bin/sh s3-bootstrap /bootstrap/verify.sh seed
# Repeat setup after a real object exists, then restart its storage process.
Invoke-Compose run --rm s3-bootstrap
Invoke-Compose restart s3
Invoke-Compose run --rm s3-bootstrap
Invoke-Compose run --rm --entrypoint /bin/sh s3-bootstrap /bootstrap/verify.sh check
$container = & docker compose ps -q s3
if ($LASTEXITCODE -ne 0 -or -not $container) { throw 'S3 container not found' }
$portsJson = & docker inspect --format '{{json .NetworkSettings.Ports}}' $container
if ($LASTEXITCODE -ne 0) { throw 'Cannot inspect published ports' }
$ports = $portsJson | ConvertFrom-Json
foreach ($property in $ports.PSObject.Properties) {
if ($null -ne $property.Value) { throw 'Unexpected published S3 port' }
}
Write-Output 'PASS: S3 has no published host ports.'
Write-Output 'PASS: S3 infrastructure checks completed.'
} finally {
Pop-Location
}
+1 -1
View File
@@ -16,7 +16,7 @@ def main():
action = sys.argv[1]
if action == "restart":
# Stop all running application components before restarting shared stores.
docker("compose", "--env-file", ".env", "stop", "lb", "api", "redis", "postgres")
docker("compose", "--env-file", ".env", "stop", "lb", "api", "redis", "postgres", "s3")
docker("compose", "--env-file", ".env", "up", "-d", "--wait", "--wait-timeout", "60")
elif action == "stop-one":
target = os.environ["TARGET_INSTANCE_ID"]
+19 -18
View File
@@ -10,26 +10,27 @@ if (-not (Test-Path -LiteralPath $envPath)) {
}
$secretsDirectory = Join-Path $repoRoot 'secrets'
$passwordPath = Join-Path $secretsDirectory 'postgres_password.txt'
New-Item -ItemType Directory -Path $secretsDirectory -Force | Out-Null
if (Test-Path -LiteralPath $passwordPath) {
if ((Get-Item -LiteralPath $passwordPath).Length -eq 0) {
throw 'Existing password file is empty. Supply a local password before starting PostgreSQL.'
function Ensure-LocalSecret([string] $name, [string] $prefix = '', [int] $byteCount = 32) {
$secretPath = Join-Path $secretsDirectory "$name.txt"
if (Test-Path -LiteralPath $secretPath) {
if ([string]::IsNullOrWhiteSpace([IO.File]::ReadAllText($secretPath))) {
throw "Existing secret file is empty: $name"
}
Write-Output "Existing secret preserved: $name"
return
}
Write-Output 'Existing PostgreSQL password preserved.'
exit 0
$randomBytes = New-Object byte[] $byteCount
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
try { $generator.GetBytes($randomBytes) } finally { $generator.Dispose() }
$secretValue = $prefix + ([BitConverter]::ToString($randomBytes).Replace('-', '').ToLowerInvariant())
[IO.File]::WriteAllText($secretPath, $secretValue, [Text.Encoding]::ASCII)
Write-Output "Local secret created: $name (value not printed)."
}
$randomBytes = New-Object byte[] 32
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
try {
$generator.GetBytes($randomBytes)
} finally {
$generator.Dispose()
}
$password = [Convert]::ToBase64String($randomBytes)
[System.IO.File]::WriteAllText($passwordPath, $password, [System.Text.Encoding]::ASCII)
Write-Output 'Local PostgreSQL password created in secrets/ (value not printed).'
Ensure-LocalSecret 'postgres_password'
Ensure-LocalSecret 's3_root_user' 'root' 8
Ensure-LocalSecret 's3_root_password'
Ensure-LocalSecret 's3_access_key_id' 'api-' 8
Ensure-LocalSecret 's3_secret_access_key'