Skip to content

Commit

Permalink
frontend: make coprdirs have their repo available in the buildroot
Browse files Browse the repository at this point in the history
This is useful in general but especially for pull requests that build
multiple packages which depend on each other (e.g. `python-copr` and
`copr-cli`). Up until now, it had to be workarounded by building the
dependency into the main copr repository.
  • Loading branch information
FrostyX committed Aug 11, 2024
1 parent ed6d972 commit ff65588
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 10 deletions.
67 changes: 67 additions & 0 deletions beaker-tests/Sanity/copr-cli-basic-operations/runtest-coprdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#! /bin/bash
#
# Copyright (c) 2024 Red Hat, Inc.
#
# 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 2 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/.


# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1

# Load config settings
HERE=$(dirname "$(realpath "$0")")
source "$HERE/config"
source "$HERE/helpers"


quick_package_script ()
{
cp "$HERE/files/quick-package.sh" script
echo "$1" >> script
}


rlJournalStart
rlPhaseStartSetup
setup_checks
rlAssertRpm "jq"
setupProjectName "coprdir"
rlPhaseEnd

rlPhaseStartTest
# Test that CoprDirs have their own repositories in the buildroot
tmp=`mktemp -d`
rlRun "copr-cli create --chroot $CHROOT $PROJECT"

# For an ease of implementation, the dependency and the package that
# requires it are both `hello`. In a real life the first package would
# be something like `python-copr` or `python-copr-common`, and the
# second package would be something like `copr-cli` or `copr-backend`.

# This is the dependency (e.g. python-copr)
rlRun "curl https://src.fedoraproject.org/rpms/hello/raw/rawhide/f/hello.spec > $tmp/hello-1.spec"
rlRun "sed -i '1s/^/Epoch: 6\n/' $tmp/hello-1.spec"
rlRun "copr-cli build $PROJECT:custom:foo $tmp/hello-1.spec"

# And this is the package that builds on top of it (e.g. copr-cli)
rlRun "curl https://src.fedoraproject.org/rpms/hello/raw/rawhide/f/hello.spec > $tmp/hello-2.spec"
rlRun "sed -i '1s/^/BuildRequires: hello >= 6:\n/' $tmp/hello-2.spec"
rlRun "copr-cli build $PROJECT:custom:foo $tmp/hello-2.spec"
rlPhaseEnd

rlPhaseStartCleanup
cleanProject
rlPhaseEnd
rlJournalPrintText
rlJournalEnd
6 changes: 2 additions & 4 deletions doc/user_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,8 @@ submit one build directly into the project, one build to the
subproject.

The subproject builds are isolated from each other but they can all
see builds from the main ``test`` project repository. For the time
being, the builds in the ``test:custom:foo`` subproject don't see
other builds from the same subproject. This is not a design choice but
rather a missing feature.
see builds from their own repository and from the main ``test`` project
repository.

The subproject name has to start with the project name. It is followed
by either ``:custom:`` or ``:pr:`` and a suffix. The suffix can be
Expand Down
10 changes: 9 additions & 1 deletion frontend/coprs_frontend/coprs/logic/complex_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@ def create_object(self, clazz, from_object, exclude=list()):

class BuildConfigLogic(object):
@classmethod
def generate_build_config(cls, copr, chroot_id):
def generate_build_config(cls, coprdir, chroot_id):
""" Return dict with proper build config contents """
copr = coprdir.copr
chroot = None
for i in copr.active_copr_chroots:
if i.mock_chroot.name == chroot_id:
Expand All @@ -610,6 +611,13 @@ def generate_build_config(cls, copr, chroot_id):
"name": "Copr buildroot",
})

if not coprdir.main:
repos.append({
"id": "copr_coprdir",
"baseurl": coprdir.repo_url + "/{}/".format(chroot_id),
"name": "Coprdir repository",
})

# None value of the priority won't show in API
if copr.repo_priority in [None, DEFAULT_COPR_REPO_PRIORITY]:
repo_priority = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def to_dict(build_chroot):


def build_config(build_chroot):
config = BuildConfigLogic.generate_build_config(build_chroot.build.copr, build_chroot.name)
config = BuildConfigLogic.generate_build_config(
build_chroot.build.copr_dir, build_chroot.name)
copr_chroot = CoprChrootsLogic.get_by_name_or_none(build_chroot.build.copr, build_chroot.name)
dict_data = {
"repos": config.get("repos"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def to_dict(project_chroot):


def to_build_config_dict(project_chroot):
config = BuildConfigLogic.generate_build_config(project_chroot.copr, project_chroot.name)
config = BuildConfigLogic.generate_build_config(
project_chroot.copr.main_dir, project_chroot.name)
config_dict = {
"chroot": project_chroot.name,
"repos": config["repos"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def get_build_record(task, for_backend=False):
if modules:
build_record["modules"] = {'toggle': modules}

build_config = BuildConfigLogic.generate_build_config(task.build.copr, task.mock_chroot.name)
build_config = BuildConfigLogic.generate_build_config(
task.build.copr_dir, task.mock_chroot.name)
build_record["repos"] = build_config.get("repos")
build_record["buildroot_pkgs"] = build_config.get("additional_packages")
build_record["with_opts"] = build_config.get("with_opts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ def test_generate_build_config_with_dep_mistake(self):
"/results/user1/foocopr/fedora-18-x86_64/",
"priority": None,
}
build_config = bcl.generate_build_config(self.c1, "fedora-18-x86_64")
build_config = bcl.generate_build_config(self.c1.main_dir, "fedora-18-x86_64")
assert build_config["repos"] == [main_repo]

self.c1.repos = "copr://non/existing"
build_config = bcl.generate_build_config(self.c1, "fedora-18-x86_64")
build_config = bcl.generate_build_config(self.c1.main_dir, "fedora-18-x86_64")

# We put the link there, even though baseurl points to 404. The build
# will later fail on downloading the repository and user will be
Expand Down

0 comments on commit ff65588

Please sign in to comment.