-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.ci
More file actions
92 lines (80 loc) · 3.37 KB
/
Copy pathDockerfile.ci
File metadata and controls
92 lines (80 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Dockerfile.ci — local mirror of the Ubuntu GitHub Actions build matrix.
#
# Usage:
# docker build -f Dockerfile.ci -t memxt-ci .
# docker run --rm memxt-ci
#
# Or via the helper:
# ./scripts/ci-local.sh
#
# Mirrors .github/workflows/build.yml (Linux leg) so "passes locally"
# means "passes on GH Actions Ubuntu runner".
# BUILDPLATFORM = the host running docker (e.g. linux/arm64 on an M-series Mac).
# We build for it directly so qemu emulation doesn't segfault the Zig runner.
# On GitHub Actions ubuntu-latest this resolves to linux/amd64 automatically.
FROM --platform=$BUILDPLATFORM ubuntu:24.04
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG ZIG_VERSION=0.16.0
# Derive ZIG_ARCH from BUILDPLATFORM (amd64 → x86_64, arm64 → aarch64).
RUN case "$(uname -m)" in \
x86_64|amd64) echo "x86_64" > /tmp/zig-arch ;; \
aarch64|arm64) echo "aarch64" > /tmp/zig-arch ;; \
*) echo "unsupported arch: $(uname -m)" >&2; exit 2 ;; \
esac && cat /tmp/zig-arch
ENV DEBIAN_FRONTEND=noninteractive \
PATH="/opt/zig:${PATH}"
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
xz-utils \
cmake \
build-essential \
clang \
libc++-dev \
libc++abi-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Zig from ziglang.org (same binaries mlugg/setup-zig pulls).
# Canonical URL form: zig-<arch>-<os>-<version>.tar.xz (arch first).
RUN ZIG_ARCH=$(cat /tmp/zig-arch) \
&& curl -fsSL "https://ziglang.org/download/${ZIG_VERSION}/zig-${ZIG_ARCH}-linux-${ZIG_VERSION}.tar.xz" \
-o /tmp/zig.tar.xz \
&& mkdir -p /opt/zig \
&& tar -xJf /tmp/zig.tar.xz -C /opt/zig --strip-components=1 \
&& rm /tmp/zig.tar.xz \
&& zig version
WORKDIR /src
COPY . /src
# Mirror the workflow steps: fetch GGUF, build llama.cpp statics, compile.
RUN mkdir -p lib && curl -fL -o lib/minilm.gguf \
"https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF/resolve/main/nomic-embed-text-v1.5.f16.gguf"
# Pre-build llama.cpp static libraries (build.zig links against them).
# GH Actions skips this because its jobs run a separate cmake step when
# needed; Docker reproduction forces the rebuild to match host arch.
RUN if [ -f lib/llama.cpp/CMakeLists.txt ]; then \
rm -rf lib/llama.cpp/build \
&& CC=clang CXX=clang++ \
cmake -S lib/llama.cpp -B lib/llama.cpp/build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
-DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++" \
-DGGML_METAL=OFF \
-DGGML_BLAS=OFF \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_BUILD_EXAMPLES=OFF \
-DLLAMA_BUILD_SERVER=OFF \
&& cmake --build lib/llama.cpp/build -j"$(nproc)"; \
else \
echo "!! lib/llama.cpp submodule is empty — run 'git submodule update --init --recursive' before building" >&2; \
exit 1; \
fi
# Sanity check: confirm static libs landed where build.zig expects.
RUN find lib/llama.cpp/build -name '*.a' -print | head -20 \
&& for lib in libllama.a libggml.a libggml-base.a libggml-cpu.a; do \
find lib/llama.cpp/build -name "$lib" -print -quit | grep -q . \
|| { echo "ERROR: $lib missing" >&2; exit 1; }; \
done
RUN zig build --release=fast
CMD ["sh", "-c", "./zig-out/bin/memxt init && ./zig-out/bin/memxt stats"]