diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d57937d..1fde992 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,11 +52,7 @@ build:pamac: - 'echo "root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers' - chown -R build:build . script: - - pwd - #- source PKGBUILD && pacman -Syu --noconfirm --needed --asdeps "${makedepends[@]}" "${depends[@]}" - - ls -lah - - ls -lah app/ - - sudo -u build makepkg -si + - sudo -u build makepkg -s test: image: python:3.10-slim-bullseye diff --git a/PKGBUILD b/PKGBUILD index 1dd571c..a70b36e 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,27 +1,42 @@ +# Maintainer: samicrusader # Maintainer: Oscar Krause + pkgname=fastapi-dls -pkgver=1.0.0 +pkgver=1.0 pkgrel=1 -pkgdesc="Minimal Delegated License Service (DLS)." -arch=('any') # x86_64? -url="https://git.collinwebdesigns.de/oscar.krause/fastapi-dls" -#license=('MIT') -depends=('python3' 'python-fastapi' 'uvicorn' 'python-dotenv' 'python-dateutil' 'python-jose' 'python-sqlalchemy' 'python-pycryptodome' 'python-markdown' 'openssl') -source=('README.md' 'version.env' 'app/main.py' 'app/orm.py' 'app/util.py') -sha512sums=("SKIP") +pkgdesc='NVIDIA DLS server implementation with FastAPI' +arch=('any') +url='https://git.collinwebdesigns.de/oscar.krause/fastapi-dls' +license=('MIT') +depends=('python' 'python-jose' 'python-starlette' 'python-httpx' 'python-fastapi' 'python-dotenv' 'python-dateutil' 'python-sqlalchemy' 'python-pycryptodome' 'uvicorn' 'python-markdown' 'openssl') +provider=("$pkgname") +install="$pkgname.install" +source=('git+https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git#commit=3d5203dae054020e6f56e5f457fac1fbacc6f05d' # https://gitea.publichub.eu/oscar.krause/fastapi-dls.git + "$pkgname.default" + "$pkgname.service") +sha256sums=('SKIP' + 'd8b2216b67a2f8f35ad6f07c825839794f7c34456a72caadd9fc110810348d90' + '10cb98d64f8bf37b11a60510793c187cc664e63c895d1205781c21fa2e703f32') -package() { - mkdir -p "${pkgdir}/usr/share" - - echo "pkgdir: ${pkgdir}" - echo "srcdir: ${srcdir}" - echo "startDir: ${startDir}" - - cp "${srcdir}/README.md" "${pkgdir}/usr/share/README.md" - cp "${srcdir}/version.env" "${pkgdir}/usr/share/version.env" - cp -r "${srcdir}/app" "${pkgdir}/usr/share" +check() { + cd "$srcdir/$pkgname/test" + mkdir "$srcdir/$pkgname/app/cert" + openssl genrsa -out "$srcdir/$pkgname/app/cert/instance.private.pem" 2048 + openssl rsa -in "$srcdir/$pkgname/app/cert/instance.private.pem" -outform PEM -pubout -out "$srcdir/$pkgname/app/cert/instance.public.pem" + python "$srcdir/$pkgname/test/main.py" + rm -rf "$srcdir/$pkgname/app/cert" } +package() { + install -d "$pkgdir/usr/share/doc/$pkgname" + install -d "$pkgdir/var/lib/$pkgname/cert" + cp -r "$srcdir/$pkgname/doc"/* "$pkgdir/usr/share/doc/$pkgname/" + install -Dm644 "$srcdir/$pkgname/README.md" "$pkgdir/usr/share/doc/$pkgname/README.md" -# https://bbs.archlinux.org/viewtopic.php?id=213287 -# https://itsfoss.com/create-pkgbuild/ + sed -i "s/README.md/\/usr\/share\/doc\/$pkgname\/README.md/g" "$srcdir/$pkgname/app/main.py" + sed -i "s/join(dirname(__file__), 'cert\//join('\/var\/lib\/$pkgname', 'cert\//g" "$srcdir/$pkgname/app/main.py" + install -Dm755 "$srcdir/$pkgname/app/main.py" "$pkgdir/opt/$pkgname/main.py" + install -Dm755 "$srcdir/$pkgname/app/orm.py" "$pkgdir/opt/$pkgname/orm.py" + install -Dm644 "$srcdir/$pkgname.default" "$pkgdir/etc/default/$pkgname" + install -Dm644 "$srcdir/$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service" +} diff --git a/fastapi-dls.default b/fastapi-dls.default new file mode 100644 index 0000000..079679b --- /dev/null +++ b/fastapi-dls.default @@ -0,0 +1,23 @@ +# Toggle FastAPI debug mode +DEBUG=false + +# Where the client can find the DLS server +## DLS_URL should be a hostname +DLS_URL="localhost.localdomain" +DLS_PORT=8443 +CORS_ORIGINS="https://$DLS_URL:$DLS_PORT" + +# Lease expiration in days +LEASE_EXPIRE_DAYS=90 + +# Database location +## See https://dataset.readthedocs.io/en/latest/quickstart.html for details +DATABASE="sqlite:////var/lib/fastapi-dls/db.sqlite" + +# UUIDs for identifying the instance +SITE_KEY_XID="<>" +INSTANCE_REF="<>" + +# Site-wide signing keys +INSTANCE_KEY_RSA="/var/lib/fastapi-dls/instance.private.pem" +INSTANCE_KEY_PUB="/var/lib/fastapi-dls/instance.public.pem" diff --git a/fastapi-dls.install b/fastapi-dls.install new file mode 100644 index 0000000..17ad880 --- /dev/null +++ b/fastapi-dls.install @@ -0,0 +1,14 @@ +post_install() { + sed -i "s/<>/$(uuidgen)/" /etc/default/fastapi-dls + sed -i "s/<>/$(uuidgen)/" /etc/default/fastapi-dls + + echo 'The environment variables for this server can be edited at: /etc/default/fastapi-dls' + echo 'The server can be started with: systemctl start fastapi-dls.service' + echo + echo 'A valid HTTPS certificate needs to be installed to /var/lib/fastapi-dls/cert/webserver.{crt,key}' + echo 'A self-signed certificate can be generated with: openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /var/lib/fastapi-dls/cert/webserver.key -out /var/lib/fastapi-dls/cert/webserver.crt' + echo + echo 'The signing keys for your instance need to be generated as well. Generate them with these commands:' + echo 'openssl genrsa -out /var/lib/fastapi-dls/instance.private.pem 2048' + echo 'openssl rsa -in /var/lib/fastapi-dls/instance.private.pem -outform PEM -pubout -out /var/lib/fastapi-dls/instance.public.pem' +} diff --git a/fastapi-dls.service b/fastapi-dls.service new file mode 100644 index 0000000..1bca7b7 --- /dev/null +++ b/fastapi-dls.service @@ -0,0 +1,15 @@ +[Unit] +Description=FastAPI-DLS +Documentation=https://git.collinwebdesigns.de/oscar.krause/fastapi-dls +After=network.target + +[Service] +Type=forking +EnvironmentFile=/etc/default/fastapi-dls +ExecStart=/usr/bin/python /opt/fastapi-dls/main.py +WorkingDir=/opt/fastapi-dls +Restart=on-abort +User=root + +[Install] +WantedBy=multi-user.target