From 5263a9c4bb0370c3ccc1d182aedac3b7fd28e7c6 Mon Sep 17 00:00:00 2001 From: Evgeny Smyshlyaev Date: Tue, 26 Feb 2019 22:41:31 +0300 Subject: [PATCH] CI vs RPM build (#317) --- .gitignore | 2 +- .travis.yml | 10 +++- Makefile | 27 +++++++++ build/rpmbuild/Dockerfile | 11 ++++ build/rpmbuild/Makefile | 3 + build/rpmbuild/hastic-server.spec | 94 +++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 build/rpmbuild/Dockerfile create mode 100644 build/rpmbuild/Makefile create mode 100644 build/rpmbuild/hastic-server.spec diff --git a/.gitignore b/.gitignore index 8ad8a4c..b323ada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ data -dist +dist/**/*.rpm config.json .env diff --git a/.travis.yml b/.travis.yml index 62cb69a..c6c68fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ +services: + - docker + + matrix: include: - language: node_js @@ -20,5 +24,9 @@ matrix: apt-utils gnupg curl make g++ git script: - python -m unittest discover + +script: + - make + notifications: - email: false \ No newline at end of file + email: false diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ddcd377 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +.PHONY: rpm deb + +all: rpm deb + +rpm_node8: + docker run --rm -it -v `pwd`/server:/root/rpmbuild/server \ + -v `pwd`/analytics:/root/rpmbuild/analytics \ + -v `pwd`/.git:/root/rpmbuild/.git \ + -v `pwd`/build/rpmbuild:/root/rpmbuild/rpm \ + -v `pwd`/dist/RPMS_8:/root/rpmbuild/RPMS \ + -e "NODE_VERSION=v8.0.0" \ + -e "RPM_NODE_VERSION=8" \ + -e "HASTIC_RELEASE_VERSION=`cat server/package.json| jq -r .version | sed 's/-/_/g'`" \ + amper43/hastic-rpmbuilder rpmbuild -bb rpm/hastic-server.spec + +rpm_node6: + docker run --rm -v `pwd`/server:/root/rpmbuild/server \ + -v `pwd`/analytics:/root/rpmbuild/analytics \ + -v `pwd`/.git:/root/rpmbuild/.git \ + -v `pwd`/build/rpmbuild:/root/rpmbuild/rpm \ + -v `pwd`/dist/RPMS_6:/root/rpmbuild/RPMS \ + -e "NODE_VERSION=v6.14.0" \ + -e "RPM_NODE_VERSION=6" \ + -e "HASTIC_RELEASE_VERSION=`cat server/package.json| jq -r .version | sed 's/-/_/g'`" \ + amper43/hastic-rpmbuilder rpmbuild -bb rpm/hastic-server.spec + +rpm: rpm_node8 rpm_node6 diff --git a/build/rpmbuild/Dockerfile b/build/rpmbuild/Dockerfile new file mode 100644 index 0000000..24bf0da --- /dev/null +++ b/build/rpmbuild/Dockerfile @@ -0,0 +1,11 @@ +FROM rpmbuild/centos7 + +USER root + +WORKDIR /root/rpmbuild + +RUN yum -y install https://centos7.iuscommunity.org/ius-release.rpm epel-release +RUN yum -y install python36 python36-devel python36-setuptools gcc-c++ make \ + && easy_install-3.6 pip \ + && pip3.6 install -U pip setuptools pyinstaller \ + && curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash - diff --git a/build/rpmbuild/Makefile b/build/rpmbuild/Makefile new file mode 100644 index 0000000..0daa92c --- /dev/null +++ b/build/rpmbuild/Makefile @@ -0,0 +1,3 @@ +all: + docker build -t amper43/hastic-rpmbuilder . + docker push amper43/hastic-rpmbuilder diff --git a/build/rpmbuild/hastic-server.spec b/build/rpmbuild/hastic-server.spec new file mode 100644 index 0000000..3127bed --- /dev/null +++ b/build/rpmbuild/hastic-server.spec @@ -0,0 +1,94 @@ +%define name hastic-server +%define version %{getenv:HASTIC_RELEASE_VERSION}_node%{getenv:RPM_NODE_VERSION} +%define release 0 +%define buildroot /root/rpmbuild/BUILDROOT +%define builddir /root/rpmbuild/BUILD + +Name: %{name} +Version: %{version} +Release: %{release} +Summary: hastic-server + +Group: Installation Script +License: Apache-2.0 +URL: hastic.io +BuildRoot: %{buildroot} +AutoReqProv: no +AutoReq: no +BuildArch: noarch + +%description +REST server for managing data for analytics + +%prep +rm -rf %{builddir}/* +mkdir -p %{builddir} +mkdir -p %{builddir}/.git/refs/heads +cp -r %{builddir}/../.git/HEAD %{builddir}/.git +cp -r %{builddir}/../.git/refs/heads %{builddir}/.git/refs +cp -r %{builddir}/../server %{builddir}/ +cp -r %{builddir}/../analytics %{builddir}/ +set +x +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +nvm install %{getenv:NODE_VERSION} +set -x + +%build +pushd analytics +mkdir -p dist/server +touch dist/server/server + +save=$RPM_BUILD_ROOT +unset RPM_BUILD_ROOT + +pip3 install -U pip setuptools pyinstaller +pip3 install -r requirements.txt +pyinstaller -y --additional-hooks-dir=pyinstaller_hooks --paths=analytics/ bin/server + +export RPM_BUILD_ROOT=$save +popd + +pushd server +set +x +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +nvm use %{getenv:NODE_VERSION} +set -x +npm install +npm run build +popd + +%install +mkdir -p %{buildroot}/usr/lib/hastic-server/server/dist +mkdir -p %{buildroot}/usr/lib/hastic-server/.git/refs/heads +mkdir -p %{buildroot}/usr/lib/hastic-server/analytics/dist/server +cp -r server/dist %{buildroot}/usr/lib/hastic-server/server/ +cp -r .git/HEAD %{buildroot}/usr/lib/hastic-server/.git +cp -r .git/refs/heads %{buildroot}/usr/lib/hastic-server/.git/refs +cp -r analytics/dist/server %{buildroot}/usr/lib/hastic-server/analytics/dist/ + +%post +mkdir -p /etc/hastic-server/ +if [ ! -f /etc/hastic-server/config.json ]; then + echo '{}' > /etc/hastic-server/config.json +fi +ln -s /etc/hastic-server/config.json /usr/lib/hastic-server/config.json + +mkdir -p /var/hastic-server/ +ln -s /usr/lib/hastic-server/data /var/hastic-server/data + +echo 'node /usr/lib/hastic-server/server/dist/server' > /usr/bin/hastic-server +chmod +x /usr/bin/hastic-server + + +%clean +rm -rf %{buildroot} + +%files +%attr(755, root, root) /usr/lib/hastic-server/analytics/dist/server/server +%defattr(644, root, root, 755) +/usr/lib/hastic-server + +%preun +rm /usr/bin/hastic-server