gitlab.com/flarenetwork/coreth@v0.1.1/.kurtosis/kurtosis.sh (about) 1 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 # 3 # Do not modify this file! It will get overwritten when you upgrade Kurtosis! 4 # 5 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6 7 set -euo pipefail 8 9 10 11 # ============================================================================================ 12 # Constants 13 # ============================================================================================ 14 # The directory where Kurtosis will store files it uses in between executions, e.g. access tokens 15 # Can make this configurable if needed 16 KURTOSIS_DIRPATH="${HOME}/.kurtosis" 17 18 KURTOSIS_CORE_TAG="1.8" 19 KURTOSIS_DOCKERHUB_ORG="kurtosistech" 20 INITIALIZER_IMAGE="${KURTOSIS_DOCKERHUB_ORG}/kurtosis-core_initializer:${KURTOSIS_CORE_TAG}" 21 API_IMAGE="${KURTOSIS_DOCKERHUB_ORG}/kurtosis-core_api:${KURTOSIS_CORE_TAG}" 22 23 POSITIONAL_ARG_DEFINITION_FRAGMENTS=2 24 25 26 27 # ============================================================================================ 28 # Arg Parsing 29 # ============================================================================================ 30 function print_help_and_exit() { 31 echo "" 32 echo "$(basename "${0}") [--custom-params custom_params_json] [--client-id client_id] [--client-secret client_secret] [--help] [--kurtosis-log-level kurtosis_log_level] [--list] [--parallelism parallelism] [--tests test_names] [--test-suite-log-level test_suite_log_level] test_suite_image" 33 echo "" 34 echo " --custom-params custom_params_json JSON string containing arbitrary data that will be passed as-is to your testsuite, so it can modify its behaviour based on input (default: {})" 35 echo " --client-id client_id An OAuth client ID which is needed for running Kurtosis in CI, and should be left empty when running Kurtosis on a local machine" 36 echo " --client-secret client_secret An OAuth client secret which is needed for running Kurtosis in CI, and should be left empty when running Kurtosis on a local machine" 37 echo " --help Display this message" 38 echo " --kurtosis-log-level kurtosis_log_level The log level that all output generated by the Kurtosis framework itself should log at (panic|fatal|error|warning|info|debug|trace) (default: info)" 39 echo " --list Rather than running the tests, lists the tests available to run" 40 echo " --parallelism parallelism The number of texts to execute in parallel (default: 4)" 41 echo " --tests test_names List of test names to run, separated by ',' (default or empty: run all tests)" 42 echo " --test-suite-log-level test_suite_log_level A string that will be passed as-is to the test suite container to indicate what log level the test suite container should output at; this string should be meaningful to the test suite container because Kurtosis won't know what logging framework the testsuite uses (default: info)" 43 echo " test_suite_image The Docker image containing the testsuite to execute" 44 45 echo "" 46 exit 1 # Exit with an error code, so that if it gets accidentally called in parent scripts/CI it fails loudly 47 } 48 49 50 51 # ============================================================================================ 52 # Arg Parsing 53 # ============================================================================================ 54 client_id="" 55 client_secret="" 56 custom_params_json="{}" 57 do_list="false" 58 kurtosis_log_level="info" 59 parallelism="4" 60 show_help="false" 61 test_names="" 62 test_suite_image="" 63 test_suite_log_level="info" 64 65 66 67 POSITIONAL=() 68 while [ ${#} -gt 0 ]; do 69 key="${1}" 70 case "${key}" in 71 72 --custom-params) 73 74 custom_params_json="${2}" 75 shift # Shift to clear out the flag 76 shift # Shift again to clear out the value 77 ;; 78 79 --client-id) 80 81 client_id="${2}" 82 shift # Shift to clear out the flag 83 shift # Shift again to clear out the value 84 ;; 85 86 --client-secret) 87 88 client_secret="${2}" 89 shift # Shift to clear out the flag 90 shift # Shift again to clear out the value 91 ;; 92 93 --help) 94 show_help="true" 95 shift # Shift to clear out the flag 96 97 ;; 98 99 --kurtosis-log-level) 100 101 kurtosis_log_level="${2}" 102 shift # Shift to clear out the flag 103 shift # Shift again to clear out the value 104 ;; 105 106 --list) 107 do_list="true" 108 shift # Shift to clear out the flag 109 110 ;; 111 112 --parallelism) 113 114 parallelism="${2}" 115 shift # Shift to clear out the flag 116 shift # Shift again to clear out the value 117 ;; 118 119 --tests) 120 121 test_names="${2}" 122 shift # Shift to clear out the flag 123 shift # Shift again to clear out the value 124 ;; 125 126 --test-suite-log-level) 127 128 test_suite_log_level="${2}" 129 shift # Shift to clear out the flag 130 shift # Shift again to clear out the value 131 ;; 132 133 -*) 134 echo "ERROR: Unrecognized flag '${key}'" >&2 135 exit 1 136 ;; 137 *) 138 POSITIONAL+=("${1}") 139 shift 140 ;; 141 esac 142 done 143 144 if "${show_help}"; then 145 print_help_and_exit 146 fi 147 148 # Restore positional parameters and assign them to variables 149 set -- "${POSITIONAL[@]}" 150 test_suite_image="${1:-}" 151 152 153 154 155 156 # ============================================================================================ 157 # Arg Validation 158 # ============================================================================================ 159 if [ "${#}" -ne 1 ]; then 160 echo "ERROR: Expected 1 positional variables but got ${#}" >&2 161 print_help_and_exit 162 fi 163 164 if [ -z "$test_suite_image" ]; then 165 echo "ERROR: Variable 'test_suite_image' cannot be empty" >&2 166 exit 1 167 fi 168 169 170 171 # ============================================================================================ 172 # Main Logic 173 # ============================================================================================# Because Kurtosis X.Y.Z tags are normalized to X.Y so that minor patch updates are transparently 174 # used, we need to pull the latest API & initializer images 175 echo "Pulling latest versions of API & initializer image..." 176 if ! docker pull "${INITIALIZER_IMAGE}"; then 177 echo "WARN: An error occurred pulling the latest version of the initializer image (${INITIALIZER_IMAGE}); you may be running an out-of-date version" >&2 178 else 179 echo "Successfully pulled latest version of initializer image" 180 fi 181 if ! docker pull "${API_IMAGE}"; then 182 echo "WARN: An error occurred pulling the latest version of the API image (${API_IMAGE}); you may be running an out-of-date version" >&2 183 else 184 echo "Successfully pulled latest version of API image" 185 fi 186 187 # Kurtosis needs a Docker volume to store its execution data in 188 # To learn more about volumes, see: https://docs.docker.com/storage/volumes/ 189 sanitized_image="$(echo "${test_suite_image}" | sed 's/[^a-zA-Z0-9_.-]/_/g')" 190 suite_execution_volume="$(date +%Y-%m-%dT%H.%M.%S)_${sanitized_image}" 191 if ! docker volume create "${suite_execution_volume}" > /dev/null; then 192 echo "ERROR: Failed to create a Docker volume to store the execution files in" >&2 193 exit 1 194 fi 195 196 if ! mkdir -p "${KURTOSIS_DIRPATH}"; then 197 echo "ERROR: Failed to create the Kurtosis directory at '${KURTOSIS_DIRPATH}'" >&2 198 exit 1 199 fi 200 201 docker run \ 202 `# The Kurtosis initializer runs inside a Docker container, but needs to access to the Docker engine; this is how to do it` \ 203 `# For more info, see the bottom of: http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/` \ 204 --mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \ 205 \ 206 `# Because the Kurtosis initializer runs inside Docker but needs to persist & read files on the host filesystem between execution,` \ 207 `# the container expects the Kurtosis directory to be bind-mounted at the special "/kurtosis" path` \ 208 --mount "type=bind,source=${KURTOSIS_DIRPATH},target=/kurtosis" \ 209 \ 210 `# The Kurtosis initializer image requires the volume for storing suite execution data to be mounted at the special "/suite-execution" path` \ 211 --mount "type=volume,source=${suite_execution_volume},target=/suite-execution" \ 212 \ 213 `# Keep these sorted alphabetically` \ 214 --env CLIENT_ID="${client_id}" \ 215 --env CLIENT_SECRET="${client_secret}" \ 216 --env CUSTOM_PARAMS_JSON="${custom_params_json}" \ 217 --env DO_LIST="${do_list}" \ 218 --env KURTOSIS_API_IMAGE="${API_IMAGE}" \ 219 --env KURTOSIS_LOG_LEVEL="${kurtosis_log_level}" \ 220 --env PARALLELISM="${parallelism}" \ 221 --env SUITE_EXECUTION_VOLUME="${suite_execution_volume}" \ 222 --env TEST_NAMES="${test_names}" \ 223 --env TEST_SUITE_IMAGE="${test_suite_image}" \ 224 --env TEST_SUITE_LOG_LEVEL="${test_suite_log_level}" \ 225 \ 226 "${INITIALIZER_IMAGE}"