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

feat: add Dockerfile to run unit tests in a Docker container #2188

Merged
merged 1 commit into from
Apr 1, 2023
Merged

feat: add Dockerfile to run unit tests in a Docker container #2188

merged 1 commit into from
Apr 1, 2023

Conversation

sergerdn
Copy link
Contributor

@sergerdn sergerdn commented Mar 30, 2023

This makes it easy to run the tests locally. Some tests may not be able to run in Windows environments, hence the need for a Dockerfile.



The new Dockerfile sets up a multi-stage build to install Poetry and dependencies, and then copies the project code to a final image for tests.



The Makefile has been updated to include a new 'docker_tests' target that builds the Docker image and runs the unit tests inside a container.

It would be beneficial to offer a local testing environment for developers by enabling them to run a Docker image on their local machines with the required dependencies, particularly for integration tests. While this is not included in the current PR, it would be straightforward to add in the future.

This pull request lacks documentation of the changes made at this moment.

@sergerdn sergerdn changed the title feat: add Dockerfile to run tests in a Docker container feat: add Dockerfile to run unit tests in a Docker container Mar 30, 2023
This makes it easy to run the tests locally. Some tests may not be able to run in Windows environments, hence the need for a Dockerfile.

The new Dockerfile sets up a multi-stage build to install Poetry and dependencies, and then copies the project code to a final image for tests.

The Makefile has been updated to include a new 'docker_tests' target that builds the Docker image and runs the tests inside a container.
@sergerdn
Copy link
Contributor Author

Any comments would be appreciated.

Take a look #2174

$ make docker_tests
docker build -t my-langchain-image .
[+] Building 1.1s (2/3)
[+] Building 1.4s (2/3)
[+] Building 130.7s (13/13) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                               0.4s 
 => => transferring dockerfile: 1.25kB                                                                                                                                                                                             0.1s 
 => [internal] load .dockerignore                                                                                                                                                                                                  0.3s 
 => => transferring context: 2B                                                                                                                                                                                                    0.1s 
 => [internal] load metadata for docker.io/library/python:3.11.2-bullseye                                                                                                                                                          1.7s 
 => [builder 1/5] FROM docker.io/library/python:3.11.2-bullseye@sha256:21ce92a075cf9c454a936f925e058b4d8fc0cfc7a05b9e877bed4687c51a5658                                                                                            0.0s 
 => [internal] load build context                                                                                                                                                                                                 21.4s 
 => => transferring context: 2.05MB                                                                                                                                                                                               21.1s 
 => CACHED [builder 2/5] RUN echo "Python version:" && python --version && echo ""                                                                                                                                                 0.0s 
 => CACHED [builder 3/5] RUN echo "Installing Poetry..." &&     curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -                                                               0.0s 
 => CACHED [builder 4/5] RUN echo "Poetry version:" && poetry --version && echo ""                                                                                                                                                 0.0s 
 => CACHED [builder 5/5] WORKDIR /app                                                                                                                                                                                              0.0s 
 => CACHED [dependencies 1/2] COPY pyproject.toml poetry.lock poetry.toml ./                                                                                                                                                       0.0s 
 => CACHED [dependencies 2/2] RUN poetry config virtualenvs.create false     && poetry install --no-interaction --no-ansi                                                                                                          0.0s 
 => [tests 1/1] COPY . .                                                                                                                                                                                                          72.0s 
 => exporting to image                                                                                                                                                                                                            34.2s 
 => => exporting layers                                                                                                                                                                                                           33.8s 
 => => writing image sha256:61a5604b7cdfff47cbf24660e7f91c27156dc6e731f26d53ac5327c032874433                                                                                                                                       0.0s 
 => => naming to docker.io/library/my-langchain-image                                                                                                                                                                              0.0s 
