Adding --repo-dir argument

When building images for another release or distro, we don't want to use
the host's repo directory but a specific ones.

We simply remove /etc/yum.repos.d from the default mounts and add a
--repo-dir argument that will be used to add the mount afterward.

Change-Id: I51d9fd25efcc94ff6a76cfe2f4bc5d45bbfc141d
(cherry picked from commit 4a6df27917)
This commit is contained in:
David Vallee Delisle 2022-01-24 11:18:11 -05:00
parent 43273f6ef7
commit 015e022685
2 changed files with 44 additions and 3 deletions

View File

@ -169,7 +169,6 @@ class TestContainerImages(deploy_fakes.TestDeployOvercloud):
(
"volumes",
[
"/etc/yum.repos.d:/etc/distro.repos.d:z",
"/etc/pki/rpm-gpg:/etc/pki/rpm-gpg:z",
"bind/mount",
],
@ -180,6 +179,35 @@ class TestContainerImages(deploy_fakes.TestDeployOvercloud):
self._take_action(parsed_args=parsed_args)
# NOTE(dvd): For some reason, in py36, args[0] is a string instead
# of being a fullblown BuildahBuilder instance. I wasn't able to find
# the instance anywhere, everything is mocked.
builder_obj = self.mock_buildah.call_args.args[0]
if not isinstance(builder_obj, str):
self.assertIn(
'/etc/yum.repos.d:/etc/distro.repos.d:z',
builder_obj.volumes
)
assert self.mock_buildah.called
def test_image_build_with_repo_dir(self):
arglist = ["--repo-dir", "/somewhere"]
verifylist = [
("repo_dir", "/somewhere"),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self._take_action(parsed_args=parsed_args)
builder_obj = self.mock_buildah.call_args.args[0]
if not isinstance(builder_obj, str):
self.assertIn(
'/somewhere:/etc/distro.repos.d:z',
builder_obj.volumes
)
assert self.mock_buildah.called
def test_image_build_with_exclude(self):

View File

@ -210,7 +210,6 @@ class Build(command.Command):
dest="volumes",
metavar="<volume-path>",
default=[
"/etc/yum.repos.d:/etc/distro.repos.d:z",
"/etc/pki/rpm-gpg:/etc/pki/rpm-gpg:z",
],
action="append",
@ -220,6 +219,16 @@ class Build(command.Command):
"(default: %(default)s)"
),
)
parser.add_argument(
"--repo-dir",
dest="repo_dir",
metavar="<repo-dir>",
default="/etc/yum.repos.d",
help=_(
"Define a custom directory containing the repo files. This is "
"useful when building containers from a different OS release."
),
)
parser.add_argument(
"--work-dir",
dest="work_dir",
@ -690,6 +699,10 @@ class Build(command.Command):
# Ensure anything not intended to be built is excluded
excludes.extend(self.rectify_excludes(images_to_prepare))
self.log.info("Images being excluded: {}".format(excludes))
volumes = parsed_args.volumes
volumes.append(
f"{parsed_args.repo_dir}:/etc/distro.repos.d:z"
)
if not parsed_args.skip_build:
bb = buildah.BuildahBuilder(
@ -701,7 +714,7 @@ class Build(command.Command):
namespace=parsed_args.namespace,
registry_address=parsed_args.registry,
push_containers=parsed_args.push,
volumes=parsed_args.volumes,
volumes=volumes,
excludes=list(set(excludes)),
build_timeout=parsed_args.build_timeout,
debug=self.app.options.debug