forked from flare-foundation/flare-ai-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
99 lines (78 loc) · 2.96 KB
/
Dockerfile
File metadata and controls
99 lines (78 loc) · 2.96 KB
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
# Parametric Dockerfile for running scripts with specific extras
# Usage:
# docker build -t fai-script-pdf --build-arg EXTRAS=pdf --build-arg SCRIPT=ingest_pdf.py .
# docker run --rm -it -v "$PWD/data:/app/scripts/data" fai-script-pdf
# Build arguments for parametric behavior
ARG EXTRAS=""
ARG SCRIPT="ingest_pdf.py"
# Add <builder-digest> in prod
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
# Pass build args to builder stage
ARG EXTRAS
ARG SCRIPT
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=0
WORKDIR /app
# Install system dependencies for PDF processing (if needed)
RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr \
tesseract-ocr-eng \
poppler-utils \
&& rm -rf /var/lib/apt/lists/*
# Copy dependency files first for better caching
COPY uv.lock pyproject.toml ./
# Install dependencies based on EXTRAS parameter
RUN --mount=type=cache,target=/root/.cache/uv \
if [ -n "$EXTRAS" ]; then \
echo "Installing with extras: $EXTRAS"; \
# Convert comma-separated extras to space-separated for uv
EXTRAS_ARGS=$(echo "$EXTRAS" | sed 's/,/ --extra /g'); \
echo "Installing extras: $EXTRAS_ARGS"; \
uv sync --locked --no-install-project --extra $EXTRAS_ARGS --no-dev --no-editable; \
else \
echo "Installing base dependencies only"; \
uv sync --locked --no-install-project --no-dev --no-editable; \
fi
# Copy the entire project
COPY . /app
# Install the project itself
RUN --mount=type=cache,target=/root/.cache/uv \
if [ -n "$EXTRAS" ]; then \
# Convert comma-separated extras to space-separated for uv
EXTRAS_ARGS=$(echo "$EXTRAS" | sed 's/,/ --extra /g'); \
echo "Installing project with extras: $EXTRAS_ARGS"; \
uv sync --locked --extra $EXTRAS_ARGS --no-dev --no-editable; \
else \
uv sync --locked --no-dev --no-editable; \
fi
# Clean up cache
RUN rm -rf /root/.cache/uv /root/.cache/pip
# Add <runtime-digest> in prod
FROM python:3.12-slim-bookworm AS runtime
# Pass build args to runtime stage
ARG EXTRAS
ARG SCRIPT
# Install runtime system dependencies for PDF processing (if needed)
RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr \
tesseract-ocr-eng \
poppler-utils \
&& rm -rf /var/lib/apt/lists/*
ENV PIP_NO_CACHE_DIR=1 \
UV_PYTHON_DOWNLOADS=0 \
SCRIPT_NAME="$SCRIPT"
# Create non-root user
RUN groupadd -r app && \
useradd -r -g app -d /nonexistent -s /usr/sbin/nologin app
# Copy built application from builder stage
COPY --from=builder --chown=app:app /app /app
# Set working directory and PATH
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
# Switch to non-root user
USER app
# Validate that the script exists
RUN test -f "/app/scripts/$SCRIPT" || (echo "Error: Script /app/scripts/$SCRIPT not found" && exit 1)
# Default command runs the specified script
CMD ["sh", "-c", "cd /app/scripts && python \"$SCRIPT_NAME\""]