docker run --rm my-langchain-image 
============================= test session starts ============================== 
platform linux -- Python 3.11.2, pytest-7.2.2, pluggy-1.0.0
rootdir: /app
plugins: cov-4.0.0, dotenv-0.5.2, asyncio-0.20.3
asyncio: mode=Mode.STRICT
collected 206 items
 
tests/unit_tests/test_bash.py ....                                       [  1%] 
tests/unit_tests/test_formatting.py ...                                  [  3%] 
tests/unit_tests/test_python.py .....                                    [  5%] 
tests/unit_tests/test_sql_database.py ....                               [  7%] 
tests/unit_tests/test_sql_database_schema.py ..                          [  8%] 
tests/unit_tests/test_text_splitter.py ...........                       [ 14%] 
tests/unit_tests/agents/test_agent.py .........                          [ 18%] 
tests/unit_tests/agents/test_mrkl.py .........                           [ 22%] 
tests/unit_tests/agents/test_react.py ....                               [ 24%] 
tests/unit_tests/agents/test_tools.py ........                           [ 28%] 
tests/unit_tests/callbacks/test_callback_manager.py ........             [ 32%] 
tests/unit_tests/callbacks/tracers/test_tracer.py .............          [ 38%] 
tests/unit_tests/chains/test_api.py .                                    [ 39%] 
tests/unit_tests/chains/test_base.py ..............                      [ 46%] 
tests/unit_tests/chains/test_combine_documents.py ........               [ 50%] 
tests/unit_tests/chains/test_constitutional_ai.py .                      [ 50%] 
tests/unit_tests/chains/test_conversation.py ...........                 [ 55%] 
tests/unit_tests/chains/test_hyde.py ..                                  [ 56%] 
tests/unit_tests/chains/test_llm.py .....                                [ 59%] 
tests/unit_tests/chains/test_llm_bash.py .                               [ 59%] 
tests/unit_tests/chains/test_llm_checker.py .                            [ 60%] 
tests/unit_tests/chains/test_llm_math.py ...                             [ 61%] 
tests/unit_tests/chains/test_llm_summarization_checker.py .              [ 62%] 
tests/unit_tests/chains/test_memory.py ....                              [ 64%] 
tests/unit_tests/chains/test_natbot.py ..                                [ 65%] 
tests/unit_tests/chains/test_sequential.py ...........                   [ 70%] 
tests/unit_tests/chains/test_transform.py ..                             [ 71%] 
tests/unit_tests/docstore/test_inmemory.py ....                          [ 73%] 
tests/unit_tests/llms/test_base.py ..                                    [ 74%] 
tests/unit_tests/llms/test_callbacks.py ..                               [ 75%] 
tests/unit_tests/llms/test_loading.py .                                  [ 75%] 
tests/unit_tests/llms/test_utils.py ..                                   [ 76%] 
tests/unit_tests/output_parsers/test_pydantic_parser.py ..               [ 77%] 
tests/unit_tests/output_parsers/test_regex_dict.py .                     [ 78%] 
tests/unit_tests/prompts/test_chat.py ...                                [ 79%] 
tests/unit_tests/prompts/test_few_shot.py .......                        [ 83%] 
tests/unit_tests/prompts/test_few_shot_with_templates.py .               [ 83%]
tests/unit_tests/prompts/test_length_based_example_selector.py ....      [ 85%] 
tests/unit_tests/prompts/test_loading.py ........                        [ 89%] 
tests/unit_tests/prompts/test_prompt.py ...........                      [ 94%] 
tests/unit_tests/prompts/test_utils.py .                                 [ 95%] 
tests/unit_tests/tools/test_json.py ....                                 [ 97%] 
tests/unit_tests/utilities/test_loading.py ......                        [100%] 

=============================== warnings summary ===============================
......

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! thanks

@hwchase17 hwchase17 merged commit 09f9464 into langchain-ai:master Apr 1, 2023
9 checks passed
@sergerdn sergerdn deleted the feature/add-docker branch April 1, 2023 17:02
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.

None yet

2 participants