janus-idp / backstage-showcase

This repo is moving to https://github.com/redhat-developer/red-hat-developer-hub
https://janus-idp.io
Apache License 2.0
113 stars 151 forks source link

Optimize Dockerfile performance #55

Closed christophe-f closed 1 year ago

christophe-f commented 1 year ago

What do you want to improve?

Optimize Dockerfile to run faster. We have many contributions and it takes a long time to get feedback, merge and deploy.

What is the current behavior?

The build time was already too long and doubled in the last week.

What is the new behavior?

Build faster. Much faster

:warning: Is this a breaking change?

Put an x in the boxes that apply

schultzp2020 commented 1 year ago

Currently, the majority of the dockerfile build time is allocated to running the fix-permissions script. Is there a way we could cut down the time required to run this script? @sabre1041 @tumido

tumido commented 1 year ago

@schultzp2020 I think you can make the Dockerfile to use the fix-permissions script earlier in multiple layers instead of just as the last one. What that would result into is incremental changes - container layers work in a way that they store all that is changed compared to the previous layer. So, if the fix-permissions was already executed for some files, it means the permissions don't have to be updated for them again + these files are already cached in their final state in previous layers. This should potentially (and counterintuitively) result in smaller and faster builds.

schultzp2020 commented 1 year ago

@tumido I have yet to try it; however, I do not believe that will work because the last (prod) stage doesn't copy files directly from the build stage. Instead the build stage creates tarballs, which are then extracted during the prod stage. Therefore, the majority of the files are not from previous stages that would benefit from running fix-permissions in an earlier stage.

tumido commented 1 year ago

I think tarball preserves permissions, doesn't it? Let's try it and if it doesn't work we can try to come up with something else... 🙂

Zaperex commented 1 year ago

End users will no longer be building their own backstage showcase images, so this issue is mainly for improving our own build times for showcase and RHDH.

Currently I have only identified optimizations for the first stage (dependency installations) by only copying package.json files rather than the entire repository.

schultzp2020 commented 1 year ago

There are no optimizations we can do for the dockerfile since the fix-permissions script takes the most amount of time and we do not control the script.