From 69809346b7c5c710eca080e5390244be53dc2732 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Fri, 10 Oct 2025 17:42:56 -0400 Subject: Replace tools with scripts and use them in .build.yml --- scripts/lib/docker.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 scripts/lib/docker.sh (limited to 'scripts/lib/docker.sh') diff --git a/scripts/lib/docker.sh b/scripts/lib/docker.sh new file mode 100644 index 0000000..8f841bc --- /dev/null +++ b/scripts/lib/docker.sh @@ -0,0 +1,53 @@ +# shellcheck shell=bash +[[ -n "${BOLT_DOCKER_LOADED:-}" ]] && return +readonly BOLT_DOCKER_LOADED=1 + +source "$(dirname "${BASH_SOURCE[0]}")/log.sh" + +docker_compose_up() { + local compose_file="$1" + log_info "Starting services from '$compose_file'..." + docker compose --file "$compose_file" up --detach +} + +docker_compose_down() { + local compose_file="$1" + log_info "Stopping services from '$compose_file'..." + docker compose --file "$compose_file" down +} + +docker_wait_for_healthy_container() { + local container_name="$1" + local timeout="${2:-60}" + local elapsed=0 + + log_info "Waiting for container '$container_name' to be healthy..." + while [[ $elapsed -lt $timeout ]]; do + local status + status=$(docker inspect -f '{{.State.Health.Status}}' "$container_name" 2>/dev/null || echo "not_found") + + case "$status" in + "healthy") + log_success "Container '$container_name' is healthy!" + return 0 + ;; + "not_found") + log_error "Error: Container '$container_name' not found" + return 1 + ;; + "unhealthy") + log_error "Error: Container '$container_name' is unhealthy" + return 1 + ;; + *) + log_progress + sleep 1 + ((elapsed++)) + ;; + esac + done + + log_progress_end + log_error "Timeout: Container '$container_name' did not become healthy within ${timeout} seconds" + return 1 +} -- cgit v1.2.3