Skip to content

Make --purge-data actually purge project data - #13

Merged
maxsoldev merged 2 commits into
mainfrom
fix-purge-data-leaves-projects
Oct 9, 2026
Merged

maxsoldev merged 2 commits into
mainfrom
fix-purge-data-leaves-projects

Conversation

@maxsoldev

Copy link
Copy Markdown
Collaborator

Part 4 of #7. Independent of the other two — branches off main.

The problem

--purge-data deleted $APPX_DATA, which in container mode holds only the SQLite DB and TLS certs. All project data lives in the named volumes, which the script never touched:

$ bash deploy/teardown.sh --purge-data
purged data: /mnt/appx-prod-volume/appx-data and /home/appx-agent
$ docker volume ls
local     builder-podman-storage
local     builder-workspace        # <- every project file still here
$ docker ps -a
builder-outer  Up 2 months          # <- still running

So "purge all data" left every project behind, and a later bootstrap silently inherited the old workspace.

The fix

Split the two kinds of state:

The outer container is a process → removed unconditionally. It runs with --restart unless-stopped, so the Docker daemon kept it (and the agent inside it) alive and resurrected it on reboot even after the appx service was gone. Removing it isn't destructive: its state is in the volumes, and EnsureRunning recreates it on next start.

The volumes are data → removed only under --purge-data, and only after the container is gone (docker volume rm refuses while a container still references a volume, so ordering is load-bearing).

Container and volume names are overridable per deployment, so they're read from appx.env alongside APPX_DATA before that file is deleted. Assuming the defaults would have silently skipped a renamed deployment's volumes — the worst possible failure for this command. When docker is absent the volume step warns on stderr rather than reporting a successful purge.

The non-purge path now also says where project data actually is; kept data: /var/lib/appx previously implied that directory was all of it.

Testing

The script needs root, systemd, and real users, so I ran it inside a throwaway container — filesystem-isolated (its own /etc/appx, /usr/local/bin, data dir) but driving the host's real Docker via the mounted socket, with only systemctl/userdel/groupdel/pkill stubbed. Every docker operation below is real, against volumes holding a real myapp/README.md, named via env-file overrides rather than the defaults.

--purge-data:

removed outer container: tdtest-outer (volumes kept)
purged data: /tmp/appx-data and /home/appx-agent
purged volume: tdtest-workspace
purged volume: tdtest-podman

$ docker ps -a --filter name=tdtest-outer   # container: GONE
$ docker volume ls --filter name=tdtest     # volumes: GONE
$ docker run --rm -v tdtest-workspace:/workspace alpine ls /workspace
                                            # empty — project data destroyed

Default (no flag):

removed outer container: tdtest-outer (volumes kept)
kept data: /tmp/appx-data and /home/appx-agent (re-run with --purge-data to delete)
kept volumes: tdtest-workspace and tdtest-podman (ALL project files and
  sessions live here, not in /tmp/appx-data; --purge-data deletes them)

$ docker run --rm -v tdtest-workspace:/workspace alpine cat /workspace/myapp/README.md
project data                                # preserved

Edge cases: idempotent re-run exits 0 (no outer container named ..., no volume named ...); with the env file already deleted it falls back to the documented defaults; with docker absent it prints WARNING: docker not installed — project data in the named volumes was NOT purged to stderr.

bash -n clean. go build / task test unaffected (no Go changes).

Note on what I did not change

I left the projects group in the groupdel loop even though #10 stops creating it, so an upgrade from a host-mode install still cleans it up.

🤖 Generated with Claude Code

teardown.sh --purge-data deleted $APPX_DATA, which in container mode holds
only the SQLite DB and TLS certs. Every project's files and session
transcripts live in the builder-workspace volume and the inner app images in
builder-podman-storage, neither of which the script touched — so "purge all
data" left all project data on disk, and a later bootstrap silently
inherited the old workspace.

Split the two kinds of state:

- The outer container is a PROCESS, so it is now removed unconditionally.
  It runs with `--restart unless-stopped`, which means the Docker daemon kept
  it (and the agent inside it) alive and resurrected it on reboot even after
  the appx service was gone. Removing it is not destructive — its state is in
  the volumes, and appx's EnsureRunning recreates it on next start.
- The volumes are DATA, so they are removed only under --purge-data, after
  the container that mounts them is gone (docker volume rm refuses while a
  container still references a volume).

Container and volume names are overridable per deployment, so they are read
from appx.env alongside APPX_DATA before that file is deleted; assuming the
defaults would have silently skipped a renamed deployment's volumes and left
all its project data behind. When docker is absent, the volume step warns on
stderr rather than reporting a successful purge.

The non-purge path now also states where project data actually is, since
"kept data: /var/lib/appx" previously implied that directory was all of it.

Refs #7

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@maxsoldev
maxsoldev merged commit 24dec38 into main Oct 9, 2026
1 check passed
@maxsoldev
maxsoldev deleted the fix-purge-data-leaves-projects branch October 9, 2026 09:58
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