Preserve NextPath accounts across redeploys
Homelab Main / validate (push) Failing after 1m33s Details
Homelab Main / running-update (push) Has been skipped Details
Homelab Main / debian-ops (push) Has been skipped Details

This commit is contained in:
juvenal.diaz 2026-12-05 13:53:16 -06:00
parent 5efed1af8b
commit 8471f4c34d
3 changed files with 42 additions and 3 deletions

View File

@ -29,4 +29,7 @@ NextPath is a public work in progress. Deploy it from the Debian control plane:
The service runs under systemd, stores private account data in
`/data/homelab-nextpath/data`, and exposes only its HTTP port to the tailnet/LAN.
The OCI edge supplies public TLS at `https://nextpath.lab2025.duckdns.org/`.
Redeployments never recreate the account store. Jeannie migrates the original
manual-preview file from `/data/homelab-nextpath/accounts.json` when needed and
writes a mode-0600 pre-deploy backup under `/data/homelab-nextpath/backups`.

View File

@ -6019,6 +6019,10 @@ deploy_nextpath() {
local secure_cookies="${LAB_NEXTPATH_SECURE_COOKIES:-true}"
local release_id=""
local release_dir=""
local account_store="${install_dir}/data/accounts.json"
local legacy_account_store="${install_dir}/accounts.json"
local backup_dir="${install_dir}/backups"
local backup_timestamp=""
local elapsed=0
require_debian_server "deploy-nextpath"
@ -6048,8 +6052,31 @@ deploy_nextpath() {
release_id="$(git -C "${REPO_ROOT}" rev-parse --verify HEAD)"
release_dir="${install_dir}/releases/${release_id}"
sudo install -d -o "${service_user}" -g "${service_user}" -m 0750 \
"${install_dir}" "${install_dir}/releases" "${install_dir}/data"
"${install_dir}" "${install_dir}/releases" "${install_dir}/data" "${backup_dir}"
sudo chmod 0700 "${install_dir}/data"
sudo chmod 0700 "${backup_dir}"
# The initial manual-preview instructions used the install root. Migrate
# that file once, without ever replacing a store already managed by the
# service. This lets the first Jeannie deployment keep preview accounts.
if sudo test -s "${legacy_account_store}" && ! sudo test -e "${account_store}"; then
echo "Migrating the legacy NextPath account store into the persistent data directory."
sudo mv "${legacy_account_store}" "${account_store}"
sudo chown "${service_user}:${service_user}" "${account_store}"
sudo chmod 0600 "${account_store}"
elif sudo test -e "${legacy_account_store}" && sudo test -e "${account_store}"; then
echo "Warning: both legacy and managed NextPath account stores exist; preserving both and using ${account_store}." >&2
fi
# Preserve a private point-in-time copy before every redeploy that has
# account data. The application itself atomically replaces its live file.
if sudo test -s "${account_store}"; then
backup_timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
sudo cp -p "${account_store}" "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json"
sudo chown "${service_user}:${service_user}" "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json"
sudo chmod 0600 "${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json"
echo "Preserved a private pre-deploy NextPath account backup in ${backup_dir}."
fi
sudo -u "${service_user}" install -d -m 0750 "${release_dir}"
(
cd "${REPO_ROOT}"
@ -6070,7 +6097,7 @@ User=${service_user}
Group=${service_user}
WorkingDirectory=${install_dir}/current
Environment=NEXTPATH_ADDRESS=${bind_ip}:${http_port}
Environment=NEXTPATH_ACCOUNT_STORE=${install_dir}/data/accounts.json
Environment=NEXTPATH_ACCOUNT_STORE=${account_store}
Environment=NEXTPATH_SECURE_COOKIES=${secure_cookies}
ExecStart=${install_dir}/current/nextpath
Restart=on-failure

View File

@ -14,9 +14,18 @@ class NextPathPipelineTests(unittest.TestCase):
self.assertIn("deploy_nextpath()", pipeline)
self.assertIn('require_debian_server "deploy-nextpath"', pipeline)
self.assertIn("GOTOOLCHAIN=local go test ./cmd/nextpath/...", pipeline)
self.assertIn("NEXTPATH_ACCOUNT_STORE=${install_dir}/data/accounts.json", pipeline)
self.assertIn("NEXTPATH_ACCOUNT_STORE=${account_store}", pipeline)
self.assertIn("ReadWritePaths=${install_dir}/data", pipeline)
self.assertIn("sudo chmod 0700", pipeline)
self.assertIn('legacy_account_store="${install_dir}/accounts.json"', pipeline)
self.assertIn('! sudo test -e "${account_store}"', pipeline)
self.assertIn('sudo mv "${legacy_account_store}" "${account_store}"', pipeline)
self.assertIn('sudo cp -p "${account_store}"', pipeline)
self.assertIn('"${backup_dir}/accounts-${backup_timestamp}-${release_id:0:12}.json"', pipeline)
self.assertLess(
pipeline.index('sudo cp -p "${account_store}"'),
pipeline.index('sudo systemctl restart nextpath.service'),
)
self.assertIn('curl -fsS --connect-timeout 3 "http://127.0.0.1:${http_port}/healthz"', pipeline)
self.assertIn("nextpath.service", pipeline)
self.assertIn("deploy-nextpath)", command)