-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (50 loc) · 2.53 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (50 loc) · 2.53 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
# syntax=docker/dockerfile:1
# Generic Dockerfile for nskit-based recipe CLIs
FROM python:3.14-slim-bookworm AS base
LABEL org.opencontainers.image.source="https://github.com/djpugh/nskit"
ARG PROJECT_DIR=/app
ARG SOURCE_FILES_DIRNAME=src
ARG CLI_COMMAND=nskit
ARG RECIPE_NAME=nskit
# Set up uv and other deps first
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates git && rm -rf /var/lib/apt/lists/*
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh && cp /root/.local/bin/uv /usr/local/bin/uv
# Trust the app directory for git safe.directory — recipe post-hooks (git init,
# pre-commit install) run inside Docker volume mounts where ownership metadata
# may differ from the container user, causing git 2.35.2+ to reject operations.
RUN git config --global --add safe.directory /app \
&& git config --global --add safe.directory /app/output
# Copy dependency files
WORKDIR ${PROJECT_DIR}
COPY pyproject.toml uv.lock* README.md ${PROJECT_DIR}/
# Install dependencies (not the project itself yet)
RUN --mount=type=secret,id=pypi_username,env=UV_INDEX_USERNAME,required=false \
--mount=type=secret,id=pypi_password,env=UV_INDEX_PASSWORD,required=false \
uv sync --frozen --no-install-project --no-dev || uv sync --no-install-project --no-dev
###### Test image stage ######
FROM base AS test
COPY dist/*.whl /tmp/wheels/
RUN uv pip install --system /tmp/wheels/*.whl && rm -rf /tmp/wheels
COPY pyproject.toml ${PROJECT_DIR}/
RUN --mount=type=secret,id=pypi_username,env=UV_INDEX_USERNAME,required=false \
--mount=type=secret,id=pypi_password,env=UV_INDEX_PASSWORD,required=false \
uv pip install --system --group test
COPY tests ${PROJECT_DIR}/tests
###### Runtime image stage ######
FROM base AS runtime
RUN mkdir -p ${PROJECT_DIR}/input ${PROJECT_DIR}/output
COPY ${SOURCE_FILES_DIRNAME}/ ${PROJECT_DIR}/${SOURCE_FILES_DIRNAME}
RUN --mount=type=secret,id=pypi_username,env=UV_INDEX_USERNAME,required=false \
--mount=type=secret,id=pypi_password,env=UV_INDEX_PASSWORD,required=false \
--mount=type=bind,src=.git,dst=${PROJECT_DIR}/.git \
uv sync --frozen --no-dev || uv sync --no-dev
ENV CLI_COMMAND=${CLI_COMMAND}
LABEL nskit.recipe="true"
LABEL nskit.recipe.name="${RECIPE_NAME}"
RUN useradd --create-home nskit \
&& chown -R nskit:nskit ${PROJECT_DIR}
USER nskit
RUN git config --global --add safe.directory /app \
&& git config --global --add safe.directory /app/output
ENTRYPOINT ["sh", "-c", "uv run --no-sync $CLI_COMMAND \"$@\"", "--"]