install_offline.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. # shellcheck source=wp13-common.sh
  5. source "${SCRIPT_DIR}/wp13-common.sh"
  6. usage() {
  7. cat <<'EOF'
  8. Usage: install_offline.sh [options]
  9. Verify, load, and start a DataOps offline Compose bundle.
  10. Options:
  11. --bundle-root PATH Extracted bundle root (default: parent of operations/).
  12. --env-file PATH Optional environment file.
  13. --project-name NAME Compose project (default: dataops-test).
  14. --timeout SECONDS Health timeout (default: 600).
  15. --help Show this help.
  16. EOF
  17. }
  18. BUNDLE_ROOT="$(wp13_default_root)"
  19. ENV_FILE=""
  20. PROJECT_NAME="dataops-test"
  21. TIMEOUT_SECONDS=600
  22. while [[ $# -gt 0 ]]; do
  23. case "$1" in
  24. --bundle-root) BUNDLE_ROOT="$2"; shift 2 ;;
  25. --env-file) ENV_FILE="$2"; shift 2 ;;
  26. --project-name) PROJECT_NAME="$2"; shift 2 ;;
  27. --timeout) TIMEOUT_SECONDS="$2"; shift 2 ;;
  28. --help|-h) usage; exit 0 ;;
  29. *) wp13_die "unknown argument: $1" ;;
  30. esac
  31. done
  32. BUNDLE_ROOT="$(cd "${BUNDLE_ROOT}" && pwd)"
  33. COMPOSE_FILE="${BUNDLE_ROOT}/deploy/docker/docker-compose.yml"
  34. wp13_verify_checksums "${BUNDLE_ROOT}"
  35. wp13_require_command docker
  36. if [[ -f "${BUNDLE_ROOT}/images/dataops-images.tar" ]]; then
  37. wp13_log "loading offline images"
  38. docker load -i "${BUNDLE_ROOT}/images/dataops-images.tar" >/dev/null
  39. else
  40. wp13_log "image archive not present; using preloaded local images"
  41. fi
  42. preflight_args=(
  43. --bundle-root "${BUNDLE_ROOT}"
  44. --compose-file "${COMPOSE_FILE}"
  45. --project-name "${PROJECT_NAME}"
  46. )
  47. [[ -z "${ENV_FILE}" ]] || preflight_args+=(--env-file "${ENV_FILE}")
  48. bash "${SCRIPT_DIR}/preflight.sh" "${preflight_args[@]}"
  49. wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \
  50. up -d --no-build
  51. wp13_wait_for_project "${PROJECT_NAME}" "${TIMEOUT_SECONDS}"
  52. current="$(
  53. wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \
  54. exec -T backend alembic -c alembic.ini current \
  55. | awk 'NF {print $1; exit}'
  56. )"
  57. head="$(
  58. wp13_compose "${COMPOSE_FILE}" "${PROJECT_NAME}" "${ENV_FILE}" \
  59. exec -T backend alembic -c alembic.ini heads \
  60. | awk 'NF {print $1; exit}'
  61. )"
  62. [[ -n "${current}" && "${current}" == "${head}" ]] \
  63. || wp13_die "post-install migration mismatch: current=${current:-unknown}, head=${head:-unknown}"
  64. cp "${BUNDLE_ROOT}/release-manifest.txt" \
  65. "${BUNDLE_ROOT}/installed-${PROJECT_NAME}.manifest"
  66. wp13_log "offline install completed at migration ${current}"