Реализовать лабораторную 4 на оценку 5
Добавить приватное S3-хранилище, вложения, presigned upload, reconciler и доказательства.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
@echo off
|
||||
REM Restart API and ALL state stores without deleting named volumes.
|
||||
setlocal
|
||||
cd /d "%~dp0.."
|
||||
if not exist .env (
|
||||
echo missing .env; copy .env.example and set local synthetic credentials>&2
|
||||
exit /b 2
|
||||
)
|
||||
docker compose --env-file .env restart postgres redis seaweedfs api lb
|
||||
exit /b %ERRORLEVEL%
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# Restart API and ALL state stores without deleting named volumes.
|
||||
# PostgreSQL and Redis keep their volumes; the public persistence test polls
|
||||
# /health/ready itself, so this hook only performs the restart and returns
|
||||
# non-zero on a Compose error.
|
||||
set -eu
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
if [ ! -f .env ]; then
|
||||
echo "missing .env; copy .env.example and set local synthetic credentials" >&2
|
||||
exit 2
|
||||
fi
|
||||
# Do not restart the one-shot migrate service here: the schema is already
|
||||
# persisted in the PostgreSQL volume. Restart every long-running component.
|
||||
docker compose --env-file .env restart postgres redis seaweedfs api lb
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
# Equivalent of a rolling update for Docker Compose: replace one API replica
|
||||
# at a time, keeping the service at the configured replica count. Run
|
||||
# `docker compose build api` first when testing a new image. No volumes,
|
||||
# database rows or sessions are touched.
|
||||
set -eu
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
COMPOSE="docker compose --env-file .env"
|
||||
COUNT=${API_REPLICAS:-2}
|
||||
|
||||
wait_for_healthy() {
|
||||
deadline=$(( $(date +%s) + 90 ))
|
||||
while :; do
|
||||
ids=$($COMPOSE ps -q api)
|
||||
running=0
|
||||
healthy=0
|
||||
for id in $ids; do
|
||||
state=$(docker inspect --format '{{.State.Status}}' "$id")
|
||||
health=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$id")
|
||||
if [ "$state" = "running" ]; then running=$((running + 1)); fi
|
||||
if [ "$health" = "healthy" ] || [ "$health" = "none" ]; then healthy=$((healthy + 1)); fi
|
||||
done
|
||||
if [ "$running" -ge "$COUNT" ] && [ "$healthy" -ge "$COUNT" ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$(date +%s)" -ge "$deadline" ]; then
|
||||
echo "rolling-update: replicas did not become healthy" >&2
|
||||
return 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
wait_for_healthy
|
||||
for id in $($COMPOSE ps -q api); do
|
||||
echo "replacing $id"
|
||||
docker stop --time 15 "$id" >/dev/null
|
||||
docker rm "$id" >/dev/null
|
||||
$COMPOSE up -d --no-deps --no-build --scale api="$COUNT" api
|
||||
wait_for_healthy
|
||||
done
|
||||
echo "rolling-update: all $COUNT replicas replaced"
|
||||
@@ -0,0 +1,8 @@
|
||||
# Stop exactly ONE API replica from a Windows host.
|
||||
# The public failover test sets TARGET_INSTANCE_ID; the PowerShell helper maps
|
||||
# the alias (container hostname) to the matching Compose container.
|
||||
@echo off
|
||||
setlocal
|
||||
if "%TARGET_INSTANCE_ID%"=="" exit /b 2
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0stop-one.ps1"
|
||||
exit /b %ERRORLEVEL%
|
||||
@@ -0,0 +1,21 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
Set-Location $root
|
||||
|
||||
$target = $env:TARGET_INSTANCE_ID
|
||||
if ([string]::IsNullOrWhiteSpace($target)) { exit 2 }
|
||||
|
||||
$ids = @(docker compose --env-file .env ps -q api)
|
||||
foreach ($id in $ids) {
|
||||
if ([string]::IsNullOrWhiteSpace($id)) { continue }
|
||||
$hostName = (docker inspect --format '{{.Config.Hostname}}' $id).Trim()
|
||||
$containerName = (docker inspect --format '{{.Name}}' $id).Trim().TrimStart('/')
|
||||
if ($hostName -eq $target -or $hostName.StartsWith($target) -or
|
||||
$target.StartsWith($hostName) -or $containerName -eq $target) {
|
||||
docker stop --time 5 $id | Out-Null
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
|
||||
Write-Error 'stop-one: no API replica matches TARGET_INSTANCE_ID'
|
||||
exit 3
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# Stop exactly ONE API replica identified by the public X-Instance-Id alias.
|
||||
# The public failover test sets TARGET_INSTANCE_ID and expects this script to
|
||||
# return within 10 seconds while leaving the replica stopped. It never touches
|
||||
# PostgreSQL, Redis, the LB or named volumes.
|
||||
set -eu
|
||||
|
||||
: "${TARGET_INSTANCE_ID:?test provides the target API instance alias}"
|
||||
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
ENV_FILE=${ENV_FILE:-.env}
|
||||
COMPOSE="docker compose --env-file $ENV_FILE"
|
||||
|
||||
target=$TARGET_INSTANCE_ID
|
||||
found=''
|
||||
for id in $($COMPOSE ps -q api); do
|
||||
host=$(docker inspect --format '{{.Config.Hostname}}' "$id")
|
||||
name=$(docker inspect --format '{{.Name}}' "$id")
|
||||
case "$host" in
|
||||
"$target"|"$target"*) found=$id; break ;;
|
||||
esac
|
||||
case "$target" in
|
||||
"$host"|"$host"*) found=$id; break ;;
|
||||
esac
|
||||
# INSTANCE_ID may be set explicitly by an operator; then it is not the
|
||||
# container hostname and the default mapping cannot be used.
|
||||
if [ "$host" != "$name" ] && [ "${name#/}" = "$target" ]; then
|
||||
found=$id
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$found" ]; then
|
||||
echo "stop-one: no API replica matches TARGET_INSTANCE_ID" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# -t 5 bounds the graceful drain; gunicorn exits earlier when idle. Docker
|
||||
# does not restart a container stopped explicitly, even with restart policy.
|
||||
docker stop --time 5 "$found" >/dev/null
|
||||
exit 0
|
||||
Reference in New Issue
Block a user