]> git.ipfire.org Git - pbs.git/commitdiff
api: Start a new test API using FastAPI
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Jun 2025 13:38:39 +0000 (13:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Jun 2025 13:38:39 +0000 (13:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py [new file with mode: 0644]
src/api/app.py [new file with mode: 0644]
src/api/builds.py [new file with mode: 0644]
src/systemd/pakfire-api.service.in [new file with mode: 0644]

index 2f04929bf322777dbf6972081bdb8a0d6a6c032f..d139bc3f772a9baa0b6224953c516bdbe7c247d3 100644 (file)
@@ -120,6 +120,13 @@ EXTRA_DIST += \
 CLEANFILES += \
        src/buildservice/constants.py
 
+api_PYTHON = \
+       src/api/__init__.py \
+       src/api/app.py \
+       src/api/builds.py
+
+apidir = $(pkgpythondir)/api
+
 web_PYTHON = \
        src/web/__init__.py \
        src/web/auth.py \
@@ -393,6 +400,7 @@ static_fontsdir = $(staticdir)/fonts
 # ------------------------------------------------------------------------------
 
 systemdsystemunit_DATA = \
+       src/systemd/pakfire-api.service \
        src/systemd/pakfire-web.service
 
 CLEANFILES += \
@@ -402,6 +410,7 @@ INSTALL_DIRS += \
        $(systemdsystemunitdir)
 
 EXTRA_DIST += \
+       src/systemd/pakfire-api.service.in \
        src/systemd/pakfire-web.service.in
 
 dist_database_DATA = \
diff --git a/src/api/__init__.py b/src/api/__init__.py
new file mode 100644 (file)
index 0000000..e8d2bdd
--- /dev/null
@@ -0,0 +1,24 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+# Import the app
+from .app import app
+
+from . import builds
diff --git a/src/api/app.py b/src/api/app.py
new file mode 100644 (file)
index 0000000..ad27330
--- /dev/null
@@ -0,0 +1,29 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import fastapi
+
+app = fastapi.FastAPI(
+       title = "Pakfire Build Service API",
+       version = "0.0.1",
+
+       # Enable debug mode
+       debug = True,
+)
diff --git a/src/api/builds.py b/src/api/builds.py
new file mode 100644 (file)
index 0000000..f519329
--- /dev/null
@@ -0,0 +1,25 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+from .app import app
+
+@app.get("/builds/{build_id}")
+async def get(build_id: str):
+       return { "GOT" : "HERE" }
diff --git a/src/systemd/pakfire-api.service.in b/src/systemd/pakfire-api.service.in
new file mode 100644 (file)
index 0000000..7969b0f
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Pakfire API
+After=network.target
+
+[Service]
+ExecStart=/usr/bin/uvicorn pbs.api:app --port=9001
+User=_pakfire
+
+[Install]
+WantedBy=multi-user.target