Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (52 loc) · 2.03 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (52 loc) · 2.03 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
# Multi-stage build for Co‑op Translator
# Builder stage: build wheel using Poetry
FROM python:3.13-slim AS builder
ENV PIP_NO_CACHE_DIR=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# System deps required for build steps
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
python3-dev \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install --no-cache-dir poetry==2.4.2 poetry-plugin-export==1.10.0
# Copy only dependency files first for better caching
COPY pyproject.toml poetry.lock* ./
# Export env to ensure Poetry installs with the same Python
ENV POETRY_VIRTUALENVS_CREATE=false
# Export main dependencies and build a local wheelhouse for all deps
RUN poetry export --without-hashes --only main -f requirements.txt -o requirements.txt
RUN pip wheel -r requirements.txt -w /wheels
# Now copy the application source
COPY src ./src
COPY README.md ./
# Build a wheel from the current source
RUN poetry build --no-interaction --format wheel
# Runtime stage: minimal image with just runtime libs and the package wheel
FROM python:3.13-slim AS runtime
ENV PIP_NO_CACHE_DIR=1 \
PYTHONUNBUFFERED=1 \
PATH="/usr/local/bin:${PATH}"
# Install minimal runtime system libraries required by some imaging libs (opencv, pillow)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work
VOLUME ["/work"]
# Copy the built wheel and dependency wheelhouse from the builder and install them
COPY --from=builder /app/dist/*.whl /tmp/
COPY --from=builder /wheels /wheels
RUN pip install --no-index --find-links=/wheels /tmp/*.whl \
&& rm -f /tmp/*.whl
# Default entrypoint to the primary CLI; override with --entrypoint for other commands
ENTRYPOINT ["translate"]
CMD ["--help"]
# Example runs (documentation only):
# docker run --rm -it --env-file .env -v ${PWD}:/work IMAGE_TAG translate -l "fr es" -md
# docker run --rm -it --env-file .env -v ${PWD}:/work --entrypoint migrate-links IMAGE_TAG -l "all" -y