build.sh 2.9 KB
Newer Older
1
#!/bin/bash
P
Peter Pan 已提交
2
set -e
3 4 5 6 7 8 9 10

TOP_DIR=$(pwd)
FRONTEND_DIR=$TOP_DIR/frontend
BACKEND_DIR=$TOP_DIR/visualdl
BUILD_DIR=$TOP_DIR/build

mkdir -p $BUILD_DIR

11
build_frontend_from_source() {
12
    cd $FRONTEND_DIR
P
Peter Pan 已提交
13 14 15
    PUBLIC_PATH="/app" API_URL="/api" ./scripts/build.sh
}

16
build_frontend() {
17 18 19 20 21 22
    local PACKAGE="visualdl"
    local TAG="latest"
    local TARBALL="${PACKAGE}@${TAG}"

    # get version
    local VERSION=`npm view ${TARBALL} dist-tags.${TAG}`
P
Peter Pan 已提交
23
    if [ "$?" -ne "0" ]; then
24
        echo "Cannot get version"
P
Peter Pan 已提交
25 26
        exit 1
    fi
27 28 29 30
    local FILENAME="${PACKAGE}-${VERSION}.tgz"

    # get sha1sum
    local SHA1SUM=`npm view ${TARBALL} dist.shasum`
P
Peter Pan 已提交
31
    if [ "$?" -ne "0" ]; then
32
        echo "Cannot get sha1sum"
P
Peter Pan 已提交
33 34
        exit 1
    fi
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    rm -f "$BUILD_DIR/${PACKAGE}-*.tgz.sha1"
    echo "${SHA1SUM} ${FILENAME}" > "$BUILD_DIR/${FILENAME}.sha1"

    local DOWNLOAD="1"
    # cached file exists
    if [ -f "$BUILD_DIR/$FILENAME" ]; then
        # check sha1sum
        (cd $BUILD_DIR && sha1sum -c "${FILENAME}.sha1")
        # check pass, use chached file
        if [ "$?" -eq "0" ]; then
            echo "Using cached npm package file ${FILENAME}"
            DOWNLOAD="0"
        fi
    fi

    if [ "$DOWNLOAD" -eq "1" ]; then
        echo "Donwloading npm package, please wait..."

        # remove cache
        rm -f "$BUILD_DIR/${PACKAGE}-*.tgz"

        # download file
        FILENAME=`(cd $BUILD_DIR && npm pack ${TARBALL})`

        # check sha1sum of downloaded file
        (cd $BUILD_DIR && sha1sum -c "${FILENAME}.sha1")
        if [ "$?" -ne "0" ]; then
            echo "Check sum failed, download may not finish correctly."
            exit 1
        else
            echo "Check sum pass."
        fi
    fi

    # extract
    tar zxf "$BUILD_DIR/$FILENAME" -C "$BUILD_DIR"
71 72
}

P
Peter Pan 已提交
73
build_frontend_fake() {
74
    mkdir -p "$BUILD_DIR/package/serverless"
75 76 77 78
}

build_backend() {
    cd $BUILD_DIR
O
Oraoto 已提交
79 80 81 82 83
    if [[ $WITH_PYTHON3 ]]; then
        cmake -DWITH_PYTHON3=ON .. ${PYTHON_FLAGS}
    else
        cmake .. ${PYTHON_FLAGS}
    fi
84 85 86 87 88
    make -j2
}

build_onnx_graph() {
    export PATH="$BUILD_DIR/third_party/protobuf/src/extern_protobuf-build/:$PATH"
P
Peter Pan 已提交
89
    cd $TOP_DIR/visualdl/server/model/onnx
90
    protoc onnx.proto --python_out .
P
Peter Pan 已提交
91 92
    cd $TOP_DIR/visualdl/server/model/paddle
    protoc framework.proto --python_out .
93 94 95 96 97 98 99 100
}

clean_env() {
    rm -rf $TOP_DIR/visualdl/server/dist
    rm -rf $BUILD_DIR/bdist*
    rm -rf $BUILD_DIR/lib*
    rm -rf $BUILD_DIR/temp*
    rm -rf $BUILD_DIR/scripts*
101
    rm -rf $BUILD_DIR/package
102 103 104
}

package() {
P
Peter Pan 已提交
105
    mkdir -p $TOP_DIR/visualdl/server/dist
106
    cp -rf $BUILD_DIR/package/serverless/* $TOP_DIR/visualdl/server/dist
P
Peter Pan 已提交
107 108
    cp $BUILD_DIR/visualdl/logic/core.so $TOP_DIR/visualdl
    cp $BUILD_DIR/visualdl/logic/core.so $TOP_DIR/visualdl/python/
109 110 111 112 113
}

ARG=$1
echo "ARG: " $ARG

114 115
clean_env

P
Peter Pan 已提交
116 117 118 119 120 121
if [ "$ARG" = "travis-CI" ]; then
    build_frontend_fake
else
    build_frontend
fi

122 123 124
build_backend
build_onnx_graph
package