Skip to content

Scripts: add a stack update script - #404

Closed
jackspiering wants to merge 7 commits into
mainfrom
scripts/update-stack
Closed

jackspiering wants to merge 7 commits into
mainfrom
scripts/update-stack

Conversation

@jackspiering

@jackspiering jackspiering commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds scripts/update-stack.sh. It compares a stack folder that you copied out of the clone ("Run the stack from a copy") with the latest version of the service, and updates compose.yaml and .env without losing your changes. It targets bash and the GNU tools on Linux.

  • Downloads the GitHub archive of main (about 350 KB) with curl or wget, once per run. It needs no clone, and an existing clone is not read or changed.
  • Only compose.yaml and .env are compared and updated. ts/, the data folders, the README, and other files stay as they are.
  • --apply saves the upstream compose.yaml and .env in .scaletail/. The next run merges three versions with git merge-file: your file, that saved copy, and the new upstream file. Each file that changes is first copied to .scaletail/backup-<time>/.
  • A conflict writes markers into the file (after the backup), like git. The next run refuses while markers remain, and docker compose refuses the file too, so nothing runs half-merged.
  • First run, without a saved copy: .env gets the variables it lacks, with their comments. compose.yaml is replaced by the upstream version. The script says whether settings differ or only comments, keeps your old file in the backup, and prints the diff command that compares the two.
  • Never prints the contents of compose.yaml or .env, only variable names. Old stacks set the auth key in compose.yaml, so a diff could show it.
  • Skips a stack when SERVICE changes upstream, unless --force. Prints the ## Upgrading section of the README when there are updates.
  • Never starts, stops, or restarts containers. After --apply it runs docker compose config --quiet when Docker is available, and prints only whether it passed.
  • Exit status: 0 up to date or updated, 1 updates available, a conflict, or a skipped stack, 2 error.

Also adds scripts/test-update-stack.sh (9 cases on a fake archive served from a temporary folder, no network), the scripts.yml workflow (ShellCheck and the test), and docs in the root README.md and AGENTS.md.

Example output, from an old Gotify copy with an edited image tag and .env (paths shortened):

Upstream: commit adb87c1 from https://codeload.github.com/tailscale-dev/ScaleTail/tar.gz/refs/heads/main

== ~/stacks/gotify (service: gotify)
  compose.yaml  merge    (your changes stay)
  .env          merge    (your changes stay)
                added: COMPOSE_PROFILES, GOTIFY_CLIENT_TOKENS, GOTIFY_URLS, IGOTIFY_IMAGE_URL, SECNTFY_TOKENS
  status: updated
  Upgrading section of the README:
     | Earlier versions of this stack set `GOTIFY_DEFAULTUSER_PASS=admin` in `compose.yaml`. ...
  saved:  the upstream files in .scaletail/ (commit adb87c1)
  backup: .scaletail/backup-20261030-080952/
  compose: docker compose config is valid
  Next:   docker compose pull && docker compose up -d   (in ~/stacks/gotify)

Related Issues

  • None.

