#!/usr/bin/env bash # The ordered local start-up: compile, Docker preflight, dependency wait, migrate-and-start, smoke. # # scripts/bootstrap-local.sh # # It runs the development stack, compose.yaml at the repository root: the application container in # the `local` runtime and the PostgreSQL service of the `jpa` profile. Naming a service on the # command line switches its profile on, so no --profile is needed here. # # 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 the compose healthcheck before the # smoke probe runs. The default composition is web only: it opens no datasource and runs no # Flyway. A service that adds the persistence-jpa line gets startup Flyway inside the same wait. # # Until 2026-11-07 it merged docker-compose.yml with docker-compose.local.yml and asked for a `db` # service neither file had defined since the database moved to a third file, so the documented # first run stopped at stage 2. set -euo pipefail readonly repository_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" readonly health_endpoint="${BOOTSTRAP_HEALTH_ENDPOINT:-http://localhost:8080/api/healthcheck}" readonly smoke_timeout_seconds="${BOOTSTRAP_SMOKE_TIMEOUT_SECONDS:-60}" if [[ $# -gt 0 ]]; then echo "bootstrap: takes no arguments; the stack is compose.yaml. Backing services by profile:" \ "docker compose --profile up -d --wait (see the head of compose.yaml)" >&2 exit 64 fi compose=(docker compose -f "${repository_dir}/compose.yaml") echo "bootstrap 1/4: compiling the default application composition" (cd "${repository_dir}" && ./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 PostgreSQL dependency and waiting for readiness" "${compose[@]}" up -d --wait db echo "bootstrap 3/4: building and starting the app and waiting for its health" "${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