Skip to content

Commit

Permalink
Migrated to nxs-fw-libs-1.13, Added CentsOS 7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
borisershov committed Mar 14, 2018
1 parent 770ddeb commit 0ccec83
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .nxs-fw-settings/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"project_name": "nxs-chat-srv",
"nxs_fw_version": "1.12",
"nxs_fw_version": "1.13",
"project_modules": [
"nxs-cfg-json",
"nxs-curl",
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,27 @@ Important: Bot will send notifications to Telegram account in the following case

### CentOS

Coming soon ...
* Add Nixys repository key:
```
rpm --import http://packages.nixys.ru/packages.nixys.ru.gpg.key
```

* Add the repository. Currently CentOS 7 is available:
```
cat <<EOF > /etc/yum.repos.d/packages.nixys.ru.repo
[packages.nixys.ru]
name=Nixys Packages for CentOS \$releasever - \$basearch
baseurl=http://packages.nixys.ru/centos/\$releasever/\$basearch
enabled=1
gpgcheck=1
gpgkey=http://packages.nixys.ru/packages.nixys.ru.gpg.key
EOF
```

* Install nxs-chat-srv package:
```
yum install nxs-chat-srv
```

### Other OS

Expand Down
253 changes: 212 additions & 41 deletions build-pkgs
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
#!/bin/bash

VER="0.2.0"
BUILD_DIR="/tmp/nxs-build"

P_NAME="nxs-chat-srv"

VER="0.2.1"
BUILD_VERSION="1"

RELEASE=""
command='build'
BUILD_TYPE="docker"
USE_CHOWN="false"
DEB_TAR_ORIG=""

USER=`whoami`

while getopts c:r: option
HELP_MSG="Simple script to make packages for different OS releases.\n\
\n\
Options:\n\
-r RELEASE : make build for specified OS release (e.g. debian:9, centos:7, etc). You may use 'all' to make builds for all releases.\n\
-c COMMAND : at this moment only 'build' command is available.\n\
-t BUILD_TYPE : specify how to make your build ('docker' or 'local'). 'local' build would be useful for CI/CD process.\n\
-C : if specified, chown command with sudo for output files will be used after build process is finished\n\
-d DEB_TAR_ORIG: use debian tar orig file to make package. It is useful if you make packages for debian:8 and debian:9 together.\n\
-h : show help message (this message).\n\
"

while getopts c:r:t:Cd:h option
do
case "${option}" in
r) RELEASE=${OPTARG};;
c) command=${OPTARG};;
t) BUILD_TYPE=${OPTARG};;
C) USE_CHOWN="true";;
d) DEB_TAR_ORIG=${OPTARG};;
h) echo -e ${HELP_MSG}; exit 0;;
esac
done

Expand All @@ -21,78 +45,218 @@ then
read RELEASE
fi

P_NAME="nxs-chat-srv"
if [ ! "${BUILD_TYPE}" == "docker" ] && [ ! "${BUILD_TYPE}" == "local" ];
then

USER=`whoami`
echo "Wrong build type. Only 'docker' or 'local' types are available."
exit 1
fi

function copy_source()
{
local dst_package_dir="$1"

# Coping source code into build environment
rsync -qr \
.nxs-fw-settings \
docs \
src \
Makefile \
config.mk \
distrib.mk \
LICENSE \
README.md \
${dst_package_dir}
}

function build_package_deb_local()
{
local build_path="$1"
local tpl_path="${build_path}/deb-tpl"

(
cd ${build_path}/${P_NAME}

dh_make -p ${P_NAME}_${VER} --copyright lgpl3 --single --templates ${tpl_path} --yes --createorig

dpkg-buildpackage
)
}

function build_package_deb()
{

r=$1

bv="deb${r}u${BUILD_VERSION}"

local deb_tar_orig_path="$2"

# Preparing docker image
sudo docker inspect nxs-build_${P_NAME}_debian:${r} > /dev/null 2>&1;
local dst_root_dir="${BUILD_DIR}/${P_NAME}/debian-${r}"
local dst_package_dir="${dst_root_dir}/${P_NAME}"
local dst_install_file="${dst_root_dir}/deb-tpl/${P_NAME}.install"
local dc_name="nxs-build_${P_NAME}_debian:${r}"

if [ $? -ne 0 ];
# Preparing docker image
if [ "${BUILD_TYPE}" == "docker" ];
then

sudo docker build -t nxs-build_${P_NAME}_debian:${r} build-pkgs-conf/docker/debian-${r} || exit 1
docker build -t ${dc_name} build-pkgs-conf/docker/debian-${r} || exit 1
fi

# Preparing build environment
sudo rm -rf /tmp/nxs-build/${P_NAME}/debian-${r} || exit 1
sudo mkdir -p /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME} || exit 1
sudo mkdir -p /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME}/objs || exit 1
sudo mkdir -p /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME}/pkg || exit 1

# Coping source code into build environment
sudo rsync -qr \
.nxs-fw-settings \
docs \
src \
Makefile \
config.mk \
distrib.mk \
LICENSE \
README.md \
/tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME}
rm -rf ${dst_root_dir} || exit 1
mkdir -p ${dst_package_dir} || exit 1

