github.com/turingchain2020/turingchain@v1.1.21/build/docker-compose-pre.sh (about) 1 #!/usr/bin/env bash 2 3 set -e 4 set -o pipefail 5 #set -o verbose 6 #set -o xtrace 7 8 sedfix="" 9 if [ "$(uname)" == "Darwin" ]; then 10 sedfix=".bak" 11 fi 12 13 OP="${1}" 14 PROJ="${2}" 15 DAPP="${3}" 16 17 TESTCASEFILE="testcase.sh" 18 FORKTESTFILE="fork-test.sh" 19 20 function down_dapp() { 21 app=$1 22 23 if [ -d "${app}" ] && [ "${app}" != "system" ] && [ -d "${app}-ci" ]; then 24 cd "${app}"-ci/ && pwd 25 26 echo "============ down dapp=$app start =================" 27 ./docker-compose-down.sh "${PROJ}" "${app}" 28 echo "============ down dapp=$app end =================" 29 30 cd .. && rm -rf ./"${app}"-ci 31 fi 32 } 33 34 function run_dapp() { 35 app=$1 36 test=$2 37 38 echo "============ run dapp=$app start =================" 39 rm -rf "${app}"-ci && mkdir -p "${app}"-ci && cp ./"${app}"/* ./"${app}"-ci && echo $? 40 cp -n ./* ./"${app}"-ci/ && echo $? 41 cd "${app}"-ci/ && pwd 42 43 if [ "$test" == "$FORKTESTFILE" ]; then 44 sed -i $sedfix 's/^system_coins_file=.*/system_coins_file="..\/system\/coins\/fork-test.sh"/g' system-fork-test.sh 45 if ! ./system-fork-test.sh "${PROJ}" "${app}"; then 46 exit 1 47 fi 48 elif [ "$test" == "$TESTCASEFILE" ]; then 49 if ! ./docker-compose.sh "${PROJ}" "${app}"; then 50 exit 1 51 fi 52 fi 53 cd .. 54 echo "============ run dapp=$app end =================" 55 56 } 57 58 function run_single_app() { 59 app=$1 60 testfile=$2 61 62 if [ -d "${app}" ] && [ "${app}" != "system" ]; then 63 if [ -e "$app/$testfile" ]; then 64 run_dapp "${app}" "$testfile" 65 if [ "$#" -gt 2 ]; then 66 down_dapp "${app}" 67 fi 68 else 69 echo "#### dapp=$app not exist the test file: $testfile ####" 70 fi 71 else 72 echo "#### dapp=$app not exist or is system dir ####" 73 fi 74 } 75 76 function main() { 77 if [ "${OP}" == "run" ]; then 78 if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then 79 echo "============ run main start =================" 80 if ! ./docker-compose.sh "$PROJ"; then 81 exit 1 82 fi 83 ./docker-compose-down.sh "$PROJ" 84 echo "============ run main end =================" 85 86 find . -maxdepth 1 -type d -name "*-ci" -exec rm -rf {} \; 87 dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///') 88 for app in $dir; do 89 run_single_app "${app}" "$TESTCASEFILE" "down" 90 done 91 elif [ -n "${DAPP}" ]; then 92 run_single_app "${DAPP}" "$TESTCASEFILE" 93 else 94 ./docker-compose.sh "${PROJ}" 95 fi 96 elif [ "${OP}" == "down" ]; then 97 if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then 98 dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///') 99 for app in $dir; do 100 down_dapp "${app}" 101 done 102 ./docker-compose-down.sh "${PROJ}" 103 elif [ -n "${DAPP}" ]; then 104 down_dapp "${DAPP}" 105 else 106 ./docker-compose-down.sh "${PROJ}" 107 fi 108 elif [ "${OP}" == "forktest" ]; then 109 if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then 110 echo "============ run main start =================" 111 if ! ./system-fork-test.sh "$PROJ"; then 112 exit 1 113 fi 114 echo "============ down main test =================" 115 ./docker-compose-down.sh "$PROJ" 116 echo "============ run main end =================" 117 # remove all the *-ci folders 118 find . -maxdepth 1 -type d -name "*-ci" -exec rm -rf {} \; 119 dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///') 120 for app in $dir; do 121 run_single_app "${app}" "$FORKTESTFILE" "down" 122 done 123 elif [ -n "${DAPP}" ]; then 124 run_single_app "${DAPP}" "$FORKTESTFILE" 125 else 126 ./system-fork-test.sh "${PROJ}" 127 fi 128 fi 129 130 } 131 132 # run script 133 main