build-local-test-kit.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. # Build a local test-kit Docker image with your code changes
  3. #
  4. # This script compiles Manticore Search and creates a Docker image for CLT testing.
  5. # The image is based on test-kit-latest (contains latest dev from master) with your
  6. # compiled binaries replacing the originals.
  7. #
  8. # Usage:
  9. # ./build-local-test-kit.sh [--clean] [--help]
  10. #
  11. # Options:
  12. # --clean Remove build directory before building
  13. # --help Show this help message
  14. #
  15. # Requirements:
  16. # - Docker installed and running
  17. # - At least 10GB free disk space
  18. # - Internet connection (to pull images)
  19. #
  20. # Example:
  21. # cd misc
  22. # ./build-local-test-kit.sh --clean
  23. set -e # Exit on error
  24. # Show help
  25. if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  26. head -n 23 "$0" | tail -n 19
  27. exit 0
  28. fi
  29. # Configuration
  30. TOOLCHAIN_IMAGE="manticoresearch/external_toolchain:vcpkg331_20250114"
  31. BASE_IMAGE="ghcr.io/manticoresoftware/manticoresearch:test-kit-latest"
  32. OUTPUT_IMAGE="test-kit:local"
  33. BUILD_TYPE="${BUILD_TYPE:-RelWithDebInfo}"
  34. # Determine paths
  35. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  36. REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  37. BUILD_DIR="$REPO_ROOT/build"
  38. # Cleanup on exit
  39. cleanup() {
  40. if [ -f "$BUILD_DIR/Dockerfile" ]; then
  41. rm -f "$BUILD_DIR/Dockerfile"
  42. fi
  43. }
  44. trap cleanup EXIT INT TERM
  45. echo "==> Building local test-kit image"
  46. echo " Repository: $REPO_ROOT"
  47. echo " Build type: $BUILD_TYPE"
  48. echo ""
  49. # Handle --clean parameter
  50. if [ "$1" = "--clean" ]; then
  51. echo "==> Removing build directory for clean build..."
  52. rm -rf "$BUILD_DIR"
  53. fi
  54. # Create directories
  55. mkdir -p "$BUILD_DIR"
  56. mkdir -p "$REPO_ROOT/cache"
  57. # Pull base image (contains latest dev from master)
  58. echo "==> Pulling base image: $BASE_IMAGE"
  59. if ! docker pull "$BASE_IMAGE"; then
  60. echo "ERROR: Failed to pull base image. Check your internet connection."
  61. exit 1
  62. fi
  63. # Step 1: Compile Manticore Search
  64. echo ""
  65. echo "==> Step 1/2: Compiling Manticore Search"
  66. echo " This may take 10-30 minutes..."
  67. echo " Press Ctrl+C to cancel"
  68. echo ""
  69. # Note: The long path (64 'a' chars) is required for CMake compatibility
  70. # with path length limitations on some platforms. Do not change it.
  71. MOUNT_PATH="/manticore_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  72. docker run --rm \
  73. --platform linux/amd64 \
  74. -v "$REPO_ROOT/cache:/cache" \
  75. -e CACHEB="/cache" \
  76. -e DIAGNOSTIC=1 \
  77. -e PACK_ICUDATA=0 \
  78. -e NO_TESTS=1 \
  79. -e DISTR=jammy \
  80. -e boost=boost_nov22 \
  81. -e sysroot=roots_nov22 \
  82. -e arch=x86_64 \
  83. -e CTEST_CMAKE_GENERATOR=Ninja \
  84. -e CTEST_CONFIGURATION_TYPE="$BUILD_TYPE" \
  85. -e WITH_COVERAGE=0 \
  86. -e SYSROOT_URL="https://repo.manticoresearch.com/repository/sysroots" \
  87. -e HOMEBREW_PREFIX="" \
  88. -e PACK_GALERA=0 \
  89. -e UNITY_BUILD=1 \
  90. -v "$REPO_ROOT:$MOUNT_PATH" \
  91. "$TOOLCHAIN_IMAGE" \
  92. bash -c "cd $MOUNT_PATH/build && \
  93. cmake -DDISTR=jammy .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE && \
  94. export CMAKE_TOOLCHAIN_FILE=\$(pwd)/dist/build_dockers/cross/linux.cmake && \
  95. cmake --build ."
  96. # Step 2: Create Docker image with compiled binaries
  97. echo ""
  98. echo "==> Step 2/2: Creating Docker image"
  99. # Verify binaries exist
  100. if [ ! -f "$BUILD_DIR/src/searchd" ] || [ ! -f "$BUILD_DIR/src/indexer" ] || [ ! -f "$BUILD_DIR/src/indextool" ]; then
  101. echo "ERROR: Compiled binaries not found. Build may have failed."
  102. echo "Try running with --clean for a fresh build."
  103. exit 1
  104. fi
  105. # Create Dockerfile
  106. cat > "$BUILD_DIR/Dockerfile" <<EOF
  107. FROM $BASE_IMAGE
  108. COPY src/searchd /usr/bin/searchd
  109. COPY src/indexer /usr/bin/indexer
  110. COPY src/indextool /usr/bin/indextool
  111. RUN chmod +x /usr/bin/searchd /usr/bin/indexer /usr/bin/indextool
  112. EOF
  113. # Build Docker image
  114. docker build --load -t "$OUTPUT_IMAGE" "$BUILD_DIR"
  115. echo ""
  116. echo "==> SUCCESS! Docker image '$OUTPUT_IMAGE' created"
  117. echo ""
  118. echo "Next steps:"
  119. echo " 1. Test your image:"
  120. echo " docker run --rm $OUTPUT_IMAGE searchd --version"
  121. echo ""
  122. echo " 2. Run CLT tests:"
  123. echo " cd /path/to/clt"
  124. echo " ./clt test -t /path/to/test.rec -d $OUTPUT_IMAGE"
  125. echo ""
  126. echo "For more details, see TESTING.md"