Some asset related tasks run during app start up

AI-generated summary

The discussion revolves around asset-related tasks running during application startup in Discourse, particularly concerning plugin handling and file permissions. darix questions whether a rake task can be used instead of running plugin processing during startup, as it causes permission issues with apparmor due to the app server attempting to write to application files. The error shown indicates a permission denied issue when trying to apply changes to a plugin JavaScript file. sam explains that the current behavior involves deleting plugin asset files unconditionally during plugin boot, which is a historical design choice. darix suggests moving this process to a rake task, while sam acknowledges that while possible, changing this behavior would be complex.

I was wondering … is there a rake task that we can run to do this plugin handling instead of doing that during the application start up? We run our instances with apparmor and would like to avoid allowing the app server to write application files.

systemd[1]: Stopped Discourse Puma.
systemd[1]: Started Discourse Puma.
bundler.ruby2.6-2.1.4[28628]: `/srv/www/vhosts//discourse/` is not writable.
bundler.ruby2.6-2.1.4[28628]: Bundler will use `/tmp/bundler20200127-28628-npwuek28628' as your home directory temporarily.
bundler.ruby2.6-2.1.4[28628]: [28628] Puma starting in cluster mode...
bundler.ruby2.6-2.1.4[28628]: [28628] * Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
bundler.ruby2.6-2.1.4[28628]: [28628] * Min threads: 4, max threads: 8
bundler.ruby2.6-2.1.4[28628]: [28628] * Environment: production
bundler.ruby2.6-2.1.4[28628]: [28628] * Process workers: 2
bundler.ruby2.6-2.1.4[28628]: [28628] * Preloading application
bundler.ruby2.6-2.1.4[28628]: [28628] ! Unable to load application: Errno::EACCES: Permission denied @ apply2files - app/assets/javascripts/plugins/discourse-details.js.erb
bundler.ruby2.6-2.1.4[28628]: bundler: failed to load command: /usr/bin/puma.ruby2.6 (/usr/bin/puma.ruby2.6)
bundler.ruby2.6-2.1.4[28628]: Errno::EACCES: Permission denied @ apply2files - app/assets/javascripts/plugins/discourse-details.js.erb
bundler.ruby2.6-2.1.4[28628]:   lib/plugin/instance.rb:559:in `delete'
bundler.ruby2.6-2.1.4[28628]:   lib/plugin/instance.rb:559:in `activate!'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:191:in `block in activate_plugins!'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:188:in `each'
bundler.ruby2.6-2.1.4[28628]:   lib/discourse.rb:188:in `activate_plugins!'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:270:in `block in <class:Application>'
bundler.ruby2.6-2.1.4[28628]:   lib/plugin_initialization_guard.rb:5:in `plugin_initialization_guard'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:269:in `<class:Application>'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:59:in `<module:Discourse>'
bundler.ruby2.6-2.1.4[28628]:   config/application.rb:58:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   config/environment.rb:4:in `require'
bundler.ruby2.6-2.1.4[28628]:   config/environment.rb:4:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   config.ru:6:in `require'
bundler.ruby2.6-2.1.4[28628]:   config.ru:6:in `block in <main>'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:55:in `instance_eval'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:55:in `initialize'
bundler.ruby2.6-2.1.4[28628]:   config.ru:in `new'
bundler.ruby2.6-2.1.4[28628]:   config.ru:in `<main>'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:49:in `eval'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:49:in `new_from_string'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/rack-2.0.8/lib/rack/builder.rb:40:in `parse_file'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:321:in `load_rackup'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:246:in `app'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/runner.rb:155:in `load_and_bind'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/cluster.rb:413:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/cli.rb:80:in `run'
bundler.ruby2.6-2.1.4[28628]:   /usr/lib64/ruby/gems/2.6.0/gems/puma-4.3.1/bin/puma:10:in `<top (required)>'
bundler.ruby2.6-2.1.4[28628]:   /usr/bin/puma.ruby2.6:23:in `load'
bundler.ruby2.6-2.1.4[28628]:   /usr/bin/puma.ruby2.6:23:in `<top (required)>'
systemd[1]: discourse-puma.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: discourse-puma.service: Unit entered failed state.
systemd[1]: discourse-puma.service: Failed with result 'exit-code'.
systemd[1]: discourse-puma.service: Service RestartSec=100ms expired, scheduling restart.
systemd[1]: Stopped Discourse Puma.

This is on 2.4.0.beta10.

This is going to require changes here

We are unconditionally deleting a file for plugins that define js assets on plugin boot. I guess we could be doing this stuff in tmp folder instead.

why not as part of the normal asset rake task?

Not against amending this afaik it is the way it is mostly for historical reasons, it would be a fairly complex change