From 0e3ca9aed1c219bba8b4d9644a0adc7df4af64a9 Mon Sep 17 00:00:00 2001 From: Kevin Meinhardt Date: Mon, 6 Jan 2025 16:26:23 +0100 Subject: [PATCH] Add build logs for hashing --- Dockerfile | 5 ++++- scripts/build_info.py | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 76bdf90a0d6..8ccf368e0d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -202,7 +202,10 @@ ${HOME}/scripts/build_info.py \ --commit "${DOCKER_COMMIT}" \ --version "${DOCKER_VERSION}" \ --build "${DOCKER_BUILD}" \ - --target "${DOCKER_TARGET}" + --target "${DOCKER_TARGET}" \ + --verbose + # Add verbose logging so we can debug invalid hashes + # from the build logs EOF FROM base AS production diff --git a/scripts/build_info.py b/scripts/build_info.py index 100b57a8657..1af6a47d660 100755 --- a/scripts/build_info.py +++ b/scripts/build_info.py @@ -32,6 +32,8 @@ def hash_directory( hasher.update(f.name.encode()) if f.is_file(): hasher.update(f.read_bytes()) + if verbose: + print(f'{f.name.encode()}: {hasher.hexdigest()}') elif verbose: print(f'Skipping {f}') @@ -39,7 +41,11 @@ def hash_directory( def build_info( - commit: str = None, version: str = None, build: str = None, target: str = None + commit: str = None, + version: str = None, + build: str = None, + target: str = None, + verbose: bool = False, ): """ Create a build info file with the current build information from the environment. @@ -52,9 +58,14 @@ def build_info( 'source': 'https://github.com/mozilla/addons-server', 'content_hash': { 'site_static_hash': hash_directory( - (root / 'site-static'), exclude_patterns=['staticfiles.json'] + (root / 'site-static'), + exclude_patterns=['staticfiles.json'], + verbose=verbose, + ), + 'locale_hash': hash_directory( + (root / 'locale'), + verbose=verbose, ), - 'locale_hash': hash_directory((root / 'locale')), }, } @@ -68,10 +79,13 @@ def build_info( parser.add_argument('--build', type=str, required=False) # Docker target is used to determine build time and runtime behavior parser.add_argument('--target', type=str, required=True) + parser.add_argument('--verbose', action='store_true') args = parser.parse_args() - version = build_info(args.commit, args.version, args.build, args.target) + version = build_info( + args.commit, args.version, args.build, args.target, args.verbose + ) if args.output: with open(args.output, 'w') as f: