-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDockerfile
82 lines (67 loc) · 2.04 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
############################
###### STAGE 1: Build ######
############################
# Use the same base image
FROM python:3.11-slim-bullseye AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install git and other essential build tools if needed
RUN apt-get update && apt-get install -y \
git \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy the project into the image
ADD . /app
# Sync the project into a new environment, using the frozen lockfile
WORKDIR /app
RUN uv sync --extra api --frozen
ENV PATH="/app/.venv/bin:$PATH"
# Install patchright dependencies
RUN patchright install --with-deps chromium --only-shell
############################
####### STAGE 2: Run #######
############################
FROM python:3.11-slim-bullseye
WORKDIR /app
# Install required system dependencies for Chromium
RUN apt-get update && apt-get install -y \
chromium \
chromium-driver \
libglib2.0-0 \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy only the virtual environment and application files
COPY --from=builder /app/.env /app/.env
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/src /app/src
COPY --from=builder /app/examples /app/examples
COPY --from=builder /root/.cache/ms-playwright /root/.cache/ms-playwright
# Environment setup
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="$VIRTUAL_ENV/lib/python3.11/site-packages"
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONIOENCODING=UTF-8
# Force headless mode for patchright
ENV HEADLESS=true
# Define the command to run your application
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "examples.fastapi_agent:app", "--host", "0.0.0.0", "--port", "8000"]
# REMBMBER TO START WITH
# docker build -f ./Dockerfile -t notte-api .
# docker run --init -p 8000:8000 notte-api