diff --git a/.nxs-fw-settings/settings.json b/.nxs-fw-settings/settings.json index dfa2b49..d408c5e 100644 --- a/.nxs-fw-settings/settings.json +++ b/.nxs-fw-settings/settings.json @@ -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", diff --git a/README.md b/README.md index 36a1ec3..6535c2c 100644 --- a/README.md +++ b/README.md @@ -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 < /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 diff --git a/build-pkgs b/build-pkgs index 8337177..d76d743 100755 --- a/build-pkgs +++ b/build-pkgs @@ -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 @@ -21,9 +45,43 @@ 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() { @@ -31,56 +89,158 @@ 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 } @@ -88,11 +248,15 @@ 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" ) @@ -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 ;; *) diff --git a/build-pkgs-conf/docker/centos-7/Dockerfile b/build-pkgs-conf/docker/centos-7/Dockerfile new file mode 100644 index 0000000..c41b752 --- /dev/null +++ b/build-pkgs-conf/docker/centos-7/Dockerfile @@ -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 diff --git a/build-pkgs-conf/docker/centos-7/packages.nixys.ru.repo b/build-pkgs-conf/docker/centos-7/packages.nixys.ru.repo new file mode 100644 index 0000000..039be1a --- /dev/null +++ b/build-pkgs-conf/docker/centos-7/packages.nixys.ru.repo @@ -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 diff --git a/build-pkgs-conf/docker/debian-8/Dockerfile b/build-pkgs-conf/docker/debian-8/Dockerfile index c0850a7..7633f3f 100644 --- a/build-pkgs-conf/docker/debian-8/Dockerfile +++ b/build-pkgs-conf/docker/debian-8/Dockerfile @@ -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 diff --git a/build-pkgs-conf/docker/debian-9/Dockerfile b/build-pkgs-conf/docker/debian-9/Dockerfile index 5dcf9d6..27ed9f8 100644 --- a/build-pkgs-conf/docker/debian-9/Dockerfile +++ b/build-pkgs-conf/docker/debian-9/Dockerfile @@ -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 diff --git a/build-pkgs-conf/docker/rpm-build.sh b/build-pkgs-conf/docker/rpm-build.sh new file mode 100755 index 0000000..5b1be56 --- /dev/null +++ b/build-pkgs-conf/docker/rpm-build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +P_NAME=$1 +VER=$2 + +( + cd /tmp/build + + chown -R root: /tmp/build + + tar zcfv ${P_NAME}-${VER}.tar.gz ${P_NAME}-${VER} + + rpmbuild --define "_rpmdir /tmp/build/" --define "_srcrpmdir /tmp/build/" --define "_sourcedir /tmp/build/" --target=x86_64 -ba /tmp/build/${P_NAME}.spec + + cp /tmp/build/x86_64/* /tmp/build/ + + rm -rf /tmp/build/x86_64/ + + rm ${P_NAME}-${VER}.tar.gz +) diff --git a/build-pkgs-conf/tpls/centos-7/nxs-chat-srv.spec b/build-pkgs-conf/tpls/centos-7/nxs-chat-srv.spec new file mode 100644 index 0000000..3697cb6 --- /dev/null +++ b/build-pkgs-conf/tpls/centos-7/nxs-chat-srv.spec @@ -0,0 +1,71 @@ +Name: nxs-chat-srv +Version: $$VERSION$$ +Release: $$BUILD_VERSION$$%{?dist} +Summary: Nixys chat bot that integrates Telegram and Redmine + +Group: Applications/Communications +License: GPL3 +URL: https://nixys.ru +Source0: %{name}-%{version}.tar.gz + +BuildRequires: nxs-fw-libs-1.13 libhiredis-vip libhiredis-vip-devel redhat-lsb +Requires: libevent-nxs openssl-libs jansson libcurl mariadb-libs + + +%description + Nixys chat bot that integrates Telegram and Redmine + + +%prep +%setup -q + + +%post +ldconfig +%systemd_post nxs-chat-srv.service + + +%postun +%systemd_preun nxs-chat-srv.service +rm -rf /var/log/nxs-chat-srv/ +rm -rf /var/spool/nxs-chat-srv/ + + +%build +make + + +%install +mkdir -p $RPM_BUILD_ROOT/usr/sbin +mkdir -p $RPM_BUILD_ROOT/etc/nxs-chat-srv/ssl +mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d +mkdir -p $RPM_BUILD_ROOT/lib/systemd/system +mkdir -p $RPM_BUILD_ROOT/usr/share +mkdir -p $RPM_BUILD_ROOT/var/log/nxs-chat-srv +mkdir -p $RPM_BUILD_ROOT/var/spool/nxs-chat-srv/tlgrm +mkdir -p $RPM_BUILD_ROOT/var/spool/nxs-chat-srv/rdmn +cp ./objs/nxs-chat-srv $RPM_BUILD_ROOT/usr/sbin +cp -r ./pkg/etc/nxs-chat-srv $RPM_BUILD_ROOT/etc +cp ./pkg/etc/logrotate.d/nxs-chat-srv $RPM_BUILD_ROOT/etc/logrotate.d +cp ./pkg/lib/systemd/system/nxs-chat-srv.service $RPM_BUILD_ROOT/lib/systemd/system +cp -r ./pkg/usr/share/nxs-chat-srv $RPM_BUILD_ROOT/usr/share + + +%clean +rm -rf $RPM_BUILD_ROOT + + +%files +%defattr(-,root,root,-) +/usr/sbin/nxs-chat-srv +%dir %attr(0750, root, root) /etc/nxs-chat-srv +%dir %attr(0750, root, root) /etc/nxs-chat-srv/ssl +%attr(0640, root, root) /etc/nxs-chat-srv/nxs-chat-srv.conf +%dir %attr(0750, root, root) /var/log/nxs-chat-srv +%dir %attr(0750, root, root) /var/spool/nxs-chat-srv +/etc/logrotate.d/nxs-chat-srv +/lib/systemd/system/nxs-chat-srv.service +/usr/share/nxs-chat-srv + + +%changelog diff --git a/config.mk b/config.mk index 9485305..2c07e43 100644 --- a/config.mk +++ b/config.mk @@ -9,10 +9,10 @@ ifeq ($(shell getconf LONG_BIT),32) CFLAGS32 = -D_FILE_OFFSET_BITS=64 endif -OS_DISTRIB = $(shell lsb_release -d | awk '{print $$2}') +OS_DISTRIB = $(shell lsb_release -d | awk '{print $$2}' | tr '[:lower:]' '[:upper:]') OS_RELEASE = $(shell lsb_release -r | awk '{print $$2}' | cut -d '.' -f 1) -NXS_FW_VERSION = 1.12 +NXS_FW_VERSION = 1.13 NXS_FW_CORE_INCLUDES_PATH = /usr/include/nxs-fw-libs NXS_FW_CORE_LIBS_PATH = /usr/lib/nxs-fw-libs @@ -27,7 +27,7 @@ NXS_CORE_HEADERS = $(shell find $(NXS_FW_CORE_INCLUDES_PATH)/$(NXS_FW_VERSION NXS_CORE_LINKS = -L$(NXS_FW_CORE_LIBS_PATH)/$(NXS_FW_VERSION) -lnxs-general -lnxs-cfg-json -lnxs-json -lnxs-curl -lnxs-mysql -lnxs-rest-api NXS_INCLUDES = -I/usr/include/libevent-nxs $(NXS_DISTRIB_INCLUDES_$(OS_DISTRIB)_$(OS_RELEASE)) -NXS_LINKS = -ljansson -lcurl -L/usr/lib/x86_64-linux-gnu/libevent-nxs -levent -lssl -lcrypto -levent_openssl $(NXS_DISTRIB_LINKS_$(OS_DISTRIB)_$(OS_RELEASE)) +NXS_LINKS = -ljansson -lcurl $(NXS_DISTRIB_LINKS_$(OS_DISTRIB)_$(OS_RELEASE)) NXS_USER_INCLUDES = NXS_USER_LINKS = -l:libhiredis_vip.a diff --git a/distrib.mk b/distrib.mk index d342081..d368985 100644 --- a/distrib.mk +++ b/distrib.mk @@ -1,8 +1,15 @@ -NXS_DISTRIB_LINKS_Debian_7 = -L/usr/lib/mysql -lmysqlclient -NXS_DISTRIB_INCLUDES_Debian_7 = +NXS_DISTRIB_LINKS_DEBIAN_7 = -L/usr/lib/mysql -lmysqlclient -L/usr/lib/x86_64-linux-gnu/libevent-nxs -levent -lssl -lcrypto -levent_openssl +NXS_DISTRIB_INCLUDES_DEBIAN_7 = -NXS_DISTRIB_LINKS_Debian_8 = -L/usr/lib/mysql -lmysqlclient -NXS_DISTRIB_INCLUDES_Debian_8 = +NXS_DISTRIB_LINKS_DEBIAN_8 = -L/usr/lib/mysql -lmysqlclient -L/usr/lib/x86_64-linux-gnu/libevent-nxs -levent -lssl -lcrypto -levent_openssl +NXS_DISTRIB_INCLUDES_DEBIAN_8 = + +NXS_DISTRIB_LINKS_DEBIAN_9 = -lmariadbclient -L/usr/lib/x86_64-linux-gnu/libevent-nxs -levent -lssl -lcrypto -levent_openssl +NXS_DISTRIB_INCLUDES_DEBIAN_9 = + +NXS_DISTRIB_LINKS_CENTOS_6 = -L/usr/lib64/mysql -lmysqlclient -L/usr/lib64/libevent-nxs -levent -lssl -lcrypto -levent_openssl +NXS_DISTRIB_INCLUDES_CENTOS_6 = + +NXS_DISTRIB_LINKS_CENTOS_7 = -L/usr/lib64/mysql -lmysqlclient -L/usr/lib64/libevent-nxs -levent -lssl -lcrypto -levent_openssl +NXS_DISTRIB_INCLUDES_CENTOS_7 = -NXS_DISTRIB_LINKS_Debian_9 = -lmariadbclient -NXS_DISTRIB_INCLUDES_Debian_9 = diff --git a/docs/docker/Dockerfile b/docs/docker/Dockerfile new file mode 100644 index 0000000..dde4983 --- /dev/null +++ b/docs/docker/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:9 + +RUN apt-get update \ + && apt-get -y install 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 -y install nxs-chat-srv systemd + +COPY docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/sbin/nxs-chat-srv", "-c", "/etc/nxs-chat-srv/nxs-chat-srv.conf"] diff --git a/docs/docker/docker-entrypoint.sh b/docs/docker/docker-entrypoint.sh new file mode 100755 index 0000000..26069aa --- /dev/null +++ b/docs/docker/docker-entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +# usage: file_env VAR [DEFAULT] +# ie: file_env 'XYZ_DB_PASSWORD' 'example' +# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of +# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +file_env 'NXS_CHAT_SRV_INITIALIZE' + +if [ "$NXS_CHAT_SRV_INITIALIZE" ]; +then + + "$@" $NXS_CHAT_SRV_INITIALIZE +fi + +exec "$@" diff --git a/src/nxs-chat-srv-core.h b/src/nxs-chat-srv-core.h index 7639efe..b7f8e2a 100644 --- a/src/nxs-chat-srv-core.h +++ b/src/nxs-chat-srv-core.h @@ -7,7 +7,7 @@ #include /* Project version */ -#define NXS_CHAT_SRV_VERSION "0.2.0" +#define NXS_CHAT_SRV_VERSION "0.2.1" /* Project basic global definitions */