▲ | justinsaccount 5 days ago | |||||||||||||||||||||||||
I don't really have an opinion on using caddy in a container to serve a static site. That's fine, really.. However, the way the container is built is done in the worst possible way:
This adds the entire repository to the first layer, then installs python, then runs the build which I assume will only then install the dependencies. This means that changing any file in the repository invalidates the first layer, triggering uv reinstalling python and all the dependencies again. The correct Dockerfile would be something like
| ||||||||||||||||||||||||||
▲ | nkantar 5 days ago | parent | next [-] | |||||||||||||||||||||||||
Author (not OP) here. It hadn’t really occurred to me to optimize the Dockerfile in this way because of how rarely the build is run in the first place, but I’m absolutely going to do this, since the ratio of code changes to content changes will definitely skew heavily toward the latter, and it just seems like a good habit anyway. Thanks for reminding me, and even explaining how to do it! | ||||||||||||||||||||||||||
▲ | codespin 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Getting the dockerfile order right is critical due to how docker caching works. Even if you aren't an expert it is trivial these days to copy/paste it into chatGPT and ask it to optimize or suggest improvements to the dockerfile, it will then explain it to you. | ||||||||||||||||||||||||||
▲ | globular-toast 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
My heuristic to go from least likely to change to most likely, bearing in mind dependencies, of course. | ||||||||||||||||||||||||||
▲ | krick 5 days ago | parent | prev | next [-] | |||||||||||||||||||||||||
Exactly. I wanted to also point this out in the relation of the author's desire to put all build commands in `just` configuration file. It sounds to me like a desire to use some another "slick and shiny tool" (which `just` is when compared to `make`), but what's the point exactly? The build-process will still be container-dependent and may or may not work outside of the container, and you don't get the benefit of Docker caching anymore. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
▲ | pvtmert 5 days ago | parent | prev [-] | |||||||||||||||||||||||||
delayed |