Skip to content

Commit

Permalink
Add build logs for hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Jan 24, 2025
1 parent 3c8f321 commit 0e3ca9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions scripts/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ 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}')

return hasher.hexdigest()


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.
Expand All @@ -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')),
},
}

Expand All @@ -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:
Expand Down

0 comments on commit 0e3ca9a

Please sign in to comment.