The pod_setup script fails to minify some JavaScript, due to a precompile script failure

Bug #1952681 reported by Barry Price
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
charm-k8s-discourse
Fix Released
High
Unassigned

Bug Description

Running the pod_setup script as we do on launch results in some housekeeping being done, including compression/minifying of various JavaScript files and other resources (CSS, etc) in the precompile stage.

However, on recent 2.7 releases we run into issues with uglifier failing to process some files, e.g.:

https://pastebin.canonical.com/p/FB3JHvjjp6/

Since the error is non-fatal, we can work around it for now by looping the precompile stage until success.

This bug is to track fixing it properly so that it doesn't fail in the first place (and so that we have more efficiently compressed/minified resources on live sites).

Related branches

Tom Haddon (mthaddon)
Changed in charm-k8s-discourse:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Franco Luciano Forneron Buschiazzo (gtrkiller) wrote :

I was recently reviewing the code to fix the bug, and it seems the bug has already been fixed. The error on the pastebin link is triggered by trying to use uglifier as compressor for ES6 as seen here: https://www.rubydoc.info/gems/uglifier

When I went to inspect the code, I realized there already exists a patch to change the compressor from uglifier to terser (https://github.com/terser/terser). This patch is located in the build_scripts/terser.patch file and it is called correctly on the build_scripts/build_app file.

Should that mean this bug is fixed? Or am I missing something? Thank you :)

Revision history for this message
Tom Haddon (mthaddon) wrote :

Unfortunately not - take a look at lines 43, 45 and 47 of https://git.launchpad.net/charm-k8s-discourse/tree/image/scripts/pod_setup. Even though we've patched it with terser it doesn't seem to be being used, or not used correctly. Those three particular files mentioned in the comments are failing to be minified.

Revision history for this message
Weii Wang (weii-wang) wrote :

Discourse uses its own precompile scripts so the config.assets.js_compressor setting has no effects. Discourse (<= 2.7.13) will only start to use terser to compress JS assets under these three conditions:

  1. the uglifyjs command exists in $PATH
  2. the terser command exists in $PATH
  3. SKIP_NODE_UGLIFY environment variable not set

The correct package to install terser with command line tools is the uglifyjs.terser instead of node-terser. Also, the current base image 20.04 only provides an older version of the uglifyjs.terser package which only installs a command called uglifyjs.terser, so manually creating the terser command is required for now.

Revision history for this message
Weii Wang (weii-wang) wrote :

The log confirmed that discourse will use terser with the new image.

https://pastebin.canonical.com/p/HxccNpSZWV/

asset-build-1: 63286.017445555 Compressing: vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js
asset-build-1: Compressing Javascript and Generating Source Maps
asset-build-1: terser '/srv/discourse/v2.7.10/public/assets/_vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js' -m -c -o '/srv/discourse/v2.7.10/public/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js' --source-map "base='/srv/discourse/v2.7.10/public/assets',root='/assets',url='/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js.map'"
asset-build-1: gzip -f -c -9 /srv/discourse/v2.7.10/public/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js > /srv/discourse/v2.7.10/public/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js.gz
asset-build-1:
asset-build-1: brotli -f --quality=11 /srv/discourse/v2.7.10/public/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js --output=/srv/discourse/v2.7.10/public/assets/vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js.br
asset-build-1:
asset-build-1:
asset-build-1: Done compressing vendor-dde8b5f2dd41adf78c88e7719455c3a5d4db146cb96d783a2dc1ed978892f200.js : 2.6 secs
asset-build-1:

Tom Haddon (mthaddon)
Changed in charm-k8s-discourse:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers