Skip to content

Commit

Permalink
Add ubuntu2004 and centos8 package and tar package (vesoft-inc#2339)
Browse files Browse the repository at this point in the history
* add ubuntu2004 and centos8

* modify name

* support pacakge to sh

Co-authored-by: dutor <440396+dutor@users.noreply.github.com>
  • Loading branch information
laura-ding and dutor authored Oct 16, 2020
1 parent d878eb4 commit 7789487
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ jobs:
os:
- ubuntu1604
- ubuntu1804
- ubuntu2004
- centos6
- centos7
- centos8
container:
image: vesoft/nebula-dev:${{ matrix.os }}
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
os:
- ubuntu1604
- ubuntu1804
- ubuntu2004
- centos6
- centos7
- centos8
container:
image: vesoft/nebula-dev:${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion cmake/CPackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro(package is_one)
set(CPACK_PACKAGE_CONTACT "Nebula Graph")
set(CPACK_PACKAGE_VERSION ${NEBULA_BUILD_VERSION})
set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0 + Common Clause 1.0")
set(CPACK_PACKAGE_NAME nebula-graph)
set(CPACK_PACKAGE_NAME nebula)
set(CPACK_PACKAGE_VENDOR "vesoft inc")
# set(CPACK_SET_DESTDIR TRUE)
set(CPACK_PACKAGE_RELOCATABLE ON)
Expand Down
131 changes: 104 additions & 27 deletions package/package.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# package nebula as one deb/rpm
# ./package.sh -v <version> -n <ON/OFF> -s <TRUE/FALSE> the version should be match tag name
# ./package.sh -v <version> -n <ON/OFF> -s <TRUE/FALSE> -t <auto/tar> the version should be match tag name
#

set -ex
Expand All @@ -14,8 +14,12 @@ PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"/../
enablesanitizer="OFF"
static_sanitizer="OFF"
buildtype="Release"
package_type="auto"
file_type=""
install_dir="/usr/local/nebula"
build_dir=$PROJECT_DIR/build

while getopts v:n:s:d: opt;
while getopts v:n:s:d:t: opt;
do
case $opt in
v)
Expand All @@ -34,6 +38,9 @@ do
fi
buildtype="RelWithDebInfo"
;;
t)
package_type=$OPTARG
;;
?)
echo "Invalid option, use default arguments"
;;
Expand All @@ -58,15 +65,20 @@ if [[ $strip_enable != TRUE ]] && [[ $strip_enable != FALSE ]]; then
exit -1
fi

echo "current version is [ $version ], strip enable is [$strip_enable], enablesanitizer is [$enablesanitizer], static_sanitizer is [$static_sanitizer]"
if [[ $package_type != "auto" ]] && [[ $package_type != "tar" ]]; then
echo "package type[$package_type] is wrong, exit"
echo ${usage}
exit -1
fi

echo "current version is [ $version ], strip enable is [$strip_enable], enablesanitizer is [$enablesanitizer], static_sanitizer is [$static_sanitizer], package type is [ $package_type ]"

