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

WIP: Repackage nipapd #1420

Merged
merged 7 commits into from
Jan 16, 2025
Merged
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
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ jobs:
fakeroot \
debhelper \
dh-python \
pybuild-plugin-pyproject \
junit4 \
libldap-dev \
libsasl2-dev \
python3-docutils \
python3-nose \
python3-requests \
python3-setuptools \
python3-build \
python3-wheel \
python3-all \
default-jdk \
Expand Down Expand Up @@ -79,23 +81,23 @@ jobs:
if: ${{ matrix.install == 'pip' }}
run: |
# install nipap dependencies
sudo -H pip3 install --break-system-packages -I -r nipap/requirements.txt
sudo -H pip3 install --break-system-packages -I ./nipap/
# SQL
sudo su -c "cd nipap/sql; PGPASSWORD=papin make install" postgres
# move configuration file into place
sudo mkdir /etc/nipap
sudo cp nipap/nipap.conf.dist /etc/nipap/nipap.conf
sudo sed -e "s/{{LISTEN_ADDRESS}}/127.0.0.1/" -e "s/{{LISTEN_PORT}}/1337/" -e "s/#ssl_port.\+$/ssl_port = 1338/" -e "s/#ssl_cert_file.\+$/ssl_cert_file = \/tmp\/ca\/test.bundle.crt/" -e "s/#ssl_key_file.\+$/ssl_key_file = \/tmp\/ca\/test.key/" -e "s/{{DB_USERNAME}}/nipap/" -e "s/{{DB_NAME}}/nipap/" -e "s/{{DB_PASSWORD}}/papin/" -e "s/{{DB_SSLMODE}}/require/" -e "s/{{DB_PORT}}/5432/" -e "s/{{DB_HOST}}/localhost/" -e "s/{{SYSLOG}}/true/" -i /etc/nipap/nipap.conf
# create local user for unittest
sudo nipap/nipap-passwd create-database
sudo nipap/nipap-passwd add -u unittest -p gottatest -n unittest
sudo nipap/nipap-passwd add -u readonly -p gottatest --readonly -n "Read-only user for running unit tests"
sudo nipap-passwd create-database
sudo nipap-passwd add -u unittest -p gottatest -n unittest
sudo nipap-passwd add -u readonly -p gottatest --readonly -n "Read-only user for running unit tests"
# install pynipap
cd pynipap; sudo python3 setup.py install; cd ..
cd pynipap; sudo -H pip3 install --break-system-packages -I .; cd ..
# install nipap-cli dependencies
sudo -H pip3 install --break-system-packages -r nipap-cli/requirements.txt
# start nipap backend
nipap/nipapd --no-pid-file -c /etc/nipap/nipap.conf -df 2>&1 > /tmp/nipap.log &
nipapd --no-pid-file -c /etc/nipap/nipap.conf -df 2>&1 > /tmp/nipap.log &

- name: "Install latest release from apt"
if: ${{ matrix.install == 'apt' && matrix.upgrade == true }}
Expand Down Expand Up @@ -141,8 +143,8 @@ jobs:
sudo sed -e "s/#ssl_port.\+$/ssl_port = 1338/" -e "s/#ssl_cert_file.\+$/ssl_cert_file = \/tmp\/ca\/test.bundle.crt/" -e "s/#ssl_key_file.\+$/ssl_key_file = \/tmp\/ca\/test.key/" -i /etc/nipap/nipap.conf; \
fi
# create local user for unittests
sudo nipap/nipap-passwd add -u unittest -p gottatest -f /etc/nipap/local_auth.db -n "User for running unit tests"
sudo nipap/nipap-passwd add -u readonly -p gottatest -f /etc/nipap/local_auth.db --readonly -n "Read-only user for running unit tests"
sudo nipap-passwd add -u unittest -p gottatest -f /etc/nipap/local_auth.db -n "User for running unit tests"
sudo nipap-passwd add -u readonly -p gottatest -f /etc/nipap/local_auth.db --readonly -n "Read-only user for running unit tests"
sudo sed -e "s/^db_host *=.*/db_host = localhost/" -e "s/{{SYSLOG}}/true/" -e "s/^debug.\+/debug = true/" -e "s/^user/#user/" -i /etc/nipap/nipap.conf
sudo systemctl restart nipapd.service

