# Build stage
FROM golang:1.21-alpine AS builder

WORKDIR /app

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

# Copy go mod files
COPY go.mod ./

# Initialize module and download dependencies
RUN go mod tidy || true

# Copy source code
COPY . .

# Build the binary
RUN CGO_ENABLED=0 GOOS=linux go build -o /heuristic-service ./cmd/server

# Runtime stage
FROM alpine:3.19

WORKDIR /app

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

# Copy binary from builder
COPY --from=builder /heuristic-service /app/heuristic-service

# Expose port
EXPOSE 8085

# Set environment variables
ENV PORT=8085
ENV GIN_MODE=release
ENV CONFIG_PATH=/app/ai-access.json

# Run the service
CMD ["/app/heuristic-service"]
