cann.Dockerfile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.rc2-${CHIP_TYPE}-openeuler24.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 openssl-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. -DUSE_ACL_GRAPH=ON \
  39. . && \
  40. cmake --build build --config Release -j$(nproc)
  41. # -- Organize build artifacts for copying in later stages --
  42. # Create a lib directory to store all .so files
  43. RUN mkdir -p /app/lib && \
  44. find build -name "*.so*" -exec cp -P {} /app/lib \;
  45. # Create a full directory to store all executables and Python scripts
  46. RUN mkdir -p /app/full && \
  47. cp build/bin/* /app/full/ && \
  48. cp *.py /app/full/ && \
  49. cp -r gguf-py /app/full/ && \
  50. cp -r requirements /app/full/ && \
  51. cp requirements.txt /app/full/
  52. # If you have a tools.sh script, make sure it is copied here
  53. # cp .devops/tools.sh /app/full/tools.sh
  54. # ==============================================================================
  55. # BASE STAGE
  56. # Create a minimal base image with CANN runtime and common libraries
  57. # ==============================================================================
  58. FROM ${CANN_BASE_IMAGE} AS base
  59. # -- Install runtime dependencies --
  60. RUN yum install -y libgomp curl && \
  61. yum clean all && \
  62. rm -rf /var/cache/yum
  63. # -- Set CANN environment variables (required for runtime) --
  64. ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
  65. ENV LD_LIBRARY_PATH=/app:${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
  66. ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
  67. ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
  68. # ... You can add other environment variables from the original file as needed ...
  69. WORKDIR /app
  70. # Copy compiled .so files from the build stage
  71. COPY --from=build /app/lib/ /app
  72. # ==============================================================================
  73. # FINAL STAGES (TARGETS)
  74. # ==============================================================================
  75. ### Target: full
  76. # Complete image with all tools, Python bindings, and dependencies
  77. # ==============================================================================
  78. FROM base AS full
  79. COPY --from=build /app/full /app
  80. # Install Python dependencies
  81. RUN yum install -y git python3 python3-pip && \
  82. pip3 install --no-cache-dir --upgrade pip setuptools wheel && \
  83. pip3 install --no-cache-dir -r requirements.txt && \
  84. yum clean all && \
  85. rm -rf /var/cache/yum
  86. # You need to provide a tools.sh script as the entrypoint
  87. ENTRYPOINT ["/app/tools.sh"]
  88. # If there is no tools.sh, you can set the default to start the server
  89. # ENTRYPOINT ["/app/llama-server"]
  90. ### Target: light
  91. # Lightweight image containing only llama-cli and llama-completion
  92. # ==============================================================================
  93. FROM base AS light
  94. COPY --from=build /app/full/llama-cli /app/full/llama-completion /app
  95. ENTRYPOINT [ "/app/llama-cli" ]
  96. ### Target: server
  97. # Dedicated server image containing only llama-server
  98. # ==============================================================================
  99. FROM base AS server
  100. ENV LLAMA_ARG_HOST=0.0.0.0
  101. COPY --from=build /app/full/llama-server /app
  102. HEALTHCHECK --interval=5m CMD [ "curl", "-f", "http://localhost:8080/health" ]
  103. ENTRYPOINT [ "/app/llama-server" ]