Complete lab2 grade 4 implementation and report
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$envPath = Join-Path $repoRoot '.env'
|
||||
if (-not (Test-Path -LiteralPath $envPath)) {
|
||||
Copy-Item -LiteralPath (Join-Path $repoRoot '.env.example') -Destination $envPath
|
||||
Write-Output 'Local .env created (non-secret session TTL).'
|
||||
} else {
|
||||
Write-Output 'Existing .env preserved.'
|
||||
}
|
||||
|
||||
$secretsDirectory = Join-Path $repoRoot 'secrets'
|
||||
$passwordPath = Join-Path $secretsDirectory 'postgres_password.txt'
|
||||
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@ Set-Location (Split-Path -Parent $PSScriptRoot)
|
||||
|
||||
function Read-Containers {
|
||||
$result = @()
|
||||
foreach ($service in @('api', 'postgres')) {
|
||||
foreach ($service in @('api', 'postgres', 'redis')) {
|
||||
$containerID = docker compose ps -q $service
|
||||
if ($LASTEXITCODE -ne 0 -or -not $containerID) { throw "Cannot find $service container" }
|
||||
$json = docker inspect --format '{{json .}}' $containerID
|
||||
@@ -22,9 +22,9 @@ function Read-Containers {
|
||||
}
|
||||
|
||||
$before = @(Read-Containers)
|
||||
docker compose stop api postgres
|
||||
docker compose stop api postgres redis
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Stop failed' }
|
||||
docker compose up -d --wait postgres
|
||||
docker compose up -d --wait postgres redis
|
||||
if ($LASTEXITCODE -ne 0) { throw 'PostgreSQL restart failed' }
|
||||
docker compose up -d --wait api
|
||||
if ($LASTEXITCODE -ne 0) { throw 'API restart failed' }
|
||||
@@ -39,6 +39,6 @@ foreach ($old in $before) {
|
||||
}
|
||||
}
|
||||
$evidence = [ordered]@{ before = $before; after = $after; volumes_preserved = $true }
|
||||
$path = Join-Path $PWD 'evidence/restart-containers.json'
|
||||
$path = Join-Path $PWD 'evidence/restart-all-containers.json'
|
||||
[System.IO.File]::WriteAllText($path, ($evidence | ConvertTo-Json -Depth 5), [System.Text.UTF8Encoding]::new($false))
|
||||
Write-Output 'PASS: API and PostgreSQL restarted; named volumes preserved.'
|
||||
Write-Output 'PASS: API, PostgreSQL and Redis restarted; named volumes preserved.'
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@ set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
snapshot() {
|
||||
for service in api postgres; do
|
||||
for service in api postgres redis; do
|
||||
id=$(docker compose ps -q "$service")
|
||||
test -n "$id"
|
||||
docker inspect --format '{{.Name}} {{.Id}} {{.State.StartedAt}} {{.State.Status}} {{range .Mounts}}{{if eq .Type "volume"}}{{.Name}} {{end}}{{end}}' "$id"
|
||||
@@ -11,8 +11,8 @@ snapshot() {
|
||||
}
|
||||
|
||||
snapshot > evidence/restart-containers-before.txt
|
||||
docker compose stop api postgres
|
||||
docker compose up -d --wait postgres
|
||||
docker compose stop api postgres redis
|
||||
docker compose up -d --wait postgres redis
|
||||
docker compose up -d --wait api
|
||||
snapshot > evidence/restart-containers-after.txt
|
||||
printf '%s\n' 'API and PostgreSQL restarted without removing volumes.'
|
||||
printf '%s\n' 'API, PostgreSQL and Redis restarted without removing volumes.'
|
||||
|
||||
Reference in New Issue
Block a user