saidinesh07 commited on
Commit
d85e6f9
·
verified ·
1 Parent(s): a906880

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -17
Dockerfile CHANGED
@@ -1,21 +1,27 @@
1
  # Dockerfile for InfluencerFlow AI Platform
2
- # Lightweight & Fast Build - Core Features Only
3
- # Reference: https://docs.astral.sh/uv/guides/integration/docker/
4
-
5
  FROM python:3.11-slim
6
 
7
  # Install uv from the official image
8
  COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
9
 
 
 
 
 
10
  # Set working directory
11
- WORKDIR /app
12
 
13
  # Set environment variables
14
  ENV PYTHONDONTWRITEBYTECODE=1
15
  ENV PYTHONUNBUFFERED=1
16
- ENV PYTHONPATH=/app
17
  ENV UV_SYSTEM_PYTHON=1
18
- ENV UV_CACHE_DIR=/app/.cache/uv
 
 
 
 
19
 
20
  # Install minimal system dependencies
21
  RUN apt-get update && apt-get install -y \
@@ -23,24 +29,27 @@ RUN apt-get update && apt-get install -y \
23
  && rm -rf /var/lib/apt/lists/* \
24
  && apt-get clean
25
 
26
- # Create necessary directories (includes cache path) and fix permissions
27
- RUN mkdir -p /app/data /app/logs /app/.cache/uv && chmod -R 777 /app/.cache
 
 
 
28
 
29
  # Copy project files for dependency resolution
30
- COPY pyproject.toml ./
31
 
32
  # Install ONLY core dependencies (no ML) for fast build
33
- RUN --mount=type=cache,target=/app/.cache/uv \
34
- uv sync
35
 
36
  # Copy the entire project
37
- COPY . .
38
 
39
  # Install the project itself
40
- RUN --mount=type=cache,target=/app/.cache/uv \
41
- uv sync --frozen
42
 
43
- # Set default environment variables for Hugging Face
44
  ENV HOST=0.0.0.0
45
  ENV PORT=7860
46
  ENV DEMO_MODE=true
@@ -54,5 +63,5 @@ EXPOSE 7860
54
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
55
  CMD curl -f http://localhost:7860/health || exit 1
56
 
57
- # Command to run the application
58
- CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Dockerfile for InfluencerFlow AI Platform
2
+ # Optimized for Hugging Face Spaces with proper permissions
 
 
3
  FROM python:3.11-slim
4
 
5
  # Install uv from the official image
6
  COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
7
 
8
+ # Create non-root user for Hugging Face Spaces
9
+ RUN useradd -m -u 1000 user
10
+ USER user
11
+
12
  # Set working directory
13
+ WORKDIR /home/user/app
14
 
15
  # Set environment variables
16
  ENV PYTHONDONTWRITEBYTECODE=1
17
  ENV PYTHONUNBUFFERED=1
18
+ ENV PYTHONPATH=/home/user/app
19
  ENV UV_SYSTEM_PYTHON=1
20
+ ENV UV_CACHE_DIR=/home/user/.cache/uv
21
+ ENV PATH="/home/user/.local/bin:$PATH"
22
+
23
+ # Switch to root to install system dependencies
24
+ USER root
25
 
26
  # Install minimal system dependencies
27
  RUN apt-get update && apt-get install -y \
 
29
  && rm -rf /var/lib/apt/lists/* \
30
  && apt-get clean
31
 
32
+ # Switch back to user
33
+ USER user
34
+
35
+ # Create necessary directories with proper permissions
36
+ RUN mkdir -p /home/user/app/data /home/user/app/logs /home/user/.cache/uv
37
 
38
  # Copy project files for dependency resolution
39
+ COPY --chown=user:user pyproject.toml ./
40
 
41
  # Install ONLY core dependencies (no ML) for fast build
42
+ RUN --mount=type=cache,target=/home/user/.cache/uv,uid=1000,gid=1000 \
43
+ uv sync --no-dev
44
 
45
  # Copy the entire project
46
+ COPY --chown=user:user . .
47
 
48
  # Install the project itself
49
+ RUN --mount=type=cache,target=/home/user/.cache/uv,uid=1000,gid=1000 \
50
+ uv sync --frozen --no-dev
51
 
52
+ # Set default environment variables for Hugging Face Spaces
53
  ENV HOST=0.0.0.0
54
  ENV PORT=7860
55
  ENV DEMO_MODE=true
 
63
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
64
  CMD curl -f http://localhost:7860/health || exit 1
65
 
66
+ # Command to run the application
67
+ CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]