Spaces:
Runtime error
Runtime error
Dmitry Beresnev
commited on
Commit
·
645f814
1
Parent(s):
67c785a
fix dockerfile
Browse files- Dockerfile +44 -18
Dockerfile
CHANGED
|
@@ -1,34 +1,60 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
ENV HOME=/app
|
| 5 |
-
ENV PYTHONPATH=$HOME
|
| 6 |
-
|
| 7 |
-
# Create app directory and set as working dir
|
| 8 |
-
WORKDIR $HOME
|
| 9 |
-
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
build-essential \
|
| 12 |
curl \
|
| 13 |
software-properties-common \
|
| 14 |
git \
|
|
|
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
+
# Install system dependencies as root first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
build-essential \
|
| 6 |
curl \
|
| 7 |
software-properties-common \
|
| 8 |
git \
|
| 9 |
+
wget \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
+
# Set up a new user named "user" with user ID 1000
|
| 13 |
+
RUN useradd -m -u 1000 user
|
| 14 |
|
| 15 |
+
# Switch to the "user" user
|
| 16 |
+
USER user
|
| 17 |
|
| 18 |
+
# Set home to the user's home directory
|
| 19 |
+
ENV HOME=/home/user \
|
| 20 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 21 |
+
PYTHONPATH=/home/user/app \
|
| 22 |
+
PYTHONUNBUFFERED=1 \
|
| 23 |
+
PYTHONDONTWRITEBYTECODE=1
|
| 24 |
|
| 25 |
+
# Set the working directory to the user's home directory
|
| 26 |
+
WORKDIR $HOME/app
|
| 27 |
|
| 28 |
+
# Upgrade pip with user permissions
|
| 29 |
+
RUN pip install --no-cache-dir --upgrade pip
|
| 30 |
+
|
| 31 |
+
# Copy requirements first for better Docker layer caching
|
| 32 |
+
COPY --chown=user requirements.txt $HOME/app/
|
| 33 |
+
|
| 34 |
+
# Install Python dependencies in user space
|
| 35 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 36 |
|
| 37 |
+
# Copy source code with proper ownership
|
| 38 |
+
COPY --chown=user src/ $HOME/app/src/
|
| 39 |
+
|
| 40 |
+
# Copy any additional files you need
|
| 41 |
+
COPY --chown=user *.py $HOME/app/
|
| 42 |
+
COPY --chown=user .env* $HOME/app/
|
| 43 |
+
|
| 44 |
+
# Create any directories your app needs
|
| 45 |
+
RUN mkdir -p $HOME/app/logs && \
|
| 46 |
+
mkdir -p $HOME/app/data
|
| 47 |
+
|
| 48 |
+
# Clear proxy settings
|
| 49 |
+
ENV http_proxy="" \
|
| 50 |
+
https_proxy=""
|
| 51 |
+
|
| 52 |
+
# Expose port
|
| 53 |
+
EXPOSE 7860
|
| 54 |
|
| 55 |
+
# Health check
|
| 56 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
| 57 |
+
CMD curl --fail http://localhost:7860/ || exit 1
|
| 58 |
|
| 59 |
+
# Run the application
|
| 60 |
+
CMD ["python", "-m", "uvicorn", "src.telegram_bot:app", "--host", "0.0.0.0", "--port", "7860"]
|