apimaster / Dockerfile
akborana4's picture
Update Dockerfile
e42eb20 verified
Raw
History Blame Contribute Delete
1.51 kB
# Use a lighter base if you don't actually need CUDA; otherwise, keep this.
FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04
# 1. Install System Dependencies (Added curl, git, and build-essentials)
USER root
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
curl \
git \
sudo \
build-essential \
libssl-dev \
libffi-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 2. Create non-root user (Hugging Face requirement)
RUN adduser --disabled-password --gecos '' user
RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
# Set environment variables
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONUNBUFFERED=1
WORKDIR $HOME/app
# 3. Setup Python Environment
# Using a virtual environment is lighter than Miniconda for a single-purpose bot
USER user
RUN python3 -m pip install --upgrade pip
# 4. Copy Files and Set Permissions
# Copy everything into the WORKDIR (/home/user/app)
COPY --chown=user:user . .
# 5. Install Python Requirements
# Note: Ensure 'telethon' and 'cryptography' are in reqs.txt
RUN pip install --no-cache-dir redis fastapi nest-asyncio uvicorn
RUN pip install --no-cache-dir -r reqs.txt || true
# 6. Create Persistent Directories inside WORKDIR
# Using local paths instead of /app to ensure write permissions
RUN mkdir -p sessions downloads && chmod -R 777 sessions downloads
# 7. Final Script Setup
RUN chmod +x start.sh
# Hugging Face Spaces port
EXPOSE 7860
ENTRYPOINT ["./start.sh"]