Spaces:
Paused
Paused
# syntax = docker/dockerfile:1.2 | |
FROM python:3.8 | |
# 1. Create a non-root user | |
RUN useradd -m -u 1000 user | |
# 2. Switch to the non-root user | |
USER user | |
WORKDIR /home/user | |
ENV PATH="/home/user/.local/bin:$PATH" | |
# 3. Install system packages as root | |
USER root | |
RUN apt-get update && \ | |
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ | |
ca-certificates \ | |
curl \ | |
vim \ | |
sudo \ | |
default-jre \ | |
git \ | |
gcc \ | |
build-essential \ | |
libgl1-mesa-glx \ | |
libglib2.0-0 \ | |
netcat \ | |
&& rm -rf /var/lib/apt/lists/* | |
# 4. Switch back to the non-root user | |
USER user | |
# 5. Install Python dependencies | |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel | |
RUN pip install --no-cache-dir openmim | |
RUN pip install --no-cache-dir torch==2.0.0 | |
RUN mim install mmcv-full==1.7.0 | |
RUN pip install --no-cache-dir mmdet==2.27.0 | |
RUN pip install --no-cache-dir torchserve | |
# 6. Clone and install xtcocoapi (a dependency for mmpose) | |
RUN git clone https://github.com/jin-s13/xtcocoapi.git | |
WORKDIR xtcocoapi | |
RUN pip install --no-cache-dir -r requirements.txt | |
RUN pip install -e . | |
WORKDIR /home/user | |
# 7. Install additional Python packages | |
RUN pip install --no-cache-dir mmpose==0.29.0 | |
RUN pip install --no-cache-dir torchvision==0.15.1 numpy==1.24.4 | |
# 8. Copy your application code with appropriate ownership | |
COPY --chown=user . . | |
# 9. Install your application's Python dependencies | |
RUN pip install --no-cache-dir -e . | |
# 10. Prepare TorchServe model-store and download necessary models | |
RUN mkdir -p /home/user/torchserve/model-store | |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_detector.mar -P /home/user/torchserve/model-store/ | |
RUN wget https://github.com/facebookresearch/AnimatedDrawings/releases/download/v0.0.1/drawn_humanoid_pose_estimator.mar -P /home/user/torchserve/model-store/ | |
# 11. Switch to root to copy configuration files and set permissions | |
USER root | |
# 12. Copy TorchServe configuration files | |
COPY config.properties /home/user/torchserve/config.properties | |
COPY config.local.properties /home/user/torchserve/config.local.properties | |
# 13. Copy the start.sh script and set executable permissions | |
# Option A: Using --chmod flag (Recommended) | |
COPY --chmod=0755 start.sh /home/user/start.sh | |
# Option B: Without using --chmod flag (if Docker version < 17.09) | |
# COPY start.sh /home/user/start.sh | |
# RUN chmod +x /home/user/start.sh | |
# 14. Switch back to the non-root user | |
USER user | |
# 15. Expose necessary ports | |
EXPOSE 7860 8080 8081 8082 | |
# 16. Define the entrypoint command to start both TorchServe and Gradio | |
CMD ["/home/user/start.sh"] |