Поднять API в нескольких репликах за HAProxy и добавить скрипты отказа реплики и rolling update
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
# Rolling update of the API without downtime, with docker rollout
|
||||
# (https://github.com/wowu/docker-rollout, MIT): it starts as many new
|
||||
# replicas as are running, waits until all of them are healthy, then stops
|
||||
# and removes the old ones. If a new replica does not become healthy it
|
||||
# removes the new ones and leaves the old ones serving, so the stand is never
|
||||
# left with a mix of versions.
|
||||
#
|
||||
# The migrations of the new version run first, once, while the old replicas
|
||||
# serve: they only add to the schema. docker rollout scales with `compose up`,
|
||||
# which also starts the dependencies of the API and would rerun the old,
|
||||
# exited migrate container. Recreating it beforehand from the new image,
|
||||
# without starting it, makes that `up` run the new migrations exactly once,
|
||||
# before any new replica starts.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
version=v0.14
|
||||
checksum=cdeaba6ae9eee3b0b606286e585bbda6787283d801a6ad6d9b9d2bc347fda05b
|
||||
tool=bin/docker-rollout
|
||||
|
||||
if ! printf '%s %s\n' "$checksum" "$tool" | sha256sum -c - >/dev/null 2>&1; then
|
||||
mkdir -p bin
|
||||
curl -fsSL -o "$tool.download" "https://github.com/wowu/docker-rollout/releases/download/$version/docker-rollout"
|
||||
if ! printf '%s %s\n' "$checksum" "$tool.download" | sha256sum -c - >/dev/null 2>&1; then
|
||||
rm -f "$tool.download"
|
||||
echo "docker-rollout $version: checksum mismatch, not used" >&2
|
||||
exit 1
|
||||
fi
|
||||
mv "$tool.download" "$tool"
|
||||
fi
|
||||
|
||||
docker compose build api
|
||||
docker compose up --no-start --no-deps --force-recreate migrate
|
||||
# Run through sh: Windows cannot use the script as a docker CLI plugin.
|
||||
if ! sh "$tool" rollout --wait-after-healthy 4 api; then
|
||||
# A failed migration stops the scale-up after the new containers were
|
||||
# created but before they started; remove them for a clean next attempt.
|
||||
created=$(docker compose ps -aq --status created api)
|
||||
if [ -n "$created" ]; then
|
||||
docker rm $created >/dev/null
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user