Skip to content

Fix: Avoid staging Dockerfiles into read-only build contexts#1343

Closed
mazdak wants to merge 1 commit into
apple:mainfrom
mazdak:mazdak/containercommands-readonly-build-context
Closed

Fix: Avoid staging Dockerfiles into read-only build contexts#1343
mazdak wants to merge 1 commit into
apple:mainfrom
mazdak:mazdak/containercommands-readonly-build-context

Conversation

@mazdak
Copy link
Copy Markdown
Contributor

@mazdak mazdak commented Mar 24, 2026

Type of Change

  • Bug fix

Motivation and Context

While building our docker-compose-like compose system for container, we noticed an issue in the build phase. The current build path always creates .com.apple.container.dockerfiles/ inside the context and writes a staged Dockerfile there.

That introduces an issue for:

  • read-only checkouts
  • mounted source trees
  • otherwise immutable build contexts

Those builds can fail before BuildKit starts, even when there is no .dockerignore to rewrite. Here, we fix container build so it does not require write access to the build context unless it actually needs to synthesize staged Dockerfile artifacts.

Fix

  • Add a small helper that only produces staged Dockerfile artifacts when an ignore file exists.
  • Fall back to the root .dockerignore if Dockerfile.dockerignore is absent.
  • Skip hidden-directory creation entirely when there is no ignore file to extend.

This preserves the existing staged-ignore behavior where it is needed, while avoiding unnecessary writes for simple read-only contexts.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@JaewonHur
Copy link
Copy Markdown
Contributor

Hi @mazdak Thank you for reporting this issue!

Confirming container build doesn't work with read-only build context.
We have to avoid staging Dockerfile (and ignore) in the context.

I guess this solution might not be the best one as it couldn't support docker specific ignore when the build context is read only.

We might need to update fssync to handle Dockerfile and ignore file selectively.
Let me dig more!

Thanks!

@JaewonHur
Copy link
Copy Markdown
Contributor

@mazdak I just made some PRs for this issue.
Sorry to make a duplicate PR for the same issue. Would you mind if I put you as co-author?

@mazdak
Copy link
Copy Markdown
Contributor Author

mazdak commented Mar 26, 2026

@mazdak I just made some PRs for this issue. Sorry to make a duplicate PR for the same issue. Would you mind if I put you as co-author?

No problem at all. I am happy to just see this resolved.

@mazdak mazdak closed this Mar 30, 2026
JaewonHur added a commit to apple/container-builder-shim that referenced this pull request Apr 18, 2026
This PR resolves the issue when using docker specific ignore file with read-only build context (apple/container#1343).

Once the `dockerignore` argument is provided in `PerformBuild` gRPC, it performs following two operations.

First, after unpacking transferred build context archive into `cache` directory, it creates a `DockerfileStaging` (i.e., `.com.apple.container`) directory there, and copies `Dockerfile` and `Dockerfile.dockerignore`. The path to `DockerfileStaging` is passed to the buildkit daemon so that it can correctly figure out which dockerignore file to read.

Second, it handles data requests for `Dockerfile` and `Dockerfile.dockerignore` (i.e., `diffcopy.go:sender::sendFile`), so that the requests before the actual files are written can be correctly served---i.e., refer #71 for more context about this race issue.
JaewonHur added a commit that referenced this pull request Apr 20, 2026
This PR resolves #1343.
This PR depends on apple/container-builder-shim#72.

Do not create staging directory under build context, but pass
dockerignore file bytes to the container-builder-shim.

## Type of Change
- [x] Bug fix
- [ ] New feature  
- [ ] Breaking change
- [ ] Documentation update

## Motivation and Context
[Why is this change needed?]

## Testing
- [x] Tested locally
- [ ] Added/updated tests
- [ ] Added/updated docs
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.

2 participants