#!/usr/bin/env bash # Shared helpers for the brick-by-brick deploy. Sourced by deploy.sh. # Logging, test gates, health waits, and a docker shim that works whether or not # the current shell is in the `docker` group. set -uo pipefail # ---- colors ---------------------------------------------------------------- if [ -t 1 ]; then C_R=$'\e[31m'; C_G=$'\e[32m'; C_Y=$'\e[33m'; C_B=$'\e[36m'; C_D=$'\e[2m'; C_0=$'\e[0m' else C_R=; C_G=; C_Y=; C_B=; C_D=; C_0= fi log() { printf '%s\n' "$*"; } info() { printf '%s\n' "${C_B}»${C_0} $*"; } ok() { printf '%s\n' "${C_G}✓${C_0} $*"; } warn() { printf '%s\n' "${C_Y}!${C_0} $*"; } err() { printf '%s\n' "${C_R}✗${C_0} $*" >&2; } brick(){ printf '\n%s\n' "${C_B}━━━ CĂRĂMIDĂ: $* ━━━${C_0}"; } die() { err "$*"; err "Deploy oprit (gate). Repară și re-rulează — e idempotent."; exit 1; } # ---- docker shim (portable: plain docker, else `sg docker`) ----------------- USE_SG=0 if ! docker ps >/dev/null 2>&1; then if command -v sg >/dev/null 2>&1 && sg docker -c 'docker ps' >/dev/null 2>&1; then USE_SG=1 fi fi docker() { if [ "$USE_SG" = 1 ]; then local a args="" for a in "$@"; do args+=" $(printf '%q' "$a")"; done sg docker -c "docker$args" else command docker "$@" fi } # ---- compose wrapper ------------------------------------------------------- # COMPOSE is exported by deploy.sh dc() { docker compose -f "$COMPOSE" "$@"; } # ---- health / test helpers ------------------------------------------------- # wait_health