Skip to content

The agent engineering platform.

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

sergerdn09f94642543b
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000000..4c22c093fb
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,2 @@
+.venv
+.github
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000000..580438096b
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,39 @@
+# 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"]
diff --git a/Makefile b/Makefile
index 28dd38702e..24a1818190 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-.PHONY: all clean format lint test tests test_watch integration_tests help
+.PHONY: all clean format lint test tests test_watch integration_tests docker_tests help
all: help
-
+
coverage:
poetry run pytest --cov \
--cov-config=.coveragerc \
@@ -40,6 +40,10 @@ test_watch:
integration_tests:
poetry run pytest tests/integration_tests
+docker_tests:
+ docker build -t my-langchain-image:test .
+ docker run --rm my-langchain-image:test
+
help:
@echo '----'
@echo 'coverage - run unit tests and generate coverage report'
@@ -51,3 +55,4 @@ help:
@echo 'test - run unit tests'
@echo 'test_watch - run unit tests in watch mode'
@echo 'integration_tests - run integration tests'
+ @echo 'docker_tests - run unit tests in docker'