Changeset 5861849 in Klonkt


Ignore:
Timestamp:
08/07/2026 08:42:04 AM (5 weeks ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
4f322bc
Parents:
7aa3140
git-author:
Robin <roboburr@…> (08/07/2026 08:41:51 AM)
git-committer:
roboburr <roboburr@…> (08/07/2026 08:42:04 AM)
Message:

De updater diept de checkout eenmalig uit, zodat terugrollen kan

Gevonden bij het doorlezen van /usr/local/bin/klonkt-update op een productiehost
met zeven instances. Terugrollen was daar niet moeilijk maar onmogelijk:

git fetch --depth 1 origin main
git checkout -qf -B main FETCH_HEAD

--depth 1 haalt alleen de nieuwste commit op en checkout -f gooit de vorige boom
weg. Na een update stond de vorige versie NERGENS meer op die machine. Een
slechte release neemt alle instances tegelijk mee, en de enige uitweg was opnieuw
van GitHub halen -- als GitHub op dat moment bereikbaar is en als je weet welke
commit je wilt.

De updater diept nu EENMALIG uit (fetch --unshallow) als de checkout ondiep is, en
haalt daarna gewoon op. Dat koopt de geschiedenis terug; elke volgende fetch houdt
hem. De check gaat via rev-parse --is-shallow-repository, want --unshallow op een
complete repo is een fout, geen no-op.

Daarnaast drukt hij na een geslaagde update de vorige commit af mét het commando
om terug te gaan. Geschiedenis alleen is geen terugrol; om drie uur 's nachts heb
je ook de regel nodig.

Getest op een echte ondiepe kloon (file:// transport, want git negeert --depth bij
een lokaal pad): 1 commit -> deepen -> 1045 commits -> checkout van HEAD~3 werkt.
Tweede run slaat het deepenen over. Het gegenereerde script is met bash -n
gecontroleerd.

install.sh blijft ondiep klonen: dat houdt een verse installatie snel, en de
eerste klonkt-update diept alsnog uit. Voor de installatie zelf valt er toch
niets terug te rollen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/klonkt-refresh-updater.sh

    r7aa3140 r5861849  
    3030D="${KLONKT_DIR}"
    3131B=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD 2>/dev/null || true)
    32 runuser -u ${KLONKT_USER} -- git -C "\$D" fetch --depth 1 origin ${BRANCH}
     32# Deepen a shallow checkout ONCE. \`fetch --depth 1\` keeps only the newest commit
     33# and \`checkout -f\` throws away the tree that was there, so after an update the
     34# previous version existed nowhere on the machine: a bad release could not be
     35# undone without the network, and only if you knew which commit to ask for.
     36# One deepening buys back the history; every later fetch keeps it.
     37if [ "\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse --is-shallow-repository 2>/dev/null)" = "true" ]; then
     38  echo "deepening the checkout once so updates can be rolled back..."
     39  runuser -u ${KLONKT_USER} -- git -C "\$D" fetch --unshallow origin ${BRANCH} || true
     40fi
     41runuser -u ${KLONKT_USER} -- git -C "\$D" fetch origin ${BRANCH}
    3342runuser -u ${KLONKT_USER} -- git -C "\$D" checkout -qf -B ${BRANCH} FETCH_HEAD
    3443A=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD)
     
    5463else
    5564  echo "Klonkt updated (\$A) + restarted \$N instance(s)."
     65fi
     66# History alone is not a rollback; at three in the morning you also need the
     67# command. Print it while the previous commit is still known.
     68if [ -n "\$B" ]; then
     69  echo
     70  echo "Previous version: \$B"
     71  echo "To go back:"
     72  echo "  runuser -u ${KLONKT_USER} -- git -C \$D checkout -qf -B ${BRANCH} \$B"
     73  echo "  then restart the instances (systemctl restart 'klonkt@*')"
    5674fi
    5775EOF
Note: See TracChangeset for help on using the changeset viewer.