-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (37 loc) · 1.78 KB
/
Copy pathDockerfile
File metadata and controls
39 lines (37 loc) · 1.78 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
ARG PIXI_ENV=cpu
# Stage 1: Build — install deps via pixi, generate shell-hook
FROM ghcr.io/prefix-dev/pixi:0.65.0 AS build
ARG PIXI_ENV
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*
# Copy only dependency manifests + minimal stub for editable install
COPY pixi.toml pixi.lock pyproject.toml ./
RUN mkdir -p src/samapi \
&& echo '__version__ = "0.0.0"' > src/samapi/__init__.py
# Heavy install + shell-hook — cached unless pixi.toml/pixi.lock/pyproject.toml change
RUN --mount=type=cache,target=/root/.cache/rattler \
--mount=type=cache,target=/root/.cache/pip \
CONDA_OVERRIDE_CUDA=12.0 pixi install --frozen -e ${PIXI_ENV} \
&& CONDA_OVERRIDE_CUDA=12.0 pixi shell-hook -e ${PIXI_ENV} -s bash > /shell-hook.sh
# Now copy real source (cheap layer, doesn't bust install cache)
COPY src/ ./src/
# Stage 2: Runtime — lean image, no pixi
FROM ubuntu:24.04 AS runtime
ARG PIXI_ENV
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 libglib2.0-0 curl ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy pixi env + source + activation hook (same path prefix required)
COPY --from=build /app/.pixi/envs/${PIXI_ENV} /app/.pixi/envs/${PIXI_ENV}
COPY --from=build /app/src /app/src
COPY --from=build /app/pyproject.toml /app/pixi.toml /app/pixi.lock /app/
COPY --from=build /shell-hook.sh /shell-hook.sh
RUN mkdir -p /app/weights
ENV SAMAPI_ROOT_DIR=/app/weights
ENV SAMAPI_DEVICE=cpu
ENV UVICORN_PORT=8780
EXPOSE ${UVICORN_PORT}
HEALTHCHECK --interval=10s --timeout=3s --retries=5 --start-period=120s \
CMD curl -sf http://localhost:${UVICORN_PORT}/health || exit 1
ENTRYPOINT ["/bin/bash", "-c", "source /shell-hook.sh && exec \"$@\"", "--"]
CMD ["python", "-m", "samapi.server"]