Skip to content

Commit 7ee6414

Browse files
committed
Improve efficiency upon checking git dependency hashes
1 parent bff5c75 commit 7ee6414

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

tools/deployment-cli-tools/ch_cli_tools/configurationgenerator.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
DEPLOYMENT_CONFIGURATION_PATH, BASE_IMAGES_PATH, STATIC_IMAGES_PATH
1818
from .utils import get_cluster_ip, env_variable, get_sub_paths, guess_build_dependencies_from_dockerfile, image_name_from_dockerfile_path, \
1919
get_template, merge_configuration_directories, dict_merge, app_name_from_path, \
20-
find_dockerfiles_paths
20+
find_dockerfiles_paths, get_git_commit_hash
2121

2222

2323
KEY_HARNESS = 'harness'
@@ -525,7 +525,33 @@ def values_set_legacy(values):
525525

526526
def generate_tag_from_content(content_path, ignore=()):
527527
from dirhash import dirhash
528-
return dirhash(content_path, 'sha1', ignore=ignore)
528+
content_path = str(content_path)
529+
ignore = set(ignore)
530+
531+
# Cloned git repos always live under {content_path}/dependencies/ (possibly
532+
# nested one extra level, e.g. dependencies/{path}/{repo}).
533+
# Use their commit hash instead of hashing their content with dirhash.
534+
git_hashes = []
535+
dependencies_path = os.path.join(content_path, 'dependencies')
536+
if os.path.isdir(dependencies_path):
537+
ignore.add('dependencies')
538+
for dirpath, dirnames, _ in os.walk(dependencies_path):
539+
for dirname in list(dirnames):
540+
subdir = os.path.join(dirpath, dirname)
541+
if os.path.isdir(os.path.join(subdir, '.git')):
542+
dirnames.remove(dirname) # don't descend into the repo
543+
commit_hash = get_git_commit_hash(subdir)
544+
if commit_hash:
545+
logging.info(f"Using git commit hash {commit_hash} for cloned repo at {subdir}")
546+
git_hashes.append(commit_hash)
547+
else:
548+
logging.warning(f"Could not get git commit hash for repo at {subdir}")
549+
550+
content_hash = dirhash(content_path, 'sha1', ignore=ignore)
551+
552+
if git_hashes:
553+
return sha1((content_hash + ''.join(git_hashes)).encode('utf-8')).hexdigest()
554+
return content_hash
529555

530556

531557
def extract_env_variables_from_values(values, envs=tuple(), prefix=''):

0 commit comments

Comments
 (0)