# Stage 1: Build the Go binary
FROM golang:1.22-alpine AS builder

WORKDIR /app

COPY go.mod ./
COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server .

# Stage 2: Ultra-lightweight runtime container
FROM alpine:3.19

RUN apk add --no-cache ca-certificates tzdata

WORKDIR /app

# Copy binary and static front-end assets
COPY --from=builder /app/server /app/server
COPY --from=builder /app/public /app/public

EXPOSE 8080

ENTRYPOINT ["/app/server"]
