@@ -5,23 +5,30 @@ FROM debian:12-slim
5
5
ARG DEBIAN_FRONTEND=noninteractive
6
6
7
7
# Define the default allowed models and the default model
8
- ARG ALLOWED_MODELS="stable-diffusion-v3.5 stable-diffusion-xl flux-schnell"
9
8
ARG DEFAULT_MODEL="stable-diffusion-v3.5"
9
+ ARG HOST="0.0.0.0"
10
+ ARG PORT="8100"
10
11
11
- # Set default model as a build argument and runtime environment variable
12
+ # Set environment variables for the default model and allowed models
13
+ ENV ALLOWED_MODELS="stable-diffusion-v3.5 stable-diffusion-xl flux-schnell"
12
14
ENV DEFAULT_MODEL=${DEFAULT_MODEL}
15
+ ENV HOST=${HOST}
16
+ ENV PORT=${PORT}
17
+
18
+ # Do checking if the default model is in the allowed models list
19
+ RUN if [[ ! "${ALLOWED_MODELS}" =~ "${DEFAULT_MODEL}" ]]; then \
20
+ echo "Error: The default model '${DEFAULT_MODEL}' is not in the allowed models list." >&2; \
21
+ exit 1; \
22
+ fi
13
23
14
24
# Ensure the container is running as root for package installations
15
25
USER root
16
26
17
- # Set the working directory early for clarity and organization
18
- WORKDIR /usr/src/app
19
-
20
27
# Install system dependencies, including Python 3.11 and venv
21
28
RUN apt-get update \
22
29
&& apt-get install -y --no-install-recommends \
23
30
ffmpeg \
24
- wget \
31
+ curl \
25
32
git \
26
33
gnupg2 \
27
34
libtbb12 \
@@ -30,23 +37,21 @@ RUN apt-get update \
30
37
&& apt-get clean && rm -rf /var/lib/apt/lists/*
31
38
32
39
# Install Intel GPU drivers with error handling and version pinning
33
- RUN mkdir /tmp/neo \
34
- && cd /tmp/neo \
35
- && wget -q https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17791.9/intel-igc-core_1.0.17791.9_amd64.deb \
36
- && wget -q https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17791.9/intel-igc-opencl_1.0.17791.9_amd64.deb \
37
- && wget -q https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/intel-level-zero-gpu_1.6.31294.12_amd64.deb \
38
- && wget -q https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/intel-opencl-icd_24.39.31294.12_amd64.deb \
39
- && wget -q https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/libigdgmm12_22.5.2_amd64.deb \
40
+ WORKDIR /tmp/neo
41
+ RUN curl -sSLO https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17791.9/intel-igc-core_1.0.17791.9_amd64.deb \
42
+ && curl -sSLO https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17791.9/intel-igc-opencl_1.0.17791.9_amd64.deb \
43
+ && curl -sSLO https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/intel-level-zero-gpu_1.6.31294.12_amd64.deb \
44
+ && curl -sSLO https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/intel-opencl-icd_24.39.31294.12_amd64.deb \
45
+ && curl -sSLO https://github.com/intel/compute-runtime/releases/download/24.39.31294.12/libigdgmm12_22.5.2_amd64.deb \
40
46
&& dpkg -i *.deb \
41
47
&& rm -rf /tmp/neo
42
48
43
49
# Install Intel NPU drivers with error handling and version pinning
44
- RUN mkdir /tmp/npu-driver \
45
- && cd /tmp/npu-driver \
46
- && wget -q https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-driver-compiler-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
47
- && wget -q https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-fw-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
48
- && wget -q https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-level-zero-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
49
- && wget -q https://github.com/oneapi-src/level-zero/releases/download/v1.17.6/level-zero_1.17.6+u22.04_amd64.deb \
50
+ WORKDIR /tmp/npu-driver
51
+ RUN curl -sSLO https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-driver-compiler-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
52
+ && curl -sSLO https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-fw-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
53
+ && curl -sSLO https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-level-zero-npu_1.10.0.20241107-11729849322_ubuntu22.04_amd64.deb \
54
+ && curl -sSLO https://github.com/oneapi-src/level-zero/releases/download/v1.17.6/level-zero_1.17.6+u22.04_amd64.deb \
50
55
&& dpkg -i *.deb \
51
56
&& rm -rf /tmp/npu-driver
52
57
@@ -57,46 +62,25 @@ RUN groupadd -r openvino && useradd -r -g openvino -G video openvino
57
62
RUN mkdir -p /home/openvino && \
58
63
chown -R openvino:openvino /home/openvino
59
64
60
- # Copy application files and adjust permissions (excluding the virtual environments)
61
- COPY . /usr/src/app
62
- RUN find /usr/src/app -not -path "/usr/src/app/*/.venv*" -exec chown openvino:openvino {} + \
63
- && find /usr/src/app -not -path "/usr/src/app/*/.venv*" -exec chmod 755 {} +
64
-
65
- # Remove existing virtual environments to ensure a clean install
66
- RUN rm -rf /usr/src/app/*/.venv
67
-
68
- # Create a Python virtual environment for each model and install dependencies
69
- RUN for model in $ALLOWED_MODELS; do \
70
- python3.11 -m venv /usr/src/app/$model/.venv; \
71
- /usr/src/app/$model/.venv/bin/python -m pip install --no-cache-dir --upgrade pip; \
72
- if [ -f "/usr/src/app/$model/requirements.txt" ]; then \
73
- /usr/src/app/$model/.venv/bin/python -m pip install --no-cache-dir -r /usr/src/app/$model/requirements.txt; \
74
- fi; \
75
- chown -R openvino:openvino /usr/src/app/$model/.venv; \
76
- done
77
-
78
- # Set the environment variable for the virtual environment based on the selected model
79
- ENV PATH="/usr/src/app/${SELECTED_MODEL}/.venv/bin:$PATH"
80
-
81
- # Switch to the non-root user for security
82
65
USER openvino
66
+ WORKDIR /usr/src/app/${DEFAULT_MODEL}
83
67
84
- # Set the working directory based on the selected model
85
- WORKDIR /usr/src/app/${SELECTED_MODEL}
68
+ # Create a virtual environment for the default model and install dependencies
69
+ RUN python3 -m venv .venv
70
+ ENV PATH="/usr/src/app/${DEFAULT_MODEL}/.venv/bin:$PATH"
71
+ COPY --chown=openvino:openvino ./${DEFAULT_MODEL}/requirements.txt .
72
+ RUN python3 -m pip install --no-cache-dir --upgrade pip \
73
+ && python3 -m pip install --no-cache-dir -r requirements.txt
74
+
75
+ # Copy the model files and scripts into the container
76
+ COPY --chown=openvino:openvino ./${DEFAULT_MODEL} .
86
77
87
78
# Expose port for the microservice
88
- EXPOSE 8100
89
-
90
- # Allow runtime injection of Hugging Face Token and model selection
91
- # If HF_TOKEN is not provided, models requiring it will fail securely.
92
- CMD ["bash" , "-c" , \
93
- "SELECTED_MODEL=${MODEL:-$DEFAULT_MODEL} && \
94
- export PATH=/usr/src/app/${SELECTED_MODEL}/.venv/bin:$PATH && \
95
- export HF_TOKEN=${HF_TOKEN:-''} && \
96
- echo Using model: $SELECTED_MODEL && \
97
- echo HF_TOKEN set to: ${HF_TOKEN:0:5}****** && \
98
- /usr/src/app/${SELECTED_MODEL}/.venv/bin/python /usr/src/app/${SELECTED_MODEL}/backend/server.py" ]
79
+ EXPOSE ${PORT}
80
+
81
+ # Set the entrypoint to the server script
82
+ CMD ["bash" , "-c" , "python3 backend/server.py" ]
99
83
100
84
# Add a basic health check
101
85
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
102
- CMD exit 0
86
+ CMD curl -f http://localhost:${PORT}/health || exit 1
0 commit comments