File size: 2,957 Bytes
582714f
 
 
0c01d1e
 
2a99322
 
0c01d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83df668
 
de1b385
b7805f6
 
 
0c01d1e
b7805f6
2a99322
0c01d1e
2a99322
0c01d1e
 
 
 
5e4ff04
1aa5770
 
 
582714f
 
 
 
 
 
 
 
 
 
 
1aa5770
 
 
582714f
 
 
 
 
1aa5770
582714f
 
 
 
 
 
 
 
 
 
256f37c
1aa5770
256f37c
1aa5770
256f37c
 
 
 
 
 
1aa5770
 
 
 
3b7ec04
582714f
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Use a Python image with uv pre-installed
FROM ghcr.io/astral-sh/uv:python3.11-bookworm

# Install Chrome and its dependencies
RUN apt-get -y update && apt-get install -y wget gnupg2
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update && apt-get install -y \
    google-chrome-stable \
    fonts-ipafont-gothic \
    fonts-wqy-zenhei \
    fonts-thai-tlwg \
    fonts-kacst \
    fonts-symbola \
    fonts-noto \
    fonts-freefont-ttf \
    libxss1 \
    libx11-xcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxi6 \
    libxtst6 \
    libnss3 \
    libcups2 \
    libxrandr2 \
    libasound2 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libgtk-3-0 \
    libgbm1

# Install chromedriver
RUN apt-get install -yqq unzip
RUN CHROMEDRIVER_VERSION=133.0.6943.126 && \
    wget -O /tmp/chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip && \
    unzip /tmp/chromedriver-linux64.zip -d /tmp && \
    mv /tmp/chromedriver-linux64/chromedriver /usr/local/bin/ && \
    chmod +x /usr/local/bin/chromedriver && \
    rm -rf /tmp/chromedriver-linux64.zip /tmp/chromedriver-linux64

# Set display port and shared memory settings
ENV DISPLAY=:99
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null

# Create a shared memory volume
VOLUME /dev/shm

# Create a non-root user
RUN useradd -m -u 1000 appuser

# Install the project into `/app`
WORKDIR /app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1

# Copy from the cache instead of linking since it's a mounted volume
ENV UV_LINK_MODE=copy

# Install the project's dependencies using the lockfile and settings
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    uv sync --frozen --no-install-project --no-dev

# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-dev

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

# Reset the entrypoint, don't invoke `uv`
ENTRYPOINT []

# Run setup.py
RUN python setup.py

# Create cache directories and set permissions
RUN mkdir -p /.cache/selenium && \
    mkdir -p /tmp/screenshots && \
    chown -R appuser:appuser /.cache/selenium && \
    chown -R appuser:appuser /tmp/screenshots && \
    chmod 755 /.cache/selenium && \
    chmod 755 /tmp/screenshots

# Set temporary directory environment variable
ENV TMPDIR=/tmp/screenshots

# Set user
USER appuser

EXPOSE 7860
# Run the FastAPI application by default
CMD ["python", "main.py"]