Spaces:
Build error
Build error
Vo Minh Vu
commited on
Commit
·
6c670dd
1
Parent(s):
4c9e449
Update Dockerfile
Browse files- Dockerfile +22 -8
Dockerfile
CHANGED
|
@@ -1,25 +1,39 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
| 6 |
COPY requirements.txt .
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
-
|
| 10 |
-
USER user
|
| 11 |
ENV HOME=/home/user \
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
# Create static directory with proper permissions
|
| 19 |
-
RUN mkdir -p /app/static &&
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Expose port
|
| 22 |
EXPOSE 8000
|
| 23 |
|
| 24 |
# Run the application
|
| 25 |
-
CMD ["uvicorn", "app
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Set working directory
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
# Create non-root user for security best practices
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
|
| 9 |
+
# Copy requirements first for better caching
|
| 10 |
COPY requirements.txt .
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
+
# Set environment variables
|
|
|
|
| 14 |
ENV HOME=/home/user \
|
| 15 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 16 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 17 |
+
PYTHONUNBUFFERED=1 \
|
| 18 |
+
# Set model cache to a writable location
|
| 19 |
+
TRANSFORMERS_CACHE=/tmp/transformers_cache \
|
| 20 |
+
HF_HOME=/tmp/hf_home
|
| 21 |
|
| 22 |
+
# Create cache directories with proper permissions
|
| 23 |
+
RUN mkdir -p /tmp/transformers_cache /tmp/hf_home && \
|
| 24 |
+
chmod 777 /tmp/transformers_cache /tmp/hf_home
|
| 25 |
|
| 26 |
+
# Copy application code
|
| 27 |
+
COPY --chown=user:user . /app/
|
| 28 |
|
| 29 |
# Create static directory with proper permissions
|
| 30 |
+
RUN mkdir -p /app/static && chown -R user:user /app/static
|
| 31 |
+
|
| 32 |
+
# Switch to non-root user
|
| 33 |
+
USER user
|
| 34 |
|
| 35 |
# Expose port
|
| 36 |
EXPOSE 8000
|
| 37 |
|
| 38 |
# Run the application
|
| 39 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|