Skip to content
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

Do not store pip cache during docker build #463

Merged

Conversation

don-attilio
Copy link
Contributor

Hi, thanks for developing the guardrails.
Removing the pip cache in a layer subsequent to the pip install does not reduce image size because the cache stays in the final image. It is more effective and cleaner not using any caching at all.

Adding the option --no-cache-dir during pip command reduces the final artifact size for each of the Dockerfiles in the repo, like listed below.

  1. Dockerfile: from 1.68GB to 1.58GB;
  2. nemoguardrails/library/jailbreak_detection/Dockerfile: from 12.3GB to 9.37GB;
  3. nemoguardrails/library/jailbreak_detection/Dockerfile-GPU: from 12.3GB to 9.41GB;
  4. nemoguardrails/library/factchecking/align_score/Dockerfile: from 9.6GB to 7.6GB;

For the last three dockerfiles, I reordered the COPY and RUN directives in order to avoid having to download the dependencies every time a single line of code changes.
There could be definitely be more optimizations, such as multi-layer builds.

@don-attilio don-attilio changed the title Feature/remove pip cache from docker image Do not store pip cache during docker build Apr 19, 2024
@drazvan
Copy link
Collaborator

drazvan commented Jul 10, 2024

Thanks @don-attilio!
👍

@drazvan drazvan self-assigned this Jul 10, 2024
@drazvan drazvan self-requested a review July 10, 2024 10:38
@drazvan drazvan merged commit a0df778 into NVIDIA:develop Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants