From 691ac3fa59be1cbe59553685b2d2cb793bab2e49 Mon Sep 17 00:00:00 2001 From: Mikhail Merkulov Date: Wed, 7 Feb 2024 18:48:28 +0200 Subject: [PATCH] Dockerized chroma arguments customization (#1658) ## Description of changes *Summarize the changes made by this PR.* - New functionality - Added an ability to customize the default arguments that are passed from `docker run` or `docker compose` `command` field to `uvicorn chromadb.app:app`. I needed it to be able to customize the port because in certain scenarios it cannot be change (i.e. ECS where internal port is proxies as is). The default arguments are not changed: `--workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30` - Added ENV variables for basic customization with default values: ``` CHROMA_HOST_ADDR="0.0.0.0" CHROMA_HOST_PORT=8000 CHROMA_WORKERS=1 CHROMA_LOG_CONFIG="chromadb/log_config.yml" CHROMA_TIMEOUT_KEEP_ALIVE=30 ``` ## Test plan *How are these changes tested?* - Tested locally using `docker build` and `docker run` commands - Tested customization in `docker-compose` - now it works as expected. ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?* TODO: Deployment docs needs to be updated to cover container arguments customization. --- Dockerfile | 11 ++++++++++- bin/docker_entrypoint.sh | 12 +++++++++++- docker-compose.test-auth.yml | 2 +- docker-compose.test.yml | 2 +- docker-compose.yml | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f90733edbb..c871a4cd8c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,15 @@ COPY --from=builder /install /usr/local COPY ./bin/docker_entrypoint.sh /docker_entrypoint.sh COPY ./ /chroma +RUN chmod +x /docker_entrypoint.sh + +ENV CHROMA_HOST_ADDR "0.0.0.0" +ENV CHROMA_HOST_PORT 8000 +ENV CHROMA_WORKERS 1 +ENV CHROMA_LOG_CONFIG "chromadb/log_config.yml" +ENV CHROMA_TIMEOUT_KEEP_ALIVE 30 + EXPOSE 8000 -CMD ["/docker_entrypoint.sh"] +ENTRYPOINT ["/docker_entrypoint.sh"] +CMD [ "--workers ${CHROMA_WORKERS} --host ${CHROMA_HOST_ADDR} --port ${CHROMA_HOST_PORT} --proxy-headers --log-config ${CHROMA_LOG_CONFIG} --timeout-keep-alive ${CHROMA_TIMEOUT_KEEP_ALIVE}"] \ No newline at end of file diff --git a/bin/docker_entrypoint.sh b/bin/docker_entrypoint.sh index e6f2df70be8..e9498b4fd7c 100755 --- a/bin/docker_entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -1,5 +1,15 @@ #!/bin/bash +set -e export IS_PERSISTENT=1 export CHROMA_SERVER_NOFILE=65535 -exec uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30 +args="$@" + +if [[ $args =~ ^uvicorn.* ]]; then + echo "Starting server with args: $(eval echo "$args")" + echo -e "\033[31mWARNING: Please remove 'uvicorn chromadb.app:app' from your command line arguments. This is now handled by the entrypoint script." + exec $(eval echo "$args") +else + echo "Starting 'uvicorn chromadb.app:app' with args: $(eval echo "$args")" + exec uvicorn chromadb.app:app $(eval echo "$args") +fi diff --git a/docker-compose.test-auth.yml b/docker-compose.test-auth.yml index 259d4c54e79..d3297b5a04f 100644 --- a/docker-compose.test-auth.yml +++ b/docker-compose.test-auth.yml @@ -11,7 +11,7 @@ services: dockerfile: Dockerfile volumes: - chroma-data:/chroma/chroma - command: uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 8000 --log-config chromadb/log_config.yml --timeout-keep-alive 30 + command: "--workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30" environment: - ANONYMIZED_TELEMETRY=False - ALLOW_RESET=True diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c8cae63b3eb..4384bad1982 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -11,7 +11,7 @@ services: dockerfile: Dockerfile volumes: - chroma-data:/chroma/chroma - command: uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 8000 --log-config chromadb/log_config.yml --timeout-keep-alive 30 + command: "--workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30" environment: - ANONYMIZED_TELEMETRY=False - ALLOW_RESET=True diff --git a/docker-compose.yml b/docker-compose.yml index 4cd653b01c7..20d09656907 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: # Default configuration for persist_directory in chromadb/config.py # Read more about deployments: https://docs.trychroma.com/deployment - chroma-data:/chroma/chroma - command: uvicorn chromadb.app:app --reload --workers 1 --host 0.0.0.0 --port 8000 --log-config chromadb/log_config.yml --timeout-keep-alive 30 + command: "--workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30" environment: - IS_PERSISTENT=TRUE - CHROMA_SERVER_AUTH_PROVIDER=${CHROMA_SERVER_AUTH_PROVIDER}