rails / mission_control-jobs

Dashboard and Active Job extensions to operate and troubleshoot background jobs
MIT License
604 stars 69 forks source link

Setting a controller base class that uses http_basic_authenticate_with breaks bin/rails assets:precompile #118

Open collimarco opened 6 months ago

collimarco commented 6 months ago

Start with an application that is working fine and a docker image that is building successfully.

The application already has a Admin::AdminController that looks like this:

class Admin::AdminController < ApplicationController
  layout 'admin'
  http_basic_authenticate_with name: 'admin', password: Rails.application.credentials.admin_password, realm: 'Admin'
end

Then add this gem and add this line to an initializer:

MissionControl::Jobs.base_controller_class = "Admin::AdminController"

Or, alternatively, add this line to config/application.rb:

config.mission_control.jobs.base_controller_class = "Admin::AdminController"

Once you add that line of configuration, you start getting this error when you try to build the Docker image:

 > [10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
3.508 bin/rails aborted!
3.509 ArgumentError: Expected password: to be a String, got NilClass (ArgumentError)
3.509 
3.509             raise ArgumentError, "Expected password: to be a String, got #{password.class}" unless password.is_a?(String)
3.509                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3.509 /app/app/controllers/admin/admin_controller.rb:3:in `<class:AdminController>'
3.509 /app/app/controllers/admin/admin_controller.rb:1:in `<main>'
3.509 /app/config/environment.rb:5:in `<main>'
3.510 Tasks: TOP => environment

Is that configuration of mission_control causing an eager loading of controller file or something? Or it's causing the controller file to be loaded before credentials are fully loaded?

Any solution?

smitssjors commented 6 months ago

This might help https://github.com/rails/rails/issues/51772.

collimarco commented 6 months ago

@smitssjors Thanks for the help! I already moved to Devise also for admins... so I have solved in some way.

I was just curious about why that error for credentials is raised only when I set that controller as the base controller for mission control. When I normally use that controller, without mission control, the docker image compiled normally without errors.