Skip to content

Commit

Permalink
Support to package (vesoft-inc#100)
Browse files Browse the repository at this point in the history
* Make CMakeLists modular

* Support package

* modify package.sh

* rebase upstream

* rebase upstream

* rebase upstream

* update

Co-authored-by: dutor <[email protected]>
  • Loading branch information
laura-ding and dutor authored Aug 17, 2020
1 parent ffe94df commit 0913c46
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 33 deletions.
35 changes: 11 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
136 changes: 136 additions & 0 deletions package/package.sh
Original file line number Diff line number Diff line change
@@ -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 <version> -n <ON/OFF> -s <TRUE/FALSE>
#

set -ex

version=""
package_one=ON
strip_enable="FALSE"
usage="Usage: ${0} -v <version> -n <ON/OFF> -s <TRUE/FALSE>"
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: <version>
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: <strip_enable>
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
11 changes: 11 additions & 0 deletions package/postinst
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions package/rpm_postinst
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
install(
FILES
gflags.json
PERMISSIONS
OWNER_WRITE OWNER_READ
GROUP_READ
WORLD_READ
DESTINATION
share/resources
)
3 changes: 0 additions & 3 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ install(
install(
FILES
nebula.service
services.sh
PERMISSIONS
OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
Expand All @@ -41,8 +40,6 @@ install(
install(
FILES
utils.sh
meta.hosts
storage.hosts
PERMISSIONS
OWNER_WRITE OWNER_READ
GROUP_READ
Expand Down
Empty file removed scripts/meta.hosts
Empty file.
7 changes: 2 additions & 5 deletions scripts/nebula.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function usage {
echo "Usage: ${USAGE_INFO}"
}

[[ -z ${USAGE_INFO} ]] && USAGE_INFO="${0} [-v] [-c /path/to/config] <start|stop|restart|status|kill> <metad|graphd|storaged|all>"
[[ -z ${USAGE_INFO} ]] && USAGE_INFO="${0} [-v] [-c /path/to/config] <start|stop|restart|status|kill> <metad|storaged|all>"

if [[ $# == 0 ]]; then
usage
Expand Down Expand Up @@ -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}'"
Expand Down
Empty file removed scripts/storage.hosts
Empty file.
2 changes: 1 addition & 1 deletion src/codec/test/RowWriterV2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 0913c46

Please sign in to comment.