<#1184 fix: clear error for missing .dockerignore ...
# flyte-github
a
#1184 fix: clear error for missing .dockerignore in with_dockerignore Pull request opened by EngHabu Problem
Image.with_dockerignore(path)
stored the path as-is, and both build paths copied it into the build context with a bare
shutil.copy(layer.path, context_path)
. When the file wasn't there at build time — typically running
flyte deploy
from outside the project root — that raised a raw, uninformative
FileNotFoundError
which leaked to Sentry as if it were an SDK bug. Sentry: FLYTE-SDK-4Z (
FileNotFoundError: [Errno 2] No such file or directory: '.dockerignore'
, observed on 2.4.4). Fix Validate at build time only — in
remote_builder._get_layers_proto
and
docker_builder.DockerIgnoreHandler.handle
. Those are the only two places the file genuinely has to exist, and both raise a clear
ImageBuildError
(a
RuntimeUserError
, so it's shown to the user and filtered from Sentry) instead of the raw
FileNotFoundError
.
with_dockerignore()
itself is unchanged from
main
. Why no check at definition time An earlier revision validated inside
with_dockerignore()
. Per @pingsutw's review, that was wrong: image definitions are module-level code that also executes inside the container at task runtime, where the developer's
.dockerignore
is absent — so a definition-time check would raise spuriously.
DockerIgnore.update_hash
already falls back to hashing the path string when the file is missing, confirming "may not exist" was the intended contract. That revision also resolved the path to absolute. Dropped as well: it wasn't load-bearing. The Sentry stack shows the copy failing in
_get_layers_proto
, which runs client-side in the same process that defined the image, so there's no cwd mismatch to correct. Tests •
tests/flyte/test_image.py
— a missing
.dockerignore
must not raise at definition time, and
img.uri
must still compute (locks in the contract above). •
tests/flyte/imagebuild/test_docker_builder.py
— the build-time handler raises
ImageBuildError
for a missing file; happy-path copy still works.
tests/flyte/test_image.py
+
tests/flyte/imagebuild/
→ 184 passed. (
test_image_build_engine.py::test_persistent_cache_write_and_read
fails identically on
main
— pre-existing test-isolation issue, unrelated.) fixes FLYTE-SDK-4Z 🤖 Generated with Claude Code flyteorg/flyte-sdk