Spaces:
Runtime error
Runtime error
Commit
·
9de4eee
1
Parent(s):
efd3dc5
Updated Dockerfile
Browse files- Dockerfile +40 -10
- main/main.py +2 -1
Dockerfile
CHANGED
@@ -1,20 +1,50 @@
|
|
1 |
-
# Use
|
2 |
-
FROM python:
|
3 |
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
WORKDIR /app
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
EXPOSE 7860
|
18 |
|
19 |
# Command to run the application
|
20 |
-
CMD ["uvicorn", "main.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
# Use Red Hat Universal Base Image (UBI) 9 with Python 3.11
|
2 |
+
FROM registry.access.redhat.com/ubi9/python-311:latest
|
3 |
|
4 |
+
# Switch to root for system installations
|
5 |
+
USER 0
|
6 |
|
7 |
+
# Install system dependencies
|
8 |
+
RUN dnf install -y \
|
9 |
+
gcc \
|
10 |
+
gcc-c++ \
|
11 |
+
git \
|
12 |
+
make \
|
13 |
+
&& dnf clean all \
|
14 |
+
&& rm -rf /var/cache/dnf
|
15 |
|
16 |
+
# Create application user (using Red Hat standard practices)
|
17 |
+
RUN useradd -u 1001 -g 0 -M -d /app user && \
|
18 |
+
mkdir -p /app && \
|
19 |
+
chown -R 1001:0 /app && \
|
20 |
+
chmod -R g=u /app
|
21 |
+
|
22 |
+
# Set working directory
|
23 |
WORKDIR /app
|
24 |
|
25 |
+
# Switch to non-root user
|
26 |
+
USER 1001
|
27 |
+
|
28 |
+
# Copy requirements first to leverage Docker cache
|
29 |
+
COPY --chown=1001:0 ./requirements.txt requirements.txt
|
30 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
31 |
+
pip install --no-cache-dir --upgrade -r requirements.txt
|
32 |
+
|
33 |
+
# Copy application code
|
34 |
+
COPY --chown=1001:0 . /app
|
35 |
+
COPY --chown=1001:0 main/ /app/main
|
36 |
+
|
37 |
+
# Create directory for models cache
|
38 |
+
RUN mkdir -p /app/.cache/huggingface && \
|
39 |
+
chmod -R g=u /app/.cache
|
40 |
|
41 |
+
# Environment variables
|
42 |
+
ENV PYTHONUNBUFFERED=1
|
43 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
44 |
+
ENV HOME=/app
|
45 |
+
ENV HUGGINGFACE_HOME=/app/.cache/huggingface
|
46 |
|
47 |
EXPOSE 7860
|
48 |
|
49 |
# Command to run the application
|
50 |
+
CMD ["uvicorn", "main.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main/main.py
CHANGED
@@ -73,7 +73,8 @@ def create_app():
|
|
73 |
# Launch inference workers (assuming single uvicorn worker for now)
|
74 |
_MANAGER, _WORKER_PROCESSES = server.launch_inference_worker(num_uvicorn_servers=1)
|
75 |
|
76 |
-
# Get the FastAPI
|
|
|
77 |
app = server.app
|
78 |
|
79 |
# Add CORS middleware
|
|
|
73 |
# Launch inference workers (assuming single uvicorn worker for now)
|
74 |
_MANAGER, _WORKER_PROCESSES = server.launch_inference_worker(num_uvicorn_servers=1)
|
75 |
|
76 |
+
# Get the FastAPI appls
|
77 |
+
|
78 |
app = server.app
|
79 |
|
80 |
# Add CORS middleware
|