Skip to content

Commit

Permalink
cachi2: support both Cachito and Cachi2
Browse files Browse the repository at this point in the history
User/admin may specify which version of remote sources should be used
(or used by default):
 - 1: Cachito (current default)
 - 2: Cachi2

Build pipeline will then use the right task based on condition using
result from the init task.

STONEBLD-2591

Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed Nov 18, 2024
1 parent 0faf9eb commit f653ac9
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions atomic_reactor/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def parse_args(args: Optional[Sequence[str]] = None) -> dict:
binary_container_init.set_defaults(func=task.binary_container_init)
binary_container_init.add_argument("--platforms-result", metavar="FILE", default=None,
help="file to write final platforms result")
binary_container_init.add_argument("--remote-sources-version-result", metavar="FILE",
default=None,
help="file to write final remote-sources version result")

binary_container_cachito = tasks.add_parser(
"binary-container-cachito",
Expand Down
5 changes: 5 additions & 0 deletions atomic_reactor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class ReactorConfigKeys(object):
OPERATOR_MANIFESTS_KEY = 'operator_manifests'
IMAGE_SIZE_LIMIT_KEY = 'image_size_limit'
BUILDER_CA_BUNDLE_KEY = 'builder_ca_bundle'
REMOTE_SOURCES_DEFAULT_VERSION = 'remote_sources_default_version'


class ODCSConfig(object):
Expand Down Expand Up @@ -511,3 +512,7 @@ def image_size_limit(self):
@property
def builder_ca_bundle(self):
return self._get_value(ReactorConfigKeys.BUILDER_CA_BUNDLE_KEY, fallback=None)

@property
def remote_sources_default_version(self):
return self._get_value(ReactorConfigKeys.REMOTE_SOURCES_DEFAULT_VERSION, fallback=1)
2 changes: 2 additions & 0 deletions atomic_reactor/inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def __init__(
plugin_files: Optional[List[str]] = None,
keep_plugins_running: bool = False,
platforms_result: Optional[str] = None,
remote_sources_version_result: Optional[str] = None,
annotations_result: Optional[str] = None,
):
"""
Expand Down Expand Up @@ -493,6 +494,7 @@ def __init__(
self.source = source or DummySource(None, None)
self.user_params = user_params or self._default_user_params.copy()
self.platforms_result = platforms_result
self.remote_sources_version_result = remote_sources_version_result
self.annotations_result = annotations_result

self.keep_plugins_running = keep_plugins_running
Expand Down
12 changes: 12 additions & 0 deletions atomic_reactor/plugins/check_user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,21 @@ def validate_user_config_files(self):
read_fetch_artifacts_url(self.workflow)
read_content_sets(self.workflow)

def resolve_remote_sources_version(self) -> int:
"""Resolve which version of remote sources should be used"""
version = self.workflow.source.config.remote_sources_version
if not version:
version = self.workflow.conf.remote_sources_default_version

self.log.info("Remote sources version to be used: %d", version)
if self.workflow.remote_sources_version_result:
with open(self.workflow.remote_sources_version_result, 'w') as f:
f.write(f"{version}")

def run(self):
"""
run the plugin
"""
self.dockerfile_checks()
self.validate_user_config_files()
self.resolve_remote_sources_version()
6 changes: 6 additions & 0 deletions atomic_reactor/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@
}
},
"additionalProperties": false
},
"remote_sources_default_version": {
"description": "Default version of remote sources resolving which will be used when user doesn't explicitly specify it",
"type": "number",
"minimum": 1,
"maximum": 2
}
},
"definitions": {
Expand Down
1 change: 1 addition & 0 deletions atomic_reactor/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self, build_path):
self.compose.pop('inherit', None)
self.remote_source = self.data.get('remote_source')
self.remote_sources = self.data.get('remote_sources')
self.remote_sources_version = self.data.get('remote_sources_version', 1)
self.operator_manifests = self.data.get('operator_manifests')

self.platforms = self.data.get('platforms') or {'not': [], 'only': []}
Expand Down
2 changes: 2 additions & 0 deletions atomic_reactor/tasks/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class InitTaskParams(TaskParams):
"""Binary container init task parameters"""
platforms_result: Optional[str]
remote_sources_version_result: Optional[str]


@dataclass(frozen=True)
Expand Down Expand Up @@ -68,6 +69,7 @@ def prepare_workflow(self) -> inner.DockerBuildWorkflow:
plugins_conf=self.plugins_conf,
keep_plugins_running=self.keep_plugins_running,
platforms_result=self._params.platforms_result,
remote_sources_version_result=self._params.remote_sources_version_result,
)
return workflow

Expand Down
45 changes: 45 additions & 0 deletions tekton/pipelines/binary-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ spec:
- name: osbs-image
description: The location of the OSBS builder image (FQDN pullspec)
type: string
- name: cachi2-image
description: The location of the Cachi2 image (FQDN pullspec)
type: string
- name: user-params
type: string
description: User parameters in JSON format
Expand Down Expand Up @@ -140,11 +143,53 @@ spec:
value: "$(context.pipelineRun.name)"
- name: user-params
value: '$(params.user-params)'
when:
- input: "$(tasks.binary-container-init.results.remote_sources_version_result)"
operator: in
values: ["1"]
timeout: "0"

- name: binary-container-cachi2
runAfter:
- binary-container-init
taskRef:
name: binary-container-cachi2-0-1
workspaces:
- name: ws-build-dir
workspace: ws-container
subPath: build-dir
- name: ws-context-dir
workspace: ws-container
subPath: context-dir
- name: ws-home-dir
workspace: ws-home-dir
- name: ws-registries-secret
workspace: ws-registries-secret
- name: ws-koji-secret
workspace: ws-koji-secret
- name: ws-reactor-config-map
workspace: ws-reactor-config-map
- name: ws-autobot-keytab
workspace: ws-autobot-keytab
params:
- name: osbs-image
value: "$(params.osbs-image)"
- name: cachi2-image
value: "$(params.cachi2-image)"
- name: pipeline-run-name
value: "$(context.pipelineRun.name)"
- name: user-params
value: '$(params.user-params)'
when:
- input: "$(tasks.binary-container-init.results.remote_sources_version_result)"
operator: in
values: ["2"]
timeout: "0"

- name: binary-container-prebuild
runAfter:
- binary-container-cachito
- binary-container-cachi2
taskRef:
resolver: git
params:
Expand Down
12 changes: 11 additions & 1 deletion tekton/tasks/binary-container-init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:

results:
- name: platforms_result
- name: remote_sources_version_result

stepTemplate:
env:
Expand All @@ -46,4 +47,13 @@ spec:
cpu: 395m
script: |
set -x
atomic-reactor -v task --user-params='$(params.user-params)' --build-dir=$(workspaces.ws-build-dir.path) --context-dir=$(workspaces.ws-context-dir.path) --config-file=$(workspaces.ws-reactor-config-map.path)/config.yaml --namespace=$(context.taskRun.namespace) --pipeline-run-name="$(params.pipeline-run-name)" binary-container-init --platforms-result=$(results.platforms_result.path)
atomic-reactor -v task \
--user-params='$(params.user-params)' \
--build-dir=$(workspaces.ws-build-dir.path) \
--context-dir=$(workspaces.ws-context-dir.path) \
--config-file=$(workspaces.ws-reactor-config-map.path)/config.yaml \
--namespace=$(context.taskRun.namespace) \
--pipeline-run-name="$(params.pipeline-run-name)" \
binary-container-init \
--platforms-result=$(results.platforms_result.path) \
--remote-sources-version-result=$(results.remote_sources_version_result.path)
1 change: 1 addition & 0 deletions tests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class StubConfig(object):
image_build_method = None
release_env_var = None
remote_sources_version = 1


class StubSource(object):
Expand Down

0 comments on commit f653ac9

Please sign in to comment.