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

[Enhancement] Disable pip cache in Dockerfiles to reduce image size #878

Closed

Conversation

idubnori
Copy link
Contributor

@idubnori idubnori commented Apr 21, 2024

User description

Remove the pip cache is created when pip install from the docker image layer. Currently, 80MB is being consumed needlessly and reduce it.

$ docker images | grep pr-agent                                         
pr-agent                                 no-pip-cache      3f43414e6ff8   About a minute ago   1.3GB
codiumai/pr-agent                        github_action     3b96010bd372   4 days ago           1.38GB

Note


Type

enhancement


Description

  • Added ARG PIP_NO_CACHE_DIR=1 to Dockerfiles to disable pip cache, reducing the image size across different Docker configurations.
  • This change affects the GitHub Actions Dockerfile, the main Dockerfile, and the AWS Lambda Dockerfile.

Changes walkthrough

Relevant files
Enhancement
Dockerfile.github_action
Disable pip cache in GitHub Actions Dockerfile                     

Dockerfile.github_action

  • Added ARG PIP_NO_CACHE_DIR=1 to disable pip cache and reduce image
    size.
  • +2/-0     
    Dockerfile
    Disable pip cache in main Dockerfile                                         

    docker/Dockerfile

  • Added ARG PIP_NO_CACHE_DIR=1 to disable pip cache and reduce image
    size.
  • +2/-0     
    Dockerfile.lambda
    Disable pip cache in Lambda Dockerfile                                     

    docker/Dockerfile.lambda

  • Added ARG PIP_NO_CACHE_DIR=1 to disable pip cache in AWS Lambda Docker
    image.
  • +2/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added the enhancement New feature or request label Apr 21, 2024
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (3833d0f)

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review

    ⏱️ Estimated effort to review [1-5]

    1, because the changes are minimal and straightforward across multiple Dockerfiles, involving only the addition of a single line to disable pip caching.

    🏅 Score

    95

    🧪 Relevant tests

    No

    🔍 Possible issues

    No

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Change the ARG command to ENV to ensure the no-cache setting persists across all Docker layers.

    Consider setting the PIP_NO_CACHE_DIR environment variable directly using the ENV command
    instead of ARG to ensure that it persists in the environment for all subsequent commands
    and layers, enhancing the reproducibility and consistency of Docker builds.

    Dockerfile.github_action [3]

    -ARG PIP_NO_CACHE_DIR=1
    +ENV PIP_NO_CACHE_DIR=1
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @idubnori idubnori changed the title refactor: remove pip cache in docker image layer refactor: remove pip cache files in docker image layer Apr 21, 2024
    @mrT23
    Copy link
    Collaborator

    mrT23 commented Apr 24, 2024

    @idubnori
    I am hesitant about this change.

    What are the downside of adding this line ? why it is not enabled by default ?
    will it take longer to re-build ?
    won't this introduce versioning problems ?

    @idubnori
    Copy link
    Contributor Author

    @mrT23 Thank you for your reply.

    What are the downside of adding this line ? why it is not enabled by default ?

    I think no downside as long as using inside dockerfile. The pip cache should be intended to eliminate the need to re-download the same package file locally. There is no scenario cached packages are reused in the current dockerfile.

    will it take longer to re-build ?

    If you are building docker in a local environment, the previous layer cache will not be reused, so pip install will be re-run only for the first time build after this changes. After that, unless the pyproject.toml requirements.txt is changed, the docker layer cache will be used and pip install will not be executed. If building docker in an immutable environment (e.g. github actions hosted runner), pip install will be performed each time and the build time will not change.

    won't this introduce versioning problems ?

    If building an other docker image based on the pr-agent docker image, it may be less risky to leave the cache in place, but I think it is the edge case. To minimize the version problem or risk, instead of disabling the pip cache, I think use cache purge after pip install, rather than disabling the pip cache. (use && pip cache purge instead of PIP_NO_CACHE_DIR=1)

    @idubnori
    Copy link
    Contributor Author

    If more concerns or questions, I would like to suggest wait for comments from other contributors or PR can be closed. This PR is not very effective, also not important for me at this time.

    @hussam789
    Copy link
    Collaborator

    /describe
    --pr_description.extra_instructions="
    For the title, use the format [type]: [summary]
    "
    --pr_description.generate_ai_title=true

    @hussam789
    Copy link
    Collaborator

    sss

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot removed the enhancement New feature or request label May 2, 2024
    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot changed the title refactor: remove pip cache files in docker image layer [Enhancement] Disable pip cache in Dockerfiles to reduce image size May 2, 2024
    Copy link

    PR Description updated to latest commit (3833d0f)

    @mrT23
    Copy link
    Collaborator

    mrT23 commented May 5, 2024

    ok, thanks @idubnori
    i will close the PR for now, but the effort to reduce the docker size is welcomed.

    @mrT23 mrT23 closed this May 5, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    3 participants