-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
90 lines (71 loc) · 3.5 KB
/
Copy pathDockerfile
File metadata and controls
90 lines (71 loc) · 3.5 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
# syntax=docker/dockerfile:1
# =============================================================================
# Stage 1 -- builder
# Compiles kleos-server and kleos-cli in release mode.
# SQLCipher is vendored at compile time via the "sqlcipher" feature so no
# system libsqlcipher is needed at runtime.
# =============================================================================
FROM rust:1.94-bookworm AS builder
WORKDIR /build
# Install build-time deps needed by vendored SQLCipher and OpenSSL bindings.
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
libssl-dev \
clang \
protobuf-compiler \
libprotobuf-dev \
libpcsclite-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy the full workspace so Cargo can resolve the dependency graph.
COPY . .
# Cap release-build memory so it fits the 16 GB CI runners. Fat LTO with a
# single codegen unit was SIGKILLed (OOM) while compiling kleos-server on the
# arm64 runner; thin LTO with 16 codegen units builds within memory and faster,
# with negligible runtime cost for a server binary. Scoped to this build only.
ENV CARGO_PROFILE_RELEASE_LTO=thin \
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16
# Build with BuildKit cache mounts so the Cargo registry and compiled
# dependencies survive across rebuilds — only changed crates are recompiled.
# Binaries are copied to /tmp here because cache mounts are not accessible
# from other stages.
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target \
cargo build --release -p kleos-server -p kleos-cli \
&& cp target/release/kleos-server /tmp/kleos-server \
&& cp target/release/kleos-cli /tmp/kleos-cli
# =============================================================================
# Stage 2 -- runtime
# Minimal Debian image with only the libraries the binaries actually dlopen.
# =============================================================================
FROM debian:bookworm-slim AS runtime
LABEL org.opencontainers.image.source="https://github.com/Ghost-Frame/Kleos" \
org.opencontainers.image.description="Kleos memory server (formerly Engram) -- personal knowledge graph and semantic memory store" \
org.opencontainers.image.licenses="Elastic-2.0"
# Install runtime dependencies:
# libssl3 -- required by reqwest (native-tls)
# ca-certificates -- required for outbound HTTPS calls
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl3 \
ca-certificates \
libpcsclite1 \
&& rm -rf /var/lib/apt/lists/*
# Create a dedicated non-root user for running the server.
RUN groupadd --system --gid 1000 kleos \
&& useradd --system --uid 1000 --gid kleos --no-create-home --shell /sbin/nologin kleos
# Persistent data lives here. A named volume or bind-mount should be attached.
RUN mkdir -p /data && chown kleos:kleos /data
COPY --from=builder /tmp/kleos-server /usr/local/bin/kleos-server
COPY --from=builder /tmp/kleos-cli /usr/local/bin/kleos-cli
RUN chmod 755 /usr/local/bin/kleos-server /usr/local/bin/kleos-cli
# Legacy aliases for backward compatibility.
RUN ln -s /usr/local/bin/kleos-server /usr/local/bin/engram-server \
&& ln -s /usr/local/bin/kleos-cli /usr/local/bin/engram-cli
USER kleos
# Environment -- bind to all interfaces inside the container.
# KLEOS_* vars are preferred. The env shim falls back to ENGRAM_* automatically.
ENV KLEOS_HOST=0.0.0.0
ENV KLEOS_DATA_DIR=/data
ENV KLEOS_DB_PATH=/data/kleos.db
VOLUME ["/data"]
EXPOSE 4200
CMD ["/usr/local/bin/kleos-server"]