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

fix: missing requirements.txt on lambda dockerfile #826

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

s1moe2
Copy link
Contributor

@s1moe2 s1moe2 commented Mar 26, 2024

User description

The bug resolved by this PR is described in issue #824.

Problem A:
When in commit bc2cf75b7 pyproject.toml was introduced, requirements.txt was replaced, which is an error because inside the build containers this file will not be there for the build with pyproject.toml to work as expected.

Problem B:
After solving problem A, when trying to boot the container in Lambda I got again an exception with the trace

ImportError: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh()

All git commands will error until this is rectified.

This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|none|n|0: for no warning or exception
    - warn|w|warning|1: for a printed warning
    - error|e|raise|r|2: for a raised exception

Example:
    export GIT_PYTHON_REFRESH=quiet

Adding git to the image via "yum install" resolved this.


Type

bug_fix


Description

  • Fixes the issue where requirements.txt was missing in the Docker build for Lambda, causing build failures.
  • Ensures both pyproject.toml and requirements.txt are now copied into the Docker image for successful builds.

Changes walkthrough

Relevant files
Bug fix
Dockerfile.lambda
Fix Missing `requirements.txt` in Lambda Dockerfile           

docker/Dockerfile.lambda

  • Added requirements.txt to the files copied into the Docker image.
  • +1/-1     

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

    Copy link
    Contributor

    PR Description updated to latest commit (d250cb4)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    1, because the change is minimal and straightforward, involving only the addition of a file to the Dockerfile.

    🏅 Score

    95

    🧪 Relevant tests

    No

    🔍 Possible issues

    No

    🔒 Security concerns

    No

    🔀 Multiple PR themes

    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
    Contributor

    codiumai-pr-agent-pro bot commented Mar 26, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Use COPY instead of ADD for adding files to the Docker image.

    Instead of using ADD for adding files to the Docker image, it's recommended to use COPY as
    it is more transparent and consistent for files and directories copying. ADD has
    additional features like local-only tar extraction and remote URL support, which are not
    needed in this context.

    docker/Dockerfile.lambda [7]

    -ADD pyproject.toml requirements.txt .
    +COPY pyproject.toml requirements.txt .
     
    Pin versions of Python packages in requirements.txt.

    Consider pinning the version of Python packages in requirements.txt to ensure reproducible
    builds and avoid potential future compatibility issues. Unpinned packages will always
    install the latest version, which might break the application if a new version introduces
    breaking changes.

    docker/Dockerfile.lambda [7]

    -ADD pyproject.toml requirements.txt .
    +# Ensure requirements.txt has pinned versions, e.g.,
    +# flask==1.1.2
    +# requests==2.25.1
     
    Clear pip cache after installation to reduce Docker image size.

    After installing packages with pip, it's a good practice to clear the pip cache to reduce
    the Docker image size. This can be done by adding && rm -rf /root/.cache/pip at the end of
    the RUN pip install commands.

    docker/Dockerfile.lambda [8-9]

    -RUN pip install . && rm pyproject.toml
    -RUN pip install mangum==0.17.0
    +RUN pip install . && rm pyproject.toml && rm -rf /root/.cache/pip
    +RUN pip install mangum==0.17.0 && rm -rf /root/.cache/pip
     
    Specify a specific version of the base image in the Dockerfile.

    It's recommended to specify a specific version of the base image in the Dockerfile to
    ensure the build's consistency and reliability. Using the latest version of the base image
    can lead to unexpected behavior if the base image is updated.

    docker/Dockerfile.lambda [0]

    -(The suggestion applies to the entire Dockerfile, which is not visible in the provided diff. Please ensure the base image is specified with a version.)
    +# Example change, assuming the base image is python:
    +FROM python:3.8
     
    Enhancement
    Use multi-stage builds to optimize Docker image size.

    Consider using a multi-stage build to optimize the Docker image size. This allows you to
    separate the build environment from the runtime environment, copying only the necessary
    artifacts from the build stage to the final image.

    docker/Dockerfile.lambda [0]

    -(The suggestion applies to the entire Dockerfile, which is not visible in the provided diff. Consider structuring the Dockerfile with multi-stage builds if not already done.)
    +# Example multi-stage build:
    +# Build stage
    +FROM python:3.8 AS builder
    +COPY . /app
    +WORKDIR /app
    +RUN pip install . && rm -rf /root/.cache/pip
     
    +# Final stage
    +FROM python:3.8-slim
    +COPY --from=builder /app /app
    +

    ✨ 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.

    @mrT23 mrT23 merged commit cd4deef into Codium-ai:main Mar 27, 2024
    @s1moe2 s1moe2 deleted the fix/issue-824 branch March 27, 2024 11:03
    @s1moe2 s1moe2 restored the fix/issue-824 branch March 27, 2024 11:06
    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.

    2 participants