From 06a482da5f950a44ccc5ad746af238d80e700d5d Mon Sep 17 00:00:00 2001
From: Xinglu Yee <2520865+yixinglu@users.noreply.github.com>
Date: Mon, 28 Oct 2019 12:55:36 +0800
Subject: [PATCH] Update docker related configuration (#1074)

* Reset log level and stderrthreshold

Fold too long line in Dockerfile

Decrease data loading interval seconds and fix typos

* Set default constructor and destructor

Comment exposed ports

Format commands

Increase number worker threads

Export ports of web server

Add build docker image bash

Fix nebula spec

Add package and build matrix test

Fix expose ports in docker compose yaml file

Upgrade new docker image and docker-compose deployment method

Mount local directory to container

Ignore docker data/logs folders

Restart on failure

* Move docker-compose configure file to other repo

vesoft/nebula-docker-compose

Fix docker image tag

* Use matrix of action to parallel jobs

* Update package script

Delete package type parameter for package script

Fix package errors

Source bash environment variables

Add BASH_ENV variable

Use absolute path for cmake and ctest

Add library path

Add nebula bin env variable

Test package

Test env variable for library path

Fix package project path error

Update env variables

Fix system check branch error

* Rename ci workflow file

* Fix package error

* Rename and cancel multithreads for ctest in CI

* Try test in singlethread and add tag release package trigger

* Fix uploaded artifacts name

Ignore docs path for build workflow

Use short commit sha when no version

Exact match

Add badge image link

Address comments of PR review
---
 README.md                       | 10 ++++
 conf/nebula-graphd.conf.default |  2 +
 package/nebula.spec             | 25 ++++-----
 package/package.sh              | 89 +++++++++++++++++----------------
 src/daemons/GraphDaemon.cpp     |  6 ---
 src/executor/GraphService.cpp   |  7 ---
 src/executor/GraphService.h     | 14 +++---
 7 files changed, 77 insertions(+), 76 deletions(-)

diff --git a/README.md b/README.md
index ce1e7655..e8ad1286 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,16 @@
   <img src="docs/logo.png"/>
   <br> English | <a href="README-CN.md">涓枃</a>
   <br>A distributed, scalable, lighting-fast graph database<br>
+  <a href="https://github.com/vesoft-inc/nebula/actions?workflow=build">
+    <img src="https://github.com/vesoft-inc/nebula/workflows/build/badge.svg" />
+  </a>
+  <a href="https://github.com/vesoft-inc/nebula/actions?workflow=docker">
+    <img src="https://github.com/vesoft-inc/nebula/workflows/docker/badge.svg" />
+  </a>
+  <a href="https://github.com/vesoft-inc/nebula/actions?workflow=package">
+    <img src="https://github.com/vesoft-inc/nebula/workflows/package/badge.svg" />
+  </a>
+  <br>
 </p>
 
 <!-- <p align="center">
diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default
index f53f5ac2..19096111 100644
--- a/conf/nebula-graphd.conf.default
+++ b/conf/nebula-graphd.conf.default
@@ -18,6 +18,8 @@
 # Destination filename of stdout and stderr, which will also reside in log_dir.
 --stdout_log_file=stdout.log
 --stderr_log_file=stderr.log
+# Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively.
+--stderrthreshold=2
 
 ########## networking ##########
 # Meta Server Address
diff --git a/package/nebula.spec b/package/nebula.spec
index 65b78799..ff3e5ef1 100755
--- a/package/nebula.spec
+++ b/package/nebula.spec
@@ -15,17 +15,18 @@ License:  Apache 2.0 + Common Clause 1.0
 BuildRoot:%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 
 # TODO: we should check dependence's version after adapt to different system versions
-BuildRequires:   make
-BuildRequires:   autoconf
-BuildRequires:   automake
-BuildRequires:   libtool
-BuildRequires:   unzip
-BuildRequires:   readline
-BuildRequires:   ncurses
-BuildRequires:   ncurses-devel
-BuildRequires:   python
-BuildRequires:   java-1.8.0-openjdk
-BuildRequires:   java-1.8.0-openjdk-devel
+# BuildRequires only find dynamic libraries but all of nebula dependencies have been compiled to static libraries, so comment out them temporarily
+# BuildRequires:   make
+# BuildRequires:   autoconf
+# BuildRequires:   automake
+# BuildRequires:   libtool
+# BuildRequires:   unzip
+# BuildRequires:   readline
+# BuildRequires:   ncurses
+# BuildRequires:   ncurses-devel
+# BuildRequires:   python
+# BuildRequires:   java-1.8.0-openjdk
+# BuildRequires:   java-1.8.0-openjdk-devel
 
 %description
 A high performance distributed graph database
@@ -33,7 +34,7 @@ A high performance distributed graph database
 %prep
 
 %build
-cmake -DCMAKE_BUILD_TYPE=Release -DNEBULA_BUILD_VERSION=%{_version} -DCMAKE_INSTALL_PREFIX=%{_install_dir} -DENABLE_TESTING=OFF./
+cmake -DCMAKE_BUILD_TYPE=Release -DNEBULA_BUILD_VERSION=%{_version} -DCMAKE_INSTALL_PREFIX=%{_install_dir} -DENABLE_TESTING=OFF ./
 make -j$(nproc)
 
 %install
diff --git a/package/package.sh b/package/package.sh
index 0b3b41c4..9736ae0d 100755
--- a/package/package.sh
+++ b/package/package.sh
@@ -1,13 +1,19 @@
-#!/bin/bash
+#!/usr/bin/env bash
 #
 #  package nebula as one deb/rpm
-# ./package.sh -v <version> -t <packageType> -s <strip_enable> the version should be match tag name
+# ./package.sh -v <version> -s <strip_enable> the version should be match tag name
 #
 
+set -ex
+
+export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu:$LIBRARY_PATH
+
+NEBULA_DEP_BIN=/opt/nebula/third-party/bin
+
 version=""
-pType=""
 strip_enable="FALSE"
-usage="Usage: ${0} -v <version> -t <RPM/DEB> -s <TRUE/FALSE>"
+usage="Usage: ${0} -v <version> -s <TRUE/FALSE>"
+PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"/../
 
 while getopts v:t:s: opt;
 do
@@ -15,9 +21,6 @@ do
         v)
             version=$OPTARG
             ;;
