amaye15 commited on
Commit
20998ce
·
1 Parent(s): f844490

Feat - Use UV Installer

Browse files
Files changed (1) hide show
  1. Dockerfile +72 -10
Dockerfile CHANGED
@@ -1,9 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Stage 1: Build stage
2
  FROM python:3.12-slim as builder
3
 
4
  # Set environment variables
5
- ENV PYTHONDONTWRITEBYTECODE=1
6
- ENV PYTHONUNBUFFERED=1
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Create a non-root user
9
  RUN useradd -m -u 1000 user
@@ -14,11 +76,8 @@ WORKDIR /app
14
  # Copy only the requirements file first to leverage Docker cache
15
  COPY --chown=user ./requirements.txt /app/requirements.txt
16
 
17
- # Install dependencies in a virtual environment
18
- RUN python -m venv /opt/venv
19
- ENV PATH="/opt/venv/bin:$PATH"
20
- RUN pip install --no-cache-dir --upgrade pip && \
21
- pip install --no-cache-dir -r requirements.txt
22
 
23
  # Copy the rest of the application code
24
  COPY --chown=user . /app
@@ -30,13 +89,16 @@ FROM python:3.12-slim
30
  RUN useradd -m -u 1000 user
31
  USER user
32
 
33
- # Copy the virtual environment from the builder stage
34
- COPY --from=builder /opt/venv /opt/venv
35
- ENV PATH="/opt/venv/bin:$PATH"
36
 
37
  # Set the working directory
38
  WORKDIR /app
39
 
 
 
 
40
  # Copy only the necessary files from the builder stage
41
  COPY --from=builder --chown=user /app /app
42
 
 
1
+ # # Stage 1: Build stage
2
+ # FROM python:3.12-slim as builder
3
+
4
+ # # Set environment variables
5
+ # ENV PYTHONDONTWRITEBYTECODE=1
6
+ # ENV PYTHONUNBUFFERED=1
7
+
8
+ # # Create a non-root user
9
+ # RUN useradd -m -u 1000 user
10
+
11
+ # # Set the working directory
12
+ # WORKDIR /app
13
+
14
+ # # Copy only the requirements file first to leverage Docker cache
15
+ # COPY --chown=user ./requirements.txt /app/requirements.txt
16
+
17
+ # # Install dependencies in a virtual environment
18
+ # RUN python -m venv /opt/venv
19
+ # ENV PATH="/opt/venv/bin:$PATH"
20
+ # RUN pip install --no-cache-dir --upgrade pip && \
21
+ # pip install --no-cache-dir -r requirements.txt
22
+
23
+ # # Copy the rest of the application code
24
+ # COPY --chown=user . /app
25
+
26
+ # # Stage 2: Runtime stage
27
+ # FROM python:3.12-slim
28
+
29
+ # # Create a non-root user
30
+ # RUN useradd -m -u 1000 user
31
+ # USER user
32
+
33
+ # # Copy the virtual environment from the builder stage
34
+ # COPY --from=builder /opt/venv /opt/venv
35
+ # ENV PATH="/opt/venv/bin:$PATH"
36
+
37
+ # # Set the working directory
38
+ # WORKDIR /app
39
+
40
+ # # Copy only the necessary files from the builder stage
41
+ # COPY --from=builder --chown=user /app /app
42
+
43
+ # # Expose the port the app runs on
44
+ # EXPOSE 7860
45
+
46
+ # # Health check to ensure the application is running
47
+ # HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
48
+ # CMD curl -f http://localhost:7860/health || exit 1
49
+
50
+ # # Command to run the application with hot reloading
51
+ # CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "7860", "--reload"]
52
+
53
  # Stage 1: Build stage
54
  FROM python:3.12-slim as builder
55
 
56
  # Set environment variables
57
+ ENV PYTHONDONTWRITEBYTECODE=1 \
58
+ PYTHONUNBUFFERED=1 \
59
+ PATH="/root/.local/bin:$PATH"
60
+
61
+ # Install system dependencies (curl and ca-certificates for uv installer)
62
+ RUN apt-get update && apt-get install -y --no-install-recommends \
63
+ curl \
64
+ ca-certificates \
65
+ && rm -rf /var/lib/apt/lists/*
66
+
67
+ # Install uv using the official installer
68
+ RUN curl -sSfL https://astral.sh/uv/install.sh | sh
69
 
70
  # Create a non-root user
71
  RUN useradd -m -u 1000 user
 
76
  # Copy only the requirements file first to leverage Docker cache
77
  COPY --chown=user ./requirements.txt /app/requirements.txt
78
 
79
+ # Install dependencies using uv
80
+ RUN uv pip install --no-cache-dir -r requirements.txt
 
 
 
81
 
82
  # Copy the rest of the application code
83
  COPY --chown=user . /app
 
89
  RUN useradd -m -u 1000 user
90
  USER user
91
 
92
+ # Set environment variables
93
+ ENV PATH="/home/user/.local/bin:$PATH" \
94
+ PYTHONUNBUFFERED=1
95
 
96
  # Set the working directory
97
  WORKDIR /app
98
 
99
+ # Copy the virtual environment and installed dependencies from the builder stage
100
+ COPY --from=builder --chown=user /root/.local /home/user/.local
101
+
102
  # Copy only the necessary files from the builder stage
103
  COPY --from=builder --chown=user /app /app
104