Skip to content

Commit 1b752da

Browse files
committed
docker: fix cann devops
1 parent 24ff483 commit 1b752da

File tree

1 file changed

+130
-130
lines changed

1 file changed

+130
-130
lines changed

.devops/cann.Dockerfile

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

0 commit comments

Comments
 (0)