Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert binary build git url to https url with 'git' in path based on a option #2080

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading