This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add util for waiting for container startup; use in dbcopyall8
`make dev.dbcopyall8` doesn't work unless the mysql containers have been started and are ready to run. This is not the only place we need to wait for a functional check on a container, so in this commit I've gone ahead and started a utility for doing so. This first pass only supports MySQL, but we should at least add Mongo as well, as that's also needed in one of the provisioning scripts. I've moved the _db_copy8_targets from being an order-only prerequisite to being a recursive make call. I'm not sure why the order-only syntax was in use here, but in any case I needed to add in a script call before those targets were called, so it's likely moot. Also: - Drop unneeded `bash -c` wrappers from db copy docker exec calls
- Loading branch information
Showing
3 changed files
with
50 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# Wait for the listed services to become ready. | ||
# | ||
# This does not start the containers; that should be performed separately | ||
# via `make dev.up` in order to allow for parallel startup. | ||
|
||
set -eu -o pipefail | ||
|
||
function print_usage { | ||
echo "Usage: $0 service1 service2 ..." | ||
} | ||
|
||
if [[ $# == 0 ]]; then | ||
print_usage | ||
exit 0 | ||
fi | ||
|
||
function wait_db { | ||
container_name="$1" | ||
mysql_probe="SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')" | ||
until docker compose exec -T "$container_name" mysql -uroot -se "$mysql_probe" &> /dev/null; do | ||
printf "." >&2 | ||
sleep 1 | ||
done | ||
echo >&2 "$container_name is ready" | ||
} | ||
|
||
|
||
for service_name in "$@"; do | ||
case "$service_name" in | ||
mysql*) | ||
wait_db "$service_name" | ||
;; | ||
# TODO: Add other services... | ||
*) | ||
echo >&2 "Unknown service: $service_name" | ||
exit 1 | ||
;; | ||
esac | ||
done |