Expand Down Expand Up @@ -242,7 +244,7 @@ jobs:
python3-requests \
postgresql-16-ip4r

sudo -H pip3 install -I --break-system-packages -r nipap/requirements.txt # needed to run test suite
sudo -H pip3 install -I --break-system-packages ./nipap/ # needed to run test suite

# Set up PostgreSQL
sudo service postgresql start
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.nipapd
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#

FROM ubuntu:noble
MAINTAINER Kristian Larsson <[email protected]>

Check failure on line 36 in Dockerfile.nipapd

View workflow job for this annotation

GitHub Actions / docker

DL4000 info: MAINTAINER is deprecated

ENV DEBIAN_FRONTEND=noninteractive

# apt update, upgrade & install packages
RUN apt-get update -qy && apt-get upgrade -qy \

Check failure on line 41 in Dockerfile.nipapd

View workflow job for this annotation

GitHub Actions / docker

DL3008 info: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
&& apt-get install --no-install-recommends -qy build-essential \
libpq-dev \
libldap-dev \
Expand Down Expand Up @@ -66,8 +66,7 @@
COPY nipap /nipap
WORKDIR /nipap
RUN pip3 --no-input install --break-system-packages --no-cache-dir envtpl==0.7.2 \
&& pip3 --no-input install -I --break-system-packages --no-cache-dir -r requirements.txt \
&& python3 setup.py install
&& pip3 --no-input install -I --break-system-packages --no-cache-dir .

EXPOSE 1337
ENV LISTEN_ADDRESS=0.0.0.0 LISTEN_PORT=1337 SYSLOG=false DB_PORT=5432 DB_SSLMODE=disable DB_NAME=nipap
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.www
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

FROM ubuntu:noble

MAINTAINER Lukas Garberg <[email protected]>

Check failure on line 28 in Dockerfile.www

View workflow job for this annotation

GitHub Actions / docker

DL4000 info: MAINTAINER is deprecated

ENV DEBIAN_FRONTEND=noninteractive

ENV NIPAPD_HOST=nipapd NIPAPD_PORT=1337 WWW_USERNAME=guest WWW_PASSWORD=guest

# apt update, upgrade & install packages
RUN apt-get update -qy && apt-get upgrade -qy \

Check failure on line 35 in Dockerfile.www

View workflow job for this annotation

GitHub Actions / docker

DL3008 info: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
&& apt-get install --no-install-recommends -qy apache2 \
build-essential \
libapache2-mod-wsgi-py3 \
Expand Down Expand Up @@ -63,8 +63,8 @@
COPY pynipap /pynipap
COPY nipap /nipap
COPY nipap-www /nipap-www
RUN cd /pynipap && pip3 --no-input install --break-system-packages --no-cache-dir . && \

Check failure on line 66 in Dockerfile.www

View workflow job for this annotation

GitHub Actions / docker

DL3003 info: Use WORKDIR to switch to a directory
cd /nipap && pip3 --no-input install --break-system-packages --no-cache-dir -r requirements.txt && python3 setup.py install && \
cd /nipap && pip3 --no-input install --break-system-packages --no-cache-dir . && \
cd /nipap-www && pip3 --no-input install --break-system-packages --no-cache-dir -r requirements.txt && python3 setup.py install && \
cd ..

Expand Down
4 changes: 2 additions & 2 deletions nipap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ buildrpm: sql2py
builddeb: sql2py
# build the source package in the parent directory
# then rename it to project_version.orig.tar.gz
$(PYTHON) setup.py sdist --dist-dir=../ #--prune
$(PYTHON) -m build --sdist --outdir=../
rename -f 's/$(PROJECT)-(\d.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
# build the package
debuild -us -uc
Expand All @@ -50,7 +50,7 @@ clean:
debian/nipap-common.debhelper.log \
debian/nipap-common.postinst.debhelper \
debian/nipap-common.prerm.debhelper debian/nipap-common.substvars \
debian/.debhelper debian/debhelper-build-stamp nipap.egg-info/
debian/.debhelper debian/debhelper-build-stamp nipap.egg-info/ build/
find . -name '*.pyc' -delete

VER := $(shell head -n1 ../NEWS | awk '{print $$2}')
Expand Down
1 change: 0 additions & 1 deletion nipap/debian/compat

This file was deleted.

