Skip to content

Commit 269a8eb

Browse files
committed
chore(build): Build backends on a separate layer to speed up core only changes
Signed-off-by: Richard Palethorpe <[email protected]>
1 parent 7a97ad6 commit 269a8eb

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

Dockerfile

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,40 @@ EOT
285285
###################################
286286
###################################
287287

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
291290

292-
# Install the pre-built GRPC
293291
COPY --from=grpc /opt/grpc /usr/local
294292

295-
# Rebuild with defaults backends
296293
WORKDIR /build
297294

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
300305

306+
RUN ls -l ./
307+
RUN make backend-assets
301308
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 . .
302322

303323
## Build the binary
304324
## If we're on arm64 AND using cublas/hipblas, skip some of the llama-compat backends to save space
@@ -390,8 +410,6 @@ COPY . .
390410
COPY --from=builder /build/sources ./sources/
391411
COPY --from=grpc /opt/grpc /usr/local
392412

393-
RUN make prepare-sources
394-
395413
# Copy the binary
396414
COPY --from=builder /build/local-ai ./
397415

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,18 +842,17 @@ docker-aio-all:
842842

843843
docker-image-intel:
844844
docker build \
845-
--progress plain \
846845
--build-arg BASE_IMAGE=intel/oneapi-basekit:2025.1.0-0-devel-ubuntu24.04 \
847846
--build-arg IMAGE_TYPE=$(IMAGE_TYPE) \
848-
--build-arg GO_TAGS="none" \
847+
--build-arg GO_TAGS="$(GO_TAGS)" \
849848
--build-arg MAKEFLAGS="$(DOCKER_MAKEFLAGS)" \
850849
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
851850

852851
docker-image-intel-xpu:
853852
docker build \
854853
--build-arg BASE_IMAGE=intel/oneapi-basekit:2025.1.0-0-devel-ubuntu22.04 \
855854
--build-arg IMAGE_TYPE=$(IMAGE_TYPE) \
856-
--build-arg GO_TAGS="none" \
855+
--build-arg GO_TAGS="$(GO_TAGS)" \
857856
--build-arg MAKEFLAGS="$(DOCKER_MAKEFLAGS)" \
858857
--build-arg BUILD_TYPE=sycl_f32 -t $(DOCKER_IMAGE) .
859858

0 commit comments

Comments
 (0)