diff --git a/atomic_reactor/cli/parser.py b/atomic_reactor/cli/parser.py index c86c38385..e488634ad 100644 --- a/atomic_reactor/cli/parser.py +++ b/atomic_reactor/cli/parser.py @@ -87,6 +87,13 @@ def parse_args(args: Optional[Sequence[str]] = None) -> dict: binary_container_init.add_argument("--platforms-result", metavar="FILE", default=None, help="file to write final platforms result") + binary_container_cachito = tasks.add_parser( + "binary-container-cachito", + help="binary container cachito step", + description="Execute binary container cachito steps.", + ) + binary_container_cachito.set_defaults(func=task.binary_container_cachito) + binary_container_prebuild = tasks.add_parser( "binary-container-prebuild", help="binary container pre-build step", diff --git a/atomic_reactor/cli/task.py b/atomic_reactor/cli/task.py index 8281be89e..4e6d871b3 100644 --- a/atomic_reactor/cli/task.py +++ b/atomic_reactor/cli/task.py @@ -6,7 +6,7 @@ of the BSD license. See the LICENSE file for details. """ from atomic_reactor.tasks.binary import (BinaryExitTask, BinaryPostBuildTask, BinaryPreBuildTask, - BinaryInitTask, + BinaryInitTask, BinaryCachitoTask, InitTaskParams, BinaryExitTaskParams) from atomic_reactor.tasks.binary_container_build import BinaryBuildTask, BinaryBuildTaskParams from atomic_reactor.tasks.clone import CloneTask @@ -55,6 +55,16 @@ def binary_container_init(task_args: dict): return task.run() +def binary_container_cachito(task_args: dict): + """Run binary container Cachito steps. + + :param task_args: CLI arguments for a binary-container-cachito task + """ + params = TaskParams.from_cli_args(task_args) + task = BinaryCachitoTask(params) + return task.run(init_build_dirs=True) + + def binary_container_prebuild(task_args: dict): """Run binary container pre-build steps. diff --git a/atomic_reactor/tasks/binary.py b/atomic_reactor/tasks/binary.py index c7ad97d58..88f285afd 100644 --- a/atomic_reactor/tasks/binary.py +++ b/atomic_reactor/tasks/binary.py @@ -68,6 +68,15 @@ def prepare_workflow(self) -> inner.DockerBuildWorkflow: return workflow +class BinaryCachitoTask(plugin_based.PluginBasedTask[TaskParams]): + """Binary container Cachito task.""" + + task_name = 'binary_container_cachito' + plugins_conf = [ + {"name": "resolve_remote_source"}, + ] + + class BinaryPreBuildTask(plugin_based.PluginBasedTask[TaskParams]): """Binary container pre-build task.""" @@ -77,7 +86,6 @@ class BinaryPreBuildTask(plugin_based.PluginBasedTask[TaskParams]): {"name": "bump_release"}, {"name": "add_flatpak_labels"}, {"name": "add_labels_in_dockerfile"}, - {"name": "resolve_remote_source"}, {"name": "add_help"}, {"name": "add_image_content_manifest"}, {"name": "add_dockerfile"}, diff --git a/tekton/pipelines/binary-container.yaml b/tekton/pipelines/binary-container.yaml index 5a74c2a24..7afcd2a95 100644 --- a/tekton/pipelines/binary-container.yaml +++ b/tekton/pipelines/binary-container.yaml @@ -97,9 +97,40 @@ spec: value: '$(params.user-params)' timeout: "0" - - name: binary-container-prebuild + - name: binary-container-cachito runAfter: - binary-container-init + taskRef: + name: binary-container-cachito-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: pipeline-run-name + value: "$(context.pipelineRun.name)" + - name: user-params + value: '$(params.user-params)' + timeout: "0" + + - name: binary-container-prebuild + runAfter: + - binary-container-cachito taskRef: name: binary-container-prebuild-0-2 workspaces: diff --git a/tekton/tasks/binary-container-cachito.yaml b/tekton/tasks/binary-container-cachito.yaml new file mode 100644 index 000000000..5ad07664d --- /dev/null +++ b/tekton/tasks/binary-container-cachito.yaml @@ -0,0 +1,46 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: binary-container-cachito-0-1 # dot is not allowed in the name +spec: + description: >- + OSBS cachito task for building binary container image + params: + - name: osbs-image + description: The location of the OSBS builder image (FQDN pullspec) + type: string + - name: pipeline-run-name + type: string + description: PipelineRun name to reference current PipelineRun + - name: user-params + type: string + description: User parameters in JSON format + + workspaces: + - name: ws-build-dir + - name: ws-context-dir + - name: ws-home-dir + - name: ws-registries-secret # access with $(workspaces.ws-registries-secret.path)/token + - name: ws-koji-secret # access with $(workspaces.ws-koji-secret.path)/token + - name: ws-reactor-config-map + - name: ws-autobot-keytab + + stepTemplate: + env: + - name: HOME + value: $(workspaces.ws-home-dir.path) + + steps: + - name: binary-container-cachito + image: $(params.osbs-image) + workingDir: $(workspaces.ws-home-dir.path) + resources: + requests: + memory: 512Mi + cpu: 250m + limits: + memory: 1Gi + 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-cachito diff --git a/tests/cli/test_parser.py b/tests/cli/test_parser.py index 6caebd9fc..8b3c66683 100644 --- a/tests/cli/test_parser.py +++ b/tests/cli/test_parser.py @@ -83,6 +83,10 @@ def test_parse_args_version(capsys): ["task", *REQUIRED_COMMON_ARGS, "binary-container-init"], {**EXPECTED_ARGS_CONTAINER_INIT, "func": task.binary_container_init}, ), + ( + ["task", *REQUIRED_COMMON_ARGS, "binary-container-cachito"], + {**EXPECTED_ARGS, "func": task.binary_container_cachito}, + ), ( ["task", *REQUIRED_COMMON_ARGS, "binary-container-prebuild"], {**EXPECTED_ARGS, "func": task.binary_container_prebuild}, @@ -117,6 +121,12 @@ def test_parse_args_version(capsys): {**EXPECTED_ARGS_CONTAINER_INIT, "config_file": "config.yaml", "func": task.binary_container_init}, ), + ( + ["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml", + "binary-container-cachito"], + {**EXPECTED_ARGS, "config_file": "config.yaml", + "func": task.binary_container_cachito}, + ), ( ["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml", "binary-container-prebuild"], diff --git a/tests/cli/test_task.py b/tests/cli/test_task.py index 16d03a803..952a3d4c6 100644 --- a/tests/cli/test_task.py +++ b/tests/cli/test_task.py @@ -65,6 +65,11 @@ def test_binary_container_init(): assert task.binary_container_init(INIT_TASK_ARGS) == TASK_RESULT +def test_binary_container_cachito(): + mock(binary.BinaryCachitoTask, task_args=TASK_ARGS) + assert task.binary_container_cachito(TASK_ARGS) == TASK_RESULT + + def test_binary_container_prebuild(): mock(binary.BinaryPreBuildTask, task_args=TASK_ARGS) assert task.binary_container_prebuild(TASK_ARGS) == TASK_RESULT diff --git a/tests/tasks/test_plugin_based.py b/tests/tasks/test_plugin_based.py index f951e201c..2e24d2cad 100644 --- a/tests/tasks/test_plugin_based.py +++ b/tests/tasks/test_plugin_based.py @@ -17,7 +17,9 @@ from atomic_reactor.inner import ImageBuildWorkflowData from atomic_reactor.plugin import TaskCanceledException, PluginFailedException from atomic_reactor.tasks.common import TaskParams -from atomic_reactor.tasks.binary import InitTaskParams, BinaryPreBuildTask, BinaryInitTask +from atomic_reactor.tasks.binary import ( + InitTaskParams, BinaryPreBuildTask, BinaryInitTask, BinaryCachitoTask, +) from atomic_reactor.util import DockerfileImages from atomic_reactor import inner, dirs @@ -228,8 +230,9 @@ def test_ensure_workflow_data_is_saved_init_task( assert {} == wf_data.plugins_results -def test_ensure_workflow_data_is_saved_prebuild_task( - build_dir, dummy_source, tmpdir +@pytest.mark.parametrize("taskfunc", [BinaryCachitoTask, BinaryPreBuildTask]) +def test_ensure_workflow_data_is_saved_standard_task( + build_dir, dummy_source, tmpdir, taskfunc ): context_dir = tmpdir.join("context_dir").mkdir() params = TaskParams(build_dir=str(build_dir), @@ -243,7 +246,7 @@ def test_ensure_workflow_data_is_saved_prebuild_task( .should_receive("source") .and_return(dummy_source)) - task = BinaryPreBuildTask(params) + task = taskfunc(params) (flexmock(plugin_based.inner.DockerBuildWorkflow) .should_receive("build_container_image")