diff --git a/compose.yaml b/compose.yaml index ea37317..19abcaf 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,6 @@ services: db: + container_name: fluent-api-db image: postgres:16-alpine environment: POSTGRES_USER: postgres @@ -16,6 +17,7 @@ services: retries: 5 api: + container_name: fluent-api-api build: context: . dockerfile: Dockerfile.dev @@ -54,6 +56,7 @@ services: start_period: 15s worker: + container_name: fluent-api-worker build: context: . dockerfile: Dockerfile.dev diff --git a/fapi.ps1 b/fapi.ps1 index 11d99ff..ac75199 100644 --- a/fapi.ps1 +++ b/fapi.ps1 @@ -197,10 +197,21 @@ function Invoke-Compose { else { & docker-compose @CmdArgs } } +function Test-ContainerRunning { + param([string]$Name) + $runtime = if ($RuntimeMode -eq "podman-pod") { "podman" } else { "docker" } + $names = & $runtime ps --format "{{.Names}}" 2>$null + return $names -contains $Name +} + function Invoke-ExecApi { param([string[]]$CmdArgs) + if (-not (Test-ContainerRunning "fluent-api-api")) { + Write-Err "API container (fluent-api-api) is not running. Run '.\fapi.ps1 up' first." + exit 1 + } if ($RuntimeMode -eq "podman-pod") { & podman exec fluent-api-api @CmdArgs } - else { Invoke-Compose (@("exec", "api") + $CmdArgs) } + else { & docker exec fluent-api-api @CmdArgs } } # ── Runtime mode display ────────────────────────────────────────────────────── @@ -290,8 +301,8 @@ switch ($Command) { if ($target -eq "db") { & podman exec -it fluent-api-db psql -U postgres -d fluent } else { & podman exec -it "fluent-api-$target" sh } } else { - if ($target -eq "db") { Invoke-Compose @("exec", "db", "psql", "-U", "postgres", "-d", "fluent") } - else { Invoke-Compose @("exec", $target, "sh") } + if ($target -eq "db") { & docker exec -it fluent-api-db psql -U postgres -d fluent } + else { & docker exec -it "fluent-api-$target" sh } } } @@ -338,7 +349,7 @@ switch ($Command) { "db:psql" { if ($RuntimeMode -eq "podman-pod") { & podman exec -it fluent-api-db psql -U postgres -d fluent } - else { Invoke-Compose @("exec", "db", "psql", "-U", "postgres", "-d", "fluent") } + else { & docker exec -it fluent-api-db psql -U postgres -d fluent } } "clean" { diff --git a/fapi.sh b/fapi.sh index 9a49b50..b5d1609 100755 --- a/fapi.sh +++ b/fapi.sh @@ -319,11 +319,11 @@ podman_shell() { } podman_exec_api() { - if ! $RUNTIME container exists $API_CONTAINER 2>/dev/null; then - echo_error "API container is not running. Run './fapi.sh up api' first." + if ! $RUNTIME ps --format "{{.Names}}" 2>/dev/null | grep -qx "$API_CONTAINER"; then + echo_error "API container ($API_CONTAINER) is not running. Run './fapi.sh up' first." exit 1 fi - $RUNTIME exec $API_CONTAINER "$@" + $RUNTIME exec "$API_CONTAINER" "$@" } podman_clean() { @@ -401,14 +401,18 @@ compose_status() { compose_shell() { local service="${1:-api}" if [ "$service" = "db" ]; then - $COMPOSE_CMD exec db psql -U postgres -d fluent + docker exec -it "$DB_CONTAINER" psql -U postgres -d fluent else - $COMPOSE_CMD exec "$service" sh + docker exec -it "${CONTAINER_PREFIX}$service" sh fi } compose_exec_api() { - $COMPOSE_CMD exec api "$@" + if ! docker ps --format '{{.Names}}' 2>/dev/null | grep -qx "$API_CONTAINER"; then + echo_error "API container ($API_CONTAINER) is not running. Run './fapi.sh up' first." + exit 1 + fi + docker exec "$API_CONTAINER" "$@" } compose_clean() { @@ -437,7 +441,7 @@ compose_build() { } compose_db_psql() { - $COMPOSE_CMD exec db psql -U postgres -d fluent + docker exec -it "$DB_CONTAINER" psql -U postgres -d fluent } # ── Runtime dispatch helpers ───────────────────────────────────────────────────