Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPCLOUD-4590] Build RPM package #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,38 @@ jobs:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.python-version }}
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to Test PyPI
if: github.ref == 'refs/heads/master'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v2
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ env.python-version }}
- name: Install pypa/build
run: python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/
- name: Prepare RPM package
if: github.event_name == 'release'
run: python setup.py bdist_rpm
- name: Copy spec file
if: github.event_name == 'release'
run: cp agent360.spec build/bdist.linux-x86_64/rpm/SPECS/agent360.spec
- name: Build RPM package
if: github.event_name == 'release'
run: rpmbuild -ba --define "__python python3" --define "_topdir $PWD/build/bdist.linux-x86_64/rpm" --clean ./build/bdist.linux-x86_64/rpm/SPECS/agent360.spec
- uses: actions/upload-artifact@v4
if: github.event_name == 'release'
with:
name: rpm package
path: build/bdist.linux-x86_64/rpm/SRPMS/*.rpm
- name: Publish distribution 📦 to Test PyPI
if: github.ref == 'refs/heads/master'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
90 changes: 90 additions & 0 deletions agent360.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
%define name agent360
%define version 1.3.1
%define unmangled_version 1.3.1
%define release 1
%define VenvDir /opt/agent360-venv

Summary: 360monitoring agent
Name: %{name}
Version: %{version}
Release: %{release}
Source: %{name}-%{unmangled_version}.tar.gz
License: BSD-3-Clause
Group: Networking Tools
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
BuildArch: x86_64
Vendor: 360 monitoring <360support@webpros.com>
Url: https://github.com/plesk/agent360
Requires: epel-release,gcc,python-devel,python-pip,ntp,pyOpenSSL,python2-psutil,python-netifaces,python2-simplejson


%description
360monitoring Agent
==============

360monitoring is a web service of monitoring and displaying statistics of
your server performance.

This software is an OS-agnostic agent compatible with Python 3.7 and 3.8.
It's been optimized to have a small CPU consumption and comes with an
extendable set of useful plugins.


%pre
if [ ! -f /var/log/agent360.log ]; then
touch /var/log/agent360.log && chmod a+w /var/log/agent360.log
fi

%post
if [ "$(grep -c '^agent360:' /etc/passwd)" = "0" ]; then
echo "Creating user and group agent360"
groupadd -r agent360 && adduser -r -s "/sbin/nologin" -M -N -c "agent360 daemon" -g agent360 agent360
else
echo "User creation skipped, user is already present"
fi


if [ -f /usr/lib/systemd/system/agent360.service ]; then
echo "Enabling and starting agent360 service"
systemctl daemon-reload && systemctl enable agent360.service && systemctl start agent360.service
else
echo "Cannot start agent360 service, systemd script is not present"
fi

echo "For registering with agent360 servers, please run the following command as root with a valid agent360 USERID: \"agent360 hello USERID\" and restart the agent360 service"

%preun
if [ -f /usr/lib/systemd/system/agent360.service ]; then
systemctl stop agent360.service && systemctl disable agent360.service
fi

%postun
rm -Rf %{VenvDir}/bin/agent360 /usr/share/doc/agent360 /etc/systemd/system/multi-user.target.wants/agent360.service /var/log/agent360.log /etc/agent360-token.ini >/dev/null 2>&1
if [ "$(grep -c '^agent360:' /etc/passwd)" = "1" ]; then
echo "Removing user and group agent360"
userdel agent360
else
echo "User deletion skipped, agent360 user does not exist"
fi
systemctl daemon-reload

%prep
%setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version}

%build
python3 -m build --sdist --wheel --outdir dist/

%install
python3 -m venv %{VenvDir} && echo -e "\\e[32m [SUCCESS] Virtual environment has been created\\e[m"
. %{VenvDir}/bin/activate && echo -e "\\e[32m [SUCCESS] Virtual environment has been activated\\e[m"
# Install agent360 in virtual environment
pip3 install agent360 --upgrade && echo -e "\\e[32m [SUCCESS] Finished with agent360\\e[m"
deactivate
echo /. > INSTALLED_FILES

# Create a symlink for global access
ln -sf %{VenvDir}/bin/agent360 /usr/local/bin/agent360

%files -f INSTALLED_FILES
%defattr(-,root,root)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setuptools.setup(
name='agent360',
version='1.3.0',
version='1.3.1',
description='360 agent',
long_description_content_type='text/markdown',
long_description=readme,
Expand Down
Loading