# First Stage: Build the binary using golang base image
FROM golang:1.25

RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o server .

# Second Stage: Run the compiled binary inside alpine
FROM alpine

# Fix: Alpine needs ca-certificates to verify SSL certificates.
# tzdata + TZ: the database connection sets TimeZone=Asia/Kolkata, so
# CURRENT_TIMESTAMP defaults write IST wall-clock into the timestamp columns.
# With the container defaulting to UTC, every time.Now() the app wrote was 5h30m
# behind those defaults, and "today so far" date ranges ended 5h30m in the past —
# which silently dropped anything created after noon IST from every report.
RUN apk add --no-cache ca-certificates tzdata
ENV TZ=Asia/Kolkata

# Copy from first stage
COPY --from=0 /app/server /app/server

WORKDIR /app

# Default startup command
CMD ["./server"]
