Skip to content

Commit 61b1f6f

Browse files
committed
refactor: streamline Dockerfile and remove unused files for FluxSchnell (#506)
1 parent 8eca8c7 commit 61b1f6f

File tree

10 files changed

+44
-629
lines changed

10 files changed

+44
-629
lines changed

usecases/ai/microservices/text-to-image/Dockerfile

+39-55
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@ FROM debian:12-slim
55
ARG DEBIAN_FRONTEND=noninteractive
66

77
# Define the default allowed models and the default model
8-
ARG ALLOWED_MODELS="stable-diffusion-v3.5 stable-diffusion-xl flux-schnell"
98
ARG DEFAULT_MODEL="stable-diffusion-v3.5"
9+
ARG HOST="0.0.0.0"
10+
ARG PORT="8100"
1011

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"
1214
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
1323

1424
# Ensure the container is running as root for package installations
1525
USER root
1626

17-
# Set the working directory early for clarity and organization
18-
WORKDIR /usr/src/app
19-
2027
# Install system dependencies, including Python 3.11 and venv
2128
RUN apt-get update \
2229
&& apt-get install -y --no-install-recommends \
2330
ffmpeg \
24-
wget \
31+
curl \
2532
git \
2633
gnupg2 \
2734
libtbb12 \
@@ -30,23 +37,21 @@ RUN apt-get update \
3037
&& apt-get clean && rm -rf /var/lib/apt/lists/*
3138

3239
# 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 \
4046
&& dpkg -i *.deb \
4147
&& rm -rf /tmp/neo
4248

4349
# 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 \
5055
&& dpkg -i *.deb \
5156
&& rm -rf /tmp/npu-driver
5257

@@ -57,46 +62,25 @@ RUN groupadd -r openvino && useradd -r -g openvino -G video openvino
5762
RUN mkdir -p /home/openvino && \
5863
chown -R openvino:openvino /home/openvino
5964

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
8265
USER openvino
66+
WORKDIR /usr/src/app/${DEFAULT_MODEL}
8367

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} .
8677

8778
# 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"]
9983

10084
# Add a basic health check
10185
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
102-
CMD exit 0
86+
CMD curl -f http://localhost:${PORT}/health || exit 1

usecases/ai/microservices/text-to-image/flux-dev/.gitignore

-3
This file was deleted.

usecases/ai/microservices/text-to-image/flux-dev/backend/client.py

-125
This file was deleted.

usecases/ai/microservices/text-to-image/flux-dev/backend/cmd_helper.py

-43
This file was deleted.

0 commit comments

Comments
 (0)