17 lines
522 B
Bash
17 lines
522 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
|
|
|
|
for container_id in $(docker compose ps -q api); do
|
|
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$container_id")
|
|
instance_id=$(printf '%s' "$hostname" | sha256sum | cut -c1-12)
|
|
if [[ "$instance_id" == "$TARGET_INSTANCE_ID" ]]; then
|
|
docker stop --time 6 "$container_id" >/dev/null
|
|
exit 0
|
|
fi
|
|
done
|
|
|
|
printf 'No running API container matches TARGET_INSTANCE_ID.\n' >&2
|
|
exit 1
|