Signed-off-by: Bai Jing 799286817@qq.com --- tests/openeuler_docker | 113 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 tests/openeuler_docker
diff --git a/tests/openeuler_docker b/tests/openeuler_docker new file mode 100755 index 000000000..69d8a58a6 --- /dev/null +++ b/tests/openeuler_docker @@ -0,0 +1,113 @@ +#!/bin/sh +# - dockerfile_url + +. $LKP_SRC/lib/debug.sh + +[ -n "$dockerfile_url" ] || die "dockerfile_url is empty " + +cd $BENCHMARK_ROOT + +fit_repo() +{ + yum reinstall -y git + git clone "$dockerfile_url" || exit 0 + file_dir=$(find ./ -type f -name Dockerfile | xargs grep -E '^FROM centos:(centos|)[78]') + [ -n "$file_dir" ] || exit 0 +} + +openeuler_ready() +{ + docker load < $BENCHMARK_ROOT/openeuler_docker/openeuler-20.03-lts-v1.tar +} + +centos_docker() +{ + flag=0 + for file in $(find ./ -name Dockerfile | xargs grep -E '^FROM centos:(centos|)[78]'| awk -F: '{print $1}') + do + file=${file#*/} + image=$(echo "$file" | awk -F'/' '{print $2}' | tr 'A-Z' 'a-z') + + ( + cd $BENCHMARK_ROOT/${file%/*} + if [ -f "build.sh" ] && [ -x "build.sh" ] + then + ./build.sh > /dev/null 2> /dev/null && handle_dockerfile + else + docker_build > /dev/null 2> /dev/null && handle_dockerfile + fi + ) + done +} + +handle_FROM() +{ + sed -i "s/^FROM .*/FROM openeuler-20.03-lts:v1/g" Dockerfile + +} + +handle_epel() +{ + grep -qw "epel-release" Dockerfile && { + sed -i "s/epel-release/bash/g" Dockerfile + } +} + +handle_epelrpm() +{ + + grep -qw "https://.*epel-release.*rpm" Dockerfile && { + sed -i "s|https://.*epel-release.*rpm%7Cbash%7Cg" Dockerfile + + } +} + +handle_groupadd() +{ + grep -qw "groupadd*" Dockerfile && { + sed -i '/groupadd*/i\ yum -y install shadow && \' Dockerfile + } + +} + +handle_dockerfile() +{ + flag=1 + handle_FROM + handle_epel + handle_groupadd + docker_build "-openeuler" + [ $? -ne 0 ] || docker_run "-openeuler" +} + +docker_build() +{ + docker build -t "${image}$1" . + [ $? -ne 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" + docker_stats=$(docker inspect ${image} | grep Running | awk -F ' ' '{print $2}' | tr -d ',') + [ $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