Consider using Docker custom build outputs (`--output`) for generated Dockerfiles and Readmes
- Dominant language
- Dockerfile
- Stars
- 4.9k
- Forks
- 2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 26
Description
I noticed this new feature today (requires BuildKit): https://docs.docker.com/reference/cli/docker/image/build/#output
How we generate Dockerfiles and Readmes today is a bit of an anti-pattern - we call the ImageBuilder image (with the `dotnet-docker` repo baked in), leave the container on the disk, copy the files out of the container on the disk, and then delete the container.
Using Docker's build output feature could simplify the generated files build process. All we'd need is a simple Dockerfile (one for Readmes, one for Dockerfiles) that is based on ImageBuilder. I'm imagining something like this -
```Dockerfile
FROM mcr.microsoft.com/dotnet-buildtools/image-builder:...
WORKDIR /repo
COPY . .
# Use ImageBuilder to generate Dockerfiles...
RUN ...
FROM scratch
# Copy Dockerfiles to output location
COPY /repo/src src
```
Then just building the Dockerfile with the `-o .` argument to dump the output `src/` dir into the current directory. No containers left on disk to cleanup or copy files out of. This could simplify lots of our logic in [Invoke-ImageBuilder.ps1](https://github.com/dotnet/dotnet-docker/blob/main/eng/common/Invoke-ImageBuilder.ps1.). And potentially eliminate the need for [Dockerfile.WithRepo](https://github.com/dotnet/dotnet-docker/blob/main/eng/common/Dockerfile.WithRepo)? Just an idea.
Contributor guide
Assessment
This issue has not been assessed yet.