17 changes: 11 additions & 6 deletions nipap/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ Source: nipap
Maintainer: Lukas Garberg <[email protected]>
Section: python
Priority: optional
Build-Depends: python3 (>= 3.6), debhelper (>= 10), dh-python
Standards-Version: 4.4.0

Build-Depends: debhelper-compat (= 13),
dh-python,
python3-all,
python3-setuptools
Standards-Version: 4.6.1
Homepage: https://spritelink.github.io/NIPAP/
Rules-Requires-Root: no

Package: nipap-common
Architecture: all
Depends: python3 (>= 3.6), ${misc:Depends}, python3-ipy
Multi-Arch: foreign
Depends: ${misc:Depends}, ${python3:Depends}
Suggests: python3-ldap
Description: Neat IP Address Planner
The Neat IP Address Planner, NIPAP, is a system built for efficiently managing
large amounts of IP addresses. This is the common libraries.


Package: nipapd
Architecture: all
Depends: debconf, nipap-common, python3 (>= 3.6), ${misc:Depends}, python3-psycopg2, python3-flask, python3-flask-xml-rpc-re, python3-flask-restx, python3-flask-compress, python3-tornado, python3-parsedatetime, python3-tz, python3-dateutil, python3-psutil, python3-pyparsing, python3-jwt, python3-requests
Multi-Arch: foreign
Depends: ${misc:Depends}, ${python3:Depends}, nipap-common
Description: Neat IP Address Planner XML-RPC daemon
The Neat IP Address Planner, NIPAP, is a system built for efficiently managing
large amounts of IP addresses. This is the XML-RPC daemon.
2 changes: 1 addition & 1 deletion nipap/debian/nipapd.init
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -e
# Short-Description: NIPAP XML-RPC server
### END INIT INFO

DAEMON=/usr/sbin/nipapd
DAEMON=/usr/bin/nipapd
CONFIGFILE=/etc/nipap/nipap.conf
NAME=NIPAPd
PIDFILE=/var/run/nipap/nipapd.pid
Expand Down
8 changes: 5 additions & 3 deletions nipap/debian/nipapd.install
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
etc
usr/sbin/nipap-passwd
usr/sbin/nipapd
usr/bin/nipapd
usr/bin/nipap-passwd
usr/share/nipap
usr/share/nipap/nipap.conf.dist etc/nipap
usr/share/man/man8/nipapd.8
usr/share/man/man1/nipap-passwd.1
3 changes: 3 additions & 0 deletions nipap/debian/py3dist-overrides
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask-restx python3-flask-restx
Flask python3-flask (>= 2.0.0)
flask-xml-rpc-re python3-flask-xml-rpc-re
1 change: 1 addition & 0 deletions nipap/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# This file was automatically generated by stdeb 0.6.0+git at
# Tue, 18 Oct 2011 21:55:07 +0200
export DH_VERBOSE=1

%:
dh $@ --with python3 --buildsystem=pybuild
9 changes: 5 additions & 4 deletions nipap/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/sh

envtpl --allow-missing --keep-template /nipap/nipap.conf.dist -o /etc/nipap/nipap.conf
mkdir -p /etc/nipap/
envtpl --allow-missing --keep-template /usr/local/share/nipap/nipap.conf.dist -o /etc/nipap/nipap.conf
/bin/bash /nipap/wait-for-it.sh -t 60 $DB_HOST:$DB_PORT -- sleep 5

/usr/sbin/nipap-passwd create-database
/usr/local/bin/nipap-passwd create-database
if [ -n "$NIPAP_USERNAME" -a -n "$NIPAP_PASSWORD" ]; then
echo "Creating user '$NIPAP_USERNAME'"
/usr/sbin/nipap-passwd add --username $NIPAP_USERNAME --name "NIPAP user" --password $NIPAP_PASSWORD
/usr/local/bin/nipap-passwd add --username $NIPAP_USERNAME --name "NIPAP user" --password $NIPAP_PASSWORD
fi
echo "Starting nipap daemon.."
exec /usr/sbin/nipapd --debug --foreground --auto-install-db --auto-upgrade-db --no-pid-file
exec /usr/local/bin/nipapd --debug --foreground --auto-install-db --auto-upgrade-db --no-pid-file
6 changes: 5 additions & 1 deletion nipap/nipap-passwd → nipap/nipap/nipap_passwd.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import nipap.authlib
from nipap.nipapconfig import NipapConfig, NipapConfigError

if __name__ == '__main__':

def run():
# parse arguments
parser = argparse.ArgumentParser(description='NIPAP User configuration')
parser.add_argument('action',
Expand Down Expand Up @@ -175,3 +175,7 @@

else:
parser.print_help()


if __name__ == '__main__':
run()
8 changes: 6 additions & 2 deletions nipap/nipapd → nipap/nipap/nipapd.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def drop_privileges(uid_name='nobody', gid_name='nogroup'):
old_umask = os.umask(0o077)


if __name__ == '__main__':
def run():
parser = argparse.ArgumentParser(description='NIPAP backend server')
parser.add_argument('--auto-install-db', action='store_true', help='automatically install db schema')
parser.add_argument('--auto-upgrade-db', action='store_true', help='automatically upgrade db schema')
Expand Down Expand Up @@ -270,7 +270,7 @@ def drop_privileges(uid_name='nobody', gid_name='nogroup'):
logger.debug('Tracing is disabled')

Compress(app)

# Set up sockets for handling plaintext and SSL connections
sockets = []
ssl_sockets = []
Expand Down Expand Up @@ -358,3 +358,7 @@ def drop_privileges(uid_name='nobody', gid_name='nogroup'):
except Exception as exc:
logger.error(exc)
sys.exit(1)


if __name__ == '__main__':
garberg marked this conversation as resolved.
Show resolved Hide resolved
run()
84 changes: 84 additions & 0 deletions nipap/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[project]
name = "nipap"
dynamic = ["version", "description"]
readme = "README.rst"
license = {text = "MIT"}
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3'
]
keywords = ["nipap"]
dependencies = [
"zipp==3.21.0",
"importlib_metadata==8.5.0",
"Flask==3.0.3",
"Flask-Compress==1.17",
"flask-xml-rpc-re==0.1.4",
"flask-restx==1.3.0",
"requests==2.32.3",
"IPy==1.01",
"Jinja2==3.1.5",
"MarkupSafe==3.0.2",
"Werkzeug==3.1.3",
"certifi==2024.12.14",
"itsdangerous==2.2.0",
"parsedatetime==2.6",
"psutil==6.1.1",
"psycopg2==2.9.10",
"pyparsing==3.2.1",
"python-dateutil==2.8.2",
"pytz==2024.2",
"pyjwt==2.10.1",
"tornado==6.4.2",
# "docutils==0.21.2"
]

[project.optional-dependencies]
instrumentation = [
"opentelemetry-api==1.29.0",
"opentelemetry-exporter-otlp==1.29.0",
"opentelemetry-exporter-otlp-proto-common==1.29.0",
"opentelemetry-exporter-otlp-proto-grpc==1.29.0",
"opentelemetry-exporter-otlp-proto-http==1.29.0",
"opentelemetry-instrumentation==0.50b0",
"opentelemetry-instrumentation-dbapi==0.50b0",
"opentelemetry-instrumentation-flask==0.50b0",
"opentelemetry-instrumentation-psycopg2==0.50b0",
"opentelemetry-instrumentation-wsgi==0.50b0",
"opentelemetry-proto==1.29.0",
"opentelemetry-sdk==1.29.0",
"opentelemetry-semantic-conventions==0.50b0",
"opentelemetry-util-http==0.50b0"
]

ldap_auth = [
"python-ldap==3.4.4"
]

[project.urls]
Homepage = "http://SpriteLink.github.io/NIPAP"

[project.scripts]
nipapd = "nipap.nipapd:run"
nipap-passwd = "nipap.nipap_passwd:run"

[tool.setuptools.dynamic]
version = {attr = "nipap.__version__"}

[build-system]
requires = [
"setuptools",
# Need to be pinned to 0.20.1 in Ubuntu 24.04 as using the latest 0.21.2
# gives a diff during .deb package build. Unfortunately the files are
# generated twice - first once in a virtualenv (using the version specified
# here) and then once without a virtualenv using the one from the system.
# There two runs produce different outputs (wich they shouldn't) causing a
# diff and the package utils to b0rk out.
"docutils==0.20.1"
]
build-backend = "setuptools.build_meta"
39 changes: 0 additions & 39 deletions nipap/requirements.txt

This file was deleted.

Loading
Loading