Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brotli compression support #379

Merged
merged 18 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ jobs:

- name: Install template app
run: |
git clone https://github.com/cesium-ml/baselayer_template_app
git clone https://github.com/Theodlz/baselayer_template_app
cd baselayer_template_app
git checkout brotli
cd ..
cp -rf baselayer baselayer_template_app/

- uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions services/nginx/mime.types
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ application/geopackage+sqlite3 gpkg;
application/gltf-buffer glbin glbuf;
application/gml+xml gml;
application/gzip gz tgz;
application/br br;
application/hyperstudio stk;
application/inkml+xml ink inkml;
application/ipfix ipfix;
Expand Down
19 changes: 19 additions & 0 deletions services/nginx/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
error_log log/error.log error;
pid run/nginx.pid;

{% if server.use_brotli and not server.is_macos %}
load_module modules/ngx_http_brotli_filter_module.so; # for compressing responses on-the-fly
load_module modules/ngx_http_brotli_static_module.so; # for serving pre-compressed files
{% endif %}


# Choose number of NGINX worker processes based on number of CPUs
worker_processes auto;

Expand All @@ -21,6 +27,19 @@ http {
text/javascript
application/javascript;

{% if server.use_brotli %}
# also enable brotli compression
brotli on;
brotli_comp_level 6;
brotli_types text/plain
text/css
application/json
application/x-javascript
application/xml
text/javascript
application/javascript;
{% endif %}

# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
Expand Down
23 changes: 23 additions & 0 deletions tools/fill_conf_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,35 @@ def hash_filter(string, htype):
return h.hexdigest()


def nginx_brotli_module_installed():
# we run the `nginx -V` command to check if the nginx server is compiled with brotli support
# if it is, we'll find "brotli" in the output
import subprocess

try:
output = subprocess.check_output(
["nginx", "-V"], stderr=subprocess.STDOUT
).decode("utf-8")
return "brotli" in output
except subprocess.CalledProcessError:
return False


def is_macos():
return os.uname().sysname == "Darwin"


custom_filters = {"md5sum": md5sum, "version": version, "hash": hash_filter}

USE_BROTLI = nginx_brotli_module_installed()
IS_MACOS = is_macos()


def fill_config_file_values(template_paths):
log("Compiling configuration templates")
env, cfg = load_env()
cfg["server"]["use_brotli"] = USE_BROTLI
Theodlz marked this conversation as resolved.
Show resolved Hide resolved
cfg["server"]["is_macos"] = IS_MACOS
Theodlz marked this conversation as resolved.
Show resolved Hide resolved

for template_path in template_paths:
with status(template_path):
Expand Down
Loading