1ARG UBUNTU_VERSION=22.04
2
3FROM ubuntu:$UBUNTU_VERSION AS build
4
5ARG TARGETARCH
6
7RUN apt-get update && \
8 apt-get install -y build-essential git cmake libssl-dev
9
10WORKDIR /app
11
12COPY . .
13
14RUN if [ "$TARGETARCH" = "amd64" ] || [ "$TARGETARCH" = "arm64" ]; then \
15 cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=OFF -DLLAMA_BUILD_TESTS=OFF -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON; \
16 else \
17 echo "Unsupported architecture"; \
18 exit 1; \
19 fi && \
20 cmake --build build -j $(nproc)
21
22RUN mkdir -p /app/lib && \
23 find build -name "*.so*" -exec cp -P {} /app/lib \;
24
25RUN mkdir -p /app/full \
26 && cp build/bin/* /app/full \
27 && cp *.py /app/full \
28 && cp -r gguf-py /app/full \
29 && cp -r requirements /app/full \
30 && cp requirements.txt /app/full \
31 && cp .devops/tools.sh /app/full/tools.sh
32
33## Base image
34FROM ubuntu:$UBUNTU_VERSION AS base
35
36RUN apt-get update \
37 && apt-get install -y libgomp1 curl\
38 && apt autoremove -y \
39 && apt clean -y \
40 && rm -rf /tmp/* /var/tmp/* \
41 && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
42 && find /var/cache -type f -delete
43
44COPY --from=build /app/lib/ /app
45
46### Full
47FROM base AS full
48
49COPY --from=build /app/full /app
50
51WORKDIR /app
52
53RUN apt-get update \
54 && apt-get install -y \
55 git \
56 python3 \
57 python3-pip \
58 && pip install --upgrade pip setuptools wheel \
59 && pip install -r requirements.txt \
60 && apt autoremove -y \
61 && apt clean -y \
62 && rm -rf /tmp/* /var/tmp/* \
63 && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
64 && find /var/cache -type f -delete
65
66ENTRYPOINT ["/app/tools.sh"]
67
68### Light, CLI only
69FROM base AS light
70
71COPY --from=build /app/full/llama-cli /app/full/llama-completion /app
72
73WORKDIR /app
74
75ENTRYPOINT [ "/app/llama-cli" ]
76
77### Server, Server only
78FROM base AS server
79
80ENV LLAMA_ARG_HOST=0.0.0.0
81
82COPY --from=build /app/full/llama-server /app
83
84WORKDIR /app
85
86HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]
87
88ENTRYPOINT [ "/app/llama-server" ]