# Telegram connector image.
#
# The connector imports only the shared scrabble/pkg module, so the build drops the
# other workspace modules (backend, gateway, loadtest), the loadtest-only
# scrabble/gateway replace and the scrabble-solver replace from a copy of go.work: it
# needs neither their sources nor the solver sibling checkout.
# Build from the repository ROOT so go.work, pkg/ and platform/telegram/ are all in
# the context (see deploy/docker-compose.yml, which sets context: ../../..).
FROM golang:1.26.3-alpine AS build
WORKDIR /src

COPY go.work go.work.sum ./
COPY pkg ./pkg
COPY platform/telegram ./platform/telegram

# Reduce the workspace to what the connector needs: only pkg + platform/telegram.
RUN go work edit -dropuse=./backend -dropuse=./gateway -dropuse=./loadtest -dropreplace=scrabble/gateway@v0.0.0 -dropreplace=scrabble-solver

RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -o /out/telegram ./platform/telegram/cmd/telegram

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/telegram /usr/local/bin/telegram
ENTRYPOINT ["/usr/local/bin/telegram"]
