-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
138 lines (116 loc) · 4.89 KB
/
Dockerfile
File metadata and controls
138 lines (116 loc) · 4.89 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# =============================================================================
# LadybugDB — Docker Multi-Stage Build (v3)
# =============================================================================
# Triple-binary: AVX-512, AVX-2, and generic x86-64
# Runtime auto-selects best binary via /proc/cpuinfo
#
# BUILD:
# docker build -t ladybugdb .
#
# RUN:
# docker run -p 8080:8080 ladybugdb
# docker run -p 8080:8080 -e LADYBUG_DATA_DIR=/data -v ./data:/data ladybugdb
#
# RAILWAY:
# Auto-detects via RAILWAY_* env vars → binds 0.0.0.0:$PORT
#
# CLAUDE CODE:
# Auto-detects via CLAUDE_* env vars → binds 127.0.0.1:5432
# =============================================================================
# =============================================================================
# STAGE 1: Builder — compile three binaries
# Rust 1.94 stable (edition 2024 support, full rmp-serde/time compat)
# =============================================================================
FROM rust:1.94-slim-bookworm AS builder
RUN apt-get update && apt-get install -y \
pkg-config libssl-dev cmake protobuf-compiler git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /build
# --- Dependency caching ---
COPY Cargo.toml Cargo.lock* ./
RUN mkdir -p src/bin && \
echo "fn main() {}" > src/bin/server.rs && \
echo "pub fn dummy() {}" > src/lib.rs && \
cargo fetch 2>/dev/null || true
# --- Full source ---
COPY . .
# --- Clone sibling repos (OBLIGATORY deps) ---
# Cargo.toml uses path = "../rustynum/...", "../crewai-rust", "../n8n-rs/..."
# From WORKDIR /build, "../" resolves to "/", so repos go to /<name>.
# Cargo validates ALL path deps at resolution time regardless of features.
RUN if [ ! -f /rustynum/rustynum-rs/Cargo.toml ]; then \
git clone --depth 1 https://github.com/AdaWorldAPI/rustynum /rustynum; \
fi
RUN if [ ! -f /crewai-rust/Cargo.toml ]; then \
git clone --depth 1 https://github.com/AdaWorldAPI/crewai-rust /crewai-rust; \
fi
RUN if [ ! -f /n8n-rs/n8n-rust/crates/n8n-arrow/Cargo.toml ]; then \
git clone --depth 1 https://github.com/AdaWorldAPI/n8n-rs /n8n-rs; \
fi
# Features to enable (flight enables Arrow Flight gRPC)
# NOTE: lancedb feature has API compatibility issues - enable after fixing lance module
ARG FEATURES="simd,parallel,flight"
# --- AVX-512 binary (Railway, cloud servers) ---
RUN RUSTFLAGS="-C target-cpu=x86-64-v4 -C link-arg=-s" \
cargo build --release --bin ladybug-server --features "$FEATURES" && \
cp target/release/ladybug-server /build/ladybug-avx512 && \
cargo clean -p ladybug
# --- AVX-2 binary (most modern x86-64) ---
RUN RUSTFLAGS="-C target-cpu=x86-64-v3 -C link-arg=-s" \
cargo build --release --bin ladybug-server --features "$FEATURES" && \
cp target/release/ladybug-server /build/ladybug-avx2 && \
cargo clean -p ladybug
# --- Generic binary (any x86-64) ---
RUN RUSTFLAGS="-C link-arg=-s" \
cargo build --release --bin ladybug-server --features "$FEATURES" && \
cp target/release/ladybug-server /build/ladybug-generic
# --- Flight gRPC binary (single build, runtime selects SIMD) ---
RUN RUSTFLAGS="-C target-cpu=x86-64-v3 -C link-arg=-s" \
cargo build --release --bin ladybug-flight --features "$FEATURES" && \
cp target/release/ladybug-flight /build/ladybug-flight
# =============================================================================
# STAGE 2: Runtime (minimal ~50MB)
# =============================================================================
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl procps \
&& rm -rf /var/lib/apt/lists/* \
&& useradd -m -s /bin/bash ladybug \
&& mkdir -p /data && chown ladybug:ladybug /data
# Copy all server binaries (HTTP)
COPY --from=builder /build/ladybug-avx512 /usr/local/bin/
COPY --from=builder /build/ladybug-avx2 /usr/local/bin/
COPY --from=builder /build/ladybug-generic /usr/local/bin/
# Copy Flight gRPC binary
COPY --from=builder /build/ladybug-flight /usr/local/bin/
# Copy docs
COPY --from=builder /build/README.md /opt/ladybug/
COPY --from=builder /build/docs/ /opt/ladybug/docs/
# Auto-select entrypoint
COPY <<'ENTRY' /usr/local/bin/ladybug-start
#!/bin/sh
set -e
if grep -q "avx512f" /proc/cpuinfo 2>/dev/null; then
BIN=ladybug-avx512; LVL=AVX-512
elif grep -q "avx2" /proc/cpuinfo 2>/dev/null; then
BIN=ladybug-avx2; LVL=AVX-2
else
BIN=ladybug-generic; LVL=Generic
fi
echo "[ladybugdb] SIMD: ${LVL} → ${BIN}"
exec "/usr/local/bin/${BIN}" "$@"
ENTRY
RUN chmod +x /usr/local/bin/ladybug-start
USER ladybug
WORKDIR /home/ladybug
ENV LADYBUG_HOST=0.0.0.0
ENV LADYBUG_PORT=8080
ENV LADYBUG_FLIGHT_PORT=50051
ENV LADYBUG_DATA_DIR=/data
# HTTP REST API
EXPOSE 8080
# Arrow Flight gRPC
EXPOSE 50051
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${LADYBUG_PORT}/health || exit 1
ENTRYPOINT ["ladybug-start"]