File size: 1,500 Bytes
7110c78 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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"] |