1
0

cann.Dockerfile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # ==============================================================================
  2. # ARGUMENTS
  3. # ==============================================================================
  4. # Define the CANN base image for easier version updates later
  5. ARG CHIP_TYPE=910b
  6. ARG CANN_BASE_IMAGE=quay.io/ascend/cann:8.3.rc1.alpha001-${CHIP_TYPE}-openeuler22.03-py3.11
  7. # ==============================================================================
  8. # BUILD STAGE
  9. # Compile all binary files and libraries
  10. # ==============================================================================
  11. FROM ${CANN_BASE_IMAGE} AS build
  12. # -- Install build dependencies --
  13. RUN yum install -y gcc g++ cmake make git libcurl-devel python3 python3-pip && \
  14. yum clean all && \
  15. rm -rf /var/cache/yum
  16. # -- Set the working directory --
  17. WORKDIR /app
  18. # -- Copy project files --
  19. COPY . .
  20. # -- Set CANN environment variables (required for compilation) --
  21. # Using ENV instead of `source` allows environment variables to persist across the entire image layer
  22. ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
  23. ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
  24. ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
  25. ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
  26. ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/runtime/lib64/stub:$LD_LIBRARY_PATH
  27. # ... You can add other environment variables from the original file as needed ...
  28. # For brevity, only core variables are listed here. You can paste the original ENV list here.
  29. # -- Build llama.cpp --
  30. # Use the passed CHIP_TYPE argument and add general build options
  31. ARG CHIP_TYPE
  32. RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh --force \
  33. && \
  34. cmake -B build \
  35. -DGGML_CANN=ON \
  36. -DCMAKE_BUILD_TYPE=Release \
  37. -DSOC_TYPE=ascend${CHIP_TYPE} \
  38. . && \
  39. cmake --build build --config Release -j$(nproc)
  40. # -- Organize build artifacts for copying in later stages --
  41. # Create a lib directory to store all .so files
  42. RUN mkdir -p /app/lib && \
  43. find build -name "*.so*" -exec cp -P {} /app/lib \;
  44. # Create a full directory to store all executables and Python scripts
  45. RUN mkdir -p /app/full && \
  46. cp build/bin/* /app/full/ && \
  47. cp *.py /app/full/ && \
  48. cp -r gguf-py /app/full/ && \
  49. cp -r requirements /app/full/ && \
  50. cp requirements.txt /app/full/
  51. # If you have a tools.sh script, make sure it is copied here
  52. # cp .devops/tools.sh /app/full/tools.sh
  53. # ==============================================================================
  54. # BASE STAGE
  55. # Create a minimal base image with CANN runtime and common libraries
  56. # ==============================================================================
  57. FROM ${CANN_BASE_IMAGE} AS base
  58. # -- Install runtime dependencies --
  59. RUN yum install -y libgomp curl && \
  60. yum clean all && \
  61. rm -rf /var/cache/yum
  62. # -- Set CANN environment variables (required for runtime) --
  63. ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
  64. ENV LD_LIBRARY_PATH=/app:${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
  65. ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
  66. ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
  67. # ... You can add other environment variables from the original file as needed ...
  68. WORKDIR /app
  69. # Copy compiled .so files from the build stage
  70. COPY --from=build /app/lib/ /app
  71. # ==============================================================================
  72. # FINAL STAGES (TARGETS)
  73. # ==============================================================================
  74. ### Target: full
  75. # Complete image with all tools, Python bindings, and dependencies
  76. # ==============================================================================
  77. FROM base AS full
  78. COPY --from=build /app/full /app
  79. # Install Python dependencies
  80. RUN yum install -y git python3 python3-pip && \
  81. pip3 install --no-cache-dir --upgrade pip setuptools wheel && \
  82. pip3 install --no-cache-dir -r requirements.txt && \
  83. yum clean all && \
  84. rm -rf /var/cache/yum
  85. # You need to provide a tools.sh script as the entrypoint
  86. ENTRYPOINT ["/app/tools.sh"]
  87. # If there is no tools.sh, you can set the default to start the server
  88. # ENTRYPOINT ["/app/llama-server"]
  89. ### Target: light
  90. # Lightweight image containing only llama-cli
  91. # ==============================================================================
  92. FROM base AS light
  93. COPY --from=build /app/full/llama-cli /app
  94. ENTRYPOINT [ "/app/llama-cli" ]
  95. ### Target: server
  96. # Dedicated server image containing only llama-server
  97. # ==============================================================================
  98. FROM base AS server
  99. ENV LLAMA_ARG_HOST=0.0.0.0
  100. COPY --from=build /app/full/llama-server /app
  101. HEALTHCHECK --interval=5m CMD [ "curl", "-f", "http://localhost:8080/health" ]
  102. ENTRYPOINT [ "/app/llama-server" ]