[elbe-devel] [PATCH 1/2] elbepack: introduce in-process repository server

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Feb 28 11:44:56 CET 2024


Installing lighttpd to serve the pbuilder repository is complex.
It requires a dedicated configuration package which is part of a
dedicated repository.

Instead add a new fileserver to the elbe daemon that provides the same
functionality.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 debian/control                     |  1 -
 debian/python3-elbe-daemon.default |  2 +-
 elbepack/daemons/repo/__init__.py  | 28 ++++++++++++++++++++++++++++
 elbepack/pbuilder.py               |  6 +++---
 4 files changed, 32 insertions(+), 5 deletions(-)
 create mode 100644 elbepack/daemons/repo/__init__.py

diff --git a/debian/control b/debian/control
index 349b0cd14037..5c02fa646658 100644
--- a/debian/control
+++ b/debian/control
@@ -123,7 +123,6 @@ Depends: ${misc:Depends},
   binfmt-support,
   btrfs-progs,
   debootstrap,
-  debathena-transform-lighttpd,
   dosfstools,
   dpkg-dev,
   python3-elbe-bin (= ${binary:Version}),
diff --git a/debian/python3-elbe-daemon.default b/debian/python3-elbe-daemon.default
index 51d7290e89e1..bc6948ac63d1 100644
--- a/debian/python3-elbe-daemon.default
+++ b/debian/python3-elbe-daemon.default
@@ -1,3 +1,3 @@
 # elbe daemon configuration
 
-DAEMON_ARGS="daemon --port=7588 --soap"
+DAEMON_ARGS="daemon --port=7588 --soap --repo"
diff --git a/elbepack/daemons/repo/__init__.py b/elbepack/daemons/repo/__init__.py
new file mode 100644
index 000000000000..94eecf56ef48
--- /dev/null
+++ b/elbepack/daemons/repo/__init__.py
@@ -0,0 +1,28 @@
+import logging
+import mimetypes
+import os
+import wsgiref.util
+
+
+logger = logging.getLogger(__name__)
+logger.setLevel(logging.DEBUG)
+
+
+# taken from wsgiref examples
+def _app(environ, respond):
+    # Get the file name and MIME type
+    fn = environ["PATH_INFO"]
+    mime_type = mimetypes.guess_type(fn)[0] or 'application/octet-stream'
+
+    # Return 200 OK if file exists, otherwise 404 Not Found
+    logger.warn('Serving as %s: "%s"', mime_type, fn)
+    if os.path.exists(fn):
+        respond("200 OK", [("Content-Type", mime_type)])
+        return wsgiref.util.FileWrapper(open(fn, "rb"))
+    else:
+        respond("404 Not Found", [("Content-Type", "text/plain")])
+        return [b"not found"]
+
+
+def get_app(engine):
+    return _app
diff --git a/elbepack/pbuilder.py b/elbepack/pbuilder.py
index 1c61d551882a..8fb60eae1692 100644
--- a/elbepack/pbuilder.py
+++ b/elbepack/pbuilder.py
@@ -16,7 +16,7 @@ def pbuilder_write_config(builddir, xml, noccache):
     fp.write('#!/bin/sh\n')
     fp.write('set -e\n')
     fp.write(f'MIRRORSITE="{xml.get_primary_mirror(False)}"\n')
-    fp.write(f'OTHERMIRROR="deb http://127.0.0.1:8080{builddir}/repo {distname} main"\n')
+    fp.write(f'OTHERMIRROR="deb http://127.0.0.1:7588/repo{builddir}/repo {distname} main"\n')
     fp.write(f'BASETGZ="{os.path.join(builddir, "pbuilder", "base.tgz")}"\n')
     fp.write(f'DISTRIBUTION="{distname}"\n')
     fp.write(f'BUILDRESULT="{os.path.join(builddir, "pbuilder", "result")}"\n')
@@ -59,7 +59,7 @@ def pbuilder_write_cross_config(builddir, xml, noccache):
     fp.write('#!/bin/sh\n')
     fp.write('set -e\n')
     fp.write(f'MIRRORSITE="{xml.get_primary_mirror(False, hostsysroot=True)}"\n')
-    fp.write(f'OTHERMIRROR="deb http://127.0.0.1:8080{builddir}/repo {distname} main"\n')
+    fp.write(f'OTHERMIRROR="deb http://127.0.0.1:7588/repo{builddir}/repo {distname} main"\n')
     fp.write(f'BASETGZ="{os.path.join(builddir, "pbuilder_cross", "base.tgz")}"\n')
 
     fp.write(f'DISTRIBUTION="{distname}"\n')
@@ -134,7 +134,7 @@ def pbuilder_write_repo_hook(builddir, xml, cross):
 
     with open(os.path.join(pbuilder_hook_dir, 'G10elbe_apt_sources'), 'w') as f:
 
-        local_http = f"deb http://127.0.0.1:8080{builddir}/repo {xml.prj.text('suite')} main\n"
+        local_http = f"deb http://127.0.0.1:7588/repo{builddir}/repo {xml.prj.text('suite')} main\n"
         mirrors = xml.create_apt_sources_list(hostsysroot=cross)
         mirrors = local_http + mirrors
 
-- 
2.44.0



More information about the elbe-devel mailing list