run.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. ## This script runs CT (and necessary dependencies) in docker container(s)
  3. set -euo pipefail
  4. # ensure dir
  5. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/../.."
  6. help() {
  7. echo
  8. echo "-h|--help: To display this usage info"
  9. echo "--app lib_dir/app_name: Print apps in json"
  10. echo "--console: Start EMQX in console mode"
  11. }
  12. WHICH_APP='novalue'
  13. CONSOLE='no'
  14. while [ "$#" -gt 0 ]; do
  15. case $1 in
  16. -h|--help)
  17. help
  18. exit 0
  19. ;;
  20. --app)
  21. WHICH_APP="$2"
  22. shift 2
  23. ;;
  24. --console)
  25. CONSOLE='yes'
  26. shift 1
  27. ;;
  28. *)
  29. echo "unknown option $1"
  30. exit 1
  31. ;;
  32. esac
  33. done
  34. if [ "${WHICH_APP}" = 'novalue' ]; then
  35. echo "must provide --app arg"
  36. exit 1
  37. fi
  38. ERLANG_CONTAINER='erlang24'
  39. DOCKER_CT_ENVS_FILE="${WHICH_APP}/docker-ct"
  40. if [ -f "$DOCKER_CT_ENVS_FILE" ]; then
  41. # shellcheck disable=SC2002
  42. CT_DEPS="$(cat "$DOCKER_CT_ENVS_FILE" | xargs)"
  43. fi
  44. CT_DEPS="${ERLANG_CONTAINER} ${CT_DEPS}"
  45. FILES=( )
  46. for dep in ${CT_DEPS}; do
  47. case "${dep}" in
  48. erlang24)
  49. FILES+=( '.ci/docker-compose-file/docker-compose.yaml' )
  50. ;;
  51. mongo)
  52. FILES+=( '.ci/docker-compose-file/docker-compose-mongo-single-tcp.yaml'
  53. '.ci/docker-compose-file/docker-compose-mongo-single-tls.yaml' )
  54. ;;
  55. redis)
  56. FILES+=( '.ci/docker-compose-file/docker-compose-redis-single-tcp.yaml'
  57. '.ci/docker-compose-file/docker-compose-redis-single-tls.yaml'
  58. '.ci/docker-compose-file/docker-compose-redis-sentinel-tcp.yaml'
  59. '.ci/docker-compose-file/docker-compose-redis-sentinel-tls.yaml' )
  60. ;;
  61. mysql)
  62. FILES+=( '.ci/docker-compose-file/docker-compose-mysql-tcp.yaml'
  63. '.ci/docker-compose-file/docker-compose-mysql-tls.yaml' )
  64. ;;
  65. pgsql)
  66. FILES+=( '.ci/docker-compose-file/docker-compose-pgsql-tcp.yaml'
  67. '.ci/docker-compose-file/docker-compose-pgsql-tls.yaml' )
  68. ;;
  69. *)
  70. echo "unknown_ct_dependency $dep"
  71. exit 1
  72. ;;
  73. esac
  74. done
  75. F_OPTIONS=""
  76. for file in "${FILES[@]}"; do
  77. F_OPTIONS="$F_OPTIONS -f $file"
  78. done
  79. # shellcheck disable=2086 # no quotes for F_OPTIONS
  80. docker-compose $F_OPTIONS up -d --build
  81. # /emqx is where the source dir is mounted to the Erlang container
  82. # in .ci/docker-compose-file/docker-compose.yaml
  83. TTY=''
  84. if [[ -t 1 ]]; then
  85. TTY='-t'
  86. fi
  87. docker exec -i $TTY "$ERLANG_CONTAINER" bash -c 'git config --global --add safe.directory /emqx'
  88. if [ "$CONSOLE" = 'yes' ]; then
  89. docker exec -i $TTY "$ERLANG_CONTAINER" bash -c "make run"
  90. else
  91. set +e
  92. docker exec -i $TTY "$ERLANG_CONTAINER" bash -c "make ${WHICH_APP}-ct"
  93. RESULT=$?
  94. # shellcheck disable=2086 # no quotes for F_OPTIONS
  95. docker-compose $F_OPTIONS down
  96. exit $RESULT
  97. fi