forked from mtusi2026/mtusi2026lab3
compose.yaml now runs one api service with API_REPLICAS replicas and no published ports, container name or hostname, behind lb, HAProxy 3.2.26 LTS pinned by digest and the only service with ports, bound to 127.0.0.1 (LB_HTTP_PORT for HTTP, LB_STATS_PORT for read-only stats). The balancer finds replicas through Docker DNS with a server template, checks GET /health/ready every second (fall 2, rise 2), balances round robin without stickiness, retries connection failures on another replica and allows a retry after a sent request only for GET and for message posts carrying Idempotency-Key, never for users, chats or login. Its own 502/503/504 answers use the contract error body with the forwarded X-Request-Id. The network is split into edge and an internal backend, every service gets CPU and memory limits, the API runs read-only with a tmpfs /tmp, two workers per replica, an 8 s request limit and a 5 s graceful stop inside an 8 s stop_grace_period. Only api builds the image, migrate reuses it once before the replicas start. PostgreSQL loads pg_stat_statements and allows 200 connections. The short TTL instance of lab 2 published the API around the balancer and is removed; its expiry check stays as an in-process test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
63 lines
2.1 KiB
YAML
63 lines
2.1 KiB
YAML
name: Application
|
|
|
|
on: [push, pull_request]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
quality:
|
|
name: Линт, типы и собственные тесты
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: astral-sh/setup-uv@v5
|
|
with:
|
|
enable-cache: true
|
|
- run: uv sync --locked --group dev
|
|
- run: make lint VENV=.venv
|
|
- run: make student-test VENV=.venv
|
|
|
|
acceptance:
|
|
name: Стенд Compose за HAProxy, smoke, рестарт и отказы зависимостей
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: astral-sh/setup-uv@v5
|
|
with:
|
|
enable-cache: true
|
|
- run: uv sync --locked --group dev
|
|
|
|
- name: Поднять стенд из чистого clone
|
|
run: make up
|
|
|
|
- name: Публичный smoke через балансировщик
|
|
run: make test
|
|
|
|
- name: Рестарт LB, API и хранилищ с сохранением volumes
|
|
run: make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
|
|
|
- name: Отказы Valkey и PostgreSQL, гонка и rollback
|
|
run: make test-faults
|
|
|
|
- name: Наружу опубликован только балансировщик
|
|
run: |
|
|
docker compose ps --format '{{.Service}} {{.Ports}}' | awk '$2 != "" && $1 != "lb" {print; bad=1} END {exit bad}'
|
|
|
|
- name: Процессы работают не от root
|
|
run: |
|
|
docker compose top | awk 'NR>1 && $3=="0" {print; bad=1} END {exit bad}'
|
|
|
|
- name: Корректная остановка реплик API по SIGTERM
|
|
run: |
|
|
start=$(date +%s)
|
|
docker compose kill --signal SIGTERM api
|
|
codes=$(docker wait $(docker compose ps -aq api) | sort -u)
|
|
elapsed=$(( $(date +%s) - start ))
|
|
echo "остановка за ${elapsed} с, коды завершения ${codes}"
|
|
test "$elapsed" -le 10 && test "$codes" = "0"
|
|
|
|
- name: Журналы стенда
|
|
if: always()
|
|
run: docker compose logs --tail 80
|