Signed-off-by: Bai Jing 799286817@qq.com --- tests/openeuler_docker | 142 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 tests/openeuler_docker
diff --git a/tests/openeuler_docker b/tests/openeuler_docker new file mode 100755 index 000000000..d713924bf --- /dev/null +++ b/tests/openeuler_docker @@ -0,0 +1,142 @@ +#!/bin/sh +# - dockerfile_url + +# exit 1 if openEuler failed +# exit 0 if +# - no centos support +# - centos failed + +. $LKP_SRC/lib/debug.sh +. $LKP_SRC/lib/log.sh + +[ -n "$dockerfile_url" ] || die "dockerfile_url is empty" + +cd $BENCHMARK_ROOT + +nr_openeuler_fail=0 + +fit_repo() +{ + yum reinstall -y git + git clone "$dockerfile_url" || exit 0 + file_dir=$(find ./ -type f -name "*Dockerfile*" | xargs grep -HE '^FROM centos:(centos|)[78]') + [ -n "$file_dir" ] || { + echo "current-repo-not-support-centos: 1" + exit 0 + } +} + +openeuler_ready() +{ + docker load < $BENCHMARK_ROOT/openeuler_docker/openeuler-20.03-lts-v1.tar +} + +centos_docker() +{ + flag=0 + i=1 + for file in $(find ./ -type f -name "*Dockerfile*" | xargs grep -HE '^FROM centos:(centos|)[78]' | awk -F: '{print $1}') + do + file_dir=${file%/*} + image=$(echo "$file" | awk -F '/' '{print $3}' | tr 'A-Z' 'a-z') + [ -n "$image" ] || image=${file#*/}_$i + if [ -f "$file_dir/build.sh" ] && [ -x "$file_dir/build.sh" ]; then + "$file_dir/build.sh" > /dev/null 2> /dev/null && { + handle_dockerfile + } + else + docker_build > /dev/null 2> /dev/null && { + handle_dockerfile + } + fi + let i++ + done + if [ "$nr_openeuler_fail" != 0 ]; then + echo "openeuler failed times: $nr_openeuler_fail" + echo "openeuler_valid_url: $dockerfile_url" + exit 1 + else + echo "current-repo-not-support-centos: 1" + exit 0 + fi +} + +handle_FROM() +{ + sed -i "s/^FROM .*/FROM openeuler-20.03-lts:v1/g" "$file" + +} + +handle_epel() +{ + grep -qw "epel-release" "$file" && { + sed -i "s/epel-release/bash/g" "$file" + } +} + +handle_epelrpm() +{ + + grep -qw "https://.*epel-release.*rpm" "$file" && { + sed -i "s|https://.*epel-release.*rpm%7Cbash%7Cg" "$file" + + } +} + +add_base_commands() +{ + # grep -qw "groupadd*" "$file" && { + # fix missing useradd, groupadd, chpasswd, etc. commands + sed -i '/FROM /a\RUN yum -y install shadow tar' "$file" +} + +handle_epel_repo() +{ + sed -i '/.* wget .*(epel|CentOS-Base).repo/ s|^|#|g' "$file" +} + +handle_dockerfile() +{ + flag=1 + handle_FROM + handle_epel + add_base_commands + if docker_build "-openeuler"; then + docker_run "-openeuler" + else + let nr_openeuler_fail++ + fi +} + +docker_build() +{ + docker build -f "$file" -t "${image}$1" . + [ $? != 0 ] && { + [ "$flag" == "1" ] && echo "${image}$1.build.fail: 1" + return 1 + } + [ "$flag" == "1" ] && echo "${image}$1.build.success: 1" + flag=0 +} + +docker_run() +{ + docker run -d --name "${image}" "${image}$1" + wait + docker_stats=$(docker inspect -f '{{.State.Running}}' ${image}) + [ $docker_stats == false ] && { + echo "${image}.run.fail: 1" + return 1 + } + + echo "${image}.run.success: 1" +} + +docker_test() +{ + fit_repo + openeuler_ready + centos_docker +} + +docker_test