Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #561 from vfreex/cachito-flags
Browse files Browse the repository at this point in the history
Add options to config Cachito flags
  • Loading branch information
vfreex committed Feb 25, 2022
2 parents 4536a58 + b8c7161 commit 01e6044
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions doozerlib/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,28 @@ def _generate_osbs_image_config(self, version: str) -> Dict:
pkg_managers = self._detect_package_manangers()
else:
raise ValueError(f"Invalid content.source.pkg_managers config for image {self.name}: {self.config.content.source.pkg_managers}")
# Configure Cachito flags
# https://github.com/containerbuildsystem/cachito#flags
flags = []
if isinstance(self.config.cachito.flags, ListModel):
flags = self.config.cachito.flags.primitive()
elif isinstance(self.runtime.group_config.cachito.flags, ListModel):
flags = set(self.runtime.group_config.cachito.flags.primitive())
if 'gomod' not in pkg_managers:
# Remove gomod related flags if gomod is not used.
flags -= {"cgo-disable", "gomod-vendor", "gomod-vendor-check"}
elif not self.dg_path.joinpath('vendor').is_dir():
# Remove gomod-vendor-check flag if vendor/ is not present when gomod is used
flags -= {"gomod-vendor-check"}
flags = list(flags)

remote_source = {
'repo': convert_remote_git_to_https(self.actual_source_url),
'ref': self.source_full_sha,
'pkg_managers': pkg_managers,
}
if 'gomod' in remote_source['pkg_managers']: # if source is golang
# if we have a vendor directory, we will need to add gomod-vendor-check as well: https://github.com/containerbuildsystem/cachito#flags
if self.dg_path.joinpath('vendor').is_dir():
remote_source.setdefault('flags', []).append('gomod-vendor-check')
if flags:
remote_source['flags'] = flags
config_overrides.update({
'remote_sources': [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def test_generate_osbs_image_config_with_cachito_enabled(self, is_dir: Mock):
"content": {
"source": {"git": {"url": "git@example.com:openshift-priv/foo.git", "branch": {"target": "release-4.10"}}}
},
"cachito": {"enabled": True}
"cachito": {"enabled": True, "flags": ["gomod-vendor-check"]}
},
}))
dg = distgit.ImageDistGitRepo(meta, autoclone=False)
Expand Down

0 comments on commit 01e6044

Please sign in to comment.