diff --git a/truss/constants.py b/truss/constants.py index 7ed237ba2..5f34d1a6d 100644 --- a/truss/constants.py +++ b/truss/constants.py @@ -27,6 +27,8 @@ CONTROL_SERVER_CODE_DIR: pathlib.Path = TEMPLATES_DIR / "control" SUPPORTED_PYTHON_VERSIONS = {"3.8", "3.9", "3.10", "3.11"} +MAX_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE = "3.12" +MIN_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE = "3.8" TRTLLM_PREDICT_CONCURRENCY = 512 TRTLLM_MIN_MEMORY_REQUEST_GI = 24 diff --git a/truss/contexts/image_builder/serving_image_builder.py b/truss/contexts/image_builder/serving_image_builder.py index b3e224ca9..c88b59e32 100644 --- a/truss/contexts/image_builder/serving_image_builder.py +++ b/truss/contexts/image_builder/serving_image_builder.py @@ -22,6 +22,8 @@ CONTROL_SERVER_CODE_DIR, DOCKER_SERVER_TEMPLATES_DIR, FILENAME_CONSTANTS_MAP, + MAX_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE, + MIN_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE, MODEL_DOCKERFILE_NAME, OPENAI_COMPATIBLE_TAG, REQUIREMENTS_TXT_FILENAME, @@ -569,9 +571,31 @@ def _render_dockerfile( ) hf_access_token = config.secrets.get(HF_ACCESS_TOKEN_SECRET_NAME) + + max_supported_python_version_in_custom_base_image = ( + MAX_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE + ) + min_supported_python_version_in_custom_base_image = ( + MIN_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE + ) + max_supported_python_minor_version_in_custom_base_image = ( + MAX_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE.split(".")[1] + ) + min_supported_python_minor_version_in_custom_base_image = ( + MIN_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE.split(".")[1] + ) + supported_python_major_version_in_custom_base_image = ( + MIN_SUPPORTED_PYTHON_VERSION_IN_CUSTOM_BASE_IMAGE.split(".")[0] + ) + dockerfile_contents = dockerfile_template.render( should_install_server_requirements=should_install_server_requirements, base_image_name_and_tag=base_image_name_and_tag, + max_supported_python_version_in_custom_base_image=max_supported_python_version_in_custom_base_image, + min_supported_python_version_in_custom_base_image=min_supported_python_version_in_custom_base_image, + max_supported_python_minor_version_in_custom_base_image=max_supported_python_minor_version_in_custom_base_image, + min_supported_python_minor_version_in_custom_base_image=min_supported_python_minor_version_in_custom_base_image, + supported_python_major_version_in_custom_base_image=supported_python_major_version_in_custom_base_image, should_install_system_requirements=should_install_system_requirements, should_install_requirements=should_install_python_requirements, should_install_user_requirements_file=should_install_user_requirements_file, diff --git a/truss/templates/base.Dockerfile.jinja b/truss/templates/base.Dockerfile.jinja index 40b4d4349..76409d0d6 100644 --- a/truss/templates/base.Dockerfile.jinja +++ b/truss/templates/base.Dockerfile.jinja @@ -5,8 +5,8 @@ ENV PYTHON_EXECUTABLE={{ config.base_image.python_executable_path or 'python3' } {% block fail_fast %} RUN grep -w 'ID=debian\|ID_LIKE=debian' /etc/os-release || { echo "ERROR: Supplied base image is not a debian image"; exit 1; } -RUN $PYTHON_EXECUTABLE -c "import sys; sys.exit(0) if sys.version_info.major == 3 and sys.version_info.minor >=8 and sys.version_info.minor <=12 else sys.exit(1)" \ - || { echo "ERROR: Supplied base image does not have 3.8 <= python <= 3.12"; exit 1; } +RUN $PYTHON_EXECUTABLE -c "import sys; sys.exit(0) if sys.version_info.major == {{supported_python_major_version_in_custom_base_image}} and sys.version_info.minor >={{min_supported_python_minor_version_in_custom_base_image}} and sys.version_info.minor <={{max_supported_python_minor_version_in_custom_base_image}} else sys.exit(1)" \ + || { echo "ERROR: Supplied base image does not have {{min_supported_python_version_in_custom_base_image}} <= python <= {{max_supported_python_version_in_custom_base_image}}"; exit 1; } {% endblock %} RUN pip install --upgrade pip --no-cache-dir \