Skip to content

Commit 439a549

Browse files
committed
Ubuntu based, to easily use uv and newer python
1 parent ad5e6f0 commit 439a549

File tree

3 files changed

+94
-49
lines changed

3 files changed

+94
-49
lines changed

Dockerfile

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,34 @@
1-
# Build: docker build -t fingr .
1+
# Build: docker build -t fingr -f Dockerfile.ubuntu .
22
# Run: docker run -it --rm fingr:latest
3-
# Distroless image for minimal attack surface and security
43

5-
# Build stage. Python 3.11 to match distroless debian12
6-
FROM python:3.11-slim AS builder
4+
FROM ubuntu:24.04
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
76

8-
WORKDIR /app
9-
10-
# Install uv and build dependencies for numpy
11-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
12-
13-
# Install system dependencies needed for numpy
14-
RUN apt-get update && \
15-
apt-get install -y --no-install-recommends \
7+
RUN apt-get update && apt-get install -y \
168
gcc \
179
g++ \
1810
libgfortran5 \
19-
libgomp1
11+
libgomp1 \
12+
cl-cffi \
13+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
14+
15+
WORKDIR /app
16+
RUN useradd --home-dir=/app fingr && chown -R fingr /app
17+
USER fingr
2018

21-
# Copy project files
22-
COPY pyproject.toml .
23-
COPY fingr/ fingr/
24-
COPY fingr.py .
19+
COPY pyproject.toml uv.lock .
2520

2621
# Install dependencies with uv
2722
# UV_COMPILE_BYTECODE: Precompile Python files to .pyc for faster startup
2823
ENV UV_COMPILE_BYTECODE=1 \
29-
UV_LINK_MODE=copy
24+
UV_LINK_MODE=copy \
25+
UV_NO_DEV=1
3026

31-
RUN uv pip install --system --no-cache .
27+
RUN uv python install 3.14
28+
RUN uv sync --locked --no-cache
3229

33-
# Runtime stage - distroless
34-
FROM gcr.io/distroless/python3-debian12:nonroot
35-
36-
# Copy required shared libraries from builder for numpy C extensions
37-
COPY --from=builder /usr/lib/x86_64-linux-gnu/libgfortran.so.5* /usr/lib/x86_64-linux-gnu/
38-
COPY --from=builder /usr/lib/x86_64-linux-gnu/libquadmath.so.0* /usr/lib/x86_64-linux-gnu/
39-
COPY --from=builder /usr/lib/x86_64-linux-gnu/libgomp.so.1* /usr/lib/x86_64-linux-gnu/
40-
COPY --from=builder /lib/x86_64-linux-gnu/libgcc_s.so.1* /lib/x86_64-linux-gnu/
41-
42-
# Copy Python packages and application
43-
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
44-
COPY fingr/ /app/fingr/
45-
COPY fingr.py /app/
46-
47-
WORKDIR /app
48-
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages
30+
COPY fingr.py ./
31+
COPY fingr/ ./fingr/
4932

5033
EXPOSE 7979
51-
ENTRYPOINT ["/usr/bin/python3", "fingr.py", "--verbose", "--host", "0.0.0.0"]
34+
ENTRYPOINT ["uv", "run", "--no-cache", "./fingr.py", "--verbose", "--host", "0.0.0.0"]

Dockerfile.distroless

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Build: docker build -t fingr .
2+
# Run: docker run -it --rm fingr:latest
3+
# Distroless image for minimal attack surface and security
4+
5+
# Build stage. Python 3.11 to match distroless debian12
6+
FROM python:3.11-slim AS builder
7+
8+
WORKDIR /app
9+
10+
# Install uv and build dependencies for numpy
11+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
12+
13+
# Install system dependencies needed for numpy
14+
RUN apt-get update && \
15+
apt-get install -y --no-install-recommends \
16+
gcc \
17+
g++ \
18+
libgfortran5 \
19+
libgomp1
20+
21+
# Copy project files
22+
COPY pyproject.toml .
23+
COPY fingr/ fingr/
24+
COPY fingr.py .
25+
26+
# Install dependencies with uv
27+
# UV_COMPILE_BYTECODE: Precompile Python files to .pyc for faster startup
28+
ENV UV_COMPILE_BYTECODE=1 \
29+
UV_LINK_MODE=copy
30+
31+
RUN uv pip install --system --no-cache .
32+
33+
# Runtime stage - distroless
34+
FROM gcr.io/distroless/python3-debian12:nonroot
35+
36+
# Copy required shared libraries from builder for numpy C extensions
37+
COPY --from=builder /usr/lib/x86_64-linux-gnu/libgfortran.so.5* /usr/lib/x86_64-linux-gnu/
38+
COPY --from=builder /usr/lib/x86_64-linux-gnu/libquadmath.so.0* /usr/lib/x86_64-linux-gnu/
39+
COPY --from=builder /usr/lib/x86_64-linux-gnu/libgomp.so.1* /usr/lib/x86_64-linux-gnu/
40+
COPY --from=builder /lib/x86_64-linux-gnu/libgcc_s.so.1* /lib/x86_64-linux-gnu/
41+
42+
# Copy Python packages and application
43+
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
44+
COPY fingr/ /app/fingr/
45+
COPY fingr.py /app/
46+
47+
WORKDIR /app
48+
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages
49+
50+
EXPOSE 7979
51+
ENTRYPOINT ["/usr/bin/python3", "fingr.py", "--verbose", "--host", "0.0.0.0"]

Dockerfile.ubuntu

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
# Build: docker buildx build -t fingr -f Dockerfile.ubuntu .
1+
# Build: docker build -t fingr -f Dockerfile.ubuntu .
22
# Run: docker run -it --rm fingr:latest
3-
# Ubuntu-based image
43

54
FROM ubuntu:24.04
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
66

7-
RUN apt-get update && apt-get install -y python3 python3-pip python3-venv && \
8-
apt-get clean && rm -rf /var/lib/apt/lists/*
7+
RUN apt-get update && apt-get install -y \
8+
gcc \
9+
g++ \
10+
libgfortran5 \
11+
libgomp1 \
12+
cl-cffi \
13+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
914

10-
COPY pyproject.toml /var/fingr/
11-
WORKDIR /var/fingr/
15+
WORKDIR /app
16+
RUN useradd --home-dir=/app fingr && chown -R fingr /app
17+
USER fingr
1218

13-
RUN python3 -m venv /var/fingr/venv && \
14-
/var/fingr/venv/bin/pip install --no-cache-dir wheel && \
15-
/var/fingr/venv/bin/pip install --no-cache-dir /var/fingr
19+
COPY pyproject.toml uv.lock .
1620

17-
COPY fingr.py motd.txt* deny.txt* useragent.txt* /var/fingr/
21+
# Install dependencies with uv
22+
# UV_COMPILE_BYTECODE: Precompile Python files to .pyc for faster startup
23+
ENV UV_COMPILE_BYTECODE=1 \
24+
UV_LINK_MODE=copy \
25+
UV_NO_DEV=1
1826

19-
RUN useradd fingr && mkdir -p /var/fingr/data && chown -R fingr /var/fingr/data
20-
USER fingr
27+
RUN uv python install 3.14
28+
RUN uv sync --locked --no-cache
29+
30+
COPY fingr.py ./
31+
COPY fingr/ ./fingr/
2132

2233
EXPOSE 7979
23-
ENTRYPOINT ["/var/fingr/venv/bin/python3", "fingr.py", "--verbose", "--host", "0.0.0.0"]
34+
ENTRYPOINT ["uv", "run", "--no-cache", "./fingr.py", "--verbose", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)