feat: support prepend.Dockerfile* files for multi-stage builds#7071
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
It's obvious that although I am using the base image as provided by ddev, I could have use any other image on each stage. |
|
And I probably still need to add some notes to the README file, the docs and tests, but before continuing I just wanted your initial "approval" on adding this. |
|
Added tests and README.txt tweaks |
|
Added docs, this should be feature complete and ready to review. |
stasadev
left a comment
There was a problem hiding this comment.
Works well, thank you!
I only have a suggestion for your go example.
|
shameless bump of this PR to see if it can be considered for next release :) |
|
I hope to get to it, and you have Stas's support, so it's likely. But from community point of view it's not as important as some other things. |
|
We'll try to get this in early in upcoming release cycle. |
d0cefa1 to
ef72d4e
Compare
rfay
left a comment
There was a problem hiding this comment.
Your contributions are so very much appreciated in so many places.
But I'm sorry, I'm not very happy with this. I spent some time with it today and it seems to me like it adds complexity to a topic that is already too complex for most people, and primarily does it to support a single user's workflow. We'll leave it open and I'll return to it later.
|
Could you please restate here exactly what your situation is? We were thinking we should try to solve it in a more generic way, instead of adding a specific feature. |
|
I just wanted to be able to do a multi stage dockerfile build successfully,
being able to add stages before ddevs own image and without having to
maintain my own image
|
|
I know you think of this in terms of stages, but if you can explain again in detail the actual problem you're trying to solve (instead of the means of solving it) we'll brainstorm with you about possible solutions. |
|
I think it's also in the discord thread linked in the PR description, but adding here the key points:
|
|
Why is it important for it to change all the time? |
I guess it's not. I don't have an answer other than keeping it up to date for the sake of it. Same reason I do a brew upgrade so often |
|
Can you say what it is that gets out of date? Is it possible to make it not have to build when things haven't changed? |
|
It only builds when something change. There are many tools. There are some
new release very so often.
Reply might be shorter than usual / Respuesta más resumida que de costumbre
Enviado desde el celular / Sent from Mobile
…On Mon, 7 Apr 2025 at 19:49 Randy Fay ***@***.***> wrote:
Can you say what it is that gets out of date?
Is it possible to make it not have to build when things haven't changed?
—
Reply to this email directly, view it on GitHub
<#7071 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFP5Y2W5S4EC37466B5232YL6GZAVCNFSM6AAAAABY4LX3ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBUHAYDCOJUGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
[image: rfay]*rfay* left a comment (ddev/ddev#7071)
<#7071 (comment)>
Can you say what it is that gets out of date?
Is it possible to make it not have to build when things haven't changed?
—
Reply to this email directly, view it on GitHub
<#7071 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFFP5Y2W5S4EC37466B5232YL6GZAVCNFSM6AAAAABY4LX3ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBUHAYDCOJUGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Maybe |
Co-authored-by: Stanislav Zhuk <stasadev@gmail.com>
Co-authored-by: Stanislav Zhuk <stasadev@gmail.com>
|
Rebased for convenience and just to run the wsl2/docker-ce tests on tb-wsl-14, which was failing before. |
|
OK, I'm willing to go with it. Please use the PR template to provide full information about this PR, including adding explicit (simple) manual testing instructions. Your narrative description is fine justifying the whole thing, but please put it as an addition to the template. After that gets done, Stas and I will do another round of review. It does look fine to me, although I don't know how people will really understand the difference between pre and prepend. |
|
Done and pushed a minor docs adjustment to match the PR testing instructions ,which I found it clearer. |
|
You'll be happy to know that heredocs are fully supported these days (simpler examples than you have). I'm trying to move to them when I see opportunities. https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/ Just a comment, no need to change anything. |
rfay
left a comment
There was a problem hiding this comment.
OK! I hope you like it and others like it!
It does add complexity, and will certainly mean some confusion between pre and prepend, but it also adds power, and hopefully power that helps your situation. Thanks for the contribution, and for scratching your own itch!
The good thing is the docs read well and prepend does come way down there after people have stopped reading.
stasadev
left a comment
There was a problem hiding this comment.
Looks good and works as expected. Thank you!
|
Thanks for your contribution and your patience on this! |
|
@hanoii, thank you very much for this contribution! I reused this technique in: Multi-stage build was required there, because variable expansion is not supported in |
The issue
We can customize the default Dockerfile by adding appending stuff to the end (through
Dockerfile* variants), and by injecting something before ddev own customizations, but still in between ddev's own Dockerfile (throughpre.Dockerfile*variants). But we cannot add anything before everything else, limiting other customization like being able to define other build stages.How This PR Solves The Issue
It adds a new
prepend.Dockerfile*variant that gets added on top of everything before anything added by ddev.Manual Testing Instructions
.ddev/web-build/prepend.Dockerfile.pr-7071with:.ddev/web-build/Dockerfile.pr-7071with:ddev startand it should build without error.ddev exec go versionand verify the command runs ok and you got the latest go version.Automated Testing Overview
This verifies that that the all of the variants work by doing a simple build stage that creates a file and then it copies it over. It tests both
prepend.Dockerfileandprepend.Dockerfile.*Release/Deployment Notes
It affects nothing.
Additional context
Most important docs for review: https://ddev--7071.org.readthedocs.build/en/7071/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage
This is a follow up for a discord thread: https://discord.com/channels/664580571770388500/1349036904015855636
The reasoning behind this is having a way to, if needed/wanted for any reason, be able to feed to ddev Dockefile build stages. This can help in splitting out big modifications of Dockerfiles into their own stages.
The change to ddev code is super simple actually, just adds any
stage.Dockerfile.*that's get added before EVERYTHING in the current Dockerfile, allowing you to do whatever you want there.While I am still working through a test project that uses this successfully, initial test works just fine and I think you can gather what we can do with this.
i.e.
This is the first part of the
.webImageBuild's Dockerfile where it concatenatesstage.Dockerfile.pimpi-my-shell.ahoyandstage.Dockerfile.pimpi-my-shell.kitty.Further below I also have a
Dockerfile.pimp-my-shellthat does:Changing something in the ahoy stage, doesn't bust the kitty stage cache. The COPY entries gets busted in order (the first one that get busted busts the others, but the COPY performance is negible.
Note
At first I was trying to support more logic, like adding all of the ARGs or auto detect FROM statements to see if I should add the FROM base image but then I figured I was getting too complex into something that's inherently complex and if one would want to use this, he should cover anything what's required in this part of the dockerfile.
Docs: https://ddev--7071.org.readthedocs.build/en/7071/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage