Skip to content

Commit

Permalink
infra/presubmit: Use apt-get update before installing (#12008)
Browse files Browse the repository at this point in the history
Otherwise, this may lead to issues such as
#11943 (comment)

Also, fix the broken `.zip` test.

---------

Co-authored-by: MarcoFalke <[email protected]>
Co-authored-by: jonathanmetzman <[email protected]>
  • Loading branch information
3 people committed Jun 4, 2024
1 parent 44abec5 commit 4bffaf8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
36 changes: 32 additions & 4 deletions infra/presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ def check_project_yaml(paths):

def _check_one_seed_corpus(path):
"""Returns False and prints error if |path| is a seed corpus."""
if os.path.dirname(os.path.dirname(path)) != 'projects':
if os.path.basename(os.path.dirname(os.path.dirname(path))) != 'projects':
return True

if os.path.splitext(path)[1] == 'zip':
if os.path.splitext(path)[1] == '.zip':
print('Don\'t commit seed corpora into the ClusterFuzz repo,'
'they bloat it forever.')
return False
Expand All @@ -249,11 +249,39 @@ def check_seed_corpus(paths):
return all([_check_one_seed_corpus(path) for path in paths])


def _check_one_apt_update(path):
"""Checks that a Dockerfile uses apt-update before apt-install"""
if os.path.basename(os.path.dirname(os.path.dirname(path))) != 'projects':
return True

if os.path.basename(path) != 'Dockerfile':
return True

with open(path, 'r') as file:
dockerfile = file.read()
if 'RUN apt install' in dockerfile or 'RUN apt-get install' in dockerfile:
print('Please add an "apt-get update" before "apt-get install". '
'Otherwise, a cached and outdated RUN layer may lead to install '
'failures.')
return False

return True


def check_apt_update(paths):
"""Checks that all Dockerfile use apt-update before apt-install"""
return all([_check_one_apt_update(path) for path in paths])


def do_checks(changed_files):
"""Runs all presubmit checks. Returns False if any fails."""
checks = [
check_license, yapf, check_project_yaml, check_lib_fuzzing_engine,
check_seed_corpus
check_license,
yapf,
check_project_yaml,
check_lib_fuzzing_engine,
check_seed_corpus,
check_apt_update,
]
# Use a list comprehension here and in other cases where we use all() so that
# we don't quit early on failure. This is more user-friendly since the more
Expand Down
2 changes: 1 addition & 1 deletion projects/xz-java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

FROM gcr.io/oss-fuzz-base/base-builder-jvm

RUN apt-get install ant -y
RUN apt-get update && apt-get install ant -y
RUN git clone --depth 1 https://github.com/tukaani-project/xz-java $SRC/xz-java

COPY build.sh $SRC/
Expand Down

0 comments on commit 4bffaf8

Please sign in to comment.