From 246fb4494c7b5d87e5577e45925d22f42f9fb5ce Mon Sep 17 00:00:00 2001 From: casjay Date: Sat, 3 Oct 2026 20:12:40 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Never=20overwrite=20existing=20c?= =?UTF-8?q?onfig=20when=20seeding=20/config=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without the .initialized marker, startup copied the baked template over existing files in /config, resetting app.ini and regenerating secrets. Seeding now only adds files that are missing. - rootfs/usr/local/etc/docker/init.d/08-gitea.sh: seed copy uses cp -Rn instead of cp -Rf - rootfs/usr/local/etc/docker/init.d/05-dockerd.sh: same change, protects a user-edited daemon.json - rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh: same change, protects user-edited runner config - TODO.AI.md: record the bug, the verification, and the upstream template follow-up Claude-Session: https://claude.ai/code/session_01Kae22tmhzhmfHyqc34PZbx --- TODO.AI.md | 11 +++++++++++ rootfs/usr/local/etc/docker/init.d/05-dockerd.sh | 2 +- rootfs/usr/local/etc/docker/init.d/08-gitea.sh | 4 ++-- rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/TODO.AI.md b/TODO.AI.md index b3ee46e..86f467b 100644 --- a/TODO.AI.md +++ b/TODO.AI.md @@ -7,6 +7,17 @@ and the container exits 1 (empty days value passed to `openssl req -days`). The file is generated, so the fix belongs in the upstream gen-dockerfile template, then regenerate. +## Fixed — startup overwrote user config when `.initialized` marker was missing (init.d seed copy) + +- `__run_precopy` in `08-gitea.sh`, `05-dockerd.sh` and `zz-act_runner.sh` did + `cp -Rf "$ETC_DIR/." "$CONF_DIR/"` whenever `$CONF_DIR/.initialized` was absent (since commit + `42d0439`), replacing an existing `app.ini` with the template: custom settings lost and + SECRET_KEY/INTERNAL_TOKEN/LFS_JWT_SECRET regenerated. Now `cp -Rn` (fills missing files, never + overwrites). Verified with a real 428-line `app.ini` and no marker: all lines and all four secrets + preserved; before the fix the same test changed SECRET_KEY and INTERNAL_TOKEN. +- The same `__run_precopy` block is generated: the upstream start-service template needs the same + `cp -Rn` change or the next regeneration will bring the bug back. + ## Fixed — Gitea retention/cleanup defaults (app.ini, 08-gitea.sh) - Template: `[actions]` artifacts 30d, logs 90d, runs 180d; enabled `cron.gc_lfs` (daily), diff --git a/rootfs/usr/local/etc/docker/init.d/05-dockerd.sh b/rootfs/usr/local/etc/docker/init.d/05-dockerd.sh index b32c3ba..051b39c 100755 --- a/rootfs/usr/local/etc/docker/init.d/05-dockerd.sh +++ b/rootfs/usr/local/etc/docker/init.d/05-dockerd.sh @@ -279,7 +279,7 @@ __run_precopy() { if [ -d "$ETC_DIR" ] && ! [ -L "$ETC_DIR" ]; then if [ ! -f "$CONF_DIR/.initialized" ]; then mkdir -p "$CONF_DIR" - cp -Rf "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true + cp -Rn "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true fi rm -Rf "$ETC_DIR" ln -sf "$CONF_DIR" "$ETC_DIR" diff --git a/rootfs/usr/local/etc/docker/init.d/08-gitea.sh b/rootfs/usr/local/etc/docker/init.d/08-gitea.sh index 29b4287..432836b 100755 --- a/rootfs/usr/local/etc/docker/init.d/08-gitea.sh +++ b/rootfs/usr/local/etc/docker/init.d/08-gitea.sh @@ -345,7 +345,7 @@ __run_precopy() { # during container startup, after the entrypoint's initial copy. Applying it here # (in the init.d phase) ensures it takes effect after Docker finishes network setup. [ -f "/usr/local/etc/resolv.conf" ] && cp -f "/usr/local/etc/resolv.conf" "/etc/resolv.conf" 2>/dev/null || true - # Seed /config/$SERVICE_NAME from the baked /etc copy on first initialisation only. + # Seed /config/$SERVICE_NAME from the baked /etc copy on first initialisation only; cp -n never overwrites existing user files. # The marker file $CONF_DIR/.initialized is written after substitution completes; # delete it to force a re-seed (e.g. after intentional config reset). # Then replace the /etc/$SERVICE_NAME directory with a symlink to /config/$SERVICE_NAME @@ -353,7 +353,7 @@ __run_precopy() { if [ -d "$ETC_DIR" ] && ! [ -L "$ETC_DIR" ]; then if [ ! -f "$CONF_DIR/.initialized" ]; then mkdir -p "$CONF_DIR" - cp -Rf "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true + cp -Rn "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true fi rm -Rf "$ETC_DIR" ln -sf "$CONF_DIR" "$ETC_DIR" diff --git a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh index 0f8b2e4..ce04748 100755 --- a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh +++ b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh @@ -379,7 +379,7 @@ __run_precopy() { if [ -d "$ETC_DIR" ] && ! [ -L "$ETC_DIR" ]; then if [ ! -f "$CONF_DIR/.initialized" ]; then mkdir -p "$CONF_DIR" - cp -Rf "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true + cp -Rn "$ETC_DIR/." "$CONF_DIR/" 2>/dev/null || true fi rm -Rf "$ETC_DIR" ln -sf "$CONF_DIR" "$ETC_DIR"