Brak opisu

run-combined-stack.sh 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. export SOC_SHARED_NETWORK="${SOC_SHARED_NETWORK:-soc_shared}"
  5. export IRIS_HTTPS_PORT="${IRIS_HTTPS_PORT:-8443}"
  6. export INTERFACE_HTTPS_PORT="${IRIS_HTTPS_PORT}"
  7. export SHUFFLE_OPENSEARCH_PORT="${SHUFFLE_OPENSEARCH_PORT:-9201}"
  8. export PAGERDUTY_STUB_PORT="${PAGERDUTY_STUB_PORT:-18080}"
  9. export SOC_INTEGRATOR_PORT="${SOC_INTEGRATOR_PORT:-8088}"
  10. if [[ $# -eq 0 ]]; then
  11. COMMAND="up"
  12. ARGS=(-d)
  13. else
  14. COMMAND="$1"
  15. shift
  16. ARGS=("$@")
  17. fi
  18. if [[ "${COMMAND}" == "help" || "${COMMAND}" == "--help" || "${COMMAND}" == "-h" ]]; then
  19. cat <<'EOF'
  20. Usage:
  21. ./run-combined-stack.sh [command] [target] [options]
  22. Commands:
  23. up Start services (default: up -d when no args)
  24. down Stop services (requires explicit target)
  25. logs View logs
  26. status Show container and endpoint status
  27. cleanup Remove unused Docker resources (containers/images/cache)
  28. help Show this help message
  29. Targets:
  30. all|--all All stacks (wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle)
  31. wazuh Wazuh single-node stack
  32. iris IRIS-web stack
  33. shuffle Shuffle stack
  34. pagerduty PagerDuty stub
  35. integrator SOC integrator stack
  36. flask-openapi-shuffle Flask OpenAPI demo stack
  37. Examples:
  38. ./run-combined-stack.sh
  39. ./run-combined-stack.sh up --all -d
  40. ./run-combined-stack.sh up iris -d
  41. ./run-combined-stack.sh up flask-openapi-shuffle -d
  42. ./run-combined-stack.sh down shuffle
  43. ./run-combined-stack.sh down --all
  44. ./run-combined-stack.sh logs integrator -f
  45. ./run-combined-stack.sh logs --all --tail 200
  46. ./run-combined-stack.sh cleanup
  47. ./run-combined-stack.sh cleanup --with-volumes
  48. ./run-combined-stack.sh status
  49. EOF
  50. exit 0
  51. fi
  52. if [[ "${COMMAND}" == "up" || "${COMMAND}" == "down" || "${COMMAND}" == "logs" ]]; then
  53. if ! docker network inspect "${SOC_SHARED_NETWORK}" >/dev/null 2>&1; then
  54. docker network create "${SOC_SHARED_NETWORK}" >/dev/null
  55. fi
  56. fi
  57. if [[ "${COMMAND}" == "status" ]]; then
  58. exec "${ROOT_DIR}/soc-status.sh"
  59. fi
  60. run_cleanup() {
  61. local with_volumes="${1:-false}"
  62. echo "Pruning stopped containers..."
  63. docker container prune -f
  64. echo "Pruning unused images..."
  65. docker image prune -a -f
  66. echo "Pruning builder cache..."
  67. docker builder prune -f
  68. if [[ "${with_volumes}" == "true" ]]; then
  69. echo "Pruning unused volumes..."
  70. docker volume prune -f
  71. fi
  72. echo "Current Docker disk usage:"
  73. docker system df
  74. }
  75. run_wazuh() {
  76. docker compose \
  77. --project-name wazuh-single \
  78. --project-directory "${ROOT_DIR}/wazuh-docker/single-node" \
  79. -f "${ROOT_DIR}/wazuh-docker/single-node/docker-compose.yml" \
  80. -f "${ROOT_DIR}/compose-overrides/wazuh.shared-network.yml" \
  81. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  82. }
  83. run_iris() {
  84. docker compose \
  85. --project-name iris-web \
  86. --project-directory "${ROOT_DIR}/iris-web" \
  87. -f "${ROOT_DIR}/iris-web/docker-compose.yml" \
  88. -f "${ROOT_DIR}/compose-overrides/iris.shared-network.yml" \
  89. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  90. }
  91. run_shuffle() {
  92. docker compose \
  93. --project-name shuffle \
  94. --project-directory "${ROOT_DIR}/Shuffle" \
  95. -f "${ROOT_DIR}/Shuffle/docker-compose.yml" \
  96. -f "${ROOT_DIR}/compose-overrides/shuffle.shared-network.yml" \
  97. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  98. }
  99. run_pagerduty_stub() {
  100. docker compose \
  101. --project-name pagerduty-stub \
  102. --project-directory "${ROOT_DIR}" \
  103. -f "${ROOT_DIR}/compose-overrides/pagerduty.stub.yml" \
  104. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  105. }
  106. run_soc_integrator() {
  107. docker compose \
  108. --project-name soc-integrator \
  109. --project-directory "${ROOT_DIR}/compose-overrides" \
  110. -f "${ROOT_DIR}/compose-overrides/soc-integrator.yml" \
  111. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  112. }
  113. run_flask_openapi_shuffle() {
  114. docker compose \
  115. --project-name flask-openapi-shuffle \
  116. --project-directory "${ROOT_DIR}/flask-openapi-shuffle" \
  117. -f "${ROOT_DIR}/flask-openapi-shuffle/docker-compose.yml" \
  118. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  119. }
  120. run_target() {
  121. local target="$1"
  122. case "${target}" in
  123. wazuh)
  124. run_wazuh
  125. ;;
  126. iris)
  127. run_iris
  128. ;;
  129. shuffle)
  130. run_shuffle
  131. ;;
  132. pagerduty)
  133. run_pagerduty_stub
  134. ;;
  135. integrator)
  136. run_soc_integrator
  137. ;;
  138. flask-openapi-shuffle)
  139. run_flask_openapi_shuffle
  140. ;;
  141. *)
  142. echo "Unknown target: ${target}"
  143. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle"
  144. exit 1
  145. ;;
  146. esac
  147. }
  148. run_all() {
  149. local mode="$1"
  150. if [[ "${mode}" == "down" ]]; then
  151. run_flask_openapi_shuffle
  152. run_soc_integrator
  153. run_pagerduty_stub
  154. run_shuffle
  155. run_iris
  156. run_wazuh
  157. else
  158. run_wazuh
  159. run_iris
  160. run_shuffle
  161. run_pagerduty_stub
  162. run_soc_integrator
  163. run_flask_openapi_shuffle
  164. fi
  165. }
  166. follow_all_logs() {
  167. COMMAND="logs"
  168. ARGS=("-f" "--tail" "${LOG_TAIL:-100}")
  169. run_wazuh &
  170. run_iris &
  171. run_shuffle &
  172. run_pagerduty_stub &
  173. run_soc_integrator &
  174. run_flask_openapi_shuffle &
  175. trap 'kill 0' INT TERM
  176. wait
  177. }
  178. run_logs_for_target() {
  179. local target="${1:-all}"
  180. case "${target}" in
  181. wazuh)
  182. run_wazuh
  183. ;;
  184. iris)
  185. run_iris
  186. ;;
  187. shuffle)
  188. run_shuffle
  189. ;;
  190. pagerduty)
  191. run_pagerduty_stub
  192. ;;
  193. integrator)
  194. run_soc_integrator
  195. ;;
  196. flask-openapi-shuffle)
  197. run_flask_openapi_shuffle
  198. ;;
  199. all|--all)
  200. run_wazuh
  201. run_iris
  202. run_shuffle
  203. run_pagerduty_stub
  204. run_soc_integrator
  205. run_flask_openapi_shuffle
  206. ;;
  207. *)
  208. echo "Unknown logs target: ${target}"
  209. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle"
  210. exit 1
  211. ;;
  212. esac
  213. }
  214. if [[ "${COMMAND}" == "down" ]]; then
  215. TARGET="${1:-}"
  216. if [[ -z "${TARGET}" ]]; then
  217. echo "Refusing to run 'down' without a target."
  218. echo "Use one of:"
  219. echo " ./run-combined-stack.sh down <wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle>"
  220. echo " ./run-combined-stack.sh down --all"
  221. exit 1
  222. fi
  223. case "${TARGET}" in
  224. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  225. ARGS=("${ARGS[@]:1}")
  226. run_target "${TARGET}"
  227. ;;
  228. all|--all)
  229. ARGS=("${ARGS[@]:1}")
  230. run_all "down"
  231. ;;
  232. *)
  233. run_all "down"
  234. ;;
  235. esac
  236. elif [[ "${COMMAND}" == "logs" ]]; then
  237. LOGS_TARGET="${1:-all}"
  238. case "${LOGS_TARGET}" in
  239. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  240. ARGS=("${ARGS[@]:1}")
  241. run_logs_for_target "${LOGS_TARGET}"
  242. ;;
  243. all|--all)
  244. ARGS=("${ARGS[@]:1}")
  245. run_logs_for_target "all"
  246. ;;
  247. *)
  248. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  249. if [[ "${arg}" == "-f" || "${arg}" == "--follow" ]]; then
  250. echo "For follow mode, specify one target:"
  251. echo "./run-combined-stack.sh logs <wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle> -f"
  252. exit 1
  253. fi
  254. done
  255. run_logs_for_target "all"
  256. ;;
  257. esac
  258. elif [[ "${COMMAND}" == "up" ]]; then
  259. TARGET="${1:-all}"
  260. case "${TARGET}" in
  261. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  262. ARGS=("${ARGS[@]:1}")
  263. run_target "${TARGET}"
  264. ;;
  265. all|--all)
  266. ARGS=("${ARGS[@]:1}")
  267. HAS_DETACH="false"
  268. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  269. if [[ "${arg}" == "-d" || "${arg}" == "--detach" ]]; then
  270. HAS_DETACH="true"
  271. break
  272. fi
  273. done
  274. if [[ "${HAS_DETACH}" == "true" ]]; then
  275. run_all "up"
  276. else
  277. ARGS+=("-d")
  278. run_all "up"
  279. follow_all_logs
  280. fi
  281. ;;
  282. *)
  283. run_all "up"
  284. ;;
  285. esac
  286. elif [[ "${COMMAND}" == "cleanup" ]]; then
  287. WITH_VOLUMES="false"
  288. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  289. case "${arg}" in
  290. --with-volumes|-v)
  291. WITH_VOLUMES="true"
  292. ;;
  293. *)
  294. ;;
  295. esac
  296. done
  297. run_cleanup "${WITH_VOLUMES}"
  298. else
  299. run_all "up"
  300. fi