加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rundocker.sh 11.78 KB
一键复制 编辑 原始数据 按行查看 历史
neilpang 提交于 2021-05-24 22:06 . add almalinux
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
Img="https://acmesh-official.github.io/acmetest/status"
LogLink="https://github.com/acmesh-official/acmetest/blob/master"
Conf="plat.conf"
Table="table.md"
DEFAULT_SCRIPT="letest.sh"
#if [ -z "$TestingDomain" ] && [ -z "$NGROK_TOKEN" ]; then
# TestingDomain=testdocker.acme.sh
#fi
#
#if [ -z "$TestingAltDomains" ] && [ -z "$NGROK_TOKEN" ]; then
# TestingAltDomains=testdocker2.acme.sh
#fi
if [ -z "$RUN_SCRIPT" ] ; then
RUN_SCRIPT="$DEFAULT_SCRIPT"
fi
_date_u() {
date -u +"%a, %d %b %Y %T %Z"
}
_info() {
if [ -z "$2" ] ; then
echo "[$(date)] $1"
else
echo "[$(date)] $1"="'$2'"
fi
}
_err() {
_info "$@" >&2
return 1
}
_debug() {
if [ -z "$DEBUG" ] ; then
return
fi
_err "$@"
return 0
}
_debug2() {
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ] ; then
_debug "$@"
fi
return
}
_debug3() {
if [ "$DEBUG" ] && [ "$DEBUG" -ge "3" ] ; then
_debug "$@"
fi
return
}
#plat
_normalizeFilename() {
_nplat="$1"
printf "%s" "$_nplat" | tr ':/ \\' '----'
}
#plat
_getOutfile() {
_gnplat="$1"
statusfile="$(_normalizeFilename "$_gnplat")"
printf "%s" "logs/$statusfile.out"
}
#plat
_getLogfile() {
_lnplat="$1"
statusfile="$(_normalizeFilename "$_lnplat")"
printf "%s" "logs/$statusfile.log"
}
_time() {
date -u "+%s"
}
#update plat code [file]
update() {
plat="$1"
code="$2"
filename="$3"
if [ -z "$filename" ] ; then
filename="$Table"
fi
if [ -z "$code" ] ; then
_err "Usage: plat exitcode [filename:table.md]"
return 1
fi
statusfile="$(_normalizeFilename "$plat")"
if [ "$code" = "0" ] ; then
__ok "$plat"
else
__fail "$plat"
fi
if [ "$CI" = "1" ] ; then
if ! git pull >/dev/null 2>&1 ; then
_err "git pull error"
fi
_status="Passed"
if [ "$code" = "0" ] ; then
if [ -f "status/ok.svg" ] ; then
cat "status/ok.svg" > "status/$statusfile.svg"
fi
_status="Passed"
else
if [ -f "status/ng.svg" ] ; then
cat "status/ng.svg" > "status/$statusfile.svg"
fi
_status="Failed"
fi
git add "status/$statusfile.svg" >/dev/null 2>&1
outfile="$(_getOutfile "$plat")"
_setopt "$filename" "|$plat| " '!' "[]($Img/$statusfile.svg?$(_time))| $(_date_u)| [$_status]($LogLink/$outfile) |"
#_sed_i 's/\x1b\[1;31;32m//g' "$outfile" >/dev/null 2>&1
#_sed_i 's/\[1;31;32m//g' "$outfile" >/dev/null 2>&1
#
#_sed_i 's/\x1b\[0m//g' "$outfile" >/dev/null 2>&1
#_sed_i 's/\[0m//g' "$outfile" >/dev/null 2>&1
git add "$outfile" >/dev/null 2>&1
git add "$filename" >/dev/null 2>&1
cat head.md "$Table" tail.md > README.md
git add *.md >/dev/null 2>&1
git commit -m "Test for $plat" >/dev/null 2>&1
if ! git push >/dev/null 2>&1 ; then
_err "git push error"
fi
fi
}
_contains(){
_str="$1"
_sub="$2"
echo $_str | grep $_sub >/dev/null 2>&1
}
#options file
_sed_i() {
options="$1"
filename="$2"
if [ -z "$filename" ] ; then
_err "Usage:_sed_i options filename"
return 1
fi
_debug2 options "$options"
if sed -h 2>&1 | grep "\-i\[SUFFIX]" >/dev/null 2>&1; then
_debug "Using sed -i"
sed -i "$options" "$filename"
else
_debug "No -i support in sed"
text="$(cat "$filename")"
echo "$text" | sed "$options" > "$filename"
fi
}
#setopt "file" "opt" "=" "value" [";"]
_setopt() {
__conf="$1"
__opt="$2"
__sep="$3"
__val="$4"
__end="$5"
if [ -z "$__opt" ] ; then
echo usage: _setopt '"file" "opt" "=" "value" [";"]'
return
fi
if [ ! -f "$__conf" ] ; then
touch "$__conf"
fi
if grep -n "^$__opt$__sep" "$__conf" > /dev/null ; then
_debug3 OK
if _contains "$__val" "&" ; then
__val="$(echo $__val | sed 's/&/\\&/g')"
fi
text="$(cat $__conf)"
echo "$text" | sed "s#^$__opt.*#$__opt$__sep$__val$__end#" > "$__conf"
else
_debug3 APP
echo "$__opt$__sep$__val$__end" >> "$__conf"
fi
}
#__INTERACTIVE=""
#if [ -t 1 ]; then
__INTERACTIVE="1"
#fi
__green() {
if [ "$__INTERACTIVE${ACME_NO_COLOR}" = "1" ]; then
printf '\033[1;31;32m'
fi
printf "$1"
if [ "$__INTERACTIVE${ACME_NO_COLOR}" = "1" ]; then
printf '\033[0m'
fi
}
__ok() {
__green "$1 [PASS]"
printf "\n"
}
__red() {
if [ "$__INTERACTIVE${ACME_NO_COLOR}" = "1" ]; then
printf '\033[1;31;40m'
fi
printf "$1"
if [ "$__INTERACTIVE${ACME_NO_COLOR}" = "1" ]; then
printf '\033[0m'
fi
}
__fail() {
__red "$1 [FAIL]" >&2
printf "\n" >&2
return 1
}
#platline baseline fieldnum
_mergefield() {
platline="$1"
baseline="$2"
fieldnum="$3"
pvalue="$(echo "$platline" | cut -d '|' -f $fieldnum)"
if [ ! "$pvalue" ] ; then
pvalue="$(echo "$baseline" | cut -d '|' -f $fieldnum)"
fi
echo "$pvalue"
}
#plat
#ubuntu:14.04
#centos:6
_runplat() {
plat="$1"
if [ ! "$plat" ] ; then
_err "Usage: _runplat ubuntu:14.04"
return 1
fi
platname="$(echo $plat | tr "/" "-")"
myplat="my$platname"
platline="$(grep "^$plat[^ |]*" "$Conf" | tr -d "\r\n")"
_debug "platline" "$platline"
basetag=""
baseline=""
if _contains "$plat" ":" ; then
basetag="$(echo "$plat" | cut -d : -f 1)"
_debug "basetag" "$basetag"
baseline="$(grep "^-$basetag[^ |]*" "$Conf" | tr -d "\r\n" )"
fi
_debug "baseline" "$baseline"
_info "Running $( __green $plat), this may take a few minutes, please wait."
mkdir -p "$myplat"
echo "FROM $plat" > "$myplat/Dockerfile"
update="$(_mergefield "$platline" "$baseline" 2)"
_debug "update" "$update"
buildq="2>&1"
if [ "$DEBUG" ] || [ "$DEBUGING" ] ; then
buildq=""
fi
install="$(_mergefield "$platline" "$baseline" 3)"
_debug "install" "$install"
if [ "$install" ] ; then
echo "RUN ${update:+$update $buildq &&} $install \\" >> "$myplat/Dockerfile"
tools="$(_mergefield "$platline" "$baseline" 4)"
if [ "$tools" ] ; then
toolsline=$(echo "$tools" | tr ',' ' ' )
if [ "$toolsline" ] ; then
echo "$toolsline $buildq" >> "$myplat/Dockerfile"
fi
fi
fi
if [ "$DEBUGING" ] ; then
cat "$myplat/Dockerfile"
fi
if [ ! -e "env.list" ]; then
touch env.list
fi
Log_Out="$(_getOutfile "$plat")"
_debug "Log_Out" "$Log_Out"
#docker pull $plat > "$Log_Out" 2>&1
if docker build -t "$myplat" "$myplat" > "$Log_Out" 2>&1 ; then
if [ -z "$LOG_FILE" ] ; then
LOG_FILE="$(_getLogfile "$plat")"
echo "" > "$LOG_FILE"
fi
_debug "LOG_FILE" "$LOG_FILE"
if [ "$DEBUGING" ] ; then
docker run --net=host --rm \
-e TestingDomain=$TestingDomain \
-e TestingAltDomains=$TestingAltDomains \
-e DEBUG="$DEBUG" \
-e LOG_FILE="$LOG_FILE" \
-e LOG_LEVEL="$LOG_LEVEL" \
-e BRANCH=$BRANCH \
-e RUN_IN_DOCKER=1 \
-e DOCKER_OS="$plat" \
-e QUICK_TEST="$QUICK_TEST" \
-e TEST_LOCAL="$TEST_LOCAL" \
-e TEST_IPV6="$TEST_IPV6" \
-e TEST_IDN="$TEST_IDN" \
-e TEST_DNS="$TEST_DNS" \
-e Le_HTTPPort="$Le_HTTPPort" \
-e CASE="$CASE" \
-e ACME_NO_COLOR="$ACME_NO_COLOR" \
-e NGROK_TOKEN=$NGROK_TOKEN \
--env-file env.list \
-v $(pwd):/acmetest \
$myplat /bin/sh -c "cd /acmetest && ./$RUN_SCRIPT"
else
if [ "$TRAVIS" = "true" ] || [ "$GITHUB_ACTIONS" = "true" ] ; then
docker run --net=host --rm \
-e TestingDomain=$TestingDomain \
-e TestingAltDomains=$TestingAltDomains \
-e DEBUG="$DEBUG" \
-e LOG_FILE="$LOG_FILE" \
-e LOG_LEVEL="$LOG_LEVEL" \
-e BRANCH=$BRANCH \
-e RUN_IN_DOCKER=1 \
-e DOCKER_OS="$plat" \
-e QUICK_TEST="$QUICK_TEST" \
-e TEST_LOCAL="$TEST_LOCAL" \
-e TEST_IPV6="$TEST_IPV6" \
-e TEST_IDN="$TEST_IDN" \
-e TEST_DNS="$TEST_DNS" \
-e Le_HTTPPort="$Le_HTTPPort" \
-e CASE="$CASE" \
-e ACME_NO_COLOR="$ACME_NO_COLOR" \
-e NGROK_TOKEN=$NGROK_TOKEN \
-e TRAVIS=$TRAVIS \
--env-file env.list \
-v $(pwd):/acmetest \
$myplat /bin/sh -c "cd /acmetest && ./$RUN_SCRIPT"
else
docker run --net=host --rm \
-e TestingDomain=$TestingDomain \
-e TestingAltDomains=$TestingAltDomains \
-e DEBUG="$DEBUG" \
-e LOG_FILE="$LOG_FILE" \
-e LOG_LEVEL="$LOG_LEVEL" \
-e BRANCH=$BRANCH \
-e RUN_IN_DOCKER=1 \
-e DOCKER_OS="$plat" \
-e QUICK_TEST="$QUICK_TEST" \
-e TEST_LOCAL="$TEST_LOCAL" \
-e TEST_IPV6="$TEST_IPV6" \
-e TEST_IDN="$TEST_IDN" \
-e TEST_DNS="$TEST_DNS" \
-e Le_HTTPPort="$Le_HTTPPort" \
-e CASE="$CASE" \
-e ACME_NO_COLOR="$ACME_NO_COLOR" \
-e NGROK_TOKEN=$NGROK_TOKEN \
-e CI=$CI \
--env-file env.list \
-v $(pwd):/acmetest \
$myplat /bin/sh -c "cd /acmetest && ./$RUN_SCRIPT" >> "$Log_Out" 2>&1
fi
fi
code="$?"
_debug "code" "$code"
if [ "$code" != "0" ] ; then
cat "$Log_Out"
if [ "$DEBUGING" ] ; then
_info "Please debuging:"
docker run --net=host --rm \
-i -t \
-e TestingDomain=$TestingDomain \
-e TestingAltDomains=$TestingAltDomains \
-e DEBUG="$DEBUG" \
-e LOG_FILE="$LOG_FILE" \
-e LOG_LEVEL="$LOG_LEVEL" \
-e BRANCH=$BRANCH \
-e RUN_IN_DOCKER=1 \
-e DOCKER_OS="$plat" \
-e QUICK_TEST="$QUICK_TEST" \
-e TEST_LOCAL="$TEST_LOCAL" \
-e TEST_IPV6="$TEST_IPV6" \
-e TEST_IDN="$TEST_IDN" \
-e Le_HTTPPort="$Le_HTTPPort" \
-e CASE="$CASE" \
-e ACME_NO_COLOR="$ACME_NO_COLOR" \
-e NGROK_TOKEN=$NGROK_TOKEN \
--env-file env.list \
-v $(pwd):/acmetest \
$myplat /bin/sh
fi
fi
else
code="$?"
_debug "code" "$code"
cat "$Log_Out"
fi
update $plat $code
return $code
}
#plat
testplat() {
plat="$1"
if [ ! "$plat" ] ; then
_err "Usage: testplat ubuntu:14.04"
return 1
fi
if [ "$CASE" ] ; then
echo "Test for case: $(__green "$CASE")"
fi
platforms=$(grep -o "^$plat[^ |]*" "$Conf" )
if [ ! "$platforms" ] ; then
platforms="$plat"
fi
_debug "$platforms"
for plat in $platforms
do
_runplat "$plat"
_rret="$?"
if [ "$_rret" != "0" ]; then
if [ -z "$DEBUG" ] && [ -z "$DEBUGING" ] ; then
_info "Let's retry once more:$plat"
_runplat "$plat"
_rret="$?"
fi
if [ "$_rret" != "0" ] ; then
_info "Failed: $plat"
_FAILED_PLATS="$_FAILED_PLATS$plat "
if [ "$TRAVIS" = "true" ] || [ "$GITHUB_ACTIONS" == "true" ]; then
return "$_rret"
fi
fi
fi
done
}
#plat1 plat2 plat3
testplats() {
if [ -z "$@" ] ; then
_err "Usage: testplats plat1 plat2 plat3 ... "
return 1
fi
for tps in "$@" ; do
[ "$tps" ] && testplat "$tps"
done
}
cleardocker() {
docker rm $(docker ps -a -q)
#docker rmi $(docker images -q -f "dangling=true")
}
showhelp() {
_info "testall|testplat|testplats|cleardocker|_cron"
}
testall() {
allplats=$(grep -v '^#' plat.conf | grep -v "^-" | cut -d "|" -f 1)
for plat in $allplats
do
if [ "$plat" ] ; then
testplat $plat
pret="$?"
if [ "$pret" != "0" ] && [ "$GITHUB_ACTIONS" == "true" ]; then
return $pret
fi
fi
done
}
_pullgit() {
git checkout status/* >/dev/null 2>&1
git checkout *.md >/dev/null 2>&1
git checkout plat.conf >/dev/null 2>&1
git pull >/dev/null 2>&1
}
_cron() {
if [ "$CI" = "1" ]; then
_pullgit
rm "$Table"
fi
_FAILED_PLATS=""
testall
if [ "$_FAILED_PLATS" ] ; then
if [ "$GITHUB_ACTIONS" != "true" ]; then
_info "Let's try once more for: $_FAILED_PLATS"
_ttft="$_FAILED_PLATS"
_FAILED_PLATS=""
testplats "$_ttft"
else
return 1
fi
fi
}
if [ -z "$1" ] ; then
showhelp
else
"$@"
fi
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化