File size: 1,820 Bytes
2eb5166
f69c49c
b9988d2
 
 
f69c49c
645f814
 
f69c49c
645f814
 
f69c49c
645f814
 
 
 
 
 
67c785a
fd7be58
 
147142a
 
6c0eb4d
645f814
 
d6d7dca
645f814
 
 
 
 
 
 
b9988d2
f69c49c
645f814
 
 
be62f09
 
 
645f814
 
 
 
 
 
 
 
 
 
 
67c785a
645f814
 
b9988d2
d5d5cab
beacc62
0c9698b
6df4a0a
beacc62
6df4a0a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
FROM python:3.12-slim

# Install curl for health check
RUN apt-get update && apt-get install -y curl && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

# Set home to the user's home directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/home/user/app \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

ENV PYTHONPATH="$HOME/.local/lib/python3.12/site-packages:$PYTHONPATH"

# Set Python path so `src.telegram_bot` is importable
ENV PYTHONPATH=/home/user/app

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Upgrade pip with user permissions
RUN pip install --no-cache-dir --upgrade pip

# Copy requirements first for better Docker layer caching
COPY --chown=user requirements.txt $HOME/app/

# Install Python dependencies in user space
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy source code with proper ownership
COPY --chown=user src/ $HOME/app/src/

# Copy the main application file
COPY --chown=user main.py $HOME/app/

# Copy any additional files you need
COPY --chown=user *.py $HOME/app/
COPY --chown=user .env* $HOME/app/

# Create any directories your app needs
RUN mkdir -p $HOME/app/logs && \
    mkdir -p $HOME/app/data


# Expose port
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl --fail http://localhost:7860/health || exit 1

# Run the application when the container starts HF
#CMD ["uvicorn", "src.telegram_bot:app", "--host", "0.0.0.0", "--port", "7860"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
# Uncomment the line below to run the application locally
#CMD ["python", "-m", "telegram_bot"]