|
| 1 | +# ============================================================================= |
| 2 | +# LadybugDB Unified — All Three Engines, One Docker, One Port |
| 3 | +# ============================================================================= |
| 4 | +# |
| 5 | +# Builds ladybug-rs (gateway + fingerprint engine) + crewai-rust (AI agents) + |
| 6 | +# n8n-rs (workflow orchestration) into a single container. |
| 7 | +# |
| 8 | +# ladybug-rs serves as the unified gateway on port 8080 with Redis/DataFusion- |
| 9 | +# like command surface. CrewAI and n8n run as internal services on 8090/8091. |
| 10 | +# |
| 11 | +# BUILD: |
| 12 | +# docker build -f Dockerfile.unified -t ladybugdb:unified . |
| 13 | +# |
| 14 | +# RUN: |
| 15 | +# docker run -p 8080:8080 \ |
| 16 | +# -e OPENAI_API_KEY=sk-... \ |
| 17 | +# -e XAI_API_KEY=xai-... \ |
| 18 | +# ladybugdb:unified |
| 19 | +# |
| 20 | +# COMMANDS (via POST /cmd): |
| 21 | +# DN.SET, DN.GET, CAM.SEARCH → ladybug (fingerprint/graph) |
| 22 | +# SQL <query> → DataFusion engine |
| 23 | +# CREW.EXECUTE, AGENT.LIST → crewai-rust (AI agents) |
| 24 | +# WF.LIST, WF.EXECUTE → n8n-rs (workflows) |
| 25 | +# RESONATE <query> → Cross-engine search |
| 26 | +# PING → Health check all services |
| 27 | +# HELP → List all commands |
| 28 | +# ============================================================================= |
| 29 | + |
| 30 | +# ============================================================================= |
| 31 | +# STAGE 1: Build ladybug-rs |
| 32 | +# ============================================================================= |
| 33 | +FROM rust:1.83-slim-bookworm AS builder-ladybug |
| 34 | + |
| 35 | +RUN apt-get update && apt-get install -y \ |
| 36 | + pkg-config libssl-dev cmake git \ |
| 37 | + && rm -rf /var/lib/apt/lists/* |
| 38 | + |
| 39 | +WORKDIR /build/ladybug |
| 40 | +COPY . . |
| 41 | + |
| 42 | +ARG LB_FEATURES="simd,parallel,codebook,hologram,quantum" |
| 43 | + |
| 44 | +# Build with CPU auto-detect |
| 45 | +RUN RUSTFLAGS="-C link-arg=-s" \ |
| 46 | + cargo build --release --bin ladybug-server --features "$LB_FEATURES" && \ |
| 47 | + cp target/release/ladybug-server /usr/local/bin/ladybug-server |
| 48 | + |
| 49 | +# ============================================================================= |
| 50 | +# STAGE 2: Build crewai-rust |
| 51 | +# ============================================================================= |
| 52 | +FROM rust:1.83-slim-bookworm AS builder-crewai |
| 53 | + |
| 54 | +RUN apt-get update && apt-get install -y \ |
| 55 | + pkg-config libssl-dev cmake git \ |
| 56 | + && rm -rf /var/lib/apt/lists/* |
| 57 | + |
| 58 | +WORKDIR /build/crewai |
| 59 | +RUN git clone --depth 1 https://github.com/AdaWorldAPI/crewai-rust . |
| 60 | + |
| 61 | +RUN RUSTFLAGS="-C link-arg=-s" \ |
| 62 | + cargo build --release --bin crewai-server && \ |
| 63 | + cp target/release/crewai-server /usr/local/bin/crewai-server |
| 64 | + |
| 65 | +# ============================================================================= |
| 66 | +# STAGE 3: Build n8n-rs |
| 67 | +# ============================================================================= |
| 68 | +FROM rust:1.83-slim-bookworm AS builder-n8n |
| 69 | + |
| 70 | +RUN apt-get update && apt-get install -y \ |
| 71 | + pkg-config libssl-dev cmake protobuf-compiler git \ |
| 72 | + && rm -rf /var/lib/apt/lists/* |
| 73 | + |
| 74 | +WORKDIR /build/n8n |
| 75 | +RUN git clone --depth 1 https://github.com/AdaWorldAPI/n8n-rs . |
| 76 | + |
| 77 | +WORKDIR /build/n8n/n8n-rust |
| 78 | +RUN RUSTFLAGS="-C link-arg=-s" \ |
| 79 | + cargo build --release --bin n8n-server && \ |
| 80 | + cp target/release/n8n-server /usr/local/bin/n8n-server |
| 81 | + |
| 82 | +# ============================================================================= |
| 83 | +# STAGE 4: Runtime — All Three Engines |
| 84 | +# ============================================================================= |
| 85 | +FROM debian:bookworm-slim AS runtime |
| 86 | + |
| 87 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 88 | + ca-certificates curl procps \ |
| 89 | + && rm -rf /var/lib/apt/lists/* \ |
| 90 | + && useradd -m -s /bin/bash ladybug \ |
| 91 | + && mkdir -p /data && chown ladybug:ladybug /data |
| 92 | + |
| 93 | +# Copy all three binaries |
| 94 | +COPY --from=builder-ladybug /usr/local/bin/ladybug-server /usr/local/bin/ |
| 95 | +COPY --from=builder-crewai /usr/local/bin/crewai-server /usr/local/bin/ |
| 96 | +COPY --from=builder-n8n /usr/local/bin/n8n-server /usr/local/bin/ |
| 97 | + |
| 98 | +# Unified entrypoint — starts all 3 services, exposes one port |
| 99 | +COPY <<'ENTRY' /usr/local/bin/ladybug-unified |
| 100 | +#!/bin/sh |
| 101 | +set -e |
| 102 | + |
| 103 | +echo "╔═══════════════════════════════════════════════════════════════╗" |
| 104 | +echo "║ LadybugDB Unified — 3 Engines, 1 Port ║" |
| 105 | +echo "╠═══════════════════════════════════════════════════════════════╣" |
| 106 | +echo "║ Gateway: 0.0.0.0:${LADYBUG_PORT:-8080} (ladybug-rs) ║" |
| 107 | +echo "║ CrewAI: 127.0.0.1:${CREWAI_PORT:-8090} (internal) ║" |
| 108 | +echo "║ n8n-rs: 127.0.0.1:${N8N_PORT:-8091} (internal) ║" |
| 109 | +echo "║ ║" |
| 110 | +echo "║ POST /cmd → Unified Redis/DataFusion command surface ║" |
| 111 | +echo "║ HELP → List all available commands ║" |
| 112 | +echo "╚═══════════════════════════════════════════════════════════════╝" |
| 113 | + |
| 114 | +# Start crewai-rust (internal, port 8090) |
| 115 | +PORT=${CREWAI_PORT:-8090} crewai-server & |
| 116 | +CREWAI_PID=$! |
| 117 | +echo "[unified] crewai-rust started (PID=$CREWAI_PID, port=${CREWAI_PORT:-8090})" |
| 118 | + |
| 119 | +# Start n8n-rs (internal, port 8091) |
| 120 | +N8N_REST_ADDR="0.0.0.0:${N8N_PORT:-8091}" n8n-server & |
| 121 | +N8N_PID=$! |
| 122 | +echo "[unified] n8n-rs started (PID=$N8N_PID, port=${N8N_PORT:-8091})" |
| 123 | + |
| 124 | +# Wait briefly for internal services to start |
| 125 | +sleep 1 |
| 126 | + |
| 127 | +# Export service URLs for the gateway |
| 128 | +export CREWAI_URL="http://127.0.0.1:${CREWAI_PORT:-8090}" |
| 129 | +export N8N_URL="http://127.0.0.1:${N8N_PORT:-8091}" |
| 130 | + |
| 131 | +# Start ladybug-rs gateway (foreground, external port) |
| 132 | +exec ladybug-server "$@" |
| 133 | +ENTRY |
| 134 | +RUN chmod +x /usr/local/bin/ladybug-unified |
| 135 | + |
| 136 | +USER ladybug |
| 137 | +WORKDIR /home/ladybug |
| 138 | + |
| 139 | +# Gateway port (only one exposed) |
| 140 | +ENV LADYBUG_HOST=0.0.0.0 |
| 141 | +ENV LADYBUG_PORT=8080 |
| 142 | +ENV LADYBUG_DATA_DIR=/data |
| 143 | +# Internal service ports |
| 144 | +ENV CREWAI_PORT=8090 |
| 145 | +ENV N8N_PORT=8091 |
| 146 | +# Service discovery |
| 147 | +ENV CREWAI_URL=http://127.0.0.1:8090 |
| 148 | +ENV N8N_URL=http://127.0.0.1:8091 |
| 149 | + |
| 150 | +EXPOSE 8080 |
| 151 | + |
| 152 | +HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \ |
| 153 | + CMD curl -f http://localhost:${LADYBUG_PORT}/health || exit 1 |
| 154 | + |
| 155 | +ENTRYPOINT ["ladybug-unified"] |
0 commit comments