1ARG UBUNTU_VERSION=24.04
 2# This needs to generally match the container host's environment.
 3ARG CUDA_VERSION=13.1.0
 4# Target the CUDA build image
 5ARG BASE_CUDA_DEV_CONTAINER=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
 6
 7ARG BASE_CUDA_RUN_CONTAINER=nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
 8
 9FROM ${BASE_CUDA_DEV_CONTAINER} AS build
10
11# CUDA architecture to build for (defaults to all supported archs)
12ARG CUDA_DOCKER_ARCH=default
13
14RUN apt-get update && \
15    apt-get install -y build-essential cmake python3 python3-pip git libssl-dev libgomp1
16
17WORKDIR /app
18
19COPY . .
20
21RUN if [ "${CUDA_DOCKER_ARCH}" != "default" ]; then \
22    export CMAKE_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${CUDA_DOCKER_ARCH}"; \
23    fi && \
24    cmake -B build -DGGML_NATIVE=OFF -DGGML_CUDA=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DLLAMA_BUILD_TESTS=OFF ${CMAKE_ARGS} -DCMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined . && \
25    cmake --build build --config Release -j$(nproc)
26
27RUN mkdir -p /app/lib && \
28    find build -name "*.so*" -exec cp -P {} /app/lib \;
29
30RUN mkdir -p /app/full \
31    && cp build/bin/* /app/full \
32    && cp *.py /app/full \
33    && cp -r gguf-py /app/full \
34    && cp -r requirements /app/full \
35    && cp requirements.txt /app/full \
36    && cp .devops/tools.sh /app/full/tools.sh
37
38## Base image
39FROM ${BASE_CUDA_RUN_CONTAINER} AS base
40
41RUN apt-get update \
42    && apt-get install -y libgomp1 curl\
43    && apt autoremove -y \
44    && apt clean -y \
45    && rm -rf /tmp/* /var/tmp/* \
46    && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
47    && find /var/cache -type f -delete
48
49COPY --from=build /app/lib/ /app
50
51### Full
52FROM base AS full
53
54COPY --from=build /app/full /app
55
56WORKDIR /app
57
58RUN apt-get update \
59    && apt-get install -y \
60    git \
61    python3 \
62    python3-pip \
63    python3-wheel \
64    && pip install --break-system-packages --upgrade setuptools \
65    && pip install --break-system-packages -r requirements.txt \
66    && apt autoremove -y \
67    && apt clean -y \
68    && rm -rf /tmp/* /var/tmp/* \
69    && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
70    && find /var/cache -type f -delete
71
72
73ENTRYPOINT ["/app/tools.sh"]
74
75### Light, CLI only
76FROM base AS light
77
78COPY --from=build /app/full/llama-cli /app/full/llama-completion /app
79
80WORKDIR /app
81
82ENTRYPOINT [ "/app/llama-cli" ]
83
84### Server, Server only
85FROM base AS server
86
87ENV LLAMA_ARG_HOST=0.0.0.0
88
89COPY --from=build /app/full/llama-server /app
90
91WORKDIR /app
92
93HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
94
95ENTRYPOINT [ "/app/llama-server" ]