Skip to content

Commit

Permalink
rm almost all remainders of ctx_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ccwienk committed Nov 12, 2024
1 parent 5b13fb8 commit 9ed77f9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 57 deletions.
61 changes: 18 additions & 43 deletions concourse/model/traits/component_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,6 @@ class UploadMode(enum.StrEnum):
default=['ignore-me'],
doc='obsolete',
),
AttributeSpec.deprecated(
name='ctx_repository_base_url',
type=str,
default=None, # if not explicitly configured, will be injected from cicd-default
doc='''
the component descriptor context repository base_url (for component descriptor v2).
If not configured, the CICD-landscape's default ctx will be used.
'''
),
AttributeSpec.deprecated(
name='ctx_repository',
type=str,
default=None, # if not explicitly configured, will be injected from cicd-default
doc='''
the component descriptor context repository cfg name (for component descriptor v2).
If not configured, the CICD-landscape's default ctx will be used.
'''
),
AttributeSpec.optional(
name='ocm_repository',
type=str,
Expand Down Expand Up @@ -297,16 +279,16 @@ def validation_policies(self):

@property
def ocm_repository(self) -> ocm.OciOcmRepository:
ocm_repo = self.raw.get('ocm_repository') or self.raw.get('ctx_repository')
# XXX hack for unittests
if not self.cfg_set:
return None
ocm_repo = self.raw.get('ocm_repository')

# ocm_repo might be:
# - a cfg-element-name (type: CtxRepositoryCfg)
# - a ocm-repository-url (type: str)
# - a OCM Repository (type: dict / gcm.OcmRepository

# XXX hack for unittests
if not self.cfg_set:
return None

if ocm_repo:
try:
ctx_repo_cfg = self.cfg_set.ctx_repository(ocm_repo)
Expand All @@ -316,6 +298,7 @@ def ocm_repository(self) -> ocm.OciOcmRepository:
baseUrl=ocm_repo,
)
else:
# todo: configure all pipelines (make ocm_repository a mandatory attribute)
ctx_repo_cfg = self.cfg_set.ctx_repository()

ctx_repo_cfg: model.ctx_repository.CtxRepositoryCfg
Expand All @@ -324,24 +307,15 @@ def ocm_repository(self) -> ocm.OciOcmRepository:
baseUrl=ctx_repo_cfg.base_url(),
)

def ctx_repository_base_url(self):
ctx_repo = self.ocm_repository
# XXX hack for unittsts
if ctx_repo is None:
return None

# use default ctx_repository_base_url, if not explicitly configured
if not (base_url := self.raw.get('ctx_repository_base_url')):
return ctx_repo.baseUrl
else:
# XXX warn or even forbid, at least if different from ctx-repo-cfg?
return base_url

def component_labels(self):
return self.raw['component_labels']

def ocm_repository_mappings(self) -> list[OcmRepositoryMappingEntry]:
ocm_repository_url = self.ctx_repository_base_url()
if self.ocm_repository:
ocm_repository_url = self.ocm_repository.baseUrl
else:
ocm_repository_url = None

ocm_repository_mappings: list[dict] = self.raw['ocm_repository_mappings']

if not ocm_repository_url and not ocm_repository_mappings:
Expand Down Expand Up @@ -383,12 +357,13 @@ def transformer(self):
def validate(self):
super().validate()

ocm_repository_url = self.ctx_repository_base_url()
ocm_repository_mappings: list[dict] = self.raw['ocm_repository_mappings']
if not ocm_repository_url and ocm_repository_mappings:
raise ModelValidationError(
'ocm_repository_url must be defined if ocm_repository_mappings are'
)
if self.ocm_repository:
ocm_repository_url = self.ocm_repository.oci_ref
ocm_repository_mappings: list[dict] = self.raw['ocm_repository_mappings']
if not ocm_repository_url and ocm_repository_mappings:
raise ModelValidationError(
'ocm_repository_url must be defined if ocm_repository_mappings are'
)

