From 8cff283a1c0ec367c528156c1bf83c59a3befef4 Mon Sep 17 00:00:00 2001 From: skafandri Date: Thu, 7 Nov 2024 14:28:36 +0100 Subject: [PATCH 1/3] [CPCLOUD-4590] Build RPM package --- .github/workflows/test-and-deploy.yml | 65 ++++++++++++++------------- setup.py | 2 +- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index c9f3850..ff53b04 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -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 }} diff --git a/setup.py b/setup.py index e3e9b91..c90891d 100644 --- a/setup.py +++ b/setup.py @@ -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, From d529958bd3d0743cc34e1e3585e23c7eb4ab2265 Mon Sep 17 00:00:00 2001 From: skafandri Date: Thu, 7 Nov 2024 14:31:37 +0100 Subject: [PATCH 2/3] [CPCLOUD-4590] Build RPM package --- agent360.spec | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 agent360.spec diff --git a/agent360.spec b/agent360.spec new file mode 100644 index 0000000..b75c52d --- /dev/null +++ b/agent360.spec @@ -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) \ No newline at end of file From 1d85ff6dda666e94b9397cdcc3d71eb9af6dcb52 Mon Sep 17 00:00:00 2001 From: skafandri Date: Thu, 7 Nov 2024 14:35:15 +0100 Subject: [PATCH 3/3] [CPCLOUD-4590] Build RPM package --- .github/workflows/test-and-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index ff53b04..e87e8b3 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -61,16 +61,16 @@ jobs: - 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' + if: github.event_name == 'release' run: python setup.py bdist_rpm - name: Copy spec file - #if: github.event_name == 'release' + 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' + 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' + if: github.event_name == 'release' with: name: rpm package path: build/bdist.linux-x86_64/rpm/SRPMS/*.rpm