diff --git a/atomic_reactor/plugins/cachi2_init.py b/atomic_reactor/plugins/cachi2_init.py index 2d2a13fa2..79d50eab5 100644 --- a/atomic_reactor/plugins/cachi2_init.py +++ b/atomic_reactor/plugins/cachi2_init.py @@ -23,7 +23,7 @@ ) from atomic_reactor.plugin import Plugin from atomic_reactor.util import map_to_user_params -from atomic_reactor.utils.cachi2 import remote_source_to_cachi2 +from atomic_reactor.utils.cachi2 import remote_source_to_cachi2, clone_only class Cachi2InitPlugin(Plugin): @@ -72,6 +72,27 @@ def run(self) -> Optional[List[Dict[str, Any]]]: return processed_remote_sources + def clone_only_remote_source(self, remote_source_path: Path): + """Step when OSBS only is doing resolution without cachi2. + + Generate SBOM and env file for next plugins + """ + # generate empty SBOM + sbom_path = remote_source_path / "bom.json" + with open(sbom_path, "w") as f: + json.dump( + { + "bomFormat": "CycloneDX", + "components": [], + }, + f + ) + + # generate empty envs + env_path = remote_source_path / "cachi2.env.json" + with open(env_path, "w") as f: + json.dump([], f) + def process_remote_sources(self) -> List[Dict[str, Any]]: """Process remote source requests and return information about the processed sources.""" @@ -97,13 +118,6 @@ def process_remote_sources(self) -> List[Dict[str, Any]]: remote_source_data = remote_source["remote_source"] - self.write_cachi2_pkg_options( - remote_source_data, - source_path / CACHI2_PKG_OPTIONS_FILE) - self.write_cachi2_for_output_dir( - source_name, - source_path / CACHI2_FOR_OUTPUT_DIR_OPT_FILE) - source_path_app = source_path / CACHI2_BUILD_APP_DIR source_path_app.mkdir() @@ -113,6 +127,18 @@ def process_remote_sources(self) -> List[Dict[str, Any]]: remote_source_data["ref"] ) + if clone_only(remote_source_data): + # OSBS is doing all work here + self.clone_only_remote_source(source_path) + else: + # write cachi2 files only when cachi2 should run + self.write_cachi2_pkg_options( + remote_source_data, + source_path / CACHI2_PKG_OPTIONS_FILE) + self.write_cachi2_for_output_dir( + source_name, + source_path / CACHI2_FOR_OUTPUT_DIR_OPT_FILE) + processed_remote_sources.append({ "source_path": str(source_path), **remote_source, diff --git a/atomic_reactor/utils/cachi2.py b/atomic_reactor/utils/cachi2.py index 43740b045..25262a440 100644 --- a/atomic_reactor/utils/cachi2.py +++ b/atomic_reactor/utils/cachi2.py @@ -161,3 +161,14 @@ def generate_request_json( "packages": [], # this will be always empty cachi2 doesn't provide nested deps } return res + + +def clone_only(remote_source: Dict[str, Any]) -> bool: + """Determine if only cloning is required without cachi2 run""" + if "pkg_managers" not in remote_source: + return False + + if not remote_source["pkg_managers"]: + return True + + return False diff --git a/tekton/tasks/binary-container-cachi2.yaml b/tekton/tasks/binary-container-cachi2.yaml index 5bb865479..3aeba2b7c 100644 --- a/tekton/tasks/binary-container-cachi2.yaml +++ b/tekton/tasks/binary-container-cachi2.yaml @@ -77,6 +77,7 @@ spec: #!/usr/bin/bash set -eux CACHI2_DIR="$(workspaces.ws-build-dir.path)/_cachi2_remote_sources" + CACHI2_PKG_OPT_PATH="cachi2_pkg_options.json" if [ ! -d "$CACHI2_DIR" ]; then echo "Skipping step: remote sources not found" @@ -91,27 +92,34 @@ spec: pushd "${REMOTE_SOURCE_PATH}" - FOR_OUTPUT_DIR="$(cat cachi2_for_output_dir_opt.txt)" + if [ -f "${CACHI2_PKG_OPT_PATH}" ]; then + # missing pkg opt config file; OSBS doesn't want to run cachi2 + FOR_OUTPUT_DIR="$(cat cachi2_for_output_dir_opt.txt)" - cachi2 --log-level="$LOG_LEVEL" fetch-deps \ - --source="${REMOTE_SOURCE_PATH}/app/" \ - --output="${REMOTE_SOURCE_PATH}" \ - "$(cat cachi2_pkg_options.json)" + cachi2 --log-level="$LOG_LEVEL" fetch-deps \ + --source="${REMOTE_SOURCE_PATH}/app/" \ + --output="${REMOTE_SOURCE_PATH}" \ + "$(cat "${CACHI2_PKG_OPT_PATH}")" - SBOMS+=("${REMOTE_SOURCE_PATH}/bom.json") + cachi2 --log-level="$LOG_LEVEL" generate-env "${REMOTE_SOURCE_PATH}" \ + --format json \ + --for-output-dir="${FOR_OUTPUT_DIR}" \ + --output "${REMOTE_SOURCE_PATH}/cachi2.env.json" + else + mkdir deps/ # create empty deps/ dir to emulate cachi2 run + fi - cachi2 --log-level="$LOG_LEVEL" generate-env "${REMOTE_SOURCE_PATH}" \ - --format json \ - --for-output-dir="${FOR_OUTPUT_DIR}" \ - --output "${REMOTE_SOURCE_PATH}/cachi2.env.json" + SBOMS+=("${REMOTE_SOURCE_PATH}/bom.json") rm -fr app/.git/ # remove git directory # create source archive before injecting files tar -czf remote-source.tar.gz app/ deps/ - cachi2 --log-level="$LOG_LEVEL" inject-files "${REMOTE_SOURCE_PATH}" \ - --for-output-dir="${FOR_OUTPUT_DIR}" + if [ -f "${CACHI2_PKG_OPT_PATH}" ]; then + cachi2 --log-level="$LOG_LEVEL" inject-files "${REMOTE_SOURCE_PATH}" \ + --for-output-dir="${FOR_OUTPUT_DIR}" + fi popd done