Verification

  • docker compose config --quiet from each changed service directory, with dummy values for required variables. N/A: no service changed.
  • The stack started, Tailscale is healthy, and the service is reachable through the Tailnet. N/A: no service changed.
  • The main function of the service works, and its data survives a restart. N/A: no service changed.
  • rumdl check --config .markdownlint.yml . on the whole repository (rumdl 0.3.0, the pinned version), and git diff --check origin/main
  • shellcheck scripts/*.sh (0.10.0): no findings.
  • bash scripts/test-update-stack.sh: all checks pass. Two deliberate breakages (no .env append, a .env value in the output) make it fail, and so does the earlier overview, which printed an auth key from an old compose.yaml.
  • Smoke tests against the real GitHub archive, on copies of Gotify from before Gotify: add optional iGotify container #388 in a scratch folder outside the clone (no containers started):
    • First run: compose.yaml is reported as settings differ, and .env gets the new variables. --apply replaces compose.yaml with a backup, and prints diff .scaletail/backup-<time>/compose.yaml compose.yaml. docker compose config then fails on required variable GOTIFY_DEFAULTUSER_PASS is missing, as the Upgrading section says, and the script reports the failure without quoting .env. A second run is up to date.
    • With a saved copy from the old version (served from a local archive), an edited image tag, and edited .env values: both files merge cleanly (output above), and the values do not appear in the output.
    • An edit to the restart: line next to the new iGotify block conflicts: the markers land in compose.yaml, the next run refuses, and after resolving it is up to date.
    • Two folders named gotify in one run, the first with pending changes and the second up to date: the second reports up to date. --service works for a folder with another name. A folder with compose.yml gets a hint to rename it.
  • CI (Compose files, Scripts, Workflow lint, lint) passes.
  • Not run: macOS (out of scope), and any live stack (no service changed).

Impact on existing users

  • None. The script is new and optional. No service changed.

Checklist

  • I have performed a self-review of my code and followed the templates structure. N/A for the template: no service changed.
  • I did not commit a working auth key, password, token, or other credential.
  • The service README uses the headings of the template, in the same order, and is up to date. N/A: no service changed.
  • I added, removed, or renamed the service in the root README.md, in alphabetical order, or this PR does not change the list of services. This PR does not change the list of services.

Additional Context

  • The second commit replaces the first version (679 lines, base detection from the git history of a full clone, marker commit, --base, --ref, --no-fetch) with a download and a saved copy (about 270 lines). Squash-merge flattens both.
  • git merge-file is used instead of diff3 -m from diffutils, because diff3 -m reports a conflict when both sides made the same change.
  • Adds the title prefix Scripts: to the lists in AGENTS.md and CONTRIBUTING.md.

scripts/update-stack.sh checks stack folders that were copied out of a clone
against the latest version in the repository and updates them with a
three-way merge, so edits to .env and compose.yaml survive. It reads the
upstream files with git only, never prints .env values, makes a backup
before it writes, and never restarts containers.

scripts/test-update-stack.sh tests it against a throwaway repository, and a
new workflow runs ShellCheck and the test on changes to scripts/.
Download the service from GitHub instead of reading a full clone, and
update compose.yaml and .env with a three-way merge against the upstream
files that the last run saved in .scaletail/. This drops the base
detection, the marker commit, --base, --ref and --no-fetch.

- The first run replaces compose.yaml with a backup, and adds missing
  .env variables.
- A conflict writes markers into the file, after a backup, and the next
  run refuses until they are resolved.
- Target bash and GNU tools on Linux, not bash 3.2 and BSD.
The first update printed a unified diff of compose.yaml. Comment and
context lines hid the settings that changed. Print a short overview:
one line per changed setting, and a single line when only comments differ.
The overview of the first update still printed many lines for an old
stack: fragments of the serve config, keys without their service, and
values such as an auth key that old stacks set in compose.yaml. Print
one label instead: settings differ, or only comments or spacing. After
--apply, print the diff command that compares the backup with the new
file. The script now prints no contents of compose.yaml or .env.
jackspiering added a commit to jackspiering/tailarr that referenced this pull request Nov 6, 2026
* feat: keep compose edits on Apply with a 3-way merge

Apply used to overwrite the deployed compose file, so an operator lost
every edit. This ports the behavior of the ScaleTail stack update script
(tailscale-dev/ScaleTail#404) into Tailarr.

- Deploy and Apply record the catalog compose file as
  .tailarr.compose.base.yaml. Apply merges the catalog change into the
  deployed file with git merge-file, run with the hardened git setup and
  without user or system git config.
- A conflict refuses Apply before any write and never writes conflict
  markers. The error says how to get past it.
- A deployment without a base (older Tailarr) gets the catalog file once,
  and the output names the backup that holds the old file and says
  whether settings or only comments differed.
- The base is part of the Apply snapshot, so a failed Apply rolls it back
  and the next Apply still sees the catalog change.
- The compose file is still written in place, so its inode survives.
- The preview shows the diff to the merged result, labels the file as
  merged, replaced, or conflict, and names .env keys the catalog dropped.
- New .env keys bring the template comment lines above them. A key the
  operator commented out is not added again.

* fix: keep adding .env keys that the catalog shipped commented out

Every ScaleTail template ships optional keys as commented-out lines, so
skipping a key that the deployed .env has only commented out would block
the catalog from ever turning one on. Drop that rule and keep the template
comments for new keys. Make the first-Apply notice and the preview note
conditional on the operator having edited the file.
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.

1 participant