Skip to content

Commit

Permalink
cachi2: add init task
Browse files Browse the repository at this point in the history
Init task contains plugins which are responsible for fetching data and
validation. It split from prebuild task. Prebuild task compared to init
task, does changes to dockerfile.

This is prerequisite for having replacebale cachito task with cachi2
task in future, as this task has to be between init and prebuild.

Parameter --platforms-result has been moved to init task from prebuild
task, as init task now runs check_and_set_platforms plugin.

STONEBLD-2587

Signed-off-by: Martin Basti <mbasti@redhat.com>
  • Loading branch information
MartinBasti committed Sep 24, 2024
1 parent dd5a25b commit 7d301e1
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 49 deletions.
11 changes: 9 additions & 2 deletions atomic_reactor/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ def parse_args(args: Optional[Sequence[str]] = None) -> dict:
)
clone.set_defaults(func=task.clone)

binary_container_init = tasks.add_parser(
"binary-container-init",
help="binary container pre-build step",
description="Execute binary container pre-build steps.",
)
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_prebuild = tasks.add_parser(
"binary-container-prebuild",
help="binary container pre-build step",
description="Execute binary container pre-build steps.",
)
binary_container_prebuild.set_defaults(func=task.binary_container_prebuild)
binary_container_prebuild.add_argument("--platforms-result", metavar="FILE", default=None,
help="file to write final platforms result")

