Skip to content

Commit

Permalink
convert binary build git url to https url with 'git' in path based on…
Browse files Browse the repository at this point in the history
… a option

* STONEBLD-1497

Signed-off-by: Robert Cerven <rcerven@redhat.com>
  • Loading branch information
rcerven committed Jul 13, 2023
1 parent e2a8768 commit 90dbf7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
13 changes: 13 additions & 0 deletions atomic_reactor/plugins/fetch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
from atomic_reactor.download import download_url
from atomic_reactor.utils.pnc import PNCUtil

try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse


class FetchSourcesPlugin(Plugin):
"""Download sources that may be used in further steps to compose Source Containers"""
Expand Down Expand Up @@ -201,8 +206,16 @@ def _get_cache_allowlist(self) -> List[Dict[str, Any]]:

def check_lookaside_cache_usage(self):
"""Check usage of lookaside cache, and fail if used"""
src_config = self.workflow.conf.source_container
rh_git_url = src_config.get('rh_git_url')
git_uri, git_commit = self.koji_build['source'].split('#')

if rh_git_url:
parsed = urlparse(git_uri)
if parsed.scheme == 'git':
new_path = '/git' + parsed.path
git_uri = parsed._replace(path=new_path, scheme='https').geturl()

source = GitSource('git', git_uri, provider_params={'git_commit': git_commit})
source_path = source.get()
sources_cache_file = os.path.join(source_path, 'sources')
Expand Down
5 changes: 5 additions & 0 deletions atomic_reactor/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@
"description": "Openshift memory request for build",
"type": "string",
"examples": ["1Gi", "3Gi"]
},
"rh_git_url": {
"description": "Convert binary build git url to RH one",
"type": "boolean",
"default": false
}
},
"additionalProperties": false
Expand Down
19 changes: 16 additions & 3 deletions tests/plugins/test_fetch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
'remote_source_url': 'remote_url'},
'operator-manifests': {},
'container_koji_task_id': 1},
'source': 'registry.com/repo#ref'}
'source': 'git://registry.com/repo#ref'}
KOJI_BUILD_MRS = {'build_id': 1, 'nvr': 'foobar-1-1', 'name': 'foobar', 'version': 1, 'release': 1,
'extra': {'image': {'parent_build_id': 10,
'pnc': {'builds': [{'id': 1234}]},
Expand Down Expand Up @@ -1128,8 +1128,10 @@ def test_denylist_srpms(self, requests_mock, koji_session, workflow, source_dir,
[],
'foobar', 'target1', False)])
@pytest.mark.parametrize('use_cache', [True, False, None])
@pytest.mark.parametrize('rh_git_url', [True, False, None])
def test_lookaside_cache(self, caplog, requests_mock, koji_session, workflow, source_dir,
allowlist_url, allowlist_json, component, target, in_list, use_cache):
allowlist_url, allowlist_json, component, target, in_list, use_cache,
rh_git_url):
mock_koji_manifest_download(source_dir, requests_mock)
koji_build_nvr = f'{component}-1-1'

Expand All @@ -1141,8 +1143,11 @@ def test_lookaside_cache(self, caplog, requests_mock, koji_session, workflow, so
rcm_json = yaml.safe_load(BASE_CONFIG_MAP)
rcm_json['source_container'] = {}

if rh_git_url is not None:
rcm_json['source_container']['rh_git_url'] = rh_git_url

if allowlist_url:
rcm_json['source_container'] = {'lookaside_cache_allowlist': allowlist_url}
rcm_json['source_container']['lookaside_cache_allowlist'] = allowlist_url

if allowlist_url and not allowlist_json:
requests_mock.register_uri('GET', allowlist_url,
Expand All @@ -1161,6 +1166,14 @@ def test_lookaside_cache(self, caplog, requests_mock, koji_session, workflow, so
runner = mock_env(workflow, source_dir, koji_build_nvr=koji_build_nvr,
config_map=yaml.safe_dump(rcm_json))

source_repo = 'git://registry.com/repo'
if rh_git_url:
source_repo = 'https://registry.com/git/repo'

(flexmock(atomic_reactor.source.GitSource)
.should_call("__init__")
.with_args('git', source_repo, provider_params=dict))

err_msg = 'Repository is using lookaside cache, which is not allowed ' \
'for source container builds'
if use_cache and allowlist_url and not allowlist_json:
Expand Down

0 comments on commit 90dbf7e

Please sign in to comment.