From 3028d0718200f3ce55103cbb5b1bb4f9cc674393 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 26 Oct 2022 17:19:12 +0200 Subject: [PATCH] fix: create src directory in any case The original behavior was to create an src directory with the content of the repository. The creation would happen in any case (remote or local repository). With the filtering in place and the default to remove the .git folder, it breaks the build as the src folder can be missing. This patch ensures that the directory is present in the tar so the build can continue as it did until now. --- repo2docker/buildpacks/base.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repo2docker/buildpacks/base.py b/repo2docker/buildpacks/base.py index 9d164ff1..af4e7129 100644 --- a/repo2docker/buildpacks/base.py +++ b/repo2docker/buildpacks/base.py @@ -627,8 +627,17 @@ class BuildPack: if not exclude: exclude = ["**/.git"] - for item in exclude_paths(".", exclude): - tar.add(item, f"src/{item}", filter=_filter_tar) + files_to_add = exclude_paths(".", exclude) + + if files_to_add: + for item in files_to_add: + tar.add(item, f"src/{item}", filter=_filter_tar) + else: + # Either the source was empty or everything was filtered out. + # In any case, create an src dir so the build can proceed. + src = tarfile.TarInfo("src") + src.type = tarfile.DIRTYPE + tar.addfile(src) tar.close() tarf.seek(0)