Repository navigation
Expand file tree
/
Copy pathDockerfile-cpu
More file actions
72 lines (59 loc) · 2.28 KB
/
Copy pathDockerfile-cpu
File metadata and controls
72 lines (59 loc) · 2.28 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
69
70
71
72
FROM python:3.12-slim-trixie AS base_stage
ENV ROOT_DIR=/app
ARG MODE=release
# MODE: 'release' or 'it' (will be interpreted as debug). This is used in the docker_entrypoint.sh script
ENV MODE=${MODE}
ENV PYTHON_VERSION="3.12"
ENV PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
ENV PYTHONUNBUFFERED=1
# uv settings
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
ENV UV_SYSTEM_PYTHON=1
ENV UV_NO_MANAGED_PYTHON=1
ENV UV_PYTHON_DOWNLOADS=never
ENV UV_TOOL_BIN_DIR=/usr/local/bin
ENV UV_PYHTON=/usr/bin/python
ENV UV_NO_DEV=1
ENV DATA_DIR=/app/data
# Build stage
FROM base_stage AS build_stage
ARG DEBIAN_FRONTEND=noninteractive
# Setup a non-root user
RUN groupadd --system --gid 999 nonroot \
&& useradd --system --gid 999 --uid 999 --create-home nonroot
# System dependencies
RUN apt update -y && \
apt install -y --no-install-recommends build-essential git dos2unix openssh-client && \
apt-get update && \
apt-get install -y --no-install-recommends curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Files
WORKDIR "$ROOT_DIR"
COPY *.toml *.lock ./
COPY src src
COPY dist dist
COPY docker_files/*.sh docker_files/
RUN dos2unix docker_files/*.sh
# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
# Virtual environment
RUN --mount=type=ssh \
--mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
git config --global --replace-all url."ssh://git@github.com/".insteadOf "https://github.com/" && \
git config --global --add url."ssh://git@github.com/".insteadOf "https://git@github.com/" && \
git config --global --add url."ssh://git@github.com/".insteadOf "git+https://git@github.com/" && \
uv sync --locked --no-editable --no-cache --no-dev --no-group docs --extra cpu --no-install-project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-editable --no-cache --no-dev --no-group docs --extra cpu
# rm unnecessary files
RUN rm -rf src/*.egg-info
# Use the non-root user to run our application
USER nonroot
# Entrypoint
ENV PATH="$ROOT_DIR/.venv/bin:$PATH"
ENTRYPOINT ["bash", "docker_files/docker_entrypoint.sh"]