-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (28 loc) · 1.34 KB
/
Dockerfile
File metadata and controls
34 lines (28 loc) · 1.34 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
# syntax=docker/dockerfile:1
ARG UV_VERSION=0.9.7
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv
# It's important that this is Debian 12 to match the distroless image.
FROM --platform=${BUILDPLATFORM} debian:12-slim AS build
# Don't write .pyc bytecode files. These speed up imports when the program is
# loaded. There's no point doing that in a container where they'll never be
# persisted across restarts.
ENV UV_PYTHON_INSTALL_DIR=/python PYTHONDONTWRITEBYTECODE=true
COPY --from=uv /uv /uvx /bin/
WORKDIR /app
ADD . .
# Create a fresh venv and install the dependencies.
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --no-dev --no-cache --no-editable --python-preference=only-managed
# Copy the function venv to our runtime stage. It's important that the path be
# the same as in the build stage, to avoid shebang paths and symlinks breaking.
FROM gcr.io/distroless/cc-debian12:nonroot AS image
LABEL org.opencontainers.image.description="A Crossplane composition function template in Python"
WORKDIR /app
# Copy python interpreter and the application from the builder
COPY --from=build --chown=python:python /python /python
COPY --from=build --chown=nonroot:nonroot /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:${PATH}"
EXPOSE 9443
USER nonroot:nonroot
ENTRYPOINT ["function"]