forked from mtusi2026/mtusi2026lab3
25 lines
672 B
Bash
Executable File
25 lines
672 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
|
|
|
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
project_dir=$(dirname -- "$script_dir")
|
|
cd "$project_dir"
|
|
|
|
target_container=''
|
|
for container_id in $(docker compose --env-file .env ps -q api); do
|
|
instance_id=$(docker inspect --format '{{.Config.Hostname}}' "$container_id")
|
|
if [ "$instance_id" = "$TARGET_INSTANCE_ID" ]; then
|
|
target_container=$container_id
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$target_container" ]; then
|
|
printf '%s\n' 'API instance from TARGET_INSTANCE_ID was not found' >&2
|
|
exit 1
|
|
fi
|
|
|
|
docker stop --time 5 "$target_container" >/dev/null
|