From db0fb488bc2e42f62c384da1d3e9753def4b9ad1 Mon Sep 17 00:00:00 2001 From: Ethan Wu Date: Sat, 27 Feb 2021 00:15:14 -0800 Subject: [PATCH] fix(docker): exclude .dockerignore from context hash Since `.dockerignore` is a means to control what is in the build context, the contents of the file itself should not be included in the context hash. See #117 for more details. Closes #117 --- rcds/challenge/docker.py | 5 ++++- tests/challenge/test_docker.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rcds/challenge/docker.py b/rcds/challenge/docker.py index 1272d12..b09c2ae 100644 --- a/rcds/challenge/docker.py +++ b/rcds/challenge/docker.py @@ -58,7 +58,10 @@ def get_context_files(root: Path) -> Iterator[Path]: for line in fd ), ) - files = filter(lambda p: not spec.match_file(p.relative_to(root)), files) + files = filter( + lambda p: not spec.match_file(p.relative_to(root)) and p != dockerignore, + files, + ) return filter(lambda p: p.is_file(), files) diff --git a/tests/challenge/test_docker.py b/tests/challenge/test_docker.py index e906e01..12df32b 100644 --- a/tests/challenge/test_docker.py +++ b/tests/challenge/test_docker.py @@ -26,7 +26,7 @@ def test_with_dockerignore(self, datadir: Path) -> None: df_root = datadir / "contexts" / "dockerignore" assert df_root.is_dir() got = {str(p.relative_to(df_root)) for p in docker.get_context_files(df_root)} - assert got == {"Dockerfile", ".dockerignore", ".file", "file"} + assert got == {"Dockerfile", ".file", "file"} def test_complex_dockerignore(self, datadir: Path) -> None: df_root = datadir / "contexts" / "complex_dockerignore"