# ==========================================
# Chat Switchboard Backend Dockerfile
# ==========================================

# Build stage
FROM golang:1.22-bookworm AS builder

WORKDIR /app

# Copy go mod files first for caching
# Build context is ./server, so paths are relative to that
COPY go.mod go.sum ./
RUN go mod download

# Copy source code from server directory
COPY . .

# Build the application
RUN CGO_ENABLED=1 go build -o /bin/engine .

# Runtime stage
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 /bin/engine /usr/local/bin/engine

WORKDIR /app

VOLUME ["/app/data"]

ENTRYPOINT ["engine"]
CMD ["serve"]