opex792 commited on
Commit
3c7fa13
·
verified ·
1 Parent(s): 63b0848

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -41
Dockerfile CHANGED
@@ -1,70 +1,50 @@
1
- # Stage 1: Build stage
2
  FROM python:3.10-slim AS builder
3
 
4
- # Install build dependencies
 
 
 
 
5
  RUN apt-get update && apt-get install -y \
6
  ffmpeg \
7
  libsndfile1 \
8
  git \
 
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # Create a non-root user
12
- RUN useradd -m -u 1000 user
13
-
14
- # Switch to non-root user
15
  USER user
16
  ENV PATH="/home/user/.local/bin:$PATH"
17
-
18
- # Set working directory
19
  WORKDIR /app
20
 
21
- # Copy requirements and setup scripts
22
- COPY --chown=user requirements.txt setup_imagebind.py README.md main.py ./
23
-
24
- # Install dependencies into a virtual environment
25
  RUN python -m venv /app/venv
26
  ENV PATH="/app/venv/bin:$PATH"
27
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
 
28
 
29
- # Run setup script to download ImageBind
30
  RUN python setup_imagebind.py
 
31
 
32
- # Install ImageBind
33
- RUN pip install --no-cache-dir .
34
 
35
- # Stage 2: Runtime stage
36
- FROM python:3.10-slim
 
37
 
38
- # Install runtime dependencies only
39
  RUN apt-get update && apt-get install -y \
40
  ffmpeg \
41
  libsndfile1 \
42
  && rm -rf /var/lib/apt/lists/*
43
 
44
- # Create a non-root user
45
- RUN useradd -m -u 1000 user
46
-
47
- # Switch to non-root user
48
- USER user
49
- ENV PATH="/home/user/.local/bin:$PATH"
50
-
51
- # Set working directory
52
  WORKDIR /app
53
 
54
- # Copy virtual environment from builder
55
- COPY --from=builder --chown=user /app/venv /app/venv
56
- ENV PATH="/app/venv/bin:$PATH"
57
-
58
- # Copy ImageBind from builder
59
- COPY --from=builder --chown=user /app/imagebind* .
60
- COPY --from=builder --chown=user /app/setup.py .
61
- COPY --from=builder --chown=user /app/build .
62
-
63
- # Copy application code
64
- COPY --chown=user main.py .
65
 
66
- # Expose the port
67
  EXPOSE 7860
68
-
69
- # Command to run the application
70
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
  FROM python:3.10-slim AS builder
2
 
3
+ ENV PYTHONUNBUFFERED=1 \
4
+ PIP_NO_CACHE_DIR=off \
5
+ PIP_DISABLE_PIP_VERSION_CHECK=on \
6
+ PIP_DEFAULT_TIMEOUT=100
7
+
8
  RUN apt-get update && apt-get install -y \
9
  ffmpeg \
10
  libsndfile1 \
11
  git \
12
+ build-essential \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ RUN useradd -m -s /bin/bash -u 1000 user
 
 
 
16
  USER user
17
  ENV PATH="/home/user/.local/bin:$PATH"
 
 
18
  WORKDIR /app
19
 
20
+ COPY --chown=user requirements.txt ./
 
 
 
21
  RUN python -m venv /app/venv
22
  ENV PATH="/app/venv/bin:$PATH"
23
+ RUN pip install --upgrade pip
24
+ RUN pip install -r requirements.txt
25
 
26
+ COPY --chown=user setup_imagebind.py README.md ./
27
  RUN python setup_imagebind.py
28
+ RUN pip install .
29
 
30
+ FROM python:3.10-slim AS runtime
 
31
 
32
+ ENV PYTHONUNBUFFERED=1 \
33
+ PATH="/app/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
34
+ APP_USER="user"
35
 
 
36
  RUN apt-get update && apt-get install -y \
37
  ffmpeg \
38
  libsndfile1 \
39
  && rm -rf /var/lib/apt/lists/*
40
 
41
+ RUN useradd -m -s /bin/bash -u 1000 ${APP_USER}
42
+ USER ${APP_USER}
 
 
 
 
 
 
43
  WORKDIR /app
44
 
45
+ COPY --from=builder --chown=${APP_USER} /app/venv /app/venv
46
+ COPY --chown=${APP_USER} main.py .
47
+ COPY --chown=${APP_USER} .env .
 
 
 
 
 
 
 
 
48
 
 
49
  EXPOSE 7860
 
 
50
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]