aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/docker.sh
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-10 17:42:56 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-10-10 17:42:56 -0400
commit69809346b7c5c710eca080e5390244be53dc2732 (patch)
tree4fdb6a63437ddd9d27eef5ddfb2cb8c2613dcb89 /scripts/lib/docker.sh
parentInstall shadow-uidmap instead of shadow (diff)
downloadcli-69809346b7c5c710eca080e5390244be53dc2732.zip
Replace tools with scripts and use them in .build.yml
Diffstat (limited to 'scripts/lib/docker.sh')
-rw-r--r--scripts/lib/docker.sh53
1 files changed, 53 insertions, 0 deletions
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
+}