# args: <version>
function build {
version=$1
san=$2
ssan=$3
build_type=$4
build_dir=$PROJECT_DIR/build
if [[ -d $build_dir ]]; then
rm -rf ${build_dir}/*
else
Expand All @@ -76,7 +88,7 @@ function build {
pushd ${build_dir}

cmake -DCMAKE_BUILD_TYPE=${build_type} -DNEBULA_BUILD_VERSION=${version} -DENABLE_ASAN=${san} --DENABLE_UBSAN=${san} \
-DENABLE_STATIC_ASAN=${ssan} -DENABLE_STATIC_UBSAN=${ssan} -DCMAKE_INSTALL_PREFIX=/usr/local/nebula -DENABLE_TESTING=OFF \
-DENABLE_STATIC_ASAN=${ssan} -DENABLE_STATIC_UBSAN=${ssan} -DCMAKE_INSTALL_PREFIX=${install_dir} -DENABLE_TESTING=OFF \
-DENABLE_PACK_ONE=${package_one} $PROJECT_DIR

if !( make -j$(nproc) ); then
Expand All @@ -87,43 +99,108 @@ function build {
popd
}


function get_package_name {
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`
if [[ ${sys_ver} == 7 ]] || [[ ${sys_ver} == 6 ]]; then
package_name=.el${sys_ver}-5.x86_64
else
package_name=.el${sys_ver}.x86_64
fi
elif [[ ${sys_name} == "Fedora" ]]; then
sys_ver=`cat /etc/redhat-release | cut -d ' ' -f3`
package_name=.fc${sys_ver}.x86_64
fi
file_type="RPM"
elif [[ -f "/etc/lsb-release" ]]; then
sys_name=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f 2 | sed 's/\.//'`
package_name=.ubuntu${sys_name}.amd64
file_type="DEB"
fi
}

# 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="

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 !( cpack -G ${pType} --verbose $args ); then
if !( cpack -G ${file_type} --verbose $args ); then
echo ">>> package nebula failed <<<"
exit -1
elif [[ "$tagetPackageName" != "" && $package_one == ON ]]; then
else
# rename package file
pkgName=`ls | grep nebula-graph | grep ${version}`
outputDir=$PROJECT_DIR/build/cpack_output
pkg_names=`ls | grep nebula | grep ${version}`
outputDir=$build_dir/cpack_output
mkdir -p ${outputDir}
mv ${pkgName} ${outputDir}/${tagetPackageName}
echo "####### taget package file is ${outputDir}/${tagetPackageName}"
for pkg_name in ${pkg_names[@]};
do
new_pkg_name=${pkg_name/\-Linux/${package_name}}
mv ${pkg_name} ${outputDir}/${new_pkg_name}
echo "####### taget package file is ${outputDir}/${new_pkg_name}"
done
fi

popd
}


function package_tar_sh {
exec_file=$build_dir/nebula-$version$package_name.sh

echo "Creating self-extractable package $exec_file"
cat > $exec_file <<EOF
#! /usr/bin/env bash
set -e
hash xz &> /dev/null || { echo "xz: Command not found"; exit 1; }
[[ \$# -ne 0 ]] && prefix=\$(echo "\$@" | sed 's;.*--prefix=(\S*).*;\1;p' -rn)
prefix=\${prefix:-/usr/local/nebula}
mkdir -p \$prefix
[[ -w \$prefix ]] || { echo "\$prefix: No permission to write"; exit 1; }
archive_offset=\$(awk '/^__start_of_archive__$/{print NR+1; exit 0;}' \$0)
tail -n+\$archive_offset \$0 | tar --no-same-owner --numeric-owner -xJf - -C \$prefix
daemons=(metad graphd storaged)
for daemon in \${daemons[@]}
do
if [[ ! -f \$prefix/etc/nebula-\$daemon.conf ]] && [[ -f \$prefix/etc/nebula-\$daemon.conf.default ]]; then
cp \$prefix/etc/nebula-\$daemon.conf.default \$prefix/etc/nebula-\$daemon.conf
chmod 644 \$prefix/etc/nebula-\$daemon.conf
fi
done
echo "Nebula Graph has been installed to \$prefix"
exit 0
__start_of_archive__
EOF
pushd $install_dir
tar -cJf - * >> $exec_file
chmod 0755 $exec_file
echo "####### taget package file is $exec_file"
popd
}

# The main
build $version $enablesanitizer $static_sanitizer $buildtype
package $strip_enable
get_package_name

if [[ $package_type == "auto" ]]; then
build $version $enablesanitizer $static_sanitizer $buildtype
package $strip_enable
else
install_dir=${build_dir}/install
build $version $enablesanitizer $static_sanitizer $buildtype
pushd ${build_dir}
make install -j$(nproc)
popd
package_tar_sh
fi

0 comments on commit 7789487

Please sign in to comment.