if [ -z "${deb_tar_orig_path}" ];
then

mkdir -p ${dst_package_dir}/objs || exit 1
mkdir -p ${dst_package_dir}/pkg || exit 1

copy_source ${dst_package_dir}
else

cp ${deb_tar_orig_path} ${dst_root_dir}
tar -xpJf ${deb_tar_orig_path} -C ${dst_package_dir}
fi

# Docker build script
sudo rsync build-pkgs-conf/docker/deb-build.sh /tmp/nxs-build/${P_NAME}/debian-${r}/ || exit 1
rsync build-pkgs-conf/docker/deb-build.sh "${dst_root_dir}" || exit 1

# Debian package template
sudo rsync -r build-pkgs-conf/tpls/debian-${r}/ /tmp/nxs-build/${P_NAME}/debian-${r}/deb-tpl || exit 1
sudo sed -i 's/\$\$BUILD_VERSION\$\$/'${bv}'/g' /tmp/nxs-build/${P_NAME}/debian-${r}/deb-tpl/changelog || exit 1
rsync -r build-pkgs-conf/tpls/debian-${r}/ ${dst_root_dir}/deb-tpl || exit 1
sed -i 's/\$\$BUILD_VERSION\$\$/'${bv}'/g' ${dst_root_dir}/deb-tpl/changelog || exit 1

# Debian package content
sudo rsync -r build-pkgs-conf/pkg/general/ /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME}/pkg
sudo rsync -r build-pkgs-conf/pkg/os/debian-${r}/ /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME}/pkg

# Docker build package
sudo docker run -it --rm -v "/tmp/nxs-build/${P_NAME}/debian-${r}:/tmp/build" -e "DEBEMAIL=$DEBEMAIL" -e "DEBFULLNAME=$DEBFULLNAME" nxs-build_${P_NAME}_debian:${r} /tmp/build/deb-build.sh ${P_NAME} ${VER} || exit 1
rsync -r build-pkgs-conf/pkg/general/ ${dst_package_dir}/pkg
rsync -r build-pkgs-conf/pkg/os/debian-${r}/ ${dst_package_dir}/pkg

if [ "${BUILD_TYPE}" == "docker" ];
then

# Docker build package
docker run -it --rm -v "${dst_root_dir}:/tmp/build" -e "DEBEMAIL=$DEBEMAIL" -e "DEBFULLNAME=$DEBFULLNAME" ${dc_name} /tmp/build/deb-build.sh ${P_NAME} ${VER} || exit 1
else

build_package_deb_local "${dst_root_dir}"
fi

# Change owner from root to current user
if [ "${USE_CHOWN}" == "true" ];
then

sudo chown -R ${USER} ${dst_root_dir}
fi

# Remove junk
sudo rm -rf /tmp/nxs-build/${P_NAME}/debian-${r}/${P_NAME} 2>/dev/null
sudo rm -rf /tmp/nxs-build/${P_NAME}/debian-${r}/deb-tpl 2>/dev/null
sudo rm -rf /tmp/nxs-build/${P_NAME}/debian-${r}/deb-build.sh 2>/dev/null
rm -rf ${dst_package_dir} 2>/dev/null
rm -rf ${dst_root_dir}/deb-tpl 2>/dev/null
rm -rf ${dst_root_dir}/deb-build.sh 2>/dev/null

# Change owner from root to current user
sudo chown -R ${USER} /tmp/nxs-build/${P_NAME}/debian-${r}
return 0
}

