FROM golang:1.25-alpine AS builder

RUN apk add --no-cache git ca-certificates

WORKDIR /build
COPY . .

# Build the basic-badger example
RUN echo ${pwd};cd examples/basic-badger && \
    go mod tidy && \
    CGO_ENABLED=0 go build -o khatru-badger .

FROM alpine:latest
RUN apk --no-cache add ca-certificates wget
WORKDIR /app
COPY --from=builder /build/examples/basic-badger/khatru-badger /app/
RUN mkdir -p /data
EXPOSE 3334
ENV DATABASE_PATH=/data/badger
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
  CMD wget --quiet --tries=1 --spider http://localhost:3334 || exit 1
CMD ["/app/khatru-badger"]
