runCI.sh 4.51 KB
Newer Older
1 2 3
#!/bin/bash

# ******************************************************************************
4
# Copyright 2018-2019 Intel Corporation
5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************

19
NGRAPH_ONNX_REPO="https://github.com/NervanaSystems/ngraph-onnx"
20
CI_PATH="$(pwd)"
21
CI_ROOT=".ci/onnx/jenkins"
22
REPO_ROOT="${CI_PATH%$CI_ROOT}"
23
DOCKER_CONTAINER="ngraph-onnx_ci_reproduction"
24 25 26

# Function run() builds image with requirements needed to build ngraph and run onnx tests, runs container and executes tox tests
function run() {
27 28 29
    set -x
    set -e

30
    cd ./dockerfiles
31
    docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -f=./ubuntu_16_04.dockerfile -t ngraph-onnx:ubuntu-16_04 .
32

33
    cd "${CI_PATH}"
34 35 36 37 38
    if [[ -z $(docker ps -a | grep -i "${DOCKER_CONTAINER}") ]];
    then
        docker run -h "$(hostname)" --privileged --name "${DOCKER_CONTAINER}" -v "${REPO_ROOT}":/root \
            -d ngraph-onnx:ubuntu-16_04 tail -f /dev/null
        BUILD="TRUE"
39 40
    fi

41 42
    if [[ "${BUILD}" == "TRUE" ]];
    then
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        BUILD_NGRAPH_CMD='cd /root && \
            mkdir -p ./build && \
            cd ./build && \
            cmake ../ -DNGRAPH_TOOLS_ENABLE=FALSE -DNGRAPH_UNIT_TEST_ENABLE=FALSE -DNGRAPH_USE_PREBUILT_LLVM=TRUE \
            -DNGRAPH_ONNX_IMPORT_ENABLE=TRUE -DCMAKE_INSTALL_PREFIX=/root/ngraph_dist && \
            make -j $(lscpu --parse=CORE | grep -v '"'#'"' | sort | uniq | wc -l) && \
            make install && \
            cd /root/python && \
            if [[ -z $(ls /root/ngraph-onnx 2>/dev/null) ]]; then
                git clone --recursive https://github.com/pybind/pybind11.git;
            fi
            export PYBIND_HEADERS_PATH=/root/python/pybind11 && \
            export NGRAPH_CPP_BUILD_PATH=/root/ngraph_dist && \
            export NGRAPH_ONNX_IMPORT_ENABLE=TRUE && \
            python3 setup.py bdist_wheel && \
            cd /root'
        docker exec "${DOCKER_CONTAINER}" bash -c "${BUILD_NGRAPH_CMD}"
    fi
61

62 63
    CLONE_CMD='cd /root &&\
        if [[ -z $(ls /root/ngraph-onnx 2>/dev/null) ]]; then
64
            git clone '"${NGRAPH_ONNX_REPO}"';
65 66 67
        fi'
    docker exec "${DOCKER_CONTAINER}" bash -c "${CLONE_CMD}"
    NGRAPH_WHL=$(docker exec ${DOCKER_CONTAINER} find /root/python/dist/ -name "ngraph*.whl")
68 69
    docker exec -e TOX_INSTALL_NGRAPH_FROM="${NGRAPH_WHL}" -e NGRAPH_BACKEND=CPU "${DOCKER_CONTAINER}" tox -c /root/ngraph-onnx/
    docker exec -e TOX_INSTALL_NGRAPH_FROM="${NGRAPH_WHL}" -e NGRAPH_BACKEND=INTEPRETER "${DOCKER_CONTAINER}" tox -c /root/ngraph-onnx/
70 71 72 73 74
}

# Function cleanup() removes items related to nGraph, created during script execution
function cleanup_ngraph() {
    set -x
75

76
    docker exec "${DOCKER_CONTAINER}" bash -c 'rm -rf /root/build/* /root/ngraph_dist /root/python/dist'
77 78 79 80
}

# Function cleanup() removes items created during script execution
function cleanup() {
81
    set -x
82

83 84 85
    docker exec "${DOCKER_CONTAINER}" bash -c "rm -rf /root/ngraph_dist /root/ngraph-onnx/.tox /root/ngraph-onnx/.onnx \
                    /root/ngraph-onnx/__pycache__ /root/ngraph-onnx/ngraph_onnx.egg-info /root/ngraph-onnx/cpu_codegen"
    docker exec "${DOCKER_CONTAINER}" bash -c 'rm -rf $(find /root/ -user root)'
86 87 88 89 90 91 92 93
    docker rm -f "${DOCKER_CONTAINER}"
}

PATTERN='[-a-zA-Z0-9_]*='
for i in "$@"
do
    case $i in
        --help*)
94
            printf "Script builds nGraph and runs tox tests inside docker container.
95 96
            Every execution after first run is going to run tox tests again.
            To rebuild nGraph and run tests again use --rebuild parameter.
97

98
            Following parameters are available:
99

100 101 102
            --help      displays this message
            --cleanup   removes docker container and files created during script execution
            --rebuild   rebuilds nGraph and runs tox tests
103 104 105 106 107 108 109
            "
            exit 0
        ;;
        --cleanup*)
            cleanup
            exit 0
        ;;
110 111 112 113
        --rebuild*)
            cleanup_ngraph
            BUILD="TRUE"
        ;;
114 115 116 117 118
    esac
done

set -x

119
run