Replace yt-cipher with a pinned Bun fork build

This commit is contained in:
Ziad Arafat committed 2026-11-23 11:30:28 -07:00
1 parent 51391d7c09
commit 020b66a53c
7 files changed
+77 -13

No files matched your search

+39 -6
View File
@@ -2,8 +2,7 @@
A Discord bot built on [Red-DiscordBot](https://github.com/Cog-Creators/Red-DiscordBot) 3.5, deployed as
rootless podman containers with quadlets. Music (Audio, AudioTrivia) runs on its own Lavalink, which updates
itself daily, together with its YouTube plugin and yt-cipher, so that playback keeps working when YouTube
changes.
itself and its YouTube plugin daily. Signature deciphering uses a pinned Bun cipher build.
## What runs
@@ -15,18 +14,52 @@ graph LR
lava -->|signatures| cipher[dogebot-yt-cipher]
lava --> yt[YouTube / SoundCloud / ...]
timer[dogebot-update.timer] -.->|build, smoke test, swap| lava
timer -.->|podman auto-update| cipher
operator -.->|reviewed source build| cipher
```
| Container | Image | Updates |
|---|---|---|
| `dogebot-red` | `localhost/dogebot-red:latest`, built from `containers/red` | rebuild after changing `uv.lock` |
| `dogebot-lavalink` | `localhost/dogebot-lavalink:current`, built from `containers/lavalink` | daily, by `dogebot-update` (below) |
| `dogebot-yt-cipher` | `ghcr.io/kikkia/yt-cipher:master` | daily, `podman auto-update` with rollback |
| `dogebot-yt-cipher` | `localhost/dogebot-yt-cipher:bun-912033c`, AlmaLinux10 + Bun | reviewed source rebuild; pinned upstream commit |
| `dogebot-postgres` | `docker.io/library/postgres:16-alpine` | daily, `podman auto-update` with rollback |
All four share the `dogebot` network. Only Lavalink publishes a port, on `127.0.0.1:2333`, for the smoke test.
## Bun cipher deployment
The cipher is built from ToddyTheNoobDud/yt-cipher-bun commit
`912033c880d4ef219261381486ee0ba586d6b7a9`, including its pinned EJS submodule.
Its published GHCR image was not anonymously accessible during migration, so
`containers/yt-cipher/Containerfile` builds the source with pinned Bun and
AlmaLinux10 base-image digests. No compiler or Bun runtime is installed on the
hypervisor. Build on the Yveltal VM:
```sh
podman build -t localhost/dogebot-yt-cipher:bun-912033c -f containers/yt-cipher/Containerfile .
```
The internal name/port remain `dogebot-yt-cipher:8001` and the existing Podman
secret `dogebot-yt-cipher-token` supplies `API_TOKEN`. Lavalink's remoteCipher
URL/password settings remain compatible. No host port is published. The runtime
is UID/GID1000 with keep-id, one worker, one CPU and512MiB maximum memory. Public
player scripts persist in the new named volume `dogebot-yt-cipher-bun-cache`.
The old Deno-specific `OVERRIDE_PLAYER_VARIANT=IAS` variable is not used by this
fork and was removed.
This local image is deliberately **not registry auto-updated**. To upgrade,
review a new upstream commit, change the source ref/image tag, build it, test an
isolated candidate, then update the Quadlet. Keep the old image/Quadlet for
rollback. The daily Lavalink/YouTube plugin and Postgres update paths remain.
The pinned source still resolves the upstream package ranges at build time;
the deployed image digest identifies the exact built artifact.
Upstream authentication rejects a missing/incorrect token with a JSON error
body and HTTP200, so status200 alone is not a valid health/authentication check.
An authenticated `/health` response must contain `status=ok` and
`service=yt-cipher-bun`. Validate actual player STS/signature processing and
Lavalink playback when upgrading.
## Cogs
Additional bot owners can be configured on the deployment host in
@@ -66,7 +99,7 @@ YouTube playback depends on three moving parts:
[Cog-Creators/Lavalink-Jars](https://github.com/Cog-Creators/Lavalink-Jars), not upstream Lavalink 4.
- The [youtube-source](https://github.com/lavalink-devs/youtube-source) plugin. It signs in to YouTube with
an OAuth refresh token and uses the `TV` and `WEB` clients.
- [yt-cipher](https://github.com/kikkia/yt-cipher), which deciphers YouTube's stream signatures for the plugin.
- [yt-cipher-bun](https://github.com/ToddyTheNoobDud/yt-cipher-bun), which deciphers YouTube's stream signatures using Bun.
`dogebot-update` (daily, from `dogebot-update.timer`):
@@ -79,7 +112,7 @@ YouTube playback depends on three moving parts:
Lavalink restarts. If the restarted service fails the same check, it rolls back.
5. If the version already running still passes, it stops there. If it fails, for example because YouTube
broke the release, it goes on to try the snapshot.
6. Runs `podman auto-update` for yt-cipher and Postgres.
6. Runs `podman auto-update` for Postgres. The Bun cipher uses the pinned source build described below.
The versions running now are in `~/.local/state/dogebot/lavalink.json`. To check music by hand:
+21
View File
@@ -0,0 +1,21 @@
# Bun runtime + source pinned independently; build this on the Yveltal VM.
FROM docker.io/oven/bun@sha256:3aa040e5445efa09d75bb428a64ba50db13e2b3ac9b6b0c7f145615f62b2ee18 AS bun
FROM quay.io/almalinuxorg/almalinux@sha256:498b0b31dab82c3be22ac50efb8bf865adce85576495da20de8cedc48b29eec6
RUN dnf -y install git ca-certificates libstdc++ && dnf clean all
COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun
ARG CIPHER_REF=912033c880d4ef219261381486ee0ba586d6b7a9
RUN git clone --no-checkout https://github.com/ToddyTheNoobDud/yt-cipher-bun.git /app \
&& cd /app && git checkout "$CIPHER_REF" \
&& git submodule update --init --recursive \
&& test -f ejs/src/yt/solver/main.ts \
&& rm -rf .git ejs/.git
WORKDIR /app
RUN bun install --production --ignore-scripts \
&& mkdir -p player_cache && touch player_cache/.keep \
&& chown -R 1000:1000 /app
LABEL org.opencontainers.image.source="https://github.com/ToddyTheNoobDud/yt-cipher-bun"
LABEL org.opencontainers.image.revision="$CIPHER_REF"
ENV PORT=8001 MAX_THREADS=1
USER 1000:1000
EXPOSE 8001
CMD ["bun", "run", "server.ts"]
+3
View File
@@ -52,6 +52,9 @@ secret dogebot-yt-cipher-token
cd "$repo"
podman build -t localhost/dogebot-red:latest -f containers/red/Containerfile .
if ! podman image exists localhost/dogebot-yt-cipher:bun-912033c; then
podman build -t localhost/dogebot-yt-cipher:bun-912033c -f containers/yt-cipher/Containerfile .
fi
if ! podman image exists localhost/dogebot-lavalink:current; then
mise exec -- uv run --frozen dogebot-update --build-only
fi
+10 -4
View File
@@ -3,15 +3,21 @@ Description=dogebot: yt-cipher (YouTube signature deciphering for Lavalink)
[Container]
ContainerName=dogebot-yt-cipher
# Follows upstream: podman auto-update pulls new builds and rolls back if it fails to start
Image=ghcr.io/ToddyTheNoobDud/yt-cipher-bun:master
AutoUpdate=registry
# Pinned source build of ToddyTheNoobDud/yt-cipher-bun; see containers/yt-cipher.
Image=localhost/dogebot-yt-cipher:bun-912033c
Pull=never
Network=dogebot.network
Environment=OVERRIDE_PLAYER_VARIANT=IAS
UserNS=keep-id
User=1000:1000
Environment=PORT=8001
Environment=MAX_THREADS=1
Volume=dogebot-yt-cipher-bun-cache:/app/player_cache
Secret=dogebot-yt-cipher-token,type=env,target=API_TOKEN
[Service]
Restart=always
MemoryMax=512M
CPUQuota=100%
[Install]
WantedBy=default.target
+2 -2
View File
@@ -1,5 +1,5 @@
[Unit]
Description=dogebot: update Lavalink, its YouTube plugin and yt-cipher
Description=dogebot: update Lavalink and its YouTube plugin
After=network-online.target dogebot-lavalink.service
[Service]
@@ -11,7 +11,7 @@ WorkingDirectory=%h/src/dogebot
Environment=HTTPS_PROXY=http://10.77.0.1:3128
# Lavalink + youtube-plugin: build, smoke test, swap in (rolls back on failure)
ExecStart=%h/.local/bin/mise exec -- uv run --frozen dogebot-update
# yt-cipher and Postgres follow their registry tags, with rollback
# Postgres follows its registry tag. Cipher is a reviewed pinned source build.
ExecStartPost=/usr/bin/podman auto-update
# Exit code 2 means no new build passed, so the running one was kept
SuccessExitStatus=2
+1 -1
View File
@@ -1,5 +1,5 @@
[Unit]
Description=dogebot: daily Lavalink/yt-cipher update
Description=dogebot: daily Lavalink/YouTube plugin update
[Timer]
OnCalendar=*-*-* 05:30:00
+1
View File
@@ -34,6 +34,7 @@ depends = ["lint", "typecheck", "test"]
description = "Build the Red and Lavalink images with podman"
run = """
podman build -t localhost/dogebot-red:latest -f containers/red/Containerfile .
podman build -t localhost/dogebot-yt-cipher:bun-912033c -f containers/yt-cipher/Containerfile .
uv run dogebot-update --build-only
"""