Spaces:
Sleeping
Sleeping
# Use an official Python image as a base | |
FROM python:3.9 | |
# Set environment variables | |
ENV PYTHONUNBUFFERED=1 \ | |
PORT=7860 \ | |
PYTHONPATH=/app \ | |
HOME=/home/chrome \ | |
CHROME_BIN=/usr/bin/google-chrome | |
# Create chrome user | |
RUN mkdir -p /home/chrome && \ | |
groupadd -r chrome && \ | |
useradd -r -g chrome -G audio,video chrome && \ | |
mkdir -p /home/chrome/Downloads && \ | |
chown -R chrome:chrome /home/chrome | |
# Set the working directory | |
WORKDIR /app | |
# Install system dependencies including Chrome | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
wget \ | |
gnupg \ | |
unzip \ | |
xvfb \ | |
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ | |
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \ | |
&& apt-get update \ | |
&& apt-get install -y google-chrome-stable \ | |
&& chown -R chrome:chrome /usr/bin/google-chrome \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Copy requirements file | |
COPY requirements.txt . | |
# Install Python dependencies | |
RUN pip install --no-cache-dir -r requirements.txt \ | |
&& pip install --no-cache-dir hypercorn | |
# Copy the current directory contents into the container | |
COPY . /app | |
# Set permissions | |
RUN chown -R chrome:chrome /app | |
# Switch to chrome user | |
USER chrome | |
# Make port 7860 available to the world outside this container | |
EXPOSE 7860 | |
# Run the app with Hypercorn | |
CMD ["hypercorn", "app:app", "--bind", "0.0.0.0:7860"] |