Improve cookiecutter docker support with BuildKit and multistage builds #3604
Replies: 3 comments
-
I like the idea of reducing duplication, yes. For context, there was some effort started a while back to go even further and unify our local/prod Dockerfiles into a single, but unfortunately, that work has been abandoned. It happened around the same time as when we added support for running the nodejs part in Docker, and it seemed like the 2 changes had conflicting goals. Another change in progress that might affect this is if our local/prod dependencies were shared a bit more (#2810 and #2776), but I haven't got time to focus on this. Thanks for sharing this gist, looks quite promising! Do you think that would work with the nodejs image? I guess the nodejs stage from the corrent prod image could be added to the prod stage of your suggestion in this case? |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I see that the nodejs support is already
implemented using multistage builds. So the nodejs stage could be easily
moved into this single Dockerfile and any artifacts generated during that
stage could be copied into the prod stage as needed, as it's being done
now.
Would it help if I open a PR and maybe we can review it and we can continue
the conversation there? I have some time to work on it next week.
El dom., 20 feb. 2022 10:37, Bruno Alla ***@***.***> escribió:
… I like the idea of reducing duplication, yes.
For context, there was some effort
<#1696> started a
while back to go even further and unify our local/prod Dockerfiles into a
single, but unfortunately, that work has been abandoned. It happened around
the same time as when we added support for running the nodejs part in
Docker <#1687>,
and it seemed like the 2 changes had conflicting goals.
Another change in progress that might affect this is if our local/prod
dependencies were shared a bit more (#2810
<#2810> and #2776
<#2776>), but I
haven't got time to focus on this.
Thanks for sharing this gist, looks quite promising! Do you think that
would work with the nodejs image? I guess the nodejs stage from the corrent
prod image could be added to the prod stage of your suggestion in this case?
—
Reply to this email directly, view it on GitHub
<#3604 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACLIKHV3PTFHXGD6JYMV7O3U4DVCJANCNFSM5OYD4LFQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
<cookiecutter/cookiecutter-django/repo-discussions/3604/comments/2214480@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
Here you can see it applied to the cookiecutter-django project. https://github.com/marianobrc/cookiecutter-django/tree/single-django-dockerfile How to run it (you need to enable dockerkit usage and docker-compose >=1.27) I've modified the Dockerfile/s and docker-compose files and I tested it locally. |
Beta Was this translation helpful? Give feedback.
-
What do you think about switching from having two Dockerfiles for development and production to having a single Dockerfile using docker buildkit and multi-stage builds? IMHO having a single Dockerfile is more maintainable, code repetition is reduced as code can be reused between stages, and the build time is also improved.
Here is an example:
https://gist.github.com/marianobrc/059c068912a5934ec0d1fa16e2790727
And here more about docker multistage builds and buildkit:
https://docs.docker.com/develop/develop-images/build_enhancements/
https://docs.docker.com/develop/develop-images/multistage-build/
Would you be open to considering making changes to the cookiecutter project to apply this approach?
Beta Was this translation helpful? Give feedback.
All reactions