binary_container_build = tasks.add_parser(
"binary-container-build",
Expand Down
15 changes: 13 additions & 2 deletions atomic_reactor/cli/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
of the BSD license. See the LICENSE file for details.
"""
from atomic_reactor.tasks.binary import (BinaryExitTask, BinaryPostBuildTask, BinaryPreBuildTask,
PreBuildTaskParams, BinaryExitTaskParams)
BinaryInitTask,
InitTaskParams, BinaryExitTaskParams)
from atomic_reactor.tasks.binary_container_build import BinaryBuildTask, BinaryBuildTaskParams
from atomic_reactor.tasks.clone import CloneTask
from atomic_reactor.tasks.common import TaskParams
Expand Down Expand Up @@ -44,12 +45,22 @@ def clone(task_args: dict):
return task.run()


def binary_container_init(task_args: dict):
"""Run binary container pre-build steps.
:param task_args: CLI arguments for a binary-container-init task
"""
params = InitTaskParams.from_cli_args(task_args)
task = BinaryInitTask(params)
return task.run()


def binary_container_prebuild(task_args: dict):
"""Run binary container pre-build steps.
:param task_args: CLI arguments for a binary-container-prebuild task
"""
params = PreBuildTaskParams.from_cli_args(task_args)
params = TaskParams.from_cli_args(task_args)
task = BinaryPreBuildTask(params)
return task.run()

Expand Down
47 changes: 28 additions & 19 deletions atomic_reactor/tasks/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@


@dataclass(frozen=True)
class PreBuildTaskParams(TaskParams):
"""Binary container prebuild task parameters"""
class InitTaskParams(TaskParams):
"""Binary container init task parameters"""
platforms_result: Optional[str]


Expand All @@ -31,10 +31,10 @@ class BinaryExitTaskParams(TaskParams):
annotations_result: Optional[str]


class BinaryPreBuildTask(plugin_based.PluginBasedTask[PreBuildTaskParams]):
class BinaryInitTask(plugin_based.PluginBasedTask[InitTaskParams]):
"""Binary container pre-build task."""

task_name = 'binary_container_prebuild'
task_name = 'binary_container_init_build'
plugins_conf = [
{"name": "distgit_fetch_artefacts"},
{"name": "check_and_set_platforms"},
Expand All @@ -44,23 +44,9 @@ class BinaryPreBuildTask(plugin_based.PluginBasedTask[PreBuildTaskParams]):
{"name": "check_base_image"},
{"name": "koji_parent"},
{"name": "resolve_composes"},
{"name": "flatpak_update_dockerfile"},
{"name": "bump_release"},
{"name": "add_flatpak_labels"},
{"name": "add_labels_in_dockerfile"},
{"name": "resolve_remote_source"},
{"name": "pin_operator_digest"},
{"name": "add_help"},
{"name": "fetch_maven_artifacts"},
{"name": "add_image_content_manifest"},
{"name": "add_dockerfile"},
{"name": "inject_yum_repos"},
{"name": "add_filesystem"},
{"name": "change_from_in_dockerfile"},
{"name": "hide_files"},
{"name": "distribution_scope"},
{"name": "add_buildargs_in_dockerfile"},
{"name": "tag_from_config"},

]

def prepare_workflow(self) -> inner.DockerBuildWorkflow:
Expand All @@ -82,6 +68,29 @@ def prepare_workflow(self) -> inner.DockerBuildWorkflow:
return workflow


class BinaryPreBuildTask(plugin_based.PluginBasedTask[TaskParams]):
"""Binary container pre-build task."""

task_name = 'binary_container_prebuild'
plugins_conf = [
{"name": "flatpak_update_dockerfile"},
{"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"},
{"name": "inject_yum_repos"},
{"name": "add_filesystem"},
{"name": "change_from_in_dockerfile"},
{"name": "hide_files"},
{"name": "distribution_scope"},
{"name": "add_buildargs_in_dockerfile"},
{"name": "tag_from_config"},
]


class BinaryPostBuildTask(plugin_based.PluginBasedTask[TaskParams]):
"""Binary container post-build task."""

Expand Down
39 changes: 35 additions & 4 deletions tekton/pipelines/binary-container.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: binary-container-0-1 # dot is not allowed in the name
name: binary-container-0-2 # dot is not allowed in the name
spec:
params:
- name: osbs-image
Expand Down Expand Up @@ -34,7 +34,7 @@ spec:
- name: task_build_result_aarch64
value: $(tasks.binary-container-build-aarch64.results.task_result)
- name: platforms_result
value: $(tasks.binary-container-prebuild.results.platforms_result)
value: $(tasks.binary-container-init.results.platforms_result)
- name: annotations
value: $(finally.binary-container-exit.results.annotations)

Expand Down Expand Up @@ -66,11 +66,42 @@ spec:
value: '$(params.user-params)'
timeout: "0"

- name: binary-container-prebuild
- name: binary-container-init
runAfter:
- clone
taskRef:
name: binary-container-prebuild-0-1
name: binary-container-init-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-init
taskRef:
name: binary-container-prebuild-0-2
workspaces:
- name: ws-build-dir
workspace: ws-container
Expand Down
49 changes: 49 additions & 0 deletions tekton/tasks/binary-container-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: binary-container-init-0-1 # dot is not allowed in the name
spec:
description: >-
OSBS init 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

results:
- name: platforms_result

stepTemplate:
env:
- name: HOME
value: $(workspaces.ws-home-dir.path)

steps:
- name: binary-container-init
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-init --platforms-result=$(results.platforms_result.path)
7 changes: 2 additions & 5 deletions tekton/tasks/binary-container-prebuild.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: binary-container-prebuild-0-1 # dot is not allowed in the name
name: binary-container-prebuild-0-2 # dot is not allowed in the name
spec:
description: >-
OSBS prebuild task for building binary container image
Expand All @@ -25,9 +25,6 @@ spec:
- name: ws-reactor-config-map
- name: ws-autobot-keytab

results:
- name: platforms_result

stepTemplate:
env:
- name: HOME
Expand All @@ -46,4 +43,4 @@ 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-prebuild --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-prebuild
20 changes: 15 additions & 5 deletions tests/cli/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
**EXPECTED_ARGS,
"platform": "x86_64",
}
EXPECTED_ARGS_CONTAINER_PREBUILD = {
EXPECTED_ARGS_CONTAINER_INIT = {
**EXPECTED_ARGS,
"platforms_result": None,
}
Expand Down Expand Up @@ -79,9 +79,13 @@ def test_parse_args_version(capsys):
["task", *REQUIRED_COMMON_ARGS, "clone"],
{**EXPECTED_ARGS, "func": task.clone},
),
(
["task", *REQUIRED_COMMON_ARGS, "binary-container-init"],
{**EXPECTED_ARGS_CONTAINER_INIT, "func": task.binary_container_init},
),
(
["task", *REQUIRED_COMMON_ARGS, "binary-container-prebuild"],
{**EXPECTED_ARGS_CONTAINER_PREBUILD, "func": task.binary_container_prebuild},
{**EXPECTED_ARGS, "func": task.binary_container_prebuild},
),
(
["task", *REQUIRED_COMMON_ARGS, "binary-container-build",
Expand All @@ -107,10 +111,16 @@ def test_parse_args_version(capsys):
["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml", "clone"],
{**EXPECTED_ARGS, "config_file": "config.yaml", "func": task.clone},
),
(
["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml",
"binary-container-init"],
{**EXPECTED_ARGS_CONTAINER_INIT, "config_file": "config.yaml",
"func": task.binary_container_init},
),
(
["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml",
"binary-container-prebuild"],
{**EXPECTED_ARGS_CONTAINER_PREBUILD, "config_file": "config.yaml",
{**EXPECTED_ARGS, "config_file": "config.yaml",
"func": task.binary_container_prebuild},
),
(
Expand All @@ -132,10 +142,10 @@ def test_parse_args_version(capsys):
"func": task.binary_container_postbuild},
),
(
["task", *REQUIRED_COMMON_ARGS, "binary-container-prebuild",
["task", *REQUIRED_COMMON_ARGS, "binary-container-init",
"--platforms-result=platforms_file"],
{**EXPECTED_ARGS, "platforms_result": "platforms_file",
"func": task.binary_container_prebuild},
"func": task.binary_container_init},
),
(
["task", *REQUIRED_COMMON_ARGS, "--config-file=config.yaml", "binary-container-exit",
Expand Down
11 changes: 8 additions & 3 deletions tests/cli/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"config_file": "reactor-config-map.yaml",
"user_params": '{"some_param": "some_value"}',
}
PRE_TASK_ARGS = {
INIT_TASK_ARGS = {
**TASK_ARGS,
"platforms_result": 'platform_result',
}
Expand Down Expand Up @@ -60,9 +60,14 @@ def test_source_build():
assert task.source_container_build(TASK_ARGS) == TASK_RESULT


def test_binary_container_init():
mock(binary.BinaryInitTask, task_args=INIT_TASK_ARGS)
assert task.binary_container_init(INIT_TASK_ARGS) == TASK_RESULT


def test_binary_container_prebuild():
mock(binary.BinaryPreBuildTask, task_args=PRE_TASK_ARGS)
assert task.binary_container_prebuild(PRE_TASK_ARGS) == TASK_RESULT
mock(binary.BinaryPreBuildTask, task_args=TASK_ARGS)
assert task.binary_container_prebuild(TASK_ARGS) == TASK_RESULT


def test_binary_container_build():
Expand Down
Loading

0 comments on commit 7d301e1

Please sign in to comment.