From 98467cb0650850bf6bc5dd27ea28c1d52dde6c0b Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Wed, 11 Sep 2024 20:30:58 +0200 Subject: [PATCH] frontend: point Copr repositories to Pulp Fix #3375 Of course only for Copr projects that has configured to have their storage in Pulp, not all Copr projects. There are three possible options how to implement this. 1. The Most straightforward is to not generate repofiles ourselves and let Pulp do it. The downside is that we would have to pass additional parameters (it is possible though) such as repo priority, module hotfixes attribute, etc, and figure out how to count repo downloads 2. Generate repofiles ourselves, only point to `baseurl` in Pulp. This IMHO the best option for keeping compatibility between storage on the backend and in Pulp, so I implement this option in this PR. 3. Adding a Lighttpd redirect for `baseurl` of the Pulp-stored projects to Pulp content URL. This will be needed in the future to ensure that users don't have to re-enable Copr repositories, once those projects are migrated to Pulp. But this will be hard to implement, so we decided to do it when the time comes. --- frontend/coprs_frontend/coprs/config.py | 5 +++ frontend/coprs_frontend/coprs/models.py | 34 ++++++++++++++++--- .../coprs/templates/coprs/copr_dir.repo | 4 +++ .../coprs/views/apiv3_ns/apiv3_rpmrepo.py | 4 +-- .../coprs/views/coprs_ns/coprs_general.py | 8 +++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/frontend/coprs_frontend/coprs/config.py b/frontend/coprs_frontend/coprs/config.py index 2ff757e5c..0fa07f989 100644 --- a/frontend/coprs_frontend/coprs/config.py +++ b/frontend/coprs_frontend/coprs/config.py @@ -205,6 +205,11 @@ class Config(object): # Possible options are "backend" and "pulp" DEFAULT_STORAGE = "backend" + # If build results for (some) projects are stored in Pulp, what is the + # shared part of the URL for all repositories, e.g. + # https://pulp.stage.devshift.net/api/pulp-content/copr + PULP_CONTENT_URL = None + class ProductionConfig(Config): DEBUG = False diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 60e5eb636..d4c80fe44 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -663,14 +663,36 @@ def repo_name(self): @property def repo_url(self): - return "/".join([app.config["BACKEND_BASE_URL"], - u"results", - self.full_name]) + """ + URL for a project repository + """ + return "/".join([self.results_url, self.full_name]) @property def repo_id(self): return "-".join([self.owner_name.replace("@", "group_"), self.name]) + @property + def pubkey_url(self): + """ + URL for the project public GPG key + """ + return "/".join([ + app.config["BACKEND_BASE_URL"], + "results", + self.full_name, + "pubkey.gpg", + ]) + + @property + def results_url(self): + """ + URL for the project results directory + """ + if self.storage == StorageEnum.pulp: + return app.config["PULP_CONTENT_URL"] + return "/".join([app.config["BACKEND_BASE_URL"], "results"]) + @property def modules_url(self): return "/".join([self.repo_url, "modules"]) @@ -849,8 +871,10 @@ def repo_name(self): @property def repo_url(self): - return "/".join([app.config["BACKEND_BASE_URL"], - u"results", self.full_name]) + """ + URL for a CoprDir repository + """ + return "/".join([self.copr.results_url, self.full_name]) @property def repo_id(self): diff --git a/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo b/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo index 73bd5de0b..46187ea3a 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo +++ b/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo @@ -1,7 +1,11 @@ [{{ repo_id }}] name={{ name }} {{- " (" + arch + ")" if arch }} +{% if not pulp %} baseurl={{ url | fix_url_https_backend }} +{% else %} +baseurl={{ url }} +{% endif %} type=rpm-md skip_if_unavailable=True gpgcheck={{ config.REPO_GPGCHECK | default("1")}} diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_rpmrepo.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_rpmrepo.py index e0392a15c..868da2f80 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_rpmrepo.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_rpmrepo.py @@ -6,7 +6,6 @@ from flask_restx import Resource, Namespace -from coprs import app from coprs.logic.coprs_logic import ( CoprsLogic, CoprDirsLogic, @@ -48,7 +47,8 @@ def get_project_rpmrepo_metadata(copr): repos_info = ReposLogic.repos_for_copr(copr, repo_dl_stat) data = { - "results_url": "/".join([app.config["BACKEND_BASE_URL"], "results"]), + "results_url": copr.results_url, + "pubkey_url": copr.pubkey_url, } repos = data['repos'] = {} diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py index 53d8af3ed..c72294d50 100644 --- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py +++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py @@ -21,6 +21,7 @@ from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter +from copr_common.enums import StorageEnum from coprs import app from coprs import cache from coprs import db @@ -861,14 +862,15 @@ def render_repo_template(copr_dir, mock_chroot, arch=None, cost=None, runtime_de copr_dir.copr, copr_dir.name, multilib=arch, dep_idx=runtime_dep, dependent=dependent) + pulp = copr_dir.copr.storage == StorageEnum.pulp url = os.path.join(copr_dir.repo_url, '') # adds trailing slash repo_url = generate_repo_url(mock_chroot, url, arch) - pubkey_url = urljoin(url, "pubkey.gpg") - + pubkey_url = copr_dir.copr.pubkey_url return flask.render_template("coprs/copr_dir.repo", copr_dir=copr_dir, url=repo_url, pubkey_url=pubkey_url, repo_id=repo_id, arch=arch, cost=cost, - name=name, repo_priority=copr_dir.copr.repo_priority) + name=name, pulp=pulp, + repo_priority=copr_dir.copr.repo_priority) def _render_external_repo_template(dep, copr_dir, mock_chroot, dep_idx):