# syntax=docker/dockerfile:1
# Zesdex — Multi-stage Docker build (Bun)
# ========================================
# Stage 1: Build with Bun → compile single self-contained CLI binary
FROM oven/bun:1.2 AS builder

WORKDIR /app
COPY bun.lockb bun.lock ./
COPY package.json tsconfig.json ./
COPY apps ./apps

RUN bun install --frozen-lockfile

# Compile a standalone self-contained executable (bundles JS + native addons).
RUN bun build apps/interfaces/cli/src/index.ts --compile --outfile=/app/zesdex

# Stage 2: Minimal runtime image
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates && \
    rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/zesdex /usr/local/bin/zesdex

ENV ZESDEX_DATA_DIR=/data
VOLUME ["/data"]

ENTRYPOINT ["/usr/local/bin/zesdex"]
