Skip to content

Report an unreadable build context as permission denied, not a missing Dockerfile - #2093

Open
devops-thiago wants to merge 1 commit into
apple:mainfrom
devops-thiago:build-context-unreadable-error
Open

Report an unreadable build context as permission denied, not a missing Dockerfile#2093
devops-thiago wants to merge 1 commit into
apple:mainfrom
devops-thiago:build-context-unreadable-error

Conversation

@devops-thiago

Copy link
Copy Markdown

Fixes #2089.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

FileManager.fileExists answers false both for a file that is absent and for one the process may not look at, and BuildCommand.validate() reported the first for both:

mkdir ctx && printf 'FROM alpine\n' > ctx/Dockerfile && chmod 000 ctx
container build ctx
Error: dockerfile not found in context dir

The message sends the user to inspect a build context that was never the problem — naming the file with -f shows the real permission error was available and discarded by the earlier check. Reproduction and details in #2089.

Description

When default Dockerfile resolution fails, the context directory is listed once: a denial throws cannot read context dir <path>: permission denied, while a directory that genuinely holds no Dockerfile lists fine and keeps the existing message. Only the default-resolution path changes; -f already surfaces the real error when it opens the file.

Testing

  • swift build clean on this branch at abff418.
  • The reproduction above now reports Error: cannot read context dir /tmp/ctxtest: permission denied — verified against the built CLI from this branch.
  • The genuinely-missing-Dockerfile case is unchanged: an empty readable context still reports dockerfile not found in context dir.

…erfile

`FileManager.fileExists` answers false both for a file that is not there and for
one the process may not look at, and `build` reported the first for both:

    $ container build -t x:1 .
    Error: dockerfile not found in context dir

with a Dockerfile sitting in that directory. Naming it with -f produced the
honest error — "you don't have permission to view it" — so the information was
available and thrown away by the earlier check. The message sends people to
inspect a build context that was never the problem.

Listing the directory separates the two cases: a denial fails, while a directory
that genuinely holds no Dockerfile lists fine. Only the default-resolution path
needs it; -f already surfaces the real error when it opens the file.

This is reachable whenever the CLI runs sandboxed, which it does when embedded
in an application bundle, and where reading the user's own project directory is
the ordinary case rather than an edge one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container build reports "dockerfile not found in context dir" when the context is unreadable

1 participant