storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/mint/mint.sh (about) 1 #!/bin/bash 2 # 3 # Mint (C) 2017, 2018 Minio, Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 CONTAINER_ID=$(grep -o -e '[0-f]\{12,\}' /proc/1/cpuset | awk '{print substr($1, 1, 12)}') 19 MINT_DATA_DIR=${MINT_DATA_DIR:-/mint/data} 20 MINT_MODE=${MINT_MODE:-core} 21 SERVER_REGION=${SERVER_REGION:-us-east-1} 22 ENABLE_HTTPS=${ENABLE_HTTPS:-0} 23 ENABLE_VIRTUAL_STYLE=${ENABLE_VIRTUAL_STYLE:-0} 24 RUN_ON_FAIL=${RUN_ON_FAIL:-0} 25 GO111MODULE=on 26 27 if [ -z "$SERVER_ENDPOINT" ]; then 28 SERVER_ENDPOINT="play.minio.io:9000" 29 ACCESS_KEY="Q3AM3UQ867SPQQA43P2F" 30 SECRET_KEY="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" 31 ENABLE_HTTPS=1 32 fi 33 34 if [ "$ENABLE_VIRTUAL_STYLE" -eq 1 ]; then 35 SERVER_IP="${SERVER_ENDPOINT%%:*}" 36 SERVER_PORT="${SERVER_ENDPOINT/*:/}" 37 # Check if SERVER_IP is actually IPv4 address 38 octets=("${SERVER_IP//./ }") 39 if [ "${#octets[@]}" -ne 4 ]; then 40 echo "$SERVER_IP must be an IP address" 41 exit 1 42 fi 43 for octet in "${octets[@]}"; do 44 if [ "$octet" -lt 0 ] 2>/dev/null || [ "$octet" -gt 255 ] 2>/dev/null; then 45 echo "$SERVER_IP must be an IP address" 46 exit 1 47 fi 48 done 49 fi 50 51 ROOT_DIR="$PWD" 52 TESTS_DIR="$ROOT_DIR/run/core" 53 54 BASE_LOG_DIR="$ROOT_DIR/log" 55 LOG_FILE="log.json" 56 ERROR_FILE="error.log" 57 mkdir -p "$BASE_LOG_DIR" 58 59 function humanize_time() 60 { 61 time="$1" 62 days=$(( time / 60 / 60 / 24 )) 63 hours=$(( time / 60 / 60 % 24 )) 64 minutes=$(( time / 60 % 60 )) 65 seconds=$(( time % 60 )) 66 67 (( days > 0 )) && echo -n "$days days " 68 (( hours > 0 )) && echo -n "$hours hours " 69 (( minutes > 0 )) && echo -n "$minutes minutes " 70 (( days > 0 || hours > 0 || minutes > 0 )) && echo -n "and " 71 echo "$seconds seconds" 72 } 73 74 function run_test() 75 { 76 if [ ! -d "$1" ]; then 77 return 1 78 fi 79 80 start=$(date +%s) 81 82 mkdir -p "$BASE_LOG_DIR/$sdk_name" 83 84 (cd "$sdk_dir" && ./run.sh "$BASE_LOG_DIR/$LOG_FILE" "$BASE_LOG_DIR/$sdk_name/$ERROR_FILE") 85 rv=$? 86 end=$(date +%s) 87 duration=$(humanize_time $(( end - start ))) 88 89 if [ "$rv" -eq 0 ]; then 90 echo "done in $duration" 91 else 92 echo "FAILED in $duration" 93 entry=$(tail -n 1 "$BASE_LOG_DIR/$LOG_FILE") 94 status=$(jq -e -r .status <<<"$entry") 95 jq_rv=$? 96 if [ "$jq_rv" -ne 0 ]; then 97 echo "$entry" 98 fi 99 ## Show error.log when status is empty or not "FAIL". 100 ## This may happen when test run failed without providing logs. 101 if [ "$jq_rv" -ne 0 ] || [ -z "$status" ] || { [ "$status" != "FAIL" ] && [ "$status" != "fail" ]; }; then 102 cat "$BASE_LOG_DIR/$sdk_name/$ERROR_FILE" 103 else 104 jq . <<<"$entry" 105 fi 106 fi 107 return $rv 108 } 109 110 function trust_s3_endpoint_tls_cert() 111 { 112 # Download the public certificate from the server 113 openssl s_client -showcerts -connect "$SERVER_ENDPOINT" </dev/null 2>/dev/null | \ 114 openssl x509 -outform PEM -out /usr/local/share/ca-certificates/s3_server_cert.crt || \ 115 exit 1 116 117 # Load the certificate in the system 118 update-ca-certificates --fresh >/dev/null 119 120 # Ask different SDKs/tools to load system certificates 121 export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt 122 export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt 123 export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt 124 } 125 126 127 function main() 128 { 129 export MINT_DATA_DIR 130 export MINT_MODE 131 export SERVER_ENDPOINT 132 export SERVER_IP 133 export SERVER_PORT 134 135 export ACCESS_KEY 136 export SECRET_KEY 137 export ENABLE_HTTPS 138 export SERVER_REGION 139 export ENABLE_VIRTUAL_STYLE 140 export RUN_ON_FAIL 141 export GO111MODULE 142 143 echo "Running with" 144 echo "SERVER_ENDPOINT: $SERVER_ENDPOINT" 145 echo "ACCESS_KEY: $ACCESS_KEY" 146 echo "SECRET_KEY: ***REDACTED***" 147 echo "ENABLE_HTTPS: $ENABLE_HTTPS" 148 echo "SERVER_REGION: $SERVER_REGION" 149 echo "MINT_DATA_DIR: $MINT_DATA_DIR" 150 echo "MINT_MODE: $MINT_MODE" 151 echo "ENABLE_VIRTUAL_STYLE: $ENABLE_VIRTUAL_STYLE" 152 echo "RUN_ON_FAIL: $RUN_ON_FAIL" 153 echo 154 echo "To get logs, run 'docker cp ${CONTAINER_ID}:/mint/log /tmp/mint-logs'" 155 echo 156 157 [ "$ENABLE_HTTPS" == "1" ] && trust_s3_endpoint_tls_cert 158 159 declare -a run_list 160 sdks=( "$@" ) 161 162 if [ "$#" -eq 0 ]; then 163 cd "$TESTS_DIR" || exit 164 sdks=(*) 165 cd .. || exit 166 fi 167 168 for sdk in "${sdks[@]}"; do 169 sdk=$(basename "$sdk") 170 run_list=( "${run_list[@]}" "$TESTS_DIR/$sdk" ) 171 done 172 173 count="${#run_list[@]}" 174 i=0 175 for sdk_dir in "${run_list[@]}"; do 176 sdk_name=$(basename "$sdk_dir") 177 (( i++ )) 178 if [ ! -d "$sdk_dir" ]; then 179 echo "Test $sdk_name not found. Exiting Mint." 180 exit 1 181 fi 182 echo -n "($i/$count) Running $sdk_name tests ... " 183 if ! run_test "$sdk_dir"; then 184 (( i-- )) 185 fi 186 done 187 188 ## Report when all tests in run_list are run 189 if [ "$i" -eq "$count" ]; then 190 echo -e "\nAll tests ran successfully" 191 else 192 echo -e "\nExecuted $i out of $count tests successfully." 193 exit 1 194 fi 195 } 196 main "$@"