|
| 1 | +ARG UBUNTU_VERSION=24.04 |
| 2 | +ARG BUILD_DATE=N/A |
| 3 | +ARG APP_VERSION=N/A |
| 4 | +ARG APP_REVISION=N/A |
| 5 | + |
| 6 | +FROM ubuntu:$UBUNTU_VERSION AS build |
| 7 | + |
| 8 | +RUN apt-get update && \ |
| 9 | + apt-get install -y gcc-13 g++-13 build-essential git cmake libssl-dev libomp-dev libnuma-dev python3 ca-certificates |
| 10 | + |
| 11 | +ENV CC=gcc-13 CXX=g++-13 |
| 12 | + |
| 13 | +WORKDIR /app |
| 14 | + |
| 15 | +COPY . . |
| 16 | + |
| 17 | +RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=OFF -DLLAMA_BUILD_TESTS=OFF -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DGGML_ZENDNN=ON && \ |
| 18 | + cmake --build build -j $(nproc) |
| 19 | + |
| 20 | +RUN mkdir -p /app/lib && \ |
| 21 | + find build -name "*.so*" -exec cp -P {} /app/lib \; |
| 22 | + |
| 23 | +RUN mkdir -p /app/full \ |
| 24 | + && cp build/bin/* /app/full \ |
| 25 | + && cp *.py /app/full \ |
| 26 | + && cp -r conversion /app/full \ |
| 27 | + && cp -r gguf-py /app/full \ |
| 28 | + && cp -r requirements /app/full \ |
| 29 | + && cp requirements.txt /app/full \ |
| 30 | + && cp .devops/tools.sh /app/full/tools.sh |
| 31 | + |
| 32 | +## Base image |
| 33 | +FROM ubuntu:$UBUNTU_VERSION AS base |
| 34 | + |
| 35 | +ARG BUILD_DATE=N/A |
| 36 | +ARG APP_VERSION=N/A |
| 37 | +ARG APP_REVISION=N/A |
| 38 | +ARG IMAGE_URL=https://github.com/ggml-org/llama.cpp |
| 39 | +ARG IMAGE_SOURCE=https://github.com/ggml-org/llama.cpp |
| 40 | +LABEL org.opencontainers.image.created=$BUILD_DATE \ |
| 41 | + org.opencontainers.image.version=$APP_VERSION \ |
| 42 | + org.opencontainers.image.revision=$APP_REVISION \ |
| 43 | + org.opencontainers.image.title="llama.cpp" \ |
| 44 | + org.opencontainers.image.description="LLM inference in C/C++" \ |
| 45 | + org.opencontainers.image.url=$IMAGE_URL \ |
| 46 | + org.opencontainers.image.source=$IMAGE_SOURCE |
| 47 | + |
| 48 | +RUN apt-get update \ |
| 49 | + && apt-get install -y libgomp1 libnuma1 curl \ |
| 50 | + && apt autoremove -y \ |
| 51 | + && apt clean -y \ |
| 52 | + && rm -rf /tmp/* /var/tmp/* \ |
| 53 | + && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \ |
| 54 | + && find /var/cache -type f -delete |
| 55 | + |
| 56 | +COPY --from=build /app/lib/ /app |
| 57 | + |
| 58 | +### Full |
| 59 | +FROM base AS full |
| 60 | + |
| 61 | +COPY --from=build /app/full /app |
| 62 | + |
| 63 | +WORKDIR /app |
| 64 | + |
| 65 | +RUN apt-get update \ |
| 66 | + && apt-get install -y \ |
| 67 | + git \ |
| 68 | + python3 \ |
| 69 | + python3-pip \ |
| 70 | + python3-wheel \ |
| 71 | + && pip install --break-system-packages --upgrade setuptools \ |
| 72 | + && pip install --break-system-packages -r requirements.txt \ |
| 73 | + && apt autoremove -y \ |
| 74 | + && apt clean -y \ |
| 75 | + && rm -rf /tmp/* /var/tmp/* \ |
| 76 | + && find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \ |
| 77 | + && find /var/cache -type f -delete |
| 78 | + |
| 79 | +ENTRYPOINT ["/app/tools.sh"] |
| 80 | + |
| 81 | +### Light, CLI only |
| 82 | +FROM base AS light |
| 83 | + |
| 84 | +COPY --from=build /app/full/llama-cli /app/full/llama-completion /app |
| 85 | + |
| 86 | +WORKDIR /app |
| 87 | + |
| 88 | +ENTRYPOINT [ "/app/llama-cli" ] |
| 89 | + |
| 90 | +### Server, Server only |
| 91 | +FROM base AS server |
| 92 | + |
| 93 | +ENV LLAMA_ARG_HOST=0.0.0.0 |
| 94 | + |
| 95 | +COPY --from=build /app/full/llama-server /app |
| 96 | + |
| 97 | +WORKDIR /app |
| 98 | + |
| 99 | +HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ] |
| 100 | + |
| 101 | +ENTRYPOINT [ "/app/llama-server" ] |
0 commit comments