#!/usr/bin/env bash # The ordered local start-up: compile, Docker preflight, dependency wait, migrate-and-start, smoke. # # scripts/bootstrap-local.sh # the `local` overlay (docker-compose.local.yml) # scripts/bootstrap-local.sh # docker-compose..yml merged onto docker-compose.yml # # This was the build-logic `ca.developer-bootstrap` plugin (`./gradlew bootstrap`). Starting # containers and probing an HTTP endpoint is not a build rule, so it is a script now (review # 2026-09-24 BUILD-O3-5). The four stages and their order are unchanged: the next stage starts only # when the previous one succeeded, and the app stage waits for startup Flyway through the compose # healthcheck before the smoke probe runs. set -euo pipefail readonly repository_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" readonly profile="${1:-local}" readonly base_compose="${repository_dir}/docker-compose.yml" readonly overlay="${repository_dir}/docker-compose.${profile}.yml" readonly health_endpoint="${BOOTSTRAP_HEALTH_ENDPOINT:-http://localhost:8080/api/healthcheck}" readonly smoke_timeout_seconds="${BOOTSTRAP_SMOKE_TIMEOUT_SECONDS:-60}" if [[ ! -f "${overlay}" ]]; then available="$(cd "${repository_dir}" && ls docker-compose.*.yml 2>/dev/null \ | sed -e 's/^docker-compose\.//' -e 's/\.yml$//' | tr '\n' ' ')" echo "bootstrap: '${profile}' names no overlay; expected $(basename "${overlay}") beside" \ "docker-compose.yml. Available: ${available:-none}" >&2 exit 64 fi compose=(docker compose -f "${base_compose}" -f "${overlay}") echo "bootstrap 1/4: compiling the default application composition" (cd "${repository_dir}/src" && ./gradlew :app-bootstrap:compileTestJava --console=plain) if ! docker info >/dev/null 2>&1; then echo "bootstrap: Docker가 필요합니다. Docker Desktop/daemon을 시작한 뒤 \`docker info\`가 성공하는지 확인하세요." >&2 exit 69 fi echo "bootstrap 2/4: starting the ${profile} PostgreSQL dependency and waiting for readiness" "${compose[@]}" up -d --wait db echo "bootstrap 3/4: building and starting the app; startup Flyway finishes before health is ready" "${compose[@]}" up -d --build --wait app echo "bootstrap 4/4: requiring HTTP 200 and status=UP from ${health_endpoint}" deadline=$((SECONDS + smoke_timeout_seconds)) last_result="no response" while ((SECONDS < deadline)); do if body="$(curl --silent --show-error --max-time 2 --write-out '\n%{http_code}' "${health_endpoint}" 2>&1)"; then status="${body##*$'\n'}" body="${body%$'\n'*}" if [[ "${status}" == "200" && "${body}" == *'"status":"UP"'* ]]; then echo "bootstrap: OK — ${health_endpoint} returned HTTP 200 and status=UP." exit 0 fi last_result="HTTP ${status}: ${body}" else last_result="${body}" fi sleep 1 done echo "bootstrap: ${health_endpoint} did not become healthy within ${smoke_timeout_seconds}s;" \ "last result: ${last_result}" >&2 exit 1