# Build stage
FROM golang:1.22-alpine AS builder

WORKDIR /app

# Install dependencies
RUN apk add --no-cache git

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o devour ./cmd/devour

# Runtime stage
FROM alpine:3.19

WORKDIR /app

# Install ca-certificates for HTTPS
RUN apk --no-cache add ca-certificates tzdata

# Copy binary from builder
COPY --from=builder /app/devour /app/devour

# Create data directories
RUN mkdir -p /app/devour_data/docs /app/devour_data/index /app/devour_data/metadata

# Set environment
ENV DEVOUR_DATA_DIR=/app/devour_data

# Entry point
ENTRYPOINT ["/app/devour"]
CMD ["--help"]
