-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build: Exploring Docker multi-stage and best practices #19962
Conversation
Dockerfile
Outdated
# changes. For local development this should always | ||
# be an empty file and therefore this layer should | ||
# cache well. | ||
# Build step |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine deps/build
Dockerfile
Outdated
COPY ./env-config.sh /tmp/env-config.sh | ||
ENV CALYPSO_ENV=production \ | ||
NODE_ENV=production | ||
COPY --from=build /calypso/build ./build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wishful thinking 😀
Depends other things…
As of e870a4d, this setup generates a working image at
|
|
Amazing work!! ⭐️ I'm so exciting about the possibility of using multi-step capabilities so that our Dockerfile can both be easy to understand while staying optimal in terms of size and speed of build. Is there anything I can do to help move this along? a question I have looking at the docker file is whether or not we can split it into more layers to help with caching. For example:
|
Thanks @samouri! I'd intended this as an exploration and investigation as to whether changes like this could improve our build speed and size. As such, I'll share my findings here. I believe the largest impact on build size is the base image change for the final layer to node alpine: Line 46 in 2927f50
Much of the multi-stage build size and speed improvements are negated by the fact that Calypso builds are rather unusual. I'd expect to build software from source, producing executables which exist and can function without the source being present. Calypso does not appear to behave this way. Notice that at least the following directories are required for running Calypso after it's been built: Lines 35 to 42 in 2927f50
The presence of so many files makes the final instruction in this layer If we can avoid the As I understand it, multi-stage builds are primarily worthwhile in cases where there image required to build an executable is large, but the environment required to run and executable and the executable itself are relatively small. That doesn't appear to be the case with Calypso, so I'm not sure how much advantage a multi-stage build has for us. Conclusion: I've learned a lot and we can make some improvements. Multi-stage probably isn't an important improvement for speed or size given the way Calypso builds work.
I think the way forward here may be to incrementally apply what's been learned in this PR to our existing builds. Things that should have real, noticeable impact:
Here's a checklist extracted from above
Some of this layer caching should already occur as long as it's not disabled by the actual build command ( The trick is getting them into the right order, when a layer has changed, all subsequent layers will need to be rebuilt. That said, most of the operations are quite cheap ( However, all of the It would also be great to add a layer to |
Exploring |
@sirreal can you provide a status-update on this awesome PR? Is it worth updating? Worth closing? Is there anything you need to keep iterating on it? |
Multi-stage is not currently an option. |
42b0c61
to
2192a23
Compare
I've rebased and updated this to reflect lessons learned, especially #21570. This is now an example of modern Docker best practices applied to Calypso. |
2192a23
to
0ed33bb
Compare
FYI, this was merged recently(ish) giving you chown on copy. See updated Example usage would be:
Doesn't seem to add much overhead in my experience - maybe not copying large enough dir's? By the way, if you want to shave off a few more mb's you could |
@lsl Thanks! This branch is a bit outdated right now, but as we reach compatibility with multi-stage builds I do hope to revisit it. The whole If you have the interested and expertise, please feel free to improve it. I do hope to continue with this in the near future 👍 |
This PR needs a rebase - is this PR still required? |
Let's close this. There are relevant findings here and improvements to be made, but the exploration here has largely served it's purpose and will continue to be available in this conversation. |
DO NOT MERGE
This is an exploration.
See: