From f8cef70d4d0fb9684d72d7030f6e2e69622bf6b3 Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Fri, 23 Aug 2024 03:42:23 +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 +++++ .../coprs/templates/coprs/copr_dir.repo | 9 +++++++-- .../coprs/views/coprs_ns/coprs_general.py | 15 +++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/frontend/coprs_frontend/coprs/config.py b/frontend/coprs_frontend/coprs/config.py index 9797d43c8..76c7efed9 100644 --- a/frontend/coprs_frontend/coprs/config.py +++ b/frontend/coprs_frontend/coprs/config.py @@ -201,6 +201,11 @@ class Config(object): ROLLING_CHROOTS_INACTIVITY_WARNING = 180 ROLLING_CHROOTS_INACTIVITY_REMOVAL = 180 + # 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/templates/coprs/copr_dir.repo b/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo index 73bd5de0b..e0dcd9ad2 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo +++ b/frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo @@ -1,11 +1,16 @@ [{{ repo_id }}] name={{ name }} {{- " (" + arch + ")" if arch }} +{% if not pulp %} baseurl={{ url | fix_url_https_backend }} -type=rpm-md -skip_if_unavailable=True gpgcheck={{ config.REPO_GPGCHECK | default("1")}} gpgkey={{ pubkey_url | fix_url_https_backend }} +{% else %} +baseurl={{ url }} +gpgcheck=0 +{% endif %} +type=rpm-md +skip_if_unavailable=True repo_gpgcheck=0 {% if cost %} cost={{ cost }} 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..ce6623716 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,20 @@ 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) - 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") + pulp = copr_dir.copr.storage == StorageEnum.pulp + if pulp: + url = "/".join([app.config["PULP_CONTENT_URL"], copr_dir.full_name]) + pubkey_url = None + else: + url = os.path.join(copr_dir.repo_url, '') # adds trailing slash + pubkey_url = urljoin(url, "pubkey.gpg") + repo_url = generate_repo_url(mock_chroot, url, arch) 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):