FROM golang:1.22-alpine AS builder

WORKDIR /app

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

# Copy Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy source
COPY . .

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /client2server-server .

# === Production ===
FROM alpine:3.19

WORKDIR /app

# Install CA certs for HTTPS
RUN apk add --no-cache ca-certificates tzdata

# Copy binary
COPY --from=builder /client2server-server .

# Single port serves both WebSocket and HTTP API (Caddy fronts everything)
EXPOSE 3843

ENV TOKEN=change_me_in_production
ENV REDPANDA_BROKERS=redpanda:9092
ENV PORT=3843

CMD ["/client2server-server"]