diff --git a/docs/install.md b/docs/install.md index 57ab7b2..7fb8d2e 100644 --- a/docs/install.md +++ b/docs/install.md @@ -295,6 +295,7 @@ git fetch --tags --force LATEST_TAG="$(git tag --sort=-creatordate | head -n1)" git checkout --detach "$LATEST_TAG" chown -R evection:evection /opt/evection/app +sed -i "s/^EVECTION_PWA_CACHE_VERSION=.*/EVECTION_PWA_CACHE_VERSION=$LATEST_TAG/" .env sudo -u evection -H /opt/evection/venv/bin/pip install . sudo -u evection -H env DJANGO_SETTINGS_MODULE=config.settings.prod \ /opt/evection/venv/bin/python manage.py migrate @@ -311,7 +312,7 @@ git tag v$(date +%Y.%m.%d) git push --tags ``` -Bump `EVECTION_PWA_CACHE_VERSION` in `.env` whenever a release changes cached -static assets (CSS/JS/icons) — it's baked into the service worker's cache name, so -changing it forces every installed PWA to drop its old cache instead of serving -stale assets after the upgrade. +`upgrade.sh` sets `EVECTION_PWA_CACHE_VERSION` in `.env` to the deployed tag on every +run — it's baked into the service worker's cache name, so this forces every installed +PWA to drop its old cache instead of serving stale assets after the upgrade. You don't +need to bump it by hand. diff --git a/scripts/install.sh b/scripts/install.sh index 4155195..3f115c5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -204,7 +204,7 @@ REDIS_URL=${EVECTION_REDIS_URL:-redis://localhost:6379/0} EVECTION_GUNICORN_BIND=$GUNICORN_BIND EVECTION_SIGNUP_ENABLED=False EVECTION_MIN_FETCH_INTERVAL_MINUTES=15 -EVECTION_PWA_CACHE_VERSION=v1 +EVECTION_PWA_CACHE_VERSION=${LATEST_TAG:-v1} EOF chown "$EVECTION_USER:$EVECTION_USER" "$ENV_FILE" chmod 600 "$ENV_FILE" diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 617bf21..2878736 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -72,6 +72,18 @@ echo "Deploying $LATEST_TAG (currently on: $CURRENT_REF)" git checkout --quiet --detach "$LATEST_TAG" chown -R "$EVECTION_USER:$EVECTION_USER" "$APP_DIR" +# Bump the PWA's cache-busting version to this release's tag on every +# deploy, not just ones that happened to touch static assets — a missed +# manual bump otherwise leaves installed PWAs serving a stale cached +# shell/pages indefinitely. Cheap even when nothing cacheable changed: +# it just makes the service worker open a fresh cache name next time it +# activates. +if grep -q '^EVECTION_PWA_CACHE_VERSION=' "$APP_DIR/.env"; then + sed -i "s/^EVECTION_PWA_CACHE_VERSION=.*/EVECTION_PWA_CACHE_VERSION=$LATEST_TAG/" "$APP_DIR/.env" +else + echo "EVECTION_PWA_CACHE_VERSION=$LATEST_TAG" >> "$APP_DIR/.env" +fi + echo "==> Installing updated dependencies" sudo -u "$EVECTION_USER" -H "$VENV_DIR/bin/pip" install --upgrade "$APP_DIR" @@ -131,7 +143,4 @@ systemctl status evection-gunicorn --no-pager -l | head -10 echo echo "==> Deployed $LATEST_TAG." -echo " If this release changed cached static assets (CSS/JS/icons), bump" -echo " EVECTION_PWA_CACHE_VERSION in $APP_DIR/.env and restart evection-gunicorn" -echo " again so installed PWAs drop their old cache instead of serving stale assets." echo " journalctl -u evection-gunicorn -f to watch logs."