#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=wp13-common.sh source "${SCRIPT_DIR}/wp13-common.sh" usage() { cat <<'EOF' Usage: preflight.sh [options] Validate an offline bundle or an existing Compose project before install/upgrade. Options: --bundle-root PATH Bundle or repository root. --compose-file PATH Compose file (default: /deploy/docker/docker-compose.yml). --env-file PATH Optional Compose environment file. --project-name NAME Compose project (default: dataops-test). --checksums-only Verify checksums and exit before Docker access. --skip-checksums Repository development mode only. --help Show this help. EOF } BUNDLE_ROOT="$(wp13_default_root)" COMPOSE_FILE="" ENV_FILE="" PROJECT_NAME="dataops-test" CHECKSUMS_ONLY=0 SKIP_CHECKSUMS=0 while [[ $# -gt 0 ]]; do case "$1" in --bundle-root) BUNDLE_ROOT="$2"; shift 2 ;; --compose-file) COMPOSE_FILE="$2"; shift 2 ;; --env-file) ENV_FILE="$2"; shift 2 ;; --project-name) PROJECT_NAME="$2"; shift 2 ;; --checksums-only) CHECKSUMS_ONLY=1; shift ;; --skip-checksums) SKIP_CHECKSUMS=1; shift ;; --help|-h) usage; exit 0 ;; *) wp13_die "unknown argument: $1" ;; esac done BUNDLE_ROOT="$(cd "${BUNDLE_ROOT}" && pwd)" COMPOSE_FILE="${COMPOSE_FILE:-${BUNDLE_ROOT}/deploy/docker/docker-compose.yml}" if [[ "${SKIP_CHECKSUMS}" -eq 0 ]]; then wp13_verify_checksums "${BUNDLE_ROOT}" fi if [[ "${CHECKSUMS_ONLY}" -eq 1 ]]; then exit 0 fi wp13_require_command docker docker version >/dev/null docker compose version >/dev/null [[ -f "${COMPOSE_FILE}" ]] || wp13_die "compose file not found: ${COMPOSE_FILE}" if [[ -n "${ENV_FILE}" ]]; then [[ -r "${ENV_FILE}" ]] || wp13_die "environment file is not readable: ${ENV_FILE}" fi wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" config --quiet wp13_log "Compose configuration resolved" while IFS= read -r image; do [[ -n "${image}" ]] || continue docker image inspect "${image}" >/dev/null 2>&1 \ || wp13_die "required offline image is missing: ${image}" done < <( wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \ config --images | LC_ALL=C sort -u ) wp13_log "all default-profile images are available locally" if [[ -n "$(wp13_project_running_ids "${PROJECT_NAME}")" ]]; then current="$( wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \ exec -T backend alembic -c alembic.ini current \ | awk 'NF {print $1; exit}' )" head="$( wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \ exec -T backend alembic -c alembic.ini heads \ | awk 'NF {print $1; exit}' )" [[ -n "${current}" && "${current}" == "${head}" ]] \ || wp13_die "database migration is not at head: current=${current:-unknown}, head=${head:-unknown}" wp13_log "database migration is at head: ${current}" else wp13_log "project is not running; migration will be checked after first start" fi available_kb="$(df -Pk "${BUNDLE_ROOT}" | awk 'NR==2 {print $4}')" [[ "${available_kb:-0}" -ge 10485760 ]] \ || wp13_die "less than 10 GiB free space is available" wp13_log "preflight passed for project ${PROJECT_NAME}"