|
1 | | -# Use Python base image |
2 | | -FROM python:3.13-slim AS build |
| 1 | +# Build a virtual environment using the Debian version that matches the |
| 2 | +# distroless image below, so the venv still works once copied over. |
| 3 | +# See https://github.com/GoogleContainerTools/distroless/blob/main/python3/README.md |
| 4 | +FROM python:3.13-slim-trixie AS build |
| 5 | + |
| 6 | +# The distroless image's Python is at /usr/bin/python, but this builder |
| 7 | +# image's Python is at /usr/local/bin/python. Add a matching /usr/bin/python |
| 8 | +# link here so the virtual environment we create points to a path that will |
| 9 | +# also exist in the final image. |
| 10 | +RUN pip install poetry \ |
| 11 | + && ln -s /usr/local/bin/python /usr/bin/python \ |
| 12 | + && /usr/bin/python -m venv /venv |
3 | 13 |
|
4 | | -# Install Poetry |
5 | | -RUN pip install poetry |
6 | | - |
7 | | -# Set working directory |
8 | 14 | WORKDIR /app |
9 | 15 |
|
10 | 16 | # Copy project files |
11 | 17 | COPY pyproject.toml poetry.lock README.rst ./ |
12 | 18 | COPY exasol/ ./exasol/ |
13 | 19 |
|
14 | | -# Build and install the wheel |
15 | | -RUN poetry build |
16 | | - |
17 | | -FROM python:3.13-slim |
18 | | - |
| 20 | +# Build the wheel and install it, with its extras, into the venv. Then |
| 21 | +# remove pip itself: `python -m venv` installs its own copy of pip into |
| 22 | +# the venv, and pip vendors its own copies of other packages (e.g. |
| 23 | +# msgpack, setuptools) that can carry known vulnerabilities. |
| 24 | +RUN poetry build \ |
| 25 | + && WHEEL=$(ls dist/*.whl) \ |
| 26 | + && /venv/bin/pip install --disable-pip-version-check "${WHEEL}[dynamodb,redis,mongodb]" \ |
| 27 | + && /venv/bin/pip uninstall -y pip |
| 28 | + |
| 29 | +# This distroless base image has no shell, no package manager, and no pip. |
| 30 | +FROM gcr.io/distroless/python3-debian13:nonroot |
19 | 31 | WORKDIR /app |
20 | | -COPY --from=build app/dist dist |
21 | | - |
22 | | -RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/* |
23 | | - |
24 | | -RUN WHEEL=$(ls dist/*.whl) && pip install "${WHEEL}[dynamodb,redis,mongodb]" \ |
25 | | - && pip uninstall -y pip |
26 | | - |
| 32 | +COPY --from=build --chown=nonroot:nonroot /venv /venv |
27 | 33 |
|
28 | 34 | # Set entrypoint |
29 | | -ENTRYPOINT ["exasol-mcp-server-http"] |
| 35 | +ENTRYPOINT ["/venv/bin/exasol-mcp-server-http"] |
0 commit comments