Files
romm/.github/workflows/docker-pr.yml
Georges-Antoine Assi c413c066c6 refactor(docker): supervise the container with s6-overlay (#4019)
* refactor(docker): supervise the container with s6-overlay

The init script was a hand-rolled supervisor: PID files, /proc polling, a
5s watchdog loop and a trap-based shutdown. Its shutdown wait was unbounded,
so a process that refused to exit stranded PID 1 and left the container up
and serving nothing, which no restart policy can detect.

s6-rc replaces it with a declared service graph. Ordering and readiness
gates that were sequential bash become dependencies, and the failure modes
become configuration:

- timeout-kill bounds SIGTERM before SIGKILL, and flag-timeout-killpg
  escalates to the whole process group.
- S6_BEHAVIOUR_IF_STAGE2_FAILS=2 exits the container when a startup step
  fails, so the restart policy retries instead of the container wedging.
- valkey gets --shutdown-on-sigterm force, so it stops refusing to exit
  when the snapshot it writes on shutdown cannot be written.

A crashed service is now restarted on its own instead of taking the whole
container down. Its leftover children are swept first, because children
reparented from a hard-killed master keep holding its listening sockets and
would make every replacement fail to bind.

Optional services have no conditional mechanism in s6-rc, so they start,
check their environment variable, and take themselves down with s6-svc -O.

Running with a read-only root filesystem now needs /run mounted exec, since
s6 executes its generated stage scripts from there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): always start the RQ scheduler under s6

The s6 service carried over the four-flag ENABLE_SCHEDULED_* gate from the
init script, which #4033 has since removed on master. Since this branch
deletes that script, the fix would be lost on rebase.

Nothing else respects the condition: startup.py registers the netplay,
upload-tmp and zip-cache cleanups unconditionally, three more flags gate
periodic tasks absent from the list, and the watcher defers its rescans
through the scheduler. Any of those leaves jobs in the scheduler registry
with no process to run them, and a stuck delayed scan_platforms entry reads
to the concurrent scan guard as a scan already queued, refusing every
manual scan.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(docker): port master's init changes to the s6 services

Master reworked docker/init_scripts/init while this branch replaced it,
so carry those changes into the s6-rc services:

- Replace rq-scheduler with `rq cron` (romm-rq-cron) on tasks.cron_config.
- Add romm-rq-scan-worker (scans queue) and romm-rq-streaming-worker
  (streaming queue, down unless config.yml enables streaming).
- Run every worker with --with-scheduler and the RomMRedis connection
  class, passing the Redis URL through RQ_REDIS_URL so the password stays
  off the command line, and read REDIS_SSL as a boolean.
- Bring gunicorn's flags in line: --no-control-socket, a private-range
  FORWARDED_ALLOW_IPS default, 4 workers and a 65s keep-alive.
- Check the sync folder and SSH keys path in romm-init, and switch the
  features off through the container environment when they're unusable.
- Accept the backend's truthy values for the watcher flags.
- Point the serving-layer guard tests at the gunicorn run script and
  drop the PID-file tests, which guarded the bash watchdog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(docker): guard the s6-overlay service tree

Check that every service is in the user bundle, depends on something
that exists, and that every longrun has its finish sweep, kill timeout
and process-group flag. Also check that the dev entrypoint starts the
same RQ workers and cron scheduler as the image, since it keeps its own
launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(dev): pass the image's RQ flags in the dev entrypoint

The dev image's RQ cron scheduler and workers ran without the RomMRedis
connection class, and the workers without --results-ttl, so they kept
redis-py's maintenance notification probe and RQ's default result TTL.
The s6 guard test now compares each rq command's flags with the image's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(docker): address Greptile review on the s6 service tree

- Cut the s6 script comments to two lines, keeping the reason each
  helper exists.
- Compare the values of the dev entrypoint's RQ options with the
  image's, not only their names, allowing for the dev image's path,
  PID files and LOGLEVEL default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): check every s6 service stays up after boot

The heartbeat only proves gunicorn and nginx came up. Enable both watchers
and require each longrun in the s6 tree to report up for 15s straight, so a
crashing or restart-looping worker, cron, valkey or watcher fails the job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(docker): enable streaming so its worker is checked too

