@@ -285,20 +285,40 @@ EOT
285
285
# ##################################
286
286
# ##################################
287
287
288
- # The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
289
- # Adjustments to the build process should likely be made here.
290
- FROM builder-base AS builder
288
+ # Compile backends first in a separate stage
289
+ FROM builder-base AS builder-backends
291
290
292
- # Install the pre-built GRPC
293
291
COPY --from=grpc /opt/grpc /usr/local
294
292
295
- # Rebuild with defaults backends
296
293
WORKDIR /build
297
294
298
- COPY . .
299
- COPY .git .
295
+ COPY ./Makefile .
296
+ COPY ./backend ./backend
297
+ COPY ./go.mod .
298
+ COPY ./go.sum .
299
+ COPY ./.git ./.git
300
+
301
+ # Some of the Go backends use libs from the main src, we could further optimize the caching by building the CPP backends before here
302
+ COPY ./pkg/grpc ./pkg/grpc
303
+ COPY ./pkg/utils ./pkg/utils
304
+ COPY ./pkg/langchain ./pkg/langchain
300
305
306
+ RUN ls -l ./
307
+ RUN make backend-assets
301
308
RUN make prepare
309
+ RUN if [ "${TARGETARCH}" = "arm64" ] || [ "${BUILD_TYPE}" = "hipblas" ]; then \
310
+ SKIP_GRPC_BACKEND="backend-assets/grpc/llama-cpp-avx512 backend-assets/grpc/llama-cpp-avx backend-assets/grpc/llama-cpp-avx2" make grpcs; \
311
+ else \
312
+ make grpcs; \
313
+ fi
314
+
315
+ # The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry.
316
+ # Adjustments to the build process should likely be made here.
317
+ FROM builder-backends AS builder
318
+
319
+ WORKDIR /build
320
+
321
+ COPY . .
302
322
303
323
# # Build the binary
304
324
# # If we're on arm64 AND using cublas/hipblas, skip some of the llama-compat backends to save space
@@ -390,8 +410,6 @@ COPY . .
390
410
COPY --from=builder /build/sources ./sources/
391
411
COPY --from=grpc /opt/grpc /usr/local
392
412
393
- RUN make prepare-sources
394
-
395
413
# Copy the binary
396
414
COPY --from=builder /build/local-ai ./
397
415
0 commit comments