function build_package_centos_local()
{
local build_path="$1"

(
cd "${build_path}"

tar zcfv ${P_NAME}-${VER}.tar.gz ${P_NAME}-${VER}

rpmbuild --define "_rpmdir ${build_path}" --define "_srcrpmdir ${build_path}" --define "_sourcedir ${build_path}" --target=x86_64 -ba "${build_path}/${P_NAME}.spec"

cp ${build_path}/x86_64/* ${build_path}/

rm -rf ${build_path}/x86_64/

rm ${P_NAME}-${VER}.tar.gz
)
}

function build_package_centos()
{

r=$1

local headers=""
local headers_dir=""
local static_libs=""
local desc=""
local files=""

local dst_root_dir="${BUILD_DIR}/${P_NAME}/centos-${r}"
local dst_package_dir="${dst_root_dir}/${P_NAME}-${VER}"
local dst_spec_file="${dst_root_dir}/${P_NAME}.spec"
local dc_name="nxs-build_${P_NAME}_centos:${r}"

# Preparing docker image
if [ "${BUILD_TYPE}" == "docker" ];
then

docker build -t ${dc_name} build-pkgs-conf/docker/centos-${r} || exit 1
fi

# Preparing build environment
rm -rf "${dst_root_dir}" || exit 1
mkdir -p "${dst_package_dir}" || exit 1
mkdir -p "${dst_package_dir}/objs" || exit 1
mkdir -p "${dst_package_dir}/pkg" || exit 1

copy_source ${dst_package_dir}

# Docker build script
cp build-pkgs-conf/docker/rpm-build.sh "${dst_root_dir}" || exit 1

# Centos spec file
cp build-pkgs-conf/tpls/centos-${r}/${P_NAME}.spec ${dst_spec_file} || exit 1
sed -i 's/\$\$BUILD_VERSION\$\$/'${BUILD_VERSION}'/g' ${dst_spec_file} || exit 1
sed -i 's/\$\$VERSION\$\$/'${VER}'/g' ${dst_spec_file} || exit 1

# Centos package content
rsync -r build-pkgs-conf/pkg/general/ ${dst_package_dir}/pkg
rsync -r build-pkgs-conf/pkg/os/centos-${r}/ ${dst_package_dir}/pkg

if [ "${BUILD_TYPE}" == "docker" ];
then

# Docker build package
docker run -it --rm -v "${dst_root_dir}:/tmp/build" ${dc_name} /tmp/build/rpm-build.sh ${P_NAME} ${VER} || exit 1
else

build_package_centos_local "${dst_root_dir}"
fi

# Change owner from root to current user
if [ "${USE_CHOWN}" == "true" ];
then

sudo chown -R ${USER} "${dst_root_dir}"
fi

# Remove junk
rm -rf "${dst_package_dir}" 2>/dev/null
rm -rf "${dst_spec_file}" 2>/dev/null
rm -rf "${dst_root_dir}/rpm-build.sh" 2>/dev/null

return 0
}

function build_package()
{
case ${RELEASE} in
"debian:8" )
build_package_deb 8
build_package_deb 8 "${DEB_TAR_ORIG}"
;;

"debian:9" )
build_package_deb 9
build_package_deb 9 "${DEB_TAR_ORIG}"
;;

"centos:7" )
build_package_centos 7
;;

"all" )
Expand All @@ -103,12 +267,19 @@ function build_package()
exit 1
fi

build_package_deb 9
build_package_deb 9 "${BUILD_DIR}/${P_NAME}/debian-8/${P_NAME}_${VER}.orig.tar.xz"
if [ $? -ne 0 ];
then
echo "can't build package: debian:9"
exit 1
fi

build_package_centos 7
if [ $? -ne 0 ];
then
echo "can't build package: centos:7"
exit 1
fi
;;

*)
Expand Down
6 changes: 6 additions & 0 deletions build-pkgs-conf/docker/centos-7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM centos:7

ADD packages.nixys.ru.repo /etc/yum.repos.d/packages.nixys.ru.repo
RUN rpm --import http://packages.nixys.ru/packages.nixys.ru.gpg.key && \
yum install -y nxs-fw-libs-1.13 libhiredis-vip libhiredis-vip-devel redhat-lsb
RUN rpmdev-setuptree
6 changes: 6 additions & 0 deletions build-pkgs-conf/docker/centos-7/packages.nixys.ru.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[packages.nixys.ru]
name=Nixys Packages for CentOS $releasever - $basearch
baseurl=http://packages.nixys.ru/centos/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=http://packages.nixys.ru/packages.nixys.ru.gpg.key
8 changes: 3 additions & 5 deletions build-pkgs-conf/docker/debian-8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM debian:8

RUN apt-key adv --fetch-keys http://packages.nixys.ru/packages.nixys.ru.gpg.key

RUN echo "deb [arch=amd64] http://packages.nixys.ru/debian/ jessie main" > /etc/apt/sources.list.d/packages.nixys.ru.list

RUN apt-get update; apt-get install -y nxs-fw-libs-1.12 libhiredis-vip libhiredis-vip-dev
RUN apt-key adv --fetch-keys http://packages.nixys.ru/packages.nixys.ru.gpg.key && \
echo "deb [arch=amd64] http://packages.nixys.ru/debian/ jessie main" > /etc/apt/sources.list.d/packages.nixys.ru.list && \
apt-get update; apt-get install -y nxs-fw-libs-1.13 libhiredis-vip libhiredis-vip-dev
11 changes: 4 additions & 7 deletions build-pkgs-conf/docker/debian-9/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM debian:9

RUN apt-get update; apt-get install -y gnupg

RUN apt-key adv --fetch-keys http://packages.nixys.ru/packages.nixys.ru.gpg.key

RUN echo "deb [arch=amd64] http://packages.nixys.ru/debian/ stretch main" > /etc/apt/sources.list.d/packages.nixys.ru.list

RUN apt-get update; apt-get install -y nxs-fw-libs-1.12 libhiredis-vip libhiredis-vip-dev
RUN apt-get update; apt-get install -y gnupg && \
apt-key adv --fetch-keys http://packages.nixys.ru/packages.nixys.ru.gpg.key && \
echo "deb [arch=amd64] http://packages.nixys.ru/debian/ stretch main" > /etc/apt/sources.list.d/packages.nixys.ru.list && \
apt-get update; apt-get install -y nxs-fw-libs-1.13 libhiredis-vip libhiredis-vip-dev
Loading

0 comments on commit 0ccec83

Please sign in to comment.