Skip to content

Commit

Permalink
frontend: point Copr repositories to Pulp
Browse files Browse the repository at this point in the history
Fix fedora-copr#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.
  • Loading branch information
FrostyX committed Sep 24, 2024
1 parent 1559b85 commit 98467cb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
5 changes: 5 additions & 0 deletions frontend/coprs_frontend/coprs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 29 additions & 5 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo
Original file line number Diff line number Diff line change
@@ -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")}}
Expand Down
4 changes: 2 additions & 2 deletions frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_rpmrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from flask_restx import Resource, Namespace

from coprs import app
from coprs.logic.coprs_logic import (
CoprsLogic,
CoprDirsLogic,
Expand Down Expand Up @@ -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'] = {}
Expand Down
8 changes: 5 additions & 3 deletions frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 98467cb

Please sign in to comment.