mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-31 02:18:50 -04:00
Dockerfile.golang builds 215 of the 434 matrix entries: every ggml/C++ engine wrapped in Go. Each of those Makefiles clones an upstream repo at a pinned SHA and compiles it once per SIMD variant (depth-anything-cpp builds four: avx, avx2, avx512, fallback), and those variant targets depend only on the clone. They cannot observe a change anywhere else in the LocalAI tree. The compile sat below `COPY . /LocalAI`, so any edit anywhere invalidated it and recompiled C++ that had not changed. Move it above that COPY, behind a copy of only the backend's own directory. This lands the compile in the part of the image the registry cache already restores. Measured on two real CI builds of this Dockerfile (jobs 90551029008 and 90551028904, both fresh runners): 13 of 17 layers CACHED from quay.io/go-skynet/ci-cache. The uncached tail is exactly `COPY . /LocalAI`, the git-config RUN and the build RUN. Putting the engine above the COPY moves it from the uncached tail into the cached region. Local measurement, depth-anything-cpp CPU, rebuild after editing a Go file outside the backend: master 78s, 216 C++ objects compiled this change 25s, 0 C++ objects compiled (67% faster) Note what this deliberately is not. An earlier attempt wired a --mount=type=cache ccache into the same RUN. BuildKit does not export cache mounts to a registry cache, so that measured well locally and is a no-op in CI (see the ccache section of .agents/ci-caching.md). This change relies only on ordinary layer caching, which the 13-of-17 figure above shows already works here. The layer copies the backend's whole directory rather than just the Makefile: the CMake targets also need CMakeLists.txt and the file list differs per backend. The cost is that editing a backend's own Go sources invalidates its engine layer. The expensive cases are unaffected, since a shared-build-input or backend.proto change, the weekly full-matrix cron and a tag push all rebuild every backend while touching none of their directories. Scoped to one backend for now: only depth-anything-cpp gains the `engine` target. The other 27 fall through the `make -n engine` guard and build exactly as before, verified against local-store and silero-vad. Rolling the target out to the remaining 12 backends that define VARIANT_TARGETS is mechanical once this is confirmed against the registry cache on master. One caveat on merge: inserting layers shifts the cache keys, so the first build of each entry after this lands is a full miss. It pays for itself on the second. Assisted-by: Claude:opus-5 [claude-code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>