# ---------- Build stage ----------
FROM golang:1.25 AS builder

WORKDIR /app

# copy dependency files first for caching
COPY go.mod ./
RUN go mod download

# copy the rest of the source (including Makefile)
COPY . .

# run the Makefile to build all binaries into bin/
RUN make

# ---------- Final stage ----------
FROM debian:bookworm-slim AS final

# install socat
RUN apt-get update && \
    apt-get install -y socat && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /opt

# copy the binaries from builder stage
COPY --from=builder /app/bin/* ./

# run the speistel binary via socat
CMD ["socat", "TCP-LISTEN:8888,reuseaddr,fork", "EXEC:/opt/speistel"]
