From 9ed77f960c3caf99e55b368ba26693106e82243e Mon Sep 17 00:00:00 2001 From: Christian Cwienk Date: Tue, 12 Nov 2024 14:04:53 +0100 Subject: [PATCH] rm almost all remainders of `ctx_repository` --- .../model/traits/component_descriptor.py | 61 ++++++------------- concourse/steps/component_descriptor.mako | 15 +++-- concourse/steps/component_descriptor.py | 4 +- .../steps/component_descriptor_test.py | 2 + .../steps/update_component_deps_test.py | 6 -- 5 files changed, 31 insertions(+), 57 deletions(-) diff --git a/concourse/model/traits/component_descriptor.py b/concourse/model/traits/component_descriptor.py index eaff2dfc8..5a2fe5ac0 100644 --- a/concourse/model/traits/component_descriptor.py +++ b/concourse/model/traits/component_descriptor.py @@ -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, @@ -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) @@ -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 @@ -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: @@ -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: diff --git a/concourse/steps/component_descriptor.mako b/concourse/steps/component_descriptor.mako index 06d34d0ae..b7e065840 100644 --- a/concourse/steps/component_descriptor.mako +++ b/concourse/steps/component_descriptor.mako @@ -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() @@ -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( @@ -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, ) @@ -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(( @@ -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) diff --git a/concourse/steps/component_descriptor.py b/concourse/steps/component_descriptor.py index e7ccc47bb..729f2b4eb 100644 --- a/concourse/steps/component_descriptor.py +++ b/concourse/steps/component_descriptor.py @@ -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, ): @@ -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, ) ], diff --git a/test/concourse/steps/component_descriptor_test.py b/test/concourse/steps/component_descriptor_test.py index ce047cabd..940754262 100644 --- a/test/concourse/steps/component_descriptor_test.py +++ b/test/concourse/steps/component_descriptor_test.py @@ -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() diff --git a/test/concourse/steps/update_component_deps_test.py b/test/concourse/steps/update_component_deps_test.py index 3fe2ca1c2..6b541e224 100644 --- a/test/concourse/steps/update_component_deps_test.py +++ b/test/concourse/steps/update_component_deps_test.py @@ -1,5 +1,3 @@ -import ocm - import pytest import test_utils @@ -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)