Skip to content

Commit

Permalink
cachi2: use reflink if possible
Browse files Browse the repository at this point in the history
use reflink to copy sources into build dir to save space

Signed-off-by: Martin Basti <[email protected]>
  • Loading branch information
MartinBasti committed Nov 8, 2024
1 parent d44efda commit c996851
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions atomic_reactor/plugins/cachi2_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import json
import os.path
import shlex
import shutil
from dataclasses import dataclass
from pathlib import Path
from shutil import copytree
from typing import Any, Optional, List, Dict

import reflink

from atomic_reactor.constants import (
CACHITO_ENV_ARG_ALIAS,
CACHITO_ENV_FILENAME,
Expand All @@ -24,7 +27,7 @@
REMOTE_SOURCE_TARBALL_FILENAME,
REMOTE_SOURCE_JSON_ENV_FILENAME,
)
from atomic_reactor.dirs import BuildDir
from atomic_reactor.dirs import BuildDir, reflink_copy
from atomic_reactor.plugin import Plugin

from atomic_reactor.utils.cachi2 import generate_request_json
Expand Down Expand Up @@ -176,9 +179,18 @@ def inject_into_build_dir(
created_dirs.append(dest_dir)

# copy app and deps generated by cachito into build_dir
# TODO: reflink?
copytree(remote_source.sources_path/'app', dest_dir/'app', symlinks=True)
copytree(remote_source.sources_path/'deps', dest_dir/'deps', symlinks=True)
copy_method = shutil.copy2
if reflink.supported_at(dest_dir):
copy_method = reflink_copy
self.log.debug(
"copy method used for cachi2 build_dir_injecting: %s", copy_method.__name__)

copytree(
remote_source.sources_path/'app', dest_dir/'app',
symlinks=True, copy_function=copy_method)
copytree(
remote_source.sources_path/'deps', dest_dir/'deps',
symlinks=True, copy_function=copy_method)

# Create cachito.env file with environment variables received from cachito request
self.generate_cachito_env_file(dest_dir, remote_source.build_args)
Expand Down

0 comments on commit c996851

Please sign in to comment.