1
- # FROM python:3.10-slim
2
- #
3
- # WORKDIR /app
4
- # COPY requirements.txt .
5
- # RUN pip install --no-cache-dir -r requirements.txt
6
- #
7
- # COPY ./app ./app
8
- #
9
- # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
1
+ # ---------- Script 1 ----------
2
+ FROM python:3.10-slim
10
3
11
- # Stage 1: Build Environment
12
- FROM python:3.10 as builder
13
4
WORKDIR /app
14
5
COPY requirements.txt .
15
- RUN pip install --user -r requirements.txt
16
-
17
- # Stage 2: Runtime Environment
18
- FROM python:3.10-slim
19
- WORKDIR /app
20
- COPY --from=builder /root/.local /root/.local
21
- COPY . .
6
+ RUN pip install --no-cache-dir -r requirements.txt
22
7
23
- # Ensure scripts in .local are usable
24
- ENV PATH=/root/.local/bin:$PATH
8
+ COPY ./app ./app
25
9
26
10
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
11
+ # ---------- Script 1 ----------
27
12
13
+ # ---------- Script 2 ----------
28
14
# Stage 1: Build Environment
15
+ # FROM python:3.10 as builder
16
+ # WORKDIR /app
17
+ # COPY requirements.txt .
18
+ # RUN pip install --user -r requirements.txt
19
+ #
20
+ # # Stage 2: Runtime Environment
21
+ # FROM python:3.10-slim
22
+ # WORKDIR /app
23
+ # COPY --from=builder /root/.local /root/.local
24
+ # COPY . .
25
+ #
26
+ # # Ensure scripts in .local are usable
27
+ # ENV PATH=/root/.local/bin:$PATH
28
+ #
29
+ # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
30
+ # ---------- Script 2 ----------
31
+
32
+ # ---------- Script 3 ----------
33
+ # # Stage 1: Build Environment
29
34
# FROM python:3.10-slim as builder
30
35
#
31
36
# RUN python -m venv /vgarbage
@@ -35,8 +40,8 @@ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
35
40
# COPY requirements.txt .
36
41
#
37
42
# RUN pip install --no-cache-dir -r requirements.txt
38
-
39
- # Stage 2: Runtime Environment
43
+ #
44
+ # # Stage 2: Runtime Environment
40
45
# FROM python:3.10-slim
41
46
# COPY --from=builder /vgarbage /vgarbage
42
47
# ENV PATH="/vgarbage/bin:$PATH"
@@ -47,3 +52,54 @@ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
47
52
# RUN rm -rf /root/.cache/pip
48
53
#
49
54
# CMD [ "uvcorn", "main.app", "--host", "0.0.0.0", "--port", "8123" ]
55
+ # ---------- Script 3 ----------
56
+
57
+ # ---------- Script 7 (Most Optimized) ----------
58
+ # # Multi-stage build with dependency optimization
59
+ # FROM python:3.10-slim as builder
60
+ #
61
+ # # Install build dependencies
62
+ # RUN apt-get update && \
63
+ # apt-get install -y --no-install-recommends gcc && \
64
+ # rm -rf /var/lib/apt/lists/*
65
+ #
66
+ # # Set up working directory
67
+ # WORKDIR /app
68
+ #
69
+ # # Copy requirements and install Python dependencies
70
+ # COPY requirements.txt .
71
+ # RUN pip install --no-cache-dir -r requirements.txt
72
+ #
73
+ # # Production stage - minimal image
74
+ # FROM python:3.10-slim
75
+ #
76
+ # # Set environment variables for performance
77
+ # ENV PYTHONDONTWRITEBYTECODE=1 \
78
+ # PYTHONUNBUFFERED=1 \
79
+ # PYTHONPATH=/app
80
+ #
81
+ # # Create non-root user
82
+ # RUN groupadd -r appgroup && \
83
+ # useradd -r -g appgroup appuser
84
+ #
85
+ # # Copy only the necessary Python dependencies
86
+ # COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
87
+ #
88
+ # # Set up working directory
89
+ # WORKDIR /app
90
+ #
91
+ # # Copy only the application code
92
+ # COPY ./app ./app
93
+ #
94
+ # # Change ownership to non-root user
95
+ # RUN chown -R appuser:appgroup /app
96
+ #
97
+ # # Switch to non-root user
98
+ # USER appuser
99
+ #
100
+ # # Expose port
101
+ # EXPOSE 8123
102
+ #
103
+ # # Run application
104
+ # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8123"]
105
+ # ---------- Script 7 (Most Optimized) ----------
0 commit comments