FROM cgr.dev/chainguard/wolfi-base:latest

RUN apk update && apk add \
    zig \
    build-base \
    git \
    sqlite-dev \
    bash \
    curl \
    unzip

# Install DuckDB
RUN curl -L -o libduckdb.zip https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip && \
    unzip libduckdb.zip -d /usr/local && \
    rm libduckdb.zip && \
    ln -s /usr/local/libduckdb.so /usr/lib/libduckdb.so && \
    cp /usr/local/duckdb.h /usr/include/duckdb.h

WORKDIR /app

# Copy SDK
COPY . .

# Build Capsule Core
WORKDIR /app/capsule-core
RUN zig build

# Expose ports
# 9000: UTCP/P2P
# 5353: mDNS
EXPOSE 9000/udp
EXPOSE 5353/udp

# Entrypoint
CMD ["./zig-out/bin/capsule", "start"]
