FROM golang:latest AS builder

WORKDIR /app

# Install build dependencies
RUN apt-get update && apt-get install -y gcc && rm -rf /var/lib/apt/lists/*

# Copy go mod files first for layer caching
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY *.go ./

# Build the binary
RUN CGO_ENABLED=1 go build -o crawler .

# Runtime stage
FROM ubuntu:latest

WORKDIR /app

# Install runtime dependencies
RUN apt-get update && apt-get install -y ca-certificates tzdata curl wget && rm -rf /var/lib/apt/lists/*

# Copy binary from builder
COPY --from=builder /app/crawler .

# Create feeds directory
RUN mkdir -p feeds

CMD ["./crawler"]
