Clear the DASH dir contents instead of rm -rf on the /opt/data mount#55
Conversation
The entrypoint reset segment state with `rm -rf /opt/data`, which targets the mount point itself. When /opt/data is a mounted volume - the normal deployment, where the DASH output is a named or bind volume - recursively deleting the mount's contents on every start is both unnecessary and risky: it removes whatever the host bound there rather than just the stale segments. Clear only the segment directory contents (mkdir -p, then find -mindepth 1 -delete), which resets the DASH output without touching the mount.
There was a problem hiding this comment.
Pull request overview
This PR updates the nginx-transcoder container entrypoint to avoid recursively deleting the /opt/data mount point at startup, and instead aims to clear only the DASH segment output directory contents.
Changes:
- Replaces
rm -rf /opt/datawith a “clear contents of/opt/data/dash” approach in both SSL and non-SSL startup paths. - Keeps the mount point intact while still resetting segment output state on container start.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| rm -rf /opt/data && mkdir -p /opt/data/dash && chown nginx /opt/data/dash && chmod 777 /opt/data/dash && mkdir -p /www && \ | ||
| mkdir -p /opt/data/dash && find /opt/data/dash -mindepth 1 -delete && chown nginx /opt/data/dash && chmod 777 /opt/data/dash && mkdir -p /www && \ |
There was a problem hiding this comment.
@roddylindsay checked - the review comment is incorrect. Alpine 3.11's BusyBox find does support both -mindepth and -delete, so the entrypoint starts fine.
Verified against the exact runtime base image in this repo's Dockerfile (FROM alpine:3.11):
$ docker run --rm alpine:3.11 sh -c '
cat /etc/alpine-release
busybox | head -1
mkdir -p /opt/data/dash/sub
touch /opt/data/dash/a.m4s /opt/data/dash/sub/b.webm
find /opt/data/dash -mindepth 1 -delete; echo "exit=$?"
echo "remaining: $(ls -A /opt/data/dash | wc -l)"'
3.11.13
BusyBox v1.31.1 () multi-call binary.
exit=0
remaining: 0busybox find --help on that image lists -mindepth, -maxdepth, -delete and -name. BusyBox has had FEATURE_FIND_DELETE long before 1.31, and Alpine enables it.
Worth noting the nested sub/b.webm in that test: it is removed along with its parent directory, which confirms -delete is doing the depth-first removal you would want here rather than failing on non-empty directories.
The mount point itself survives, which is the whole point of the change - rm -rf /opt/data on a bind mount or named volume either fails or blows away the mount's contents from underneath the host, whereas this resets only the segment output state.
Happy to swap in a rm -rf /opt/data/dash/* glob instead if you would rather not depend on find semantics at all, but it needs .[!.]* too to catch dotfiles, and it does not fail cleanly on an empty directory - so find reads better here.
One thing you may want regardless: as written the find sits inside an && chain, so any future failure would take the container down at startup. If you would prefer it to be non-fatal:
mkdir -p /opt/data/dash && { find /opt/data/dash -mindepth 1 -delete || true; } && chown nginx /opt/data/dash && ...Your call - on Alpine 3.11 it does not fail, so this is just insurance against the base image changing later.
| else | ||
| echo "Running Earshot without SSL (connections will be insecure)" | ||
| rm -rf /opt/data && mkdir -p /opt/data/dash && chown nginx /opt/data/dash && chmod 777 /opt/data/dash && mkdir -p /www && \ | ||
| mkdir -p /opt/data/dash && find /opt/data/dash -mindepth 1 -delete && chown nginx /opt/data/dash && chmod 777 /opt/data/dash && mkdir -p /www && \ |
What this fixes
nginx-transcoder/entrypoint.shresets segment state on every start withrm -rf /opt/data(in both the SSL and no-SSL branches). In the normal deployment/opt/datais the mount point for the DASH output volume (a named or bind volume), so this recursively deletes the contents of a mounted volume on each container start. That is:/opt/data, not just the segment output.Fix
Clear only the segment directory contents, leaving the mount point intact:
mkdir -p /opt/data/dash && find /opt/data/dash -mindepth 1 -deleteThis resets the DASH output exactly as before (an empty
/opt/data/dashat startup) withoutrm -rf-ing the mount.Note on CI
The red
testcheck is unrelated to this change - the workflow'sactions/cache@v2is auto-rejected by GitHub, sotestfails before it runs (lintstill passes).