mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
09f9464254
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.
40 lines
1.1 KiB
Docker
40 lines
1.1 KiB
Docker
# Use the Python base image
|
|
FROM python:3.11.2-bullseye AS builder
|
|
|
|
# Print Python version
|
|
RUN echo "Python version:" && python --version && echo ""
|
|
|
|
# Install Poetry
|
|
RUN echo "Installing Poetry..." && \
|
|
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
|
|
|
|
# Add Poetry to PATH
|
|
ENV PATH="${PATH}:/root/.local/bin"
|
|
|
|
# Test if Poetry is added to PATH
|
|
RUN echo "Poetry version:" && poetry --version && echo ""
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Use a multi-stage build to install dependencies
|
|
FROM builder AS dependencies
|
|
|
|
# Copy only the dependency files for installation
|
|
COPY pyproject.toml poetry.lock poetry.toml ./
|
|
|
|
# Install Poetry dependencies (this layer will be cached as long as the dependencies don't change)
|
|
RUN poetry install --no-interaction --no-ansi
|
|
|
|
# Use a multi-stage build to run tests
|
|
FROM dependencies AS tests
|
|
|
|
# Copy the rest of the app source code (this layer will be invalidated and rebuilt whenever the source code changes)
|
|
COPY . .
|
|
|
|
# Set entrypoint to run tests
|
|
ENTRYPOINT ["poetry", "run", "pytest"]
|
|
|
|
# Set default command to run all unit tests
|
|
CMD ["tests/unit_tests"]
|