Browse Source

Reload gunicorn when site-icons CSS updates

This starts using webassets for the site-icons.css file inside the base
template so that a cache-busting "version" string is added after the
filename as a query variable (as was already being done with the other
CSS and JS files).

It also creates a new service that's triggered by a "path changed" event
on site-icons.css, which causes gunicorn to reload. This should mean
that whenever the site-icons.css file is updated by the cronjob that
generates it, gunicorn will automatically reload and update the
cache-busting string for the CSS file, causing users' browsers to update
to the newest version.
merge-requests/102/head
Deimos 5 years ago
parent
commit
89c7c13be2
  1. 5
      salt/salt/gunicorn/gunicorn_reloader.path
  2. 10
      salt/salt/gunicorn/gunicorn_reloader.service
  3. 24
      salt/salt/gunicorn/init.sls
  4. 1
      tildes/tildes/__init__.py
  5. 4
      tildes/tildes/templates/base.jinja2

5
salt/salt/gunicorn/gunicorn_reloader.path

@ -0,0 +1,5 @@
[Path]
PathChanged=/opt/tildes/static/css/site-icons.css
[Install]
WantedBy=multi-user.target

10
salt/salt/gunicorn/gunicorn_reloader.service

@ -0,0 +1,10 @@
[Unit]
Description=gunicorn reloader
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/systemctl reload gunicorn.service
[Install]
WantedBy=multi-user.target

24
salt/salt/gunicorn/init.sls

@ -33,3 +33,27 @@
gunicorn.socket:
service.running:
- enable: True
# Set up the gunicorn_reloader service, which reloads gunicorn whenever certain files
# are changed (such as static files, to update the cache-busting strings)
/etc/systemd/system/gunicorn_reloader.service:
file.managed:
- source: salt://gunicorn/gunicorn_reloader.service
- user: root
- group: root
- mode: 644
- require_in:
- service: gunicorn_reloader.path
/etc/systemd/system/gunicorn_reloader.path:
file.managed:
- source: salt://gunicorn/gunicorn_reloader.path
- user: root
- group: root
- mode: 644
- require_in:
- service: gunicorn_reloader.path
gunicorn_reloader.path:
service.running:
- enable: True

1
tildes/tildes/__init__.py

@ -33,6 +33,7 @@ def main(global_config: Dict[str, str], **settings: str) -> PrefixMiddleware:
config.add_webasset("javascript", Bundle(output="js/tildes.js"))
config.add_webasset("javascript-third-party", Bundle(output="js/third_party.js"))
config.add_webasset("css", Bundle(output="css/tildes.css"))
config.add_webasset("site-icons-css", Bundle(output="css/site-icons.css"))
config.scan("tildes.views")

4
tildes/tildes/templates/base.jinja2

@ -37,7 +37,9 @@
{% assets "css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
<link rel="stylesheet" href="/css/site-icons.css">
{% assets "site-icons-css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
{% endassets %}
{# Favicons and other data for "pinning" the site on various platforms #}
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">

Loading…
Cancel
Save