From a079d72defdf5500dc8c4c70a3f4eb22494fd38f Mon Sep 17 00:00:00 2001 From: Marcus Furlong Date: Sun, 22 Dec 2024 16:31:55 -0500 Subject: [PATCH] update github workflows --- .../create-release-and-upload-assets.yml | 49 ++++++++++++------- .github/workflows/lint.yml | 6 +-- MANIFEST.in | 6 ++- debian/control | 8 +-- debian/python3-openvpn-monitor.postinst | 20 ++++++-- debian/python3-openvpn-monitor.prerm | 4 +- etc/openvpn-monitor/apache.conf.example | 2 +- rpm/rpm-post-install.sh | 14 +++--- setup.py | 12 +++-- 9 files changed, 78 insertions(+), 43 deletions(-) diff --git a/.github/workflows/create-release-and-upload-assets.yml b/.github/workflows/create-release-and-upload-assets.yml index 1aeba0f..e96e298 100644 --- a/.github/workflows/create-release-and-upload-assets.yml +++ b/.github/workflows/create-release-and-upload-assets.yml @@ -46,7 +46,7 @@ jobs: run: | apt update export DEBIAN_FRONTEND=noninteractive - apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage + apt -y install python3-setuptools debhelper dh-exec dh-python git-buildpackage yarnpkg - name: Fix sh so env vars propogate run: | rm /bin/sh @@ -54,14 +54,14 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - ref: master + ref: main - name: git fetch --all run: | git config --global --add safe.directory /__w/openvpn-monitor/openvpn-monitor git fetch --all - name: Get version run: | - export version=$(echo "${{ github.ref }}" | cut -dv -f2) + export version=$(echo "${{ github.ref }}" | cut -d/ -f3) echo "version=${version}" >> $GITHUB_ENV - name: Download upload_url artifact uses: actions/download-artifact@v4 @@ -73,21 +73,25 @@ jobs: export upload_url=$(> $GITHUB_ENV - - name: Build deb packages + - name: Build deb package env: EMAIL: furlongm@gmail.com COMMIT_MSG: | auto-commit skip-checks: true run: | - export version=$(echo "${{ github.ref }}" | cut -dv -f2) + export version=$(echo "${{ github.ref }}" | cut -d/ -f3) echo "${version}" > VERSION.txt git add VERSION.txt + yarnpkg --prod --modules-folder openvpn_monitor/static/dist install + find openvpn_monitor/static > debian/source/include-binaries + rm yarn.lock + git add debian/source/include-binaries openvpn_monitor/static/dist git diff --quiet && git diff --staged --quiet || git commit -m "${COMMIT_MSG}" - gbp dch --new-version=${version}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}" - git tag --delete v${version} - git tag v${version} - gbp buildpackage --git-upstream-tree=${{ github.ref }} -uc -us + gbp dch --ignore-branch --new-version=${version}-1 --release --distribution=stable --spawn-editor=never --commit --commit-msg="${COMMIT_MSG}" + git tag --delete ${version} + git tag ${version} + gbp buildpackage --git-ignore-branch --git-upstream-tree=${{ github.ref }} -uc -us - name: Get version run: echo "version=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: Upload deb @@ -97,7 +101,7 @@ jobs: with: upload_url: ${{ env.upload_url }} asset_name: ${{ format('python3-openvpn-monitor_{0}-1_all.deb', env.version) }} - asset_path: ${{ format('deb_dist/python3-openvpn-monitor_{0}-1_all.deb', env.version) }} + asset_path: ${{ format('../python3-openvpn-monitor_{0}-1_all.deb', env.version) }} asset_content_type: application/vnd.debian.binary-package build-and-upload-rpm-asset: needs: create-release @@ -107,7 +111,9 @@ jobs: steps: - name: Install build dependencies run: | - dnf -y install rpm-build python3 python3-setuptools git + dnf -y install epel-release + dnf makecache + dnf -y install rpm-build python3 python3-setuptools git yarnpkg - uses: actions/checkout@v4 - name: Download upload_url artifact uses: actions/download-artifact@v4 @@ -118,8 +124,9 @@ jobs: export upload_url=$(cat upload_url.txt) rm upload_url.txt echo "upload_url=${upload_url}" >> $GITHUB_ENV - - name: Build rpm packages + - name: Build rpm package run: | + yarnpkg --prod --modules-folder openvpn_monitor/static/dist install| sed -i -e "s/name='.*/name='python3-openvpn-monitor',/" setup.py python3 setup.py bdist_rpm - name: Get version @@ -136,6 +143,11 @@ jobs: upload-package-to-pypi: needs: create-release runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/openvpn-monitor + permissions: + id-token: write steps: - uses: actions/checkout@v4 - name: Set up python @@ -144,9 +156,12 @@ jobs: python-version: '3.x' - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish + sudo apt -y install yarnpkg + python3 -m pip install --upgrade pip + pip3 install setuptools wheel + - name: Build dists run: | - python setup.py sdist bdist_wheel - twine upload dist/* + yarnpkg --prod --modules-folder openvpn_monitor/static/dist install + python3 setup.py sdist bdist_wheel + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 40095bd..8f749e8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,11 +17,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -r requirements.txt + python3 -m pip install --upgrade pip + pip3 install -r requirements.txt - name: Lint with flake8 run: | - pip install flake8 + pip3 install flake8 # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide diff --git a/MANIFEST.in b/MANIFEST.in index 2055f9e..4816035 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,11 @@ include README.md -recursive-include openvpn_monitor *.py -include openvpn-monitor.conf.example include AUTHORS include COPYING include MANIFEST.in include VERSION.txt include requirements.txt +recursive-include openvpn_monitor *.py recursive-include openvpn_monitor/static/images * +recursive-include openvpn_monitor/templates * +include etc/openvpn-monitor/openvpn-monitor.conf.example +include etc/openvpn-monitor/apache.conf.example diff --git a/debian/control b/debian/control index 1c3e43c..73e49ea 100644 --- a/debian/control +++ b/debian/control @@ -3,18 +3,18 @@ Section: python Priority: optional Maintainer: Marcus Furlong Uploaders: Marcus Furlong -Build-Depends: debhelper (>=10-.0.0), python (>=3), dh-python +Build-Depends: debhelper (>=10.0.0), python3 (>=3.11.0), dh-python Standards-Version: 3.9.7 Homepage: https://github.com/furlongm/openvpn-monitor Vcs-Git: git://github.com/furlongm/openvpn-monitor Vcs-Browser: https://github.com/furlongm/openvpn-monitor -X-Python-Version: >= 3 +X-Python-Version: >= 3.11.0 Package: python3-openvpn-monitor Architecture: all Homepage: https://github.com/furlongm/openvpn-monitor -Depends: ${misc:Depends}, python3, apache2, libapache2-mod-wsgi, - python3-geoip2, python3-humanize, python3-flask, python3-flaskext.wtf +Depends: ${misc:Depends}, python3, apache2, libapache2-mod-wsgi-py3, + python3-geoip2, python3-humanize, python3-flask, python3-flaskext.wtf, python3-semver Description: openvpn-monitor is a web based OpenVPN monitor, that shows current connection information, such as users, location and data transferred. diff --git a/debian/python3-openvpn-monitor.postinst b/debian/python3-openvpn-monitor.postinst index e5cd634..4f3c608 100644 --- a/debian/python3-openvpn-monitor.postinst +++ b/debian/python3-openvpn-monitor.postinst @@ -1,10 +1,22 @@ -#!/bin/sh -e +#!/bin/bash -e #DEBHELPER# -if [ "$1" = "configure" ] ; then +apache_conf_file=/etc/apache2/conf-available/openvpn-monitor.conf - echo 'WSGIScriptAlias /openvpn-monitor /usr/lib/python3/dist-packages/openvpn_monitor/app.py' > /etc/apache2/conf-available/python3-openvpn-monitor.conf +if [ ! -e ${apache_conf_file} ] ; then + cp /etc/openvpn-monitor/apache.conf.example ${apache_conf_file} +fi + +site_packages=$(python3 -c 'import site; print(site.getsitepackages()[-1])') +site_packages="${site_packages//\//\\\/}" +if ! grep ${site_packages} ${apache_conf_file} >/dev/null 2>&1 ; then + sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}/" ${apache_conf_file} . /usr/share/apache2/apache2-maintscript-helper - apache2_invoke enconf python2-openvpn-monitor.conf + apache2_invoke enconf openvpn-monitor.conf fi + +systemctl enable apache2 +systemctl restart apache2 + +chown :www-data /etc/openvpn-monitor/openvpn-monitor.conf.example diff --git a/debian/python3-openvpn-monitor.prerm b/debian/python3-openvpn-monitor.prerm index 9abb37d..6f37032 100644 --- a/debian/python3-openvpn-monitor.prerm +++ b/debian/python3-openvpn-monitor.prerm @@ -1,9 +1,11 @@ #!/bin/sh -e +apache_conf_file=/etc/apache2/conf-available/openvpn-monitor.conf + if [ "$1" = "remove" ] ; then - rm /etc/apache2/conf-available/openvpn-monitor.conf . /usr/share/apache2/apache2-maintscript-helper apache2_invoke disconf openvpn-monitor.conf + rm ${apache_conf_file} fi if [ "$1" = "purge" ] ; then diff --git a/etc/openvpn-monitor/apache.conf.example b/etc/openvpn-monitor/apache.conf.example index 80e9b47..61e58ee 100644 --- a/etc/openvpn-monitor/apache.conf.example +++ b/etc/openvpn-monitor/apache.conf.example @@ -1,5 +1,5 @@ Define openvpn_monitor_pythonpath /srv/openvpn-monitor/ -WSGIScriptAlias /openvpn-monitor ${openvpn_monitor_pythonpath}/openvpn-monitor/app.py +WSGIScriptAlias /openvpn-monitor ${openvpn_monitor_pythonpath}/openvpn_monitor/app.py WSGIPythonPath ${openvpn_monitor_pythonpath} diff --git a/rpm/rpm-post-install.sh b/rpm/rpm-post-install.sh index 42655db..57de213 100755 --- a/rpm/rpm-post-install.sh +++ b/rpm/rpm-post-install.sh @@ -1,19 +1,21 @@ #!/bin/sh -if [ ! -e /etc/httpd/conf.d/openvpn-monitor.conf ] ; then - cp /etc/openvpn-monitor/apache.conf.example /etc/httpd/conf.d/openvpn-monitor.conf +apache_conf_file=/etc/httpd/conf.d/openvpn-monitor.conf + +if [ ! -e ${apache_conf_file} ] ; then + cp /etc/openvpn-monitor/apache.conf.example ${apache_conf_file} fi site_packages=$(python3 -c 'import site; print(site.getsitepackages()[-1])') -if ! grep ${site-packages} /etc/httpd/conf.d/openvpn-monitor.conf >/dev/null 2>&1 ; then - sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}" \ - /etc/httpd/conf.d/openvpn-monitor.conf +site_packages="${site_packages//\//\\\/}" +if ! grep ${site_packages} ${apache_conf_file} >/dev/null 2>&1 ; then + sed -i -e "s/^\(Define openvpn_monitor_pythonpath\).*/\1 ${site_packages}/" ${apache_conf_file} fi systemctl enable httpd systemctl restart httpd -chown :apache /etc/openvpn-monitor/openvpn-monitor.conf +chown :apache /etc/openvpn-monitor/openvpn-monitor.conf.example semanage port -a -t openvpn_port_t -p tcp 5555 setsebool -P httpd_can_network_connect 1 diff --git a/setup.py b/setup.py index 7dc7720..d45d5e2 100755 --- a/setup.py +++ b/setup.py @@ -29,17 +29,18 @@ with open('requirements.txt', 'r', encoding='utf_8') as rt: install_requires = rt.read().splitlines() -data_files = [] - -for dirpath, dirnames, filenames in os.walk('openvpn_monitor/static/images/flags'): - data_files = [('share/openvpn-monitor/images/flags', - [os.path.join(dirpath, f) for f in filenames])] +package_files = [] +for directory in ['openvpn_monitor/static', 'openvpn_monitor/templates']: + for (path, directories, filenames) in os.walk(directory): + for filename in filenames: + package_files.append(os.path.join(path, filename)) if sys.prefix == '/usr': conf_path = '/etc' else: conf_path = sys.prefix +data_files = [] for dirpath, dirnames, filenames in os.walk('etc'): for i, dirname in enumerate(dirnames): if dirname.startswith('.'): @@ -59,6 +60,7 @@ keywords='web openvpn monitor', url='http://openvpn-monitor.openbytes.ie', packages=find_packages(), + package_data={'openvpn_monitor': package_files}, install_requires=install_requires, long_description=long_description, long_description_content_type='text/markdown',