likhonsheikhdev commited on
Commit
2026cc9
·
verified ·
1 Parent(s): ba10d24

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +47 -0
Dockerfile ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Builder
2
+ FROM python:3.10-slim as builder
3
+
4
+ # Set environment variables to prevent Python from writing .pyc files and to buffer stdout/stderr
5
+ ENV PYTHONDONTWRITEBYTECODE=1
6
+ ENV PYTHONUNBUFFERED=1
7
+
8
+ # Set the working directory in the container to /app
9
+ WORKDIR /app
10
+
11
+ # Install system dependencies required for building Python packages
12
+ RUN apt-get update && \
13
+ apt-get install -y --no-install-recommends gcc build-essential && \
14
+ rm -rf /var/lib/apt/lists/*
15
+
16
+ # Copy only requirements.txt first to leverage Docker cache
17
+ COPY requirements.txt .
18
+
19
+ # Create a virtual environment
20
+ RUN python -m venv /opt/venv
21
+
22
+ # Activate the virtual environment and update PATH
23
+ ENV PATH="/opt/venv/bin:$PATH"
24
+
25
+ # Upgrade pip and install Python dependencies
26
+ RUN pip install --upgrade pip && \
27
+ pip install -r requirements.txt
28
+
29
+ # Stage 2: Final runtime image
30
+ FROM python:3.10-slim
31
+
32
+ # Set environment variables
33
+ ENV PYTHONDONTWRITEBYTECODE=1
34
+ ENV PYTHONUNBUFFERED=1
35
+ ENV PATH="/opt/venv/bin:$PATH"
36
+
37
+ # Set the working directory in the container to /app
38
+ WORKDIR /app
39
+
40
+ # Copy the virtual environment from the builder stage
41
+ COPY --from=builder /opt/venv /opt/venv
42
+
43
+ # Copy the application code into the container
44
+ COPY . /app
45
+
46
+ # Command to run the Chainlit server using shell form for environment variable expansion
47
+ CMD python -m chainlit run app.py -h --host 0.0.0.0 --port ${PORT}