#!/bin/sh # Поочерёдная замена контейнеров api. Оставшаяся реплика продолжает принимать трафик. # Новые контейнеры собираются из текущего Dockerfile; старые заменяются по одному. set -eu cd "$(dirname "$0")/.." scale="${API_REPLICAS:-2}" docker compose --env-file .env build api ids=$(docker compose --env-file .env ps -q api) for id in $ids; do docker stop -t 8 "$id" >/dev/null docker rm "$id" >/dev/null docker compose --env-file .env up -d --no-deps --no-recreate --scale "api=$scale" api >/dev/null ready=0 i=0 while [ "$i" -lt 40 ]; do if curl -fsS http://127.0.0.1:8080/health/ready >/dev/null; then ready=1 break fi i=$((i + 1)) sleep 1 done if [ "$ready" -ne 1 ]; then echo "ready did not return after replacing one replica" >&2 exit 1 fi done echo "rolling update finished"