Skip to content

fix: clear error for missing .dockerignore in with_dockerignore#1184

Open
EngHabu wants to merge 1 commit into
mainfrom
fix/sentry-4z-dockerignore-missing
Open

fix: clear error for missing .dockerignore in with_dockerignore#1184
EngHabu wants to merge 1 commit into
mainfrom
fix/sentry-4z-dockerignore-missing

Conversation

@EngHabu

@EngHabu EngHabu commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Image.with_dockerignore(path) stored the path as-is and copied it into the build context with a bare shutil.copy(layer.path, context_path) in both the remote and local docker build paths. When the path was relative (e.g. .dockerignore), the remote builder — which runs from a different working directory than where the image was defined — could not find it and raised a raw, uninformative FileNotFoundError that leaked to Sentry.

Sentry: FLYTE-SDK-4Z (FileNotFoundError: [Errno 2] No such file or directory: '.dockerignore', observed on the latest release 2.4.4).

Fix

  • with_dockerignore() now resolves the path to an absolute path at definition time, so the file remains locatable at build time regardless of the builder's working directory.
  • If the file does not exist, it raises a clear ImageBuildError (a RuntimeUserError, which is filtered from Sentry) with an actionable message, instead of a raw FileNotFoundError.
  • Added the same defensive guard at both build-time copy sites (remote_builder._get_layers_proto and docker_builder.DockerIgnoreHandler.handle).

Tests

Added two tests in tests/flyte/test_image.py:

  • a missing .dockerignore path raises ImageBuildError
  • a relative path is resolved to an absolute, still-locatable path

All existing dockerignore tests still pass (9 passed), plus test_docker_builder.py (38 passed).

fixes FLYTE-SDK-4Z

🤖 Generated with Claude Code

@EngHabu EngHabu added the sentry-fix Fix for an issue surfaced by Sentry label Jun 10, 2026
Comment thread src/flyte/_image.py
Comment on lines +1188 to +1192
if not resolved.is_file():
raise flyte.errors.ImageBuildError(
f"The .dockerignore file specified via with_dockerignore() was not found at '{path}'. "
f"Ensure the path points to an existing file."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need the check here since the dockerignore file may not exist in the image at runtime

@EngHabu EngHabu force-pushed the fix/sentry-4z-dockerignore-missing branch from 43768ec to 52b3b68 Compare June 11, 2026 16:11

@EngHabu EngHabu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EngHabu EngHabu requested review from kumare3 and pingsutw June 11, 2026 19:39
@EngHabu EngHabu force-pushed the fix/sentry-4z-dockerignore-missing branch from 52b3b68 to 5f92cbd Compare June 12, 2026 16:09
A non-existent path passed to Image.with_dockerignore() surfaced as a raw
FileNotFoundError at build time (often because a relative path like
'.dockerignore' was resolved against the builder's working directory rather
than where the image was defined).

Resolve the path to an absolute path at definition time and raise a clear
ImageBuildError (a RuntimeUserError) when the file is missing, in both the
remote and local docker build paths.

fixes FLYTE-SDK-4Z

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
@EngHabu EngHabu force-pushed the fix/sentry-4z-dockerignore-missing branch from 5f92cbd to ad604f8 Compare June 13, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sentry-fix Fix for an issue surfaced by Sentry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants