Skip to content

Clear the DASH dir contents instead of rm -rf on the /opt/data mount#55

Merged
roddylindsay merged 1 commit into
EnvelopSound:masterfrom
mormegil6:volume-safe-data-wipe
Jul 23, 2026
Merged

Clear the DASH dir contents instead of rm -rf on the /opt/data mount#55
roddylindsay merged 1 commit into
EnvelopSound:masterfrom
mormegil6:volume-safe-data-wipe

Conversation

@mormegil6

@mormegil6 mormegil6 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What this fixes

nginx-transcoder/entrypoint.sh resets segment state on every start with rm -rf /opt/data (in both the SSL and no-SSL branches). In the normal deployment /opt/data is 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:

  • unnecessary - only the stale segment files need clearing, not the mount, and
  • risky - it targets whatever the host has bound at /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 -delete

This resets the DASH output exactly as before (an empty /opt/data/dash at startup) without rm -rf-ing the mount.

Note on CI

The red test check is unrelated to this change - the workflow's actions/cache@v2 is auto-rejected by GitHub, so test fails before it runs (lint still passes).

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.
Copilot AI review requested due to automatic review settings July 22, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/data with 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 && \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mormegil6 can you check this plz?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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: 0

busybox 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 && \
@roddylindsay
roddylindsay merged commit 389da2d into EnvelopSound:master Jul 23, 2026
2 of 4 checks passed
@mormegil6
mormegil6 deleted the volume-safe-data-wipe branch July 23, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants