-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDockerfile_api
More file actions
69 lines (57 loc) · 1.93 KB
/
Dockerfile_api
File metadata and controls
69 lines (57 loc) · 1.93 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
# syntax=docker/dockerfile:1
# Accept build argument for target platform
ARG TARGETPLATFORM
ARG BUILDPLATFORM
# First stage: determine architecture
FROM --platform=$BUILDPLATFORM ubuntu:24.04 AS platform-detect
ARG TARGETPLATFORM
RUN case "$TARGETPLATFORM" in \
"linux/amd64") echo "x86_64" > /platform ;; \
"linux/arm64") echo "aarch64" > /platform ;; \
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac
# Main stage
FROM ubuntu:24.04
# Copy the platform information and set environment variable
COPY --from=platform-detect /platform /platform
RUN ARCH=$(cat /platform) && echo "export TARGETPLATFORM_ARCH=$ARCH" >> /etc/environment
ENV TARGETPLATFORM_ARCH=${TARGETPLATFORM_ARCH}
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
pngquant \
tesseract-ocr-* \
ocrmypdf \
libjpeg-dev \
libxml2 \
libxslt1-dev \
build-essential \
python3-dev \
python3-pip \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Set Python environment variables
ENV PYTHONPATH=/app/.venv/lib/python3.12/site-packages
# Set platform-specific pip configurations
RUN echo "export PIP_PLATFORM=$(cat /platform)-linux-gnu" >> /etc/environment
ENV PIP_PLATFORM=${PIP_PLATFORM}
# Install uv and set up virtual environment
ENV PATH="/root/.local/bin:$PATH"
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
/root/.local/bin/uv venv && \
. .venv/bin/activate && \
/root/.local/bin/uv pip install wheel setuptools
# Copy source code
COPY . .
# Install dependencies
RUN . .venv/bin/activate && \
/root/.local/bin/uv sync \
--python-platform="$(cat /platform)-unknown-linux-gnu" \
--no-dev
HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
EXPOSE 5000
CMD ["sh", "-c", ". .venv/bin/activate && .venv/bin/python app.py --only_api"]