当前位置:   article > 正文

Edge Computing 边缘计算 Build 方法-Docker 容器 配置-立哥开发_边缘计算 docker 批处理

边缘计算 docker 批处理

#!/bin/bash
# Copyright 2008-2021 Jacky Zong .All rights reserved.
# 在天愿作比翼鸟
# 在地愿为连理枝

export LANG="en_US.UTF-8"
WORKROOT="$(cd $(dirname "$0") && cd ../ && pwd || false)"
export GO111MODULE=on
export GOPROXY=https://goproxy.io
export CGO_ENABLED=0
cd $WORKROOT

function build() {
    OUTPUT=$WORKROOT/output
    rm -rf $OUTPUT && mkdir $OUTPUT

    OUTPUT_BIN=$OUTPUT/bin
    mkdir -p $OUTPUT_BIN

   
    cp $WORKROOT/deployments/otectl $OUTPUT_BIN
    if [ $? -ne 0 ]; then
        exit 1
    fi
    
    # build clustercontroller and cluster shim
    go build -o $OUTPUT_BIN/clustercontroller ./cmd/clustercontroller && \
        go build -o $OUTPUT_BIN/k8s_cluster_shim ./cmd/k8s_cluster_shim && \
        go build -o $OUTPUT_BIN/k3s_cluster_shim ./cmd/k3s_cluster_shim && \
        go build -o $OUTPUT_BIN/ote_controller_manager ./cmd/ote_controller_manager && \
        go build -o $OUTPUT_BIN/ote_edgehub ./cmd/edgehub && \
        go build -o $OUTPUT_BIN/ote_edgecontroller ./cmd/edgecontroller && \
        echo "build done"
}

function build_image() {
    arch=$(uname -m)
    if [[ $arch == "x86_64" ]];then
       arch="amd64"
    elif [[ $arch == "aarch64" ]];then
       arch="arm64"
    else 
       arch="386"
    fi

    export GOOS=linux
    export GOARCH=$arch
    build

    cd $OUTPUT_BIN/
    docker build -f $WORKROOT/build/dockerfile/Dockerfile.ote-cc -t ote-cc:latest .
    docker build -f $WORKROOT/build/dockerfile/Dockerfile.ote-cm -t ote-cm:latest .
    docker build -f $WORKROOT/build/dockerfile/Dockerfile.ote-shim -t ote-shim:latest .
    docker build -f $WORKROOT/build/dockerfile/Dockerfile.edge-controller -t edge-controller:latest .
    echo "build image done"
}

function test() {
    #go list ./pkg/... | grep -v "pkg/generated" | grep -v "pkg/apis" | xargs -n1 go test -cover
    go test ./pkg/... -coverprofile cover.out
    totalcover=`go tool cover -func cover.out | grep total | awk '{print $3}'`
    rm cover.out
    echo "total coverage: $totalcover"
}

function usage() {
    echo >&2 "Usage:"
    echo >&2 "  $0 build"
    echo >&2 "  $0 test"
    exit 1
}

cmd="${1:-}"
if [[ ! $cmd ]]; then
    usage
fi
shift

case "${cmd}" in
    build)
        build
        ;;
    build-image)
        build_image
        ;;
    test)
        test
        ;;
    *)
        usage
        ;;
esac

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/327834
推荐阅读
相关标签
  

闽ICP备14008679号