Skip to content

Commit

Permalink
cachi2: separate cachito task
Browse files Browse the repository at this point in the history
Separating resolve_remote_sources into a standalone cachito task in
binary build, to allow us replacement with cachi2 in future.

STONEBLD-2587

Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed Sep 24, 2024
1 parent 7d301e1 commit 0b369b2
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 7 deletions.
7 changes: 7 additions & 0 deletions atomic_reactor/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion atomic_reactor/cli/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


def binary_container_prebuild(task_args: dict):
"""Run binary container pre-build steps.
Expand Down
10 changes: 9 additions & 1 deletion atomic_reactor/tasks/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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"},
Expand Down
33 changes: 32 additions & 1 deletion tekton/pipelines/binary-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions tekton/tasks/binary-container-cachito.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/cli/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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"],
Expand Down
5 changes: 5 additions & 0 deletions tests/cli/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tests/tasks/test_plugin_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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")
Expand Down

0 comments on commit 0b369b2

Please sign in to comment.