# Build stage
FROM golang:1.25.1-trixie AS builder

WORKDIR /app

COPY . .
RUN CGO_ENABLED=1 go build -tags "sqlite_omit_load_extension" -o main ./cmd/router
RUN CGO_ENABLED=1 go build -tags "sqlite_omit_load_extension" -o init-db ./cmd/init-db

# Runtime stage
FROM debian:trixie

RUN apt-get update && apt-get install -y iputils-ping && rm -rf /var/lib/apt/lists/*

WORKDIR /root/

COPY --from=builder /app/main .
COPY --from=builder /app/init-db .
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/static ./static
COPY --from=builder /app/amp-credit-code.txt .
COPY interview-bundle.zip ./interview-bundle.zip

EXPOSE 9992

# Initialize DB and run the application
CMD ["sh", "-c", "./init-db && ./main"]
