applied changes from samicrusader <hi@samicrusader.me>

This commit is contained in:
Oscar Krause 2022-12-28 21:13:20 +01:00
parent 7f99c260ce
commit f04d4905df
5 changed files with 88 additions and 25 deletions

View File

@ -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

View File

@ -1,27 +1,42 @@
# Maintainer: samicrusader <hi@samicrusader.me>
# Maintainer: Oscar Krause <oscar.krause@collinwebdesigns.de>
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"
}

23
fastapi-dls.default Normal file
View File

@ -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="<<sitekey>>"
INSTANCE_REF="<<instanceref>>"
# Site-wide signing keys
INSTANCE_KEY_RSA="/var/lib/fastapi-dls/instance.private.pem"
INSTANCE_KEY_PUB="/var/lib/fastapi-dls/instance.public.pem"

14
fastapi-dls.install Normal file
View File

@ -0,0 +1,14 @@
post_install() {
sed -i "s/<<sitekey>>/$(uuidgen)/" /etc/default/fastapi-dls
sed -i "s/<<instanceref>>/$(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'
}

15
fastapi-dls.service Normal file
View File

@ -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