mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-14 10:19:57 +00:00
/addsticker becomes a single stateless command in util, writing to one env-configured set (STICKER_PACK_NAME, default miti99_by_miti99bot). AddStickerToSet takes the set owner's user ID rather than the caller's, so nothing is per-user any more: the sticker module's pack records, slug reservations, pending deletes, per-user locks and its eight other commands are removed with it. The pack creates itself on first use. A positive STICKERSET_INVALID from the add triggers createNewStickerSet owned by OWNER_ID, seeded with the sticker that triggered it and titled with the slug half of the name; a name that is occupied but unwritable is reported instead of taken over. The mandatory "_by_<bot_username>" suffix is Telegram's own proof of authorship, so a misconfigured pack name is refused offline before any API call. StickerSet exposes no owner ID, so ownership is only provable when Telegram refuses. Video, GIF, animation and video-note sources are transcoded to WEBM/VP9 with ffmpeg: long edge scaled to exactly 512 in either direction, cut to 3s, capped at 30fps, audio dropped, retried down a CRF ladder until under 256KB. Animated and video stickers are copied by file_id with no conversion. Sticker format is per-sticker since Bot API 7.2, so one pack holds all three. ffmpeg cannot ship in distroless/static and Go has no VP9 encoder, so the runtime base becomes alpine with apk add ffmpeg. The image grows from roughly 20MB to 213MB, and the transcode holds the single dispatcher worker — bounded at 20s per encode and a 45s handler deadline for moving sources, against 10s for stills.
41 lines
1.7 KiB
Docker
41 lines
1.7 KiB
Docker
FROM golang:1.26.5-alpine AS builder
|
|
WORKDIR /src
|
|
|
|
# The monkeyd-crawler submodule is resolved through a `replace` directive, so
|
|
# its go.mod must be present before `go mod download` can read the build list.
|
|
# Only the module files are copied here, keeping this layer cached across
|
|
# ordinary source edits.
|
|
COPY go.mod go.sum ./
|
|
COPY third_party/monkeyd-crawler/go.mod third_party/monkeyd-crawler/go.sum ./third_party/monkeyd-crawler/
|
|
RUN go mod download
|
|
|
|
COPY . .
|
|
|
|
# The deploy-notify commit SHA comes from Coolify's SOURCE_COMMIT runtime env,
|
|
# not from a build arg. Keep it out of the build so Docker cache survives across
|
|
# commits. The binary is built plain.
|
|
RUN CGO_ENABLED=0 GOOS=linux go build \
|
|
-ldflags="-s -w" \
|
|
-o /out/server \
|
|
./cmd/server
|
|
|
|
# Alpine rather than distroless/static, for one reason: /addsticker transcodes
|
|
# video and GIF sources to WEBM/VP9, which needs ffmpeg. Telegram accepts no
|
|
# other codec for a video sticker, Go's standard library has no VP9 encoder
|
|
# (golang.org/x/image/vp8 decodes only), and the binary is built CGO_ENABLED=0
|
|
# so a cgo encoder would not link either. ffmpeg is therefore a hard runtime
|
|
# dependency, and distroless/static has no way to carry it.
|
|
#
|
|
# ffmpeg comes from Alpine's own package rather than a third-party static-ffmpeg
|
|
# image, keeping the supply chain to bases already trusted by this build.
|
|
FROM alpine:3.22
|
|
# No fonts are installed here: the monkeyd module's PDF renderer falls back to a
|
|
# font compiled into the binary when the host has none.
|
|
RUN apk add --no-cache ffmpeg ca-certificates \
|
|
&& addgroup -g 65532 -S nonroot \
|
|
&& adduser -u 65532 -S -G nonroot nonroot
|
|
COPY --from=builder /out/server /server
|
|
USER nonroot:nonroot
|
|
EXPOSE 8080
|
|
ENTRYPOINT ["/server"]
|