for label in self.component_labels():
try:
Expand Down
15 changes: 9 additions & 6 deletions concourse/steps/component_descriptor.mako
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ main_repo = job_variant.main_repository()
main_repo_labels = main_repo.source_labels()
main_repo_path_env_var = main_repo.logical_name().replace('-', '_').upper() + '_PATH'
other_repos = [r for r in job_variant.repositories() if not r.is_main_repo()]
ctx_repository_base_url = descriptor_trait.ctx_repository_base_url() or ''
if descriptor_trait.ocm_repository:
ocm_repository_url = descriptor_trait.ocm_repository.oci_ref
else:
ocm_repository_url = None
retention_policy = descriptor_trait.retention_policy()
ocm_repository_mappings = descriptor_trait.ocm_repository_mappings()
Expand Down Expand Up @@ -87,7 +90,7 @@ with open(version_file_path) as f:
component_name = '${descriptor_trait.component_name()}'
component_labels = ${descriptor_trait.component_labels()}
component_name_v2 = component_name.lower() # OCI demands lowercase
ctx_repository_base_url = '${ctx_repository_base_url}'
ocm_repository_url = '${ocm_repository_url}'
${ocm_repository_lookup(ocm_repository_mappings)}
component_descriptor_lookup = cnudie.retrieve.create_default_component_descriptor_lookup(
Expand All @@ -108,7 +111,7 @@ base_descriptor_v2 = base_component_descriptor_v2(
component_labels=component_labels,
effective_version=effective_version,
source_labels=${[dataclasses.asdict(label) for label in main_repo_labels]},
ctx_repository_base_url=ctx_repository_base_url,
ocm_repository_url=ocm_repository_url,
commit=commit_hash,
repo_url=main_repo_url,
)
Expand Down Expand Up @@ -232,7 +235,7 @@ if os.path.isfile(descriptor_script):
subproc_env['COMPONENT_NAME'] = component_name
subproc_env['COMPONENT_VERSION'] = effective_version
subproc_env['EFFECTIVE_VERSION'] = effective_version
subproc_env['CURRENT_COMPONENT_REPOSITORY'] = ctx_repository_base_url
subproc_env['CURRENT_COMPONENT_REPOSITORY'] = ocm_repository_url
# pass predefined command to add dependencies for convenience purposes
add_dependencies_cmd = ' '.join((
Expand Down Expand Up @@ -284,8 +287,8 @@ else:
% if descriptor_trait.upload is comp_descr_trait.UploadMode.LEGACY:
% if not (job_variant.has_trait('release') or job_variant.has_trait('update_component_deps')):
if descriptor_v2 and ctx_repository_base_url:
ocm_repository = ocm.OciOcmRepository(baseUrl=ctx_repository_base_url)
if descriptor_v2 and ocm_repository_url:
ocm_repository = ocm.OciOcmRepository(baseUrl=ocm_repository_url)
if descriptor_v2.component.current_ocm_repo != ocm_repository:
descriptor_v2.component.repositoryContexts.append(ocm_repository)
Expand Down
4 changes: 2 additions & 2 deletions concourse/steps/component_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def base_component_descriptor_v2(
component_labels: list[ocm.Label],
effective_version: str,
source_labels: tuple,
ctx_repository_base_url: str,
ocm_repository_url: str,
commit: str,
repo_url: str,
):
Expand Down Expand Up @@ -80,7 +80,7 @@ def base_component_descriptor_v2(
version=effective_version,
repositoryContexts=[
ocm.OciOcmRepository(
baseUrl=ctx_repository_base_url,
baseUrl=ocm_repository_url,
type=ocm.AccessType.OCI_REGISTRY,
)
],
Expand Down
2 changes: 2 additions & 0 deletions test/concourse/steps/component_descriptor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def setUp(self):
variant_name='don\'t_care',
raw_dict={
'component_name': 'github.com/org/repo_name',
'upload': 'no-upload',
'ocm_repository': 'fake/ocm-repository',
},
)
self.component_descriptor_transformer = self.component_descriptor_trait.transformer()
Expand Down
6 changes: 0 additions & 6 deletions test/concourse/steps/update_component_deps_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ocm

import pytest

import test_utils
Expand Down Expand Up @@ -33,10 +31,6 @@ def job_variant():
},
)

component_descriptor_trait.ctx_repository = lambda: ocm.OciOcmRepository(
baseUrl='dummy-base-url',
)

main_repo = test_utils.repository()

job_variant = test_utils.job(main_repo)
Expand Down

0 comments on commit 9ed77f9

Please sign in to comment.