FROM crystallang/crystal:1.9.2-alpine AS builder

WORKDIR /app
COPY . .

# Install shards and build the binary
RUN shards install && \
    crystal build --release --static src/main.cr

# Create final minimal image
FROM alpine:3.19

WORKDIR /app
COPY --from=builder /app/main /app/main

# Run as non-root user
RUN adduser -D operator && \
    chown -R operator:operator /app
USER operator

ENTRYPOINT ["/app/main"]
