This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (61 loc) · 2.14 KB
/
Copy pathDockerfile
File metadata and controls
81 lines (61 loc) · 2.14 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
# Copyright (c) 2025 Joan Fabrégat <j@fabreg.at>
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, subject to the conditions in the full MIT License.
# The Software is provided "as is", without warranty of any kind.
ARG PYTHON_VERSION=3.12
# --- Builder Image ---
FROM python:${PYTHON_VERSION}-slim AS builder
WORKDIR /src
# Install Git
RUN apt-get update && \
apt-get install -y --no-install-recommends git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install uv and its dependencies
COPY --from=ghcr.io/astral-sh/uv:0.6.8 /uv /uvx /bin/
RUN chmod +x /bin/uv /bin/uvx && \
uv venv .venv
ENV PATH="/src/.venv/bin:$PATH"
# Copy dependency specification and install production dependencies
COPY uv.lock pyproject.toml ./
RUN uv sync --frozen
# --- Final Image ---
FROM python:${PYTHON_VERSION}-slim AS final
ARG PORT=8000
ARG VERSION
ARG BUILD_ID
ARG COMMIT_SHA
ENV ENV=production
ENV THREADS=4
ENV PORT=${PORT}
ENV VERSION=${VERSION}
ENV BUILD_ID=${BUILD_ID}
ENV COMMIT_SHA=${COMMIT_SHA}
ENV PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
#ENV HF_HOME=/src/.cache/huggingface
#ENV DOCLING_MODELS=${HF_HOME}
#ENV EASYOCR_MODULE_PATH=/src/.cache/easyocr
WORKDIR /src
ENV HOME=/src
# Create a non-root user to run the application
RUN addgroup --system app && \
adduser --system --group --no-create-home app && \
chown app:app /src
# Copy the virtual environment
COPY --from=builder --chown=app:app /src/.venv /src/.venv
ENV PATH="/src/.venv/bin:$PATH"
# Copy the application code
COPY --chown=app:app app/ ./app
# Ensure a non-root user
USER app:app
# Download Docling and EasyOCR models
#RUN mkdir -p ${HF_HOME} && \
# mkdir -p ${EASYOCR_MODULE_PATH} && \
RUN python -m app.download_models
EXPOSE $PORT
#CMD ["sh", "-c", "uvicorn app.api:api --host 0.0.0.0 --port $PORT --workers 1 --log-level info --timeout-keep-alive 0 --http h2c"]
CMD ["sh", "-c", "hypercorn app.api:api --bind 0.0.0.0:$PORT --workers 1 --log-level info"]