-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
59 lines (40 loc) · 1.73 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
# Use Dockerfile syntax version 1.5 for compatibility and new features
# syntax=docker/dockerfile:1.5
FROM python:3.13 as builder
# Set non-interactive mode
ENV DEBIAN_FRONTEND=noninteractive
# Prevent docker from cleaning up the apt cache
RUN rm -f /etc/apt/apt.conf.d/docker-clean
# Define ARG for platform-specific cache separation
ARG TARGETPLATFORM
# Update and install dependencies with cache separated by architecture
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache-${TARGETPLATFORM} \
--mount=type=cache,target=/var/lib/apt,id=apt-lib-${TARGETPLATFORM} \
apt-get update && \
apt-get install -y libxml2-dev libxslt-dev
WORKDIR /app
COPY requirements.txt .
# Use pip cache to speed up builds
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt -t packages
# Start from a slim Python 3.12 image for a small final image size
FROM python:3.13-slim as final
# Set non-interactive mode
ENV DEBIAN_FRONTEND=noninteractive
# Prevent docker from cleaning up the apt cache in the final image
RUN rm -f /etc/apt/apt.conf.d/docker-clean
ARG TARGETPLATFORM
# Copy built packages from the previous stage
COPY --from=builder /app/packages /app/packages
# Update and install runtime dependencies if necessary, with cache separated by architecture
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache-${TARGETPLATFORM} \
--mount=type=cache,target=/var/lib/apt,id=apt-lib-${TARGETPLATFORM} \
apt-get update && \
apt-get full-upgrade -y && \
apt-get install -y libxml2 libxslt1.1 libtk8.6
WORKDIR /app
ENV PYTHONPATH=/app/packages:$PYTHONPATH
# Copy the rest of the application's source code into the working directory
COPY . .
VOLUME [ "/app/cache"]
ENTRYPOINT [ "python", "main.py" ]