Compilertetris / DockerFile
github-actions
Auto deploy from GitHub
e544ae2
Raw
History Blame Contribute Delete
1.13 kB
# Use a lightweight Python 3.10 image as the base
FROM python:3.10-slim
# Hugging Face Spaces requires a non-root user for security.
# We create a user named 'user' with user ID 1000.
RUN useradd -m -u 1000 user
# Set environment variables to ensure Python output is logged immediately
# and to add the local bin directory to the PATH for pip installations.
ENV PATH="/home/user/.local/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Switch away from root to the new user
USER user
# Set the working directory inside the container
WORKDIR /home/user/app
# Copy the requirements file first to leverage Docker cache layers
COPY --chown=user requirements.txt .
# Upgrade pip and install the dependencies defined by Role 2
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application files (app.py, openenv.yaml, engine.py, etc.)
COPY --chown=user . .
# Expose port 7860, which is the default port Hugging Face routes traffic to
EXPOSE 7860
# Start the OpenEnv server using the entrypoint defined in app.py
CMD ["python", "app.py"]