Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ on:
branches: [main]
workflow_dispatch:

# Read-only by default for every job; the jobs that publish an image ask for
# `packages: write` themselves. A job that neither declares nor needs more gets no
# more, so a compromised step cannot push to the repository with the workflow token.
permissions:
contents: read

# Every action below is pinned to a commit, with the release it was when pinned in the
# comment. A tag like `v5` can be moved to point at anything, including code the
# publisher did not write; a commit cannot. To bump one: pick the release, resolve it
# with `gh api repos/<owner>/<repo>/git/ref/tags/<tag> --jq .object.sha` (for an
# annotated tag, `gh api repos/<owner>/<repo>/git/tags/<sha> --jq .object.sha` gives
# the commit), and update the comment with it.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
Expand All @@ -16,8 +28,8 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 22
cache: npm
Expand Down Expand Up @@ -48,21 +60,21 @@ jobs:
digest-amd64: ${{ steps.export.outputs.digest-amd64 }}
digest-arm64: ${{ steps.export.outputs.digest-arm64 }}
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: ${{ matrix.platform }}
Expand All @@ -85,7 +97,7 @@ jobs:
mkdir -p /tmp/digests
echo -n "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.suffix }}"

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: github.event_name != 'pull_request'
with:
name: digest-${{ matrix.suffix }}
Expand All @@ -102,24 +114,24 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/download-artifact@v4
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: /tmp/digests
pattern: digest-*
merge-multiple: true

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

- name: Log in to GHCR
uses: docker/login-action@v3
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Work out the tags
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
Expand Down Expand Up @@ -174,27 +186,27 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0

# The CUDA toolchain and build cache need more room than a runner has free.
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
df -h /

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Work out the tags
id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
Expand All @@ -207,7 +219,7 @@ jobs:
type=sha,format=short

- name: Build and push
uses: docker/build-push-action@v6
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
file: Dockerfile.cuda
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ changes what your listeners see, it says so.
without bound; the advert tables' rule and restore columns are indexed; a few statements
the scanner runs for every file are prepared once.

### Changed — a lighter boot, a smaller image, and nothing taken on trust

- **A network share is no longer checked twice over.** When live file detection does not
work on a volume — normal for SMB and NFS — SelfPod polls the share instead, and it was
polling every minute while the scheduled rescan also went through every file at the
rescan interval: two full sweeps of the one mount where every look at a file is a round
trip. The poll now runs at the rescan interval, which is what the notice on the
dashboard had been saying all along, and the container log says so when polling starts.
- **The container starts quicker.** The image library is loaded the first time a cover or
an episode's artwork is handled, and the QR encoder the first time a show page is drawn,
rather than before the first page can be served — whole seconds on a small NAS. The
permissions on SelfPod's own code used to be rewritten file by file on every start,
4,500 files; they are now checked and left alone when already right, and the image
ships them right for the default `PUID`/`PGID`.
- **The image is 20 MB smaller**, by leaving out the SQLite source and the seven other
platforms' binaries that the database library ships with and never reads. An image built
for one box can also leave out the speech model it will not use (`WHISPER_MODELS` in the
README's *Building your own image*); the published image still carries both.
- **`TRUST_PROXY`** says whose `X-Forwarded-*` headers to believe. The default is every
connection, as before; set it to your tunnel's or reverse proxy's address when anything
else can reach port 8080 directly, and a LAN client can no longer claim to have arrived
over HTTPS from somewhere else. A value with a typo in it trusts nobody and says so in
the log, rather than quietly going back to trusting everyone.
- **Everything the build fetches is pinned to exactly what was reviewed:** the base images
by digest, whisper.cpp by commit rather than a tag that could be moved, and every GitHub
Action by commit. The build workflow's token is read-only except where it publishes.

## 1.9.1 — 2026-09-16

### Fixed
Expand Down
65 changes: 53 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
# arm64, so this normally installs without compiling anything; python3/make/g++
# are kept as insurance against a missing prebuild.
# ---------------------------------------------------------------------------
FROM node:22-alpine AS build
# Pinned by digest (the multi-arch index, so the same line serves amd64 and arm64) and
# not just by tag, so a rebuild gets the base image that was reviewed and not whatever
# the tag points at that day. To bump: `docker buildx imagetools inspect node:22-alpine
# --format '{{.Manifest.Digest}}'`, then paste the digest here and in the runtime stage.
FROM node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402 AS build

# cmake and git are for whisper.cpp, below; the rest is insurance for native modules.
RUN apk add --no-cache python3 make g++ cmake git
Expand All @@ -20,6 +24,12 @@ COPY package.json package-lock.json ./
# platform binaries are optional deps, and dropping them breaks it at runtime.
RUN npm ci --omit=dev

# Drops the 24 MB of better-sqlite3 that this platform never reads (the SQLite source
# and the seven other platforms' binaries) — before the check below, so the check also
# proves the module loads with only what is kept. The script says what it removed.
COPY docker/trim-node-modules.mjs ./docker/
RUN node docker/trim-node-modules.mjs node_modules

# Fail the build here rather than at container start if a native module is unusable.
RUN node -e "require('better-sqlite3'); require('sharp'); console.log('native modules OK')"

Expand All @@ -28,7 +38,7 @@ COPY src ./src
# ---------------------------------------------------------------------------
# whisper.cpp — the speech recogniser behind spoken-advert detection (spec §19.6).
#
# Built from a pinned tag rather than installed, because there is no musl build to
# Built from a pinned commit rather than installed, because there is no musl build to
# install and because what goes into the image should be what was reviewed. MIT.
#
# Two builds on amd64, chosen at boot by src/lib/cpu-features.js: `-v3` uses AVX2
Expand All @@ -42,14 +52,25 @@ COPY src ./src
# The model is fetched here, checked against a pinned digest, and never fetched
# again: the running container makes no request this feature adds.
# ---------------------------------------------------------------------------
ARG WHISPER_CPP_TAG=b4938
# The commit tag b4938 pointed at when it was reviewed. A tag can be moved; a commit
# cannot. To bump: pick a release tag, then
# `gh api repos/ggml-org/whisper.cpp/git/ref/tags/<tag> --jq .object.sha` (if that
# object is itself a tag, `gh api repos/ggml-org/whisper.cpp/git/tags/<sha>` gives the
# commit) and paste it here and in Dockerfile.cuda.
ARG WHISPER_CPP_COMMIT=371b5a7561823ab2bb32142d2751e35e7534727b
# Two models. `base` is the default: 60 MB, quick, good enough for English. `small` is
# 190 MB and about three times the work, and markedly better in French — set
# WHISPER_MODEL=small on the container to use it. Both are proved at build time.
# WHISPER_MODEL=small on the container to use it. Every model baked in is proved at
# build time; WHISPER_MODELS chooses which (both, unless an image is built for one
# box that only ever uses one of them — `--build-arg WHISPER_MODELS=base` saves 190 MB).
ARG WHISPER_MODELS=base,small
ARG WHISPER_BASE_SHA256=422f1ae452ade6f30a004d7e5c6a43195e4433bc370bf23fac9cc591f01a8898
ARG WHISPER_SMALL_SHA256=ae85e4a935d7a567bd102fe55afc16bb595bdb618e11b2fc7591bc08120411bb

RUN git clone --depth 1 --branch "$WHISPER_CPP_TAG" https://github.com/ggml-org/whisper.cpp /tmp/whisper.cpp
# A shallow fetch of one commit; `git clone --branch` only takes names.
RUN git init -q /tmp/whisper.cpp \
&& git -C /tmp/whisper.cpp fetch -q --depth 1 https://github.com/ggml-org/whisper.cpp "$WHISPER_CPP_COMMIT" \
&& git -C /tmp/whisper.cpp checkout -q FETCH_HEAD

ENV WHISPER_CMAKE="-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DGGML_STATIC=ON -DGGML_NATIVE=OFF -DGGML_OPENMP=OFF \
-DWHISPER_BUILD_EXAMPLES=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF -DWHISPER_SDL2=OFF -DWHISPER_CURL=OFF"
Expand All @@ -71,15 +92,26 @@ RUN set -e; mkdir -p /app/whisper; \
esac; \
rm -rf /tmp/wb /tmp/wb2 /tmp/wb3 /tmp/whisper.cpp

RUN wget -qO /app/whisper/ggml-base-q5_1.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base-q5_1.bin \
&& echo "$WHISPER_BASE_SHA256 /app/whisper/ggml-base-q5_1.bin" | sha256sum -c - \
&& wget -qO /app/whisper/ggml-small-q5_1.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small-q5_1.bin \
&& echo "$WHISPER_SMALL_SHA256 /app/whisper/ggml-small-q5_1.bin" | sha256sum -c -
# Each model named in WHISPER_MODELS is fetched and checked against its pinned digest;
# a name this file has no digest for fails the build rather than fetching something
# unchecked, and an empty list fails it too.
RUN set -e; \
for model in $(printf '%s' "$WHISPER_MODELS" | tr ',' ' '); do \
case "$model" in \
base) sum="$WHISPER_BASE_SHA256";; \
small) sum="$WHISPER_SMALL_SHA256";; \
*) echo "WHISPER_MODELS names \"$model\", which this Dockerfile has no digest for (it knows base and small)." >&2; exit 1;; \
esac; \
wget -qO "/app/whisper/ggml-$model-q5_1.bin" "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-$model-q5_1.bin" \
&& echo "$sum /app/whisper/ggml-$model-q5_1.bin" | sha256sum -c -; \
done; \
ls /app/whisper/ggml-*.bin >/dev/null 2>&1 || { echo "WHISPER_MODELS=\"$WHISPER_MODELS\" baked no model into the image." >&2; exit 1; }

# ---------------------------------------------------------------------------
# Runtime stage
# ---------------------------------------------------------------------------
FROM node:22-alpine
# The same digest as the build stage; bump both together (see the top of the file).
FROM node:22-alpine@sha256:0a7108bf6c7bf5de370ffb1a3ed6be93d405b43ff159f681a8d18c0e2bc2e402

# su-exec drops privileges without leaving a process between PID 1 and node;
# shadow provides usermod/groupmod for the PUID/PGID pattern; tzdata makes the
Expand All @@ -95,7 +127,9 @@ RUN deluser --remove-home node \

WORKDIR /app

COPY --from=build /app/node_modules ./node_modules
# Owned by the default PUID/PGID from the start, so a container run with the defaults
# never has to chown the 4,500 files in here at boot (docker/entrypoint.sh).
COPY --from=build --chown=1000:1000 /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json
COPY --from=build /app/whisper ./whisper
COPY src ./src
Expand All @@ -108,6 +142,13 @@ COPY scripts ./scripts
# A broken build fails here, not on the NAS after the update has been applied.
RUN node docker/whisper-smoke.mjs

# The model the container uses unless WHISPER_MODEL says otherwise. It has to be one of
# the models baked in: an image whose default model is missing would start, say the
# recogniser is unavailable, and publish every episode unheard. So the build refuses.
ARG WHISPER_DEFAULT_MODEL=base
RUN test -f "/app/whisper/ggml-${WHISPER_DEFAULT_MODEL}-q5_1.bin" \
|| { echo "WHISPER_DEFAULT_MODEL=${WHISPER_DEFAULT_MODEL} is not among the models baked in ($(ls /app/whisper | grep '^ggml-' | tr '\n' ' ')). Add it to WHISPER_MODELS, or set WHISPER_DEFAULT_MODEL to one of them." >&2; exit 1; }

RUN chmod +x docker/entrypoint.sh \
&& mkdir -p /data \
&& chown selfpod:selfpod /app
Expand All @@ -117,7 +158,7 @@ ENV NODE_ENV=production \
DATA_DIR=/data \
PUID=1000 \
PGID=1000 \
WHISPER_MODEL=base
WHISPER_MODEL=${WHISPER_DEFAULT_MODEL}

EXPOSE 8080
VOLUME ["/data"]
Expand Down
Loading