Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
db:
container_name: fluent-api-db
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
Expand All @@ -16,6 +17,7 @@ services:
retries: 5

api:
container_name: fluent-api-api
build:
context: .
dockerfile: Dockerfile.dev
Expand Down Expand Up @@ -54,6 +56,7 @@ services:
start_period: 15s

worker:
container_name: fluent-api-worker
build:
context: .
dockerfile: Dockerfile.dev
Expand Down
19 changes: 15 additions & 4 deletions fapi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 ──────────────────────────────────────────────────────
Expand Down Expand Up @@ -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 }
}
}

Expand Down Expand Up @@ -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" {
Expand Down
18 changes: 11 additions & 7 deletions fapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Comment thread
kaseywright marked this conversation as resolved.
}

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() {
Expand Down Expand Up @@ -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 ───────────────────────────────────────────────────
Expand Down
Loading