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