2
2
{% - include "cache.Dockerfile.jinja" %}
3
3
{% - endif %} {#- endif model_cache_v1 #}
4
4
5
- {% - set requires_live_reload = config .live_reload and not config .docker_server %}
6
-
7
- {% - if requires_live_reload %}
8
- {% include "control_venv.Dockerfile.jinja" %}
9
- {% - endif %} {#- endif requires_live_reload #}
10
-
11
5
{% extends "base.Dockerfile.jinja" %}
12
6
13
-
14
7
{% block base_image_patch %}
15
8
{# If user base image is supplied in config, apply build commands from truss base image #}
16
9
{% if config .base_image %}
@@ -34,14 +27,14 @@ COPY ./{{ base_server_requirements_filename }} {{ base_server_requirements_filen
34
27
RUN pip install -r {{ base_server_requirements_filename }} --no-cache-dir && rm -rf /root/.cache/pip
35
28
{% - endif %} {#- endif not config.docker_server #}
36
29
37
- {% - if requires_live_reload %}
30
+ {% - if config . live_reload and not config . docker_server %}
38
31
{# Create symlink for inference server IF a user base image is supplied and live_reload is enabled. #}
39
32
{# This links the base images primary python executable path to /usr/local/bin/python. #}
40
33
{# This is specific to the user-provided base image scenario. #}
41
34
RUN readlink {{ config.base_image.python_executable_path }} & >/dev/null \
42
35
&& echo "WARNING: Overwriting existing link at /usr/local/bin/python"
43
36
RUN ln -sf {{ config.base_image.python_executable_path }} /usr/local/bin/python
44
- {% - endif %} {#- endif requires_live_reload #}
37
+ {% - endif %} {#- endif config.live_reload and not config.docker_server (for symlink) #}
45
38
{% endif %} {#- endif config.base_image #}
46
39
47
40
{% endblock %} {#- endblock base_image_patch #}
@@ -98,24 +91,34 @@ COPY ./truss /app/truss
98
91
{% - endif %} {#- endif use_local_src #}
99
92
100
93
COPY ./config.yaml /app/config.yaml
101
- {% - if requires_live_reload %}
94
+ {% - if config . live_reload and not config . docker_server %}
102
95
COPY ./control /control
103
-
104
- # NB(nikhil): Copy the virtual env, and system dependencies for the
105
- # python version specific to the control server. We need to run ldconfig
106
- # so dynamic linking works.
107
- COPY --from=control-server-venv /usr/local/lib/ /usr/local/lib/
108
- COPY --from=control-server-venv /control/.env /control/.env
109
- RUN ldconfig
110
-
96
+ # Step 1: Ensure a usable python{{ control_python_version }} is available
97
+ RUN if python{{ control_python_version }} -c 'import venv; venv.EnvBuilder(with_pip=True).create("/tmp/__probe_env")' > /dev/null 2>&1 ; then \
98
+ echo "Using system python{{ control_python_version }}"; \
99
+ python{{ control_python_version }} -m pip install --upgrade pip virtualenv && \
100
+ python{{ control_python_version }} -m virtualenv /control/.env; \
101
+ else \
102
+ echo "Installing Miniforge-based python{{ control_python_version }}..."; \
103
+ curl -fsSL -o miniforge.sh https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh && \
104
+ bash miniforge.sh -b -p /opt/conda-control && \
105
+ rm miniforge.sh && \
106
+ /opt/conda-control/bin/conda create -y -p /opt/conda-control/envs/py{{ control_python_version }} python={{ control_python_version }} && \
107
+ /opt/conda-control/envs/py{{ control_python_version }}/bin/pip install --upgrade pip virtualenv && \
108
+ /opt/conda-control/bin/conda clean -afy && \
109
+ rm -rf /opt/conda-control/pkgs && \
110
+ /opt/conda-control/envs/py{{ control_python_version }}/bin/python -m virtualenv /control/.env; \
111
+ fi
112
+
113
+ # Step 2: Install requirements into the freshly created venv
111
114
RUN /control/.env/bin/pip install -r /control/requirements.txt
112
- {% - endif %} {#- endif requires_live_reload #}
113
-
115
+ {% - endif %} {#- endif config.live_reload and not config.docker_server (for control server setup) #}
114
116
{% - if model_dir_exists %}
115
117
COPY ./{{ config.model_module_dir }} /app/model
116
118
{% - endif %} {#- endif model_dir_exists #}
117
119
{% endblock %} {#- endblock app_copy #}
118
120
121
+
119
122
{% block run %}
120
123
{% - if config .docker_server %}
121
124
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -133,7 +136,7 @@ COPY supervisord.conf {{ supervisor_config_path }}
133
136
ENV SUPERVISOR_SERVER_URL="{{ supervisor_server_url }}"
134
137
ENV SERVER_START_CMD="supervisord -c {{ supervisor_config_path }}"
135
138
ENTRYPOINT ["supervisord", "-c", "{{ supervisor_config_path }}"]
136
- {% - elif requires_live_reload %} {#- elif requires_live_reload #}
139
+ {% - elif config . live_reload %} {#- elif config.live_reload #}
137
140
ENV HASH_TRUSS="{{ truss_hash }}"
138
141
ENV CONTROL_SERVER_PORT="8080"
139
142
ENV INFERENCE_SERVER_PORT="8090"
0 commit comments