|
17 | 17 | DEPLOYMENT_CONFIGURATION_PATH, BASE_IMAGES_PATH, STATIC_IMAGES_PATH |
18 | 18 | from .utils import get_cluster_ip, env_variable, get_sub_paths, guess_build_dependencies_from_dockerfile, image_name_from_dockerfile_path, \ |
19 | 19 | get_template, merge_configuration_directories, dict_merge, app_name_from_path, \ |
20 | | - find_dockerfiles_paths |
| 20 | + find_dockerfiles_paths, get_git_commit_hash |
21 | 21 |
|
22 | 22 |
|
23 | 23 | KEY_HARNESS = 'harness' |
@@ -525,7 +525,33 @@ def values_set_legacy(values): |
525 | 525 |
|
526 | 526 | def generate_tag_from_content(content_path, ignore=()): |
527 | 527 | 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 |
529 | 555 |
|
530 | 556 |
|
531 | 557 | def extract_env_variables_from_values(values, envs=tuple(), prefix=''): |
|
0 commit comments