test_kit_docker_build.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. set -e
  3. git clone https://github.com/manticoresoftware/docker.git docker
  4. cd docker
  5. # We set it later when parse deps.txt
  6. executor_dev_path=
  7. # Downloads a package from a repository by given package name, version, date, commit, and architecture
  8. download_package() {
  9. package="$1"
  10. version_string="$2" # Now accepts full version string instead of separate components
  11. arch="$3"
  12. # If version_string contains '+', it's a full version identifier
  13. if [[ "$version_string" == *"+"* ]]; then
  14. file_name="${package}_${version_string}_${arch}.deb"
  15. else
  16. # Old format with separate components
  17. version="$version_string"
  18. date="$3"
  19. commit="$4"
  20. arch="$5"
  21. file_name="${package}_${version}-${date}-${commit}_${arch}.deb"
  22. fi
  23. # Try both repositories (with and without _dev suffix)
  24. for repo_suffix in "" "_dev"; do
  25. repo_url="https://repo.manticoresearch.com/repository/manticoresearch_jammy${repo_suffix}/dists/jammy/main/binary-amd64"
  26. file_url="${repo_url}/${file_name}"
  27. echo "Trying to download from $file_url"
  28. if wget -q --spider "$file_url" 2>/dev/null; then
  29. echo "Package found at $file_url"
  30. mkdir -p "../build"
  31. wget -q -O "../build/${file_name}" "$file_url"
  32. # For executor, we need to download the dev version and also extra package
  33. if [ "$package" = 'manticore-executor' ]; then
  34. if [[ "$version_string" == *"+"* ]]; then
  35. # Handle new format
  36. echo "Downloading executor dev package for new format version"
  37. # Extract version from version_string (before the +)
  38. version=$(echo "$version_string" | cut -d'+' -f1)
  39. # Extract date-commit from version_string (after the +)
  40. date_commit=$(echo "$version_string" | cut -d'+' -f2)
  41. echo "Wgetting from https://github.com/manticoresoftware/executor/releases/download/${version}/manticore-executor-${version}+${date_commit}-linux-amd64-dev.tar.gz"
  42. wget -q -O 'manticore-executor-dev.tar.gz' "https://github.com/manticoresoftware/executor/releases/download/${version}/manticore-executor-${version}+${date_commit}-linux-amd64-dev.tar.gz"
  43. else
  44. # Handle old format
  45. echo "Wgetting from https://github.com/manticoresoftware/executor/releases/download/v${version}/manticore-executor_${version}-${date}-${commit}_linux_amd64-dev.tar.gz"
  46. wget -q -O 'manticore-executor-dev.tar.gz' "https://github.com/manticoresoftware/executor/releases/download/v${version}/manticore-executor_${version}-${date}-${commit}_linux_amd64-dev.tar.gz"
  47. fi
  48. tar -xzf 'manticore-executor-dev.tar.gz'
  49. # Find the extracted directory
  50. executor_dev_dir=$(find . -type d -name "manticore-executor-*-linux-amd64-dev" | head -n 1)
  51. executor_dev_path=$(realpath "${executor_dev_dir}/manticore-executor")
  52. # Also add extra package
  53. if [[ "$version_string" == *"+"* ]]; then
  54. download_package "manticore-extra" "${version_string}" "all"
  55. else
  56. download_package "manticore-extra" "${version}" "${date}" "${commit}" "all"
  57. fi
  58. fi
  59. return 0
  60. fi
  61. done
  62. echo "ERROR: Package not found in any repository: ${file_name}" >&2
  63. exit 1
  64. }
  65. # Read deps.txt line by line
  66. while read -r line
  67. do
  68. echo "Processing dependency: $line"
  69. # Break if the line contains "---"
  70. if [[ $line == "---" ]]; then
  71. break
  72. fi
  73. if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+)\+([0-9]+)-([a-f0-9]+)(-?[a-zA-Z0-9]+)?$ ]]; then
  74. # Format: <package> <version>+<date>-<commit>[-<optional_suffix>]
  75. package="${BASH_REMATCH[1]}"
  76. version="${BASH_REMATCH[2]}"
  77. date="${BASH_REMATCH[3]}"
  78. commit="${BASH_REMATCH[4]}"
  79. version_string="${version}+${date}-${commit}"
  80. if [ -n "${BASH_REMATCH[5]}" ]; then
  81. version_string="${version_string}${BASH_REMATCH[5]}"
  82. fi
  83. suffix="${BASH_REMATCH[5]}" # Optional suffix without leading "-"
  84. echo "Parsed new format:"
  85. echo " Package: $package"
  86. echo " Version: $version"
  87. echo " Date: $date"
  88. echo " Commit: $commit"
  89. echo " Suffix: $suffix"
  90. echo " Full version string: $version_string"
  91. elif [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)[[:space:]]+([^[:space:]]+)$ ]]; then
  92. # Old format: <package> <version> <date> <commit>
  93. package="${BASH_REMATCH[1]}"
  94. version="${BASH_REMATCH[2]}"
  95. date="${BASH_REMATCH[3]}"
  96. commit="${BASH_REMATCH[4]}"
  97. suffix=""
  98. echo "Parsed old format:"
  99. echo " Package: $package"
  100. echo " Version: $version"
  101. echo " Date: $date"
  102. echo " Commit: $commit"
  103. else
  104. echo "ERROR: Unable to parse line: $line" >&2
  105. exit 1
  106. fi
  107. # Translate package names to the ones used in the repository
  108. case $package in
  109. buddy)
  110. # We use github clone instead of package
  111. # package="manticore-buddy"
  112. # arch="all"
  113. buddy_commit=$commit
  114. continue
  115. ;;
  116. backup)
  117. package="manticore-backup"
  118. arch="all"
  119. ;;
  120. load)
  121. package="manticore-load"
  122. arch="all"
  123. ;;
  124. mcl)
  125. package="manticore-columnar-lib"
  126. arch="amd64"
  127. ;;
  128. tzdata)
  129. package="manticore-tzdata"
  130. arch="all"
  131. ;;
  132. executor)
  133. package="manticore-executor"
  134. arch="amd64"
  135. ;;
  136. *)
  137. echo "Unknown package: $package"
  138. continue
  139. ;;
  140. esac
  141. if [[ "$line" =~ ^([^[:space:]]+)[[:space:]]+([^[:space:]]+)\+([0-9]+)-([a-f0-9]+) ]]; then
  142. download_package "${package}" "${version_string}" "${arch}"
  143. else
  144. download_package "${package}" "${version}" "${date}" "${commit}" "${arch}"
  145. fi
  146. done < ../deps.txt
  147. # we want to build the image based on specific packages, copying them from a directory coming from an artifact of a previous job
  148. deb_dir=$(realpath ../build/)
  149. # Use official docker image to create and tune our test kit
  150. docker pull manticoresearch/manticore:dev
  151. docker create \
  152. -v "$deb_dir:/build" --name manticore-test-kit \
  153. --entrypoint tail \
  154. manticoresearch/manticore:dev \
  155. -f /dev/null
  156. docker start manticore-test-kit
  157. docker cp "$executor_dev_path" manticore-test-kit:/usr/bin/manticore-executor-dev
  158. docker exec manticore-test-kit ln -sf /usr/bin/manticore-executor-dev /usr/bin/php
  159. # Let's list what's in the /build/ inside the container for debug purposes
  160. docker exec manticore-test-kit bash -c \
  161. 'echo "Removing /build/manticore_*, because it may depend on manticore-buddy of a newer version while we'\''re installing Buddy via git clone"; rm /build/manticore_*.deb; ls -la /build/'
  162. # Install deps and add manticore-executor-dev to the container
  163. docker exec manticore-test-kit bash -c \
  164. 'echo "apt list before update" && apt list --installed|grep manticore && apt-get -y update && echo "apt list after update" && apt list --installed|grep manticore && apt-get -y install manticore-galera && apt-get -y remove manticore-repo manticore && rm /etc/apt/sources.list.d/manticoresearch.list && apt-get update -y && dpkg -i --force-confnew /build/*.deb && apt-get install -y libxml2 libcurl4 libonig5 libzip4 librdkafka1 curl neovim git apache2-utils iproute2 bash && apt-get clean -y'
  165. docker exec manticore-test-kit bash -c "cat /etc/manticoresearch/manticore.conf"
  166. # Install composer cuz we need it for buddy from the git and also development
  167. docker exec manticore-test-kit bash -c \
  168. "curl -sSL https://getcomposer.org/download/2.7.0/composer.phar > /usr/bin/composer; chmod +x /usr/bin/composer"
  169. echo "Installing custom buddy from git repo with commit $buddy_commit"
  170. # Install custom buddy from git repo
  171. #
  172. buddy_path=/usr/share/manticore/modules/manticore-buddy
  173. docker exec manticore-test-kit bash -c \
  174. "rm -fr $buddy_path && \
  175. git clone https://github.com/manticoresoftware/manticoresearch-buddy.git $buddy_path && \
  176. git config --global --add safe.directory $buddy_path && \
  177. cd $buddy_path && \
  178. git checkout $buddy_commit && \
  179. composer install"
  180. docker exec manticore-test-kit bash -c "grep -q 'query_log = /var/log/manticore/query.log' /etc/manticoresearch/manticore.conf || sed -i '/listen = 127.0.0.1:9308:http/a\ query_log = /var/log/manticore/query.log' /etc/manticoresearch/manticore.conf"
  181. docker exec manticore-test-kit bash -c "grep -q 'log = /var/log/manticore/searchd.log' /etc/manticoresearch/manticore.conf || sed -i '/listen = 127.0.0.1:9308:http/a\ log = /var/log/manticore/searchd.log' /etc/manticoresearch/manticore.conf"
  182. docker exec manticore-test-kit bash -c "cat /etc/manticoresearch/manticore.conf"
  183. docker exec manticore-test-kit bash -c \
  184. "md5sum /etc/manticoresearch/manticore.conf | awk '{print \$1}' > /manticore.conf.md5"
  185. docker exec manticore-test-kit bash -c "rm -rf /tmp/*"
  186. echo "Exporting image to ../manticore_test_kit.img"
  187. # exporting the image, it also squashes all the layers into one
  188. docker export manticore-test-kit > ../manticore_test_kit.img