-        t)
-            pType=$OPTARG
-            ;;
         s)
             strip_enable=$OPTARG
             ;;
@@ -28,7 +31,9 @@ do
 done
 
 # version is null, get from tag name
-[[ -z $version ]] && version=`git describe --match 'v*' | sed 's/^v//'`
+[[ -z $version ]] && version=`git describe --exact-match --abbrev=0 --tags | sed 's/^v//'`
+# version is null, get from short commit sha
+[[ -z $version ]] && version=`git describe --always`
 
 if [[ -z $version ]]; then
     echo "version is null, exit"
@@ -37,24 +42,18 @@ if [[ -z $version ]]; then
 fi
 
 
-if [[ -z $pType ]] || ([[ $pType != RPM ]] && [[ $pType != DEB ]]); then
-    echo "package type is null or type is wrong, exit"
-    echo ${usage}
-    exit -1
-fi
-
 if [[ $strip_enable != TRUE ]] && [[ $strip_enable != FALSE ]]; then
     echo "strip enable is wrong, exit"
     echo ${usage}
     exit -1
 fi
 
-echo "current version is [ $version ], package type is [$pType], strip enable is [$strip_enable]"
+echo "current version is [ $version ], strip enable is [$strip_enable]"
 
 # args: <version>
 function build {
     version=$1
-    build_dir=../build
+    build_dir=$PROJECT_DIR/build
     if [[ -d $build_dir ]]; then
         rm -rf ${build_dir}/*
     else
@@ -63,7 +62,7 @@ function build {
 
     pushd ${build_dir}
 
-    cmake -DCMAKE_BUILD_TYPE=Release -DNEBULA_BUILD_VERSION=${version} -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF ..
+    $NEBULA_DEP_BIN/cmake -DCMAKE_C_COMPILER=$NEBULA_DEP_BIN/gcc -DCMAKE_CXX_COMPILER=$NEBULA_DEP_BIN/g++ -DCMAKE_BUILD_TYPE=Release -DNEBULA_BUILD_VERSION=${version} -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF $PROJECT_DIR
 
     if !( make -j$(nproc) ); then
         echo ">>> build nebula failed <<<"
@@ -73,46 +72,48 @@ function build {
     popd
 }
 
-# args: <pType> <strip_enable>
+# args: <strip_enable>
 function package {
-    pType=$1
-    strip_enable=$2
-    pushd ../build/
+    strip_enable=$1
+    pushd $PROJECT_DIR/build/
     args=""
     [[ $strip_enable == TRUE ]] && args="-D CPACK_STRIP_FILES=TRUE -D CPACK_RPM_SPEC_MORE_DEFINE="
-    if !( cpack -G ${pType} --verbose $args ); then
-        echo ">>> package nebula failed <<<"
-        exit -1
-    fi
 
-    systemVersion=""
     tagetPackageName=""
+    pType="RPM"
+
+    if [[ -f "/etc/redhat-release" ]]; then
+        # TODO: update minor version according to OS
+        centosMajorVersion=`cat /etc/redhat-release | tr -dc '0-9.' | cut -d \. -f1`
+        [[ "$centosMajorVersion" == "7" ]] && tagetPackageName="nebula-${version}.el7-5.x86_64.rpm"
+        [[ "$centosMajorVersion" == "6" ]] && tagetPackageName="nebula-${version}.el6-5.x86_64.rpm"
+    elif [[ -f "/etc/lsb-release" ]]; then
+        ubuntuVersion=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f 2 | sed 's/\.//'`
+        tagetPackageName="nebula-${version}.ubuntu${ubuntuVersion}.amd64.deb"
+        pType="DEB"
+    fi
 
-    if [[ ${pType} == RPM ]]; then
-        # rename rpm file
-        if [[ `cat /etc/redhat-release | grep 7.5` == "" ]]; then
-            systemVersion="el6-5"
-        else
-            systemVersion="el7-5"
-        fi
-        rpmName=`ls | grep nebula-graph | grep rpm | grep ${version}`
-        tagetPackageName=nebula-${version}.${systemVersion}.x86_64.rpm
-        mv ${rpmName} ${tagetPackageName}
+    if [[ "$tagetPackageName" == "" ]]; then
+        echo ">>> Unsupported system <<<"
+        exit -1
+    fi
 
+    if !( $NEBULA_DEP_BIN/cpack -G ${pType} --verbose $args ); then
+        echo ">>> package nebula failed <<<"
+        exit -1
     else
-        # rename deb file
-        systemVersion=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f 2 | sed 's/\.//'`
-        systemVersion=ubuntu${systemVersion}
-        debName=`ls | grep nebula-graph | grep deb | grep ${version}`
-        tagetPackageName=nebula-${version}.${systemVersion}.amd64.deb
-        mv ${debName} ${tagetPackageName}
+        # rename package file
+        pkgName=`ls | grep nebula-graph | grep ${version}`
+        outputDir=$PROJECT_DIR/build/cpack_output
+        mkdir -p ${outputDir}
+        mv ${pkgName} ${outputDir}/${tagetPackageName}
+        echo "####### taget package file is ${outputDir}/${tagetPackageName}"
     fi
 
-    echo "####### taget package file is `pwd`/${tagetPackageName}"
     popd
 }
 
 
 # The main
 build $version
-package $pType $strip_enable
+package $strip_enable
diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp
index 1c6401ef..8a1c7002 100644
--- a/src/daemons/GraphDaemon.cpp
+++ b/src/daemons/GraphDaemon.cpp
@@ -53,12 +53,6 @@ int main(int argc, char *argv[]) {
         return EXIT_FAILURE;
     }
 
-    if (FLAGS_daemonize) {
-        google::SetStderrLogging(google::FATAL);
-    } else {
-        google::SetStderrLogging(google::INFO);
-    }
-
     // Setup logging
     auto status = setupLogging();
     if (!status.ok()) {
diff --git a/src/executor/GraphService.cpp b/src/executor/GraphService.cpp
index baef7b4f..935dddd2 100644
--- a/src/executor/GraphService.cpp
+++ b/src/executor/GraphService.cpp
@@ -14,13 +14,6 @@
 namespace nebula {
 namespace graph {
 
-GraphService::GraphService() {
-}
-
-
-GraphService::~GraphService() = default;
-
-
 Status GraphService::init(std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor) {
     sessionManager_ = std::make_unique<SessionManager>();
     executionEngine_ = std::make_unique<ExecutionEngine>();
diff --git a/src/executor/GraphService.h b/src/executor/GraphService.h
index 42632f46..804e49d2 100644
--- a/src/executor/GraphService.h
+++ b/src/executor/GraphService.h
@@ -9,9 +9,9 @@
 
 #include "base/Base.h"
 #include "gen-cpp2/GraphService.h"
-#include "graph/SessionManager.h"
-#include "graph/ExecutionEngine.h"
 #include "graph/Authenticator.h"
+#include "graph/ExecutionEngine.h"
+#include "graph/SessionManager.h"
 
 namespace folly {
 class IOThreadPoolExecutor;
@@ -22,8 +22,8 @@ namespace graph {
 
 class GraphService final : public cpp2::GraphServiceSvIf {
 public:
-    GraphService();
-    ~GraphService();
+    GraphService() = default;
+    ~GraphService() = default;
 
     Status MUST_USE_RESULT init(std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor);
 
@@ -44,6 +44,6 @@ private:
     std::unique_ptr<Authenticator>              authenticator_;
 };
 
-}  // namespace graph
-}  // namespace nebula
-#endif  // GRAPH_GRAPHSERVICE_H_
+}   // namespace graph
+}   // namespace nebula
+#endif   // GRAPH_GRAPHSERVICE_H_
-- 
GitLab