From 4f7aeafa8d9fc835c604b82bd8f94308220ed0dd Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Wed, 10 Nov 2021 06:20:22 -0800 Subject: [PATCH] feat(docker): host gzip archive downloads - added config option [mkpkglists] archivedir - created by mkpkglists Signed-off-by: Kevin Morris --- aurweb/scripts/mkpkglists.py | 4 ++++ conf/config.defaults | 1 + conf/config.dev | 11 ++++++----- docker-compose.yml | 5 +++++ docker/config/nginx.conf | 19 ++++++++++++++++++- docker/php-entrypoint.sh | 4 ++++ 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/aurweb/scripts/mkpkglists.py b/aurweb/scripts/mkpkglists.py index b2d37d85..f4b0fbe5 100755 --- a/aurweb/scripts/mkpkglists.py +++ b/aurweb/scripts/mkpkglists.py @@ -19,6 +19,7 @@ on the following, right-hand side fields are added to each item. """ import gzip +import os import sys from collections import defaultdict @@ -29,6 +30,9 @@ import orjson import aurweb.config import aurweb.db +archivedir = aurweb.config.get("mkpkglists", "archivedir") +os.makedirs(archivedir, exist_ok=True) + packagesfile = aurweb.config.get('mkpkglists', 'packagesfile') packagesmetafile = aurweb.config.get('mkpkglists', 'packagesmetafile') packagesmetaextfile = aurweb.config.get('mkpkglists', 'packagesmetaextfile') diff --git a/conf/config.defaults b/conf/config.defaults index 25d6dff9..c29d7045 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -101,6 +101,7 @@ sync-dbs = core extra community multilib testing community-testing server = https://mirrors.kernel.org/archlinux/%s/os/x86_64 [mkpkglists] +archivedir = /srv/http/aurweb/web/html packagesfile = /srv/http/aurweb/web/html/packages.gz packagesmetafile = /srv/http/aurweb/web/html/packages-meta-v1.json.gz packagesmetaextfile = /srv/http/aurweb/web/html/packages-meta-ext-v1.json.gz diff --git a/conf/config.dev b/conf/config.dev index 05566e8b..9467615e 100644 --- a/conf/config.dev +++ b/conf/config.dev @@ -67,11 +67,12 @@ session_secret = secret ;commit_hash = 1234567 [mkpkglists] -packagesfile = /packages.gz -packagesmetafile = /packages-meta-v1.json.gz -packagesmetaextfile = /packages-meta-ext-v1.json.gz -pkgbasefile = /pkgbase.gz -userfile = /users.gz +archivedir = /var/lib/aurweb/archives +packagesfile = /var/lib/aurweb/archives/packages.gz +packagesmetafile = /var/lib/aurweb/archives/packages-meta-v1.json.gz +packagesmetaextfile = /var/lib/aurweb/archives/packages-meta-ext-v1.json.gz +pkgbasefile = /var/lib/aurweb/archives/pkgbase.gz +userfile = /var/lib/aurweb/archives/users.gz [aurblup] db-path = YOUR_AUR_ROOT/aurblup/ diff --git a/docker-compose.yml b/docker-compose.yml index c2b14f91..2fba1305 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -156,6 +156,7 @@ services: condition: service_started volumes: - mariadb_run:/var/run/mysqld + - archives:/var/lib/aurweb/archives php-fpm: image: aurweb:latest @@ -180,6 +181,7 @@ services: condition: service_started volumes: - mariadb_run:/var/run/mysqld + - archives:/var/lib/aurweb/archives ports: - "19000:9000" @@ -236,6 +238,8 @@ services: condition: service_healthy php-fpm: condition: service_healthy + volumes: + - archives:/var/lib/aurweb/archives sharness: image: aurweb:latest @@ -343,3 +347,4 @@ volumes: mariadb_data: {} # Share /var/lib/mysql git_data: {} # Share aurweb/aur.git smartgit_run: {} + archives: {} diff --git a/docker/config/nginx.conf b/docker/config/nginx.conf index 4288a57d..c3ffd7fa 100644 --- a/docker/config/nginx.conf +++ b/docker/config/nginx.conf @@ -94,7 +94,24 @@ http { ssl_certificate /etc/ssl/certs/web.cert.pem; ssl_certificate_key /etc/ssl/private/web.key.pem; - root /aurweb/web/html; + location ~ ^/.*\.gz$ { + # Override mime type to text/plain. + types { text/plain gz; } + default_type text/plain; + + # Filesystem location of .gz archives. + root /var/lib/aurweb/archives; + + # When we match this block, fix-up trying without a trailing slash. + try_files $uri $uri/ =404; + + # Caching headers. + expires max; + add_header Content-Encoding gzip; + add_header Cache-Control public; + add_header Last-Modified ""; + add_header ETag ""; + } location / { try_files $uri @proxy_to_app; diff --git a/docker/php-entrypoint.sh b/docker/php-entrypoint.sh index 81f70673..274f8e17 100755 --- a/docker/php-entrypoint.sh +++ b/docker/php-entrypoint.sh @@ -1,6 +1,10 @@ #!/bin/bash set -eou pipefail +for archive in packages pkgbase users packages-meta-v1.json packages-meta-ext-v1.json; do + ln -vsf /var/lib/aurweb/archives/${archive}.gz /aurweb/web/html/${archive}.gz +done + # Setup a config for our mysql db. cp -vf conf/config.dev conf/config sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config