Files
apf_portal/infra/local/dev.sh
T
Julien Gautier 2a8f875a9c
CI / scan (pull_request) Successful in 4m44s
CI / commits (pull_request) Successful in 4m58s
CI / check (pull_request) Successful in 5m15s
CI / a11y (pull_request) Successful in 3m53s
CI / perf (pull_request) Successful in 8m14s
fix(infra): exclude serve-static from 'dev.sh up all' (port collision with apps)
dev.sh up all failed at startup with 'port 4200 already allocated':
both the apps profile (portal-shell dev-server, ADR-0030) and the
serve-static profile (Caddy reverse proxy) publish 4200 by default.

Split ALL_PROFILES (teardown / status / logs scope, unchanged) from
a new UP_ALL_PROFILES (what 'up all' expands to). serve-static drops
out of up all because:
- it collides with apps on 4200, and
- it has zero value without a prior nx build --configuration=production
  (otherwise Caddy 404s every request).

serve-static stays explicit: ./infra/local/dev.sh up serve-static.
Teardown still catches it via ALL_PROFILES.

Usage text + infra/README.md cheat-sheet updated.

The script is environment-agnostic — works the same on local and on
vm-dev. No local-vs-vm mode needed.
2026-06-01 13:02:25 +02:00

173 lines
5.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Convenience wrapper around infra/local/dev.compose.yml. Documented
# in infra/README.md → "Local-dev stack" → "Convenience script".
#
# Hides the Compose-profile gotcha: `docker compose down` only acts
# on services whose profile is currently active, so anything brought
# up with `--profile X` keeps running unless the same flag is on
# `down`. Every teardown / status / log command in this script
# always includes every profile in scope, so profile-gated services
# are visible and stoppable.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_FILE="${SCRIPT_DIR}/dev.compose.yml"
# Every profile defined in dev.compose.yml, used as the teardown /
# status / logs scope so a profile started under a custom flag is
# always reachable later. Keep in sync if a new profile is added.
ALL_PROFILES=(dbtools observability serve-static apps)
# What `up all` expands to — everything you want running for a full
# dev session. `serve-static` is deliberately excluded:
# - it would collide with `apps` on host port 4200 (both publish the
# SPA there by default — Caddy serves the production build, the
# `apps` profile runs the Angular dev-server);
# - without a prior `nx build --configuration=production`, Caddy
# just 404s every request, so it adds nothing to a comprehensive
# `up all` invocation. Users who actually need it run
# `./infra/local/dev.sh up serve-static` (and `down` still tears
# it down because it's in ALL_PROFILES above).
UP_ALL_PROFILES=(dbtools observability apps)
# Build "--profile p1 --profile p2 …" as separate arguments.
build_all_profile_flags() {
local p
ALL_PROFILE_FLAGS=()
for p in "${ALL_PROFILES[@]}"; do
ALL_PROFILE_FLAGS+=(--profile "$p")
done
}
# Run docker compose with every profile flagged in.
dc_all() {
build_all_profile_flags
docker compose -f "$COMPOSE_FILE" "${ALL_PROFILE_FLAGS[@]}" "$@"
}
# Run docker compose with no profiles (core services only).
dc_core() {
docker compose -f "$COMPOSE_FILE" "$@"
}
# Run `up -d` with a custom set of profiles.
up_with_profiles() {
local p
local -a flags=()
for p in "$@"; do
flags+=(--profile "$p")
done
docker compose -f "$COMPOSE_FILE" "${flags[@]}" up -d
}
usage() {
cat <<'USAGE'
Usage: ./infra/local/dev.sh <command> [args]
Commands:
up [target...] Bring up the stack.
Targets:
(none) core only (postgres + redis + otel-collector)
all core + dbtools + observability + apps —
the full dev stack. serve-static is
EXCLUDED because it collides with apps
on port 4200; run it explicitly when
you actually want to serve a prod build.
dbtools core + pgweb
observability core + jaeger
serve-static core + caddy (production-build reverse proxy)
apps core + the three Nx dev servers in
Docker — no native Node/pnpm needed
(ADR-0030). portal-bff:3000,
portal-shell:4200, portal-admin:4300.
Multiple targets allowed (e.g. `up dbtools observability`).
down [-v] Tear the stack down. Always runs with every
profile in scope, so profile-gated services
(pgweb, jaeger) are caught too. -v also wipes
the named Docker volumes.
stop <service> Stop a single service (containers stay around).
Use `up <service>` (or restart) to bring it back.
restart <service> Restart a single service.
status docker compose ps, with every profile in scope.
logs [service] Follow logs (one service or all of them).
exec <service> <cmd> Run a command inside a running service container.
help Show this help.
<other> [args...] Anything else is passed through to
`docker compose -f dev.compose.yml ...` with
every profile in scope.
Examples:
./infra/local/dev.sh up
./infra/local/dev.sh up all
./infra/local/dev.sh up apps
./infra/local/dev.sh up observability
./infra/local/dev.sh down -v
./infra/local/dev.sh stop pgweb
./infra/local/dev.sh logs otel-collector
./infra/local/dev.sh exec postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"
USAGE
}
require_args() {
local verb="$1"
local n="$2"
local hint="$3"
if [[ $# -lt $((3 + n)) ]]; then
echo "Error: '$verb' requires $hint." >&2
echo "Try: ./infra/local/dev.sh help" >&2
exit 64
fi
}
cmd="${1:-help}"
[[ $# -gt 0 ]] && shift
case "$cmd" in
up | start)
if [[ $# -eq 0 ]]; then
dc_core up -d
elif [[ "$1" == "all" ]]; then
up_with_profiles "${UP_ALL_PROFILES[@]}"
else
up_with_profiles "$@"
fi
;;
down)
dc_all down "$@"
;;
stop)
require_args stop 1 "a service name (use 'down' to tear down the whole stack)" "$@"
dc_all stop "$@"
;;
restart)
require_args restart 1 "a service name" "$@"
dc_all restart "$@"
;;
status | ps)
dc_all ps "$@"
;;
logs)
dc_all logs -f "$@"
;;
exec)
require_args exec 2 "a service name and a command" "$@"
dc_all exec "$@"
;;
help | -h | --help | "")
usage
;;
*)
# Pass-through to docker compose, with profiles in scope.
dc_all "$cmd" "$@"
;;
esac