ci: enable nginx compression in server provision
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-05-12 16:30:35 +08:00
parent d41f260a2a
commit d641840098
4 changed files with 123 additions and 2 deletions

View File

@@ -295,12 +295,66 @@ ensure_spacetime_owner_client_token() {
echo "[server-provision] 已同步 SpacetimeDB CLI 登录态;后续首次 publish 将使用同一 client identity。"
}
render_nginx_brotli_directives() {
if ! command -v nginx >/dev/null 2>&1; then
echo " # Brotli 未启用:目标服务器未找到 nginx 命令。"
return
fi
if ! nginx -V 2>&1 | grep -qi brotli; then
echo " # Brotli 未启用:当前 nginx 未编译或加载 brotli 模块。"
return
fi
local brotli_snippet
brotli_snippet="$(mktemp)"
cat >"${brotli_snippet}" <<'EOF'
events {}
http {
brotli on;
brotli_comp_level 4;
brotli_min_length 1024;
brotli_types application/json;
}
EOF
if nginx -t -c "${brotli_snippet}" >/dev/null 2>&1; then
cat <<'EOF'
brotli on;
brotli_comp_level 4;
brotli_min_length 1024;
brotli_types
text/plain
text/css
text/javascript
application/javascript
application/json
application/xml
application/xml+rss
image/svg+xml;
EOF
else
echo " # Brotli 未启用nginx -t 不接受 brotli 指令。"
fi
rm -f "${brotli_snippet}"
}
render_nginx_template() {
local template="$1"
local rendered_brotli
rendered_brotli="$(render_nginx_brotli_directives)"
sed \
-e "s/genarrative.example.com/${SERVER_NAME}/g" \
-e "/# __GENARRATIVE_BROTLI_DIRECTIVES__/r /dev/stdin" \
-e "/# __GENARRATIVE_BROTLI_DIRECTIVES__/d" \
"${template}" <<<"${rendered_brotli}"
}
render_nginx_https_config() {
sed "s/genarrative.example.com/${SERVER_NAME}/g" deploy/nginx/genarrative.conf
render_nginx_template deploy/nginx/genarrative.conf
}
render_nginx_development_http_config() {
sed "s/genarrative.example.com/${SERVER_NAME}/g" deploy/nginx/genarrative-dev-http.conf
render_nginx_template deploy/nginx/genarrative-dev-http.conf
}
render_api_env_example() {