The streaming worker turns itself off when streaming.enabled is false in
config.yml, which the services check read as a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-24 08:29:06 -05:00

134 lines
5.0 KiB
YAML

name: Docker Image Check
# Releases and the nightly are the only other builds of docker/Dockerfile, so a
# change to what the image is built from gets built and booted here first.
on:
pull_request:
paths:
- "docker/**"
- "backend/**"
- "frontend/**"
- pyproject.toml
- uv.lock
- .python-version
- .github/workflows/docker-pr.yml
# A new push cancels a PR's superseded run; each master commit keeps its own.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
build-and-boot:
runs-on: ubuntu-24.04
timeout-minutes: 45
services:
mariadb:
image: mariadb:13.0.2
ports:
- 3306:3306
env:
MARIADB_USER: romm
MARIADB_PASSWORD: passwd
MARIADB_DATABASE: romm
MARIADB_ROOT_PASSWORD: passwd
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=5s --health-timeout=2s --health-retries=3 --health-start-period=30s
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
# The cache is public, so fork PRs read it too. Nothing is written back:
# layers built from PR content must not reach a release image.
- name: Build the full image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
file: docker/Dockerfile
context: .
platforms: linux/amd64
target: full-image
load: true
tags: romm:pr
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/romm-buildcache:release-amd64
# Host networking reaches the MariaDB service on localhost. The image
# generates its own auth key and runs its own valkey when none is set.
# The watchers and the streaming worker are off by default; turning them
# on means every longrun in the s6 tree is expected up.
- name: Start the container
run: |
mkdir -p "$RUNNER_TEMP/library" "$RUNNER_TEMP/config"
printf 'streaming:\n enabled: true\n' >"$RUNNER_TEMP/config/config.yml"
docker run -d --name romm --network host \
-e DB_HOST=127.0.0.1 \
-e DB_NAME=romm \
-e DB_USER=romm \
-e DB_PASSWD=passwd \
-e ENABLE_RESCAN_ON_FILESYSTEM_CHANGE=true \
-e ENABLE_SYNC_FOLDER_WATCHER=true \
-v "$RUNNER_TEMP/library:/romm/library" \
-v "$RUNNER_TEMP/config:/romm/config" \
romm:pr
# Startup runs the migrations first, so a green heartbeat also means the
# image migrated a fresh database.
- name: Wait for the API through nginx
run: |
for i in $(seq 1 120); do
if curl -sf http://127.0.0.1:8080/api/heartbeat >/dev/null; then
echo "API up after ${i}s"
exit 0
fi
if [[ "$(docker inspect -f '{{.State.Running}}' romm)" != "true" ]]; then
echo "::error::The container exited during startup"
exit 1
fi
sleep 1
done
echo "::error::The API did not answer within 120s"
exit 1
- name: Check the frontend is served
run: curl -sf http://127.0.0.1:8080/ | grep -q '<div id="app"'
# s6 restarts a crashed service after a second, so a single "up" reading
# can hide a crash loop. Each one has to stay up for 15s straight.
- name: Check every supervised service stays up
run: |
mapfile -t services < <(grep -lx longrun docker/s6-overlay/s6-rc.d/*/type | xargs -n1 dirname | xargs -n1 basename)
echo "Longruns: ${services[*]}"
for i in $(seq 1 90); do
pending=()
for s in "${services[@]}"; do
read -r up secs < <(docker exec romm /command/s6-svstat -o up,updownfor "/run/service/$s" || true)
if [[ "$up" != "true" || "${secs:-0}" -lt 15 ]]; then
pending+=("$s")
fi
done
if ((${#pending[@]} == 0)); then
echo "All ${#services[@]} services up for 15s after ${i}s"
exit 0
fi
if [[ "$(docker inspect -f '{{.State.Running}}' romm)" != "true" ]]; then
echo "::error::The container exited"
exit 1
fi
sleep 1
done
for s in "${pending[@]}"; do
echo "$s: $(docker exec romm /command/s6-svstat "/run/service/$s" 2>&1)"
done
echo "::error::Services not steadily up within 90s: ${pending[*]}"
exit 1
- name: Dump container logs
if: failure()
run: docker logs romm 2>&1 | tail -200 || true