File size: 1,947 Bytes
d65a04f
 
 
29a3474
d65a04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c916f05
558806d
 
 
d65a04f
 
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
64
65
FROM python:3.12-slim

# Install curl for health check
RUN apt-get update && apt-get install -y curl && apt-get install -y git && \
    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 ["python", "main.py"]
#CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
#CMD ["uvicorn", "src.tg_bot:app", "--host", "0.0.0.0", "--port", "7860"]
# Uncomment the line below to run the application locally
#CMD ["python", "-m", "telegram_bot"]