From 0913c468df9631570b25921ef2755aa7af5619f3 Mon Sep 17 00:00:00 2001 From: laura-ding <48548375+laura-ding@users.noreply.github.com> Date: Mon, 17 Aug 2020 15:18:36 +0800 Subject: [PATCH] Support to package (#100) * Make CMakeLists modular * Support package * modify package.sh * rebase upstream * rebase upstream * rebase upstream * update Co-authored-by: dutor <440396+dutor@users.noreply.github.com> --- CMakeLists.txt | 35 +++----- package/package.sh | 136 +++++++++++++++++++++++++++++ package/postinst | 11 +++ package/rpm_postinst | 10 +++ resources/CMakeLists.txt | 10 +++ scripts/CMakeLists.txt | 3 - scripts/meta.hosts | 0 scripts/nebula.service | 7 +- scripts/storage.hosts | 0 src/codec/test/RowWriterV2Test.cpp | 2 +- 10 files changed, 181 insertions(+), 33 deletions(-) create mode 100755 package/package.sh create mode 100755 package/postinst create mode 100755 package/rpm_postinst create mode 100644 resources/CMakeLists.txt delete mode 100644 scripts/meta.hosts delete mode 100644 scripts/storage.hosts diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f74fde87..e51a53966 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,13 +21,18 @@ # ENABLE_JEMALLOC -- Link jemalloc into all executables # ENABLE_NATIVE -- Build native client # ENABLE_TESTING -- Build unit test +# ENABLE_PACK_ONE -- Package to one or multi packages # cmake_minimum_required(VERSION 3.5.0) project("Nebula Storage" C CXX) +option(ENABLE_PACK_ONE "Whether to package into one" ON) option(ENABLE_MODULE_UPDATE "Automatically update module" OFF) +message(STATUS "ENABLE_PACK_ONE : ${ENABLE_PACK_ONE}") +message(STATUS "ENABLE_MODULE_UPDATE : ${ENABLE_MODULE_UPDATE}") + if (ENABLE_NATIVE) message(STATUS "ENABLE_NATIVE is ${ENABLE_NATIVE}") add_compile_options(-fPIC) @@ -106,6 +111,7 @@ include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR}/src/kvstore/plugins/hbase) nebula_add_subdirectory(src) nebula_add_subdirectory(conf) nebula_add_subdirectory(scripts) +nebula_add_subdirectory(resources) add_custom_target( clean-modules @@ -137,27 +143,8 @@ add_custom_target( DEPENDS clean-all ) -# package nebula to a deb/rpm file -set(CPACK_PACKAGE_DESCRIPTION "nebula-storage") -set(CPACK_PACKAGE_CONTACT "nebula-storage") -set(CPACK_PACKAGE_VERSION ${NEBULA_BUILD_VERSION}) -set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0 + Common Clause 1.0") -set(CPACK_PACKAGE_NAME nebula-storage) -set(CPACK_SET_DESTDIR TRUE) -set(CPACK_PACKAGE_RELOCATABLE FALSE) -set(CPACK_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) - -set(CPACK_DEB_COMPONENT_INSTALL ON) -set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/vesoft-inc/nebula/releases") -set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_SOURCE_DIR}/package/postinst) - -set(CPACK_RPM_SPEC_MORE_DEFINE "%define debug_package %{nil} - %define __os_install_post %{nil}") -set(CPACK_RPM_COMPONENT_INSTALL ON) -set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") -set(CPACK_RPM_PACKAGE_URL "https://github.com/vesoft-inc/nebula/releases") -set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/package/postinst) -set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/local) - -include(CPack) +include(CPackage) +package(${ENABLE_PACK_ONE} + "nebula-storage" + "https://github.com/vesoft-inc/nebula-storage/releases" + ${CMAKE_SOURCE_DIR}/package) diff --git a/package/package.sh b/package/package.sh new file mode 100755 index 000000000..fa92c632d --- /dev/null +++ b/package/package.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +# +# Package nebula as deb/rpm package +# +# introduce the args +# -v: The version of package, the version should be match tag name, default value is the `commitId` +# -n: Package to one or multi packages, `ON` means one package, `OFF` means multi packages, default value is `ON` +# -s: Whether to strip the package, default value is `FALSE` +# +# usage: ./package.sh -v -n -s +# + +set -ex + +version="" +package_one=ON +strip_enable="FALSE" +usage="Usage: ${0} -v -n -s " +PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"/../ +enablesanitizer="OFF" +build_type="Release" + +while getopts v:n:s:d opt; +do + case $opt in + v) + version=$OPTARG + ;; + n) + package_one=$OPTARG + ;; + s) + strip_enable=$OPTARG + ;; + d) + enablesanitizer="ON" + build_type="RelWithDebInfo" + ;; + ?) + echo "Invalid option, use default arguments" + ;; + esac +done + +# version is null, get from tag name +[[ -z $version ]] && version=`git describe --exact-match --abbrev=0 --tags | sed 's/^v//'` +# version is null, use UTC date as version +[[ -z $version ]] && version=$(date -u +%Y.%m.%d)-nightly + +if [[ -z $version ]]; then + echo "version is null, 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 ], strip enable is [$strip_enable], enablesanitizer is [$enablesanitizer]" + +# args: +function build { + version=$1 + san=$2 + build_type=$3 + build_dir=$PROJECT_DIR/build + if [[ -d $build_dir ]]; then + rm -rf ${build_dir}/* + else + mkdir ${build_dir} + fi + + pushd ${build_dir} + + cmake -DCMAKE_BUILD_TYPE=${build_type} -DNEBULA_BUILD_VERSION=${version} -DENABLE_ASAN=${san} --DENABLE_UBSAN=${san} -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF -DENABLE_PACK_ONE=${package_one} $PROJECT_DIR + + if !( make -j$(nproc) ); then + echo ">>> build nebula failed <<<" + exit -1 + fi + + popd +} + +# args: +function package { + strip_enable=$1 + pushd $PROJECT_DIR/build/ + args="" + [[ $strip_enable == TRUE ]] && args="-D CPACK_STRIP_FILES=TRUE -D CPACK_RPM_SPEC_MORE_DEFINE=" + + sys_ver="" + pType="RPM" + if [[ -f "/etc/redhat-release" ]]; then + sys_name=`cat /etc/redhat-release | cut -d ' ' -f1` + if [[ ${sys_name} == "CentOS" ]]; then + sys_ver=`cat /etc/redhat-release | tr -dc '0-9.' | cut -d \. -f1` + sys_ver=.el${sys_ver}.x86 + elif [[ ${sys_name} == "Fedora" ]]; then + sys_ver=`cat /etc/redhat-release | cut -d ' ' -f3` + sys_ver=.fc${sys_ver}.x86 + fi + pType="RPM" + elif [[ -f "/etc/lsb-release" ]]; then + sys_ver=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f 2 | sed 's/\.//'` + sys_ver=.ubuntu${sys_ver}.amd64 + pType="DEB" + fi + + if !( cpack -G ${pType} --verbose $args ); then + echo ">>> package nebula failed <<<" + exit -1 + else + # rename package file + pkg_names=`ls | grep nebula | grep ${version}` + outputDir=$PROJECT_DIR/build/cpack_output + mkdir -p ${outputDir} + for pkg_name in ${pkg_names[@]}; + do + new_pkg_name=${pkg_name/\-Linux/${sys_ver}} + mv ${pkg_name} ${outputDir}/${new_pkg_name} + echo "####### taget package file is ${outputDir}/${new_pkg_name}" + done + fi + + popd +} + + +# The main +build $version $enablesanitizer $build_type +package $strip_enable diff --git a/package/postinst b/package/postinst new file mode 100755 index 000000000..e1f191c18 --- /dev/null +++ b/package/postinst @@ -0,0 +1,11 @@ +#!/bin/bash + +install_dir=/usr/local/nebula +daemons=(metad storaged) +for daemon in ${daemons[@]} +do + if [[ ! -f ${install_dir}/etc/nebula-${daemon}.conf ]] && [[ -f ${install_dir}/etc/nebula-${daemon}.conf.default ]]; then + cp ${install_dir}/etc/nebula-${daemon}.conf.default ${install_dir}/etc/nebula-${daemon}.conf + fi +done + diff --git a/package/rpm_postinst b/package/rpm_postinst new file mode 100755 index 000000000..684ec3ab4 --- /dev/null +++ b/package/rpm_postinst @@ -0,0 +1,10 @@ +#!/bin/bash + +daemons=(metad storaged) +for daemon in ${daemons[@]} +do + if [[ ! -f $RPM_INSTALL_PREFIX/etc/nebula-${daemon}.conf ]] && [[ -f $RPM_INSTALL_PREFIX/etc/nebula-${daemon}.conf.default ]]; then + cp $RPM_INSTALL_PREFIX/etc/nebula-${daemon}.conf.default $RPM_INSTALL_PREFIX/etc/nebula-${daemon}.conf + fi +done + diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt new file mode 100644 index 000000000..8113a413b --- /dev/null +++ b/resources/CMakeLists.txt @@ -0,0 +1,10 @@ +install( + FILES + gflags.json + PERMISSIONS + OWNER_WRITE OWNER_READ + GROUP_READ + WORLD_READ + DESTINATION + share/resources +) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 5f5e47c80..4a2336c7c 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -27,7 +27,6 @@ install( install( FILES nebula.service - services.sh PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ @@ -41,8 +40,6 @@ install( install( FILES utils.sh - meta.hosts - storage.hosts PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ diff --git a/scripts/meta.hosts b/scripts/meta.hosts deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/nebula.service b/scripts/nebula.service index eef028a9e..55598e898 100755 --- a/scripts/nebula.service +++ b/scripts/nebula.service @@ -4,7 +4,7 @@ function usage { echo "Usage: ${USAGE_INFO}" } -[[ -z ${USAGE_INFO} ]] && USAGE_INFO="${0} [-v] [-c /path/to/config] " +[[ -z ${USAGE_INFO} ]] && USAGE_INFO="${0} [-v] [-c /path/to/config] " if [[ $# == 0 ]]; then usage @@ -82,14 +82,11 @@ case ${TARGET} in metad) TARGETS=(${TARGET}) ;; - graphd) - TARGETS=(${TARGET}) - ;; storaged) TARGETS=(${TARGET}) ;; all) - TARGETS=(metad graphd storaged) + TARGETS=(metad storaged) ;; *) ERROR "Unknown daemon \`${DAEMON}'" diff --git a/scripts/storage.hosts b/scripts/storage.hosts deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/codec/test/RowWriterV2Test.cpp b/src/codec/test/RowWriterV2Test.cpp index 0547c934b..9bfbeed9f 100644 --- a/src/codec/test/RowWriterV2Test.cpp +++ b/src/codec/test/RowWriterV2Test.cpp @@ -22,7 +22,7 @@ const Timestamp now = 1582183355; // Convert timestamp now to datetime string const std::string nowStr = "2020-02-20 15:22:35"; // NOLINT const Date date = {2020, 2, 20}; -const DateTime dt = {2020, 2, 20, 10, 30, 45, -8 * 3600, 0}; +const DateTime dt = {2020, 2, 20, 10, 30, 45, 0, -8 * 3600}; const Value sVal("Hello world!"); const Value iVal(64);