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

Refer serious misconduct / Apply for QTS unable to upgrade to DfE Analytics GEM (v1.8.0) #70

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

asatwal
Copy link
Collaborator

@asatwal asatwal commented Apr 19, 2023

Trello-1107

The problem is mainly seen during the rails assets:precompile step while the docker container is being built. This article here explains it well:

Three options considered to address the problem:

  1. Set env variable RAILS_SERVE_STATIC_FILES=true for precompile in the Dockerfile:
    For example:
     RUN RAILS_SERVE_STATIC_FILES=true SECRET_KEY_BASE=dummyvalue rails assets:precompile
    
  2. Catch the Ruby run time error on the insert middleware and ignore if it matches the expected error message.
    For example:
    begin
      app.config.middleware.insert_before \
      ActionDispatch::Static,
      DfE::Analytics::Middleware::SendCachedPageRequestEvent
    
    rescue RuntimeError => e
       error_message = 'No such middleware to insert before: ActionDispatch::Static'
    
       raise e unless Regexp.new(error_message, 'i').match?(e.message.squish)
    end
    
  3. Only add the DfE middleware if RAILS_SERVE_STATIC_FILES=true
    if ENV['RAILS_SERVE_STATIC_FILES'].present?
      app.config.middleware.insert_before \
      ActionDispatch::Static,
      DfE::Analytics::Middleware::SendCachedPageRequestEvent
    end
    

So Rails will always have ActionDispatch::Static apart from when it doesn't ! (When the container is being built or when RAILS_SERVE_STATIC_FILES=true). So 3 maybe is the safest option.
I'm not entirely sure when RAILS_SERVE_STATIC_FILES=false will be set. Maybe when static assets are served from a reverse proxy web server like nginx. Needless to say, when that this is the case, then we wouldn't support any web pages that are cached though different mechanisms other that Rails and even then it must be done though ActionDispatch::Static middleware.
The GIT Website works as RAILS_SERVE_STATIC_FILES=false is set in the Dockerfile, whereas
Refer serious misconduct, Register and Apply for TT, Apply for QTS don't set RAILS_SERVE_STATIC_FILES in the Dockerfile, but I see it set in Terraform, so (3) should cover all the cases I see failing.

@asatwal asatwal requested a review from duncanjbrown April 19, 2023 15:38
@asatwal asatwal self-assigned this Apr 19, 2023
@asatwal asatwal changed the title Refer serious misconduct / Apply for QTS unable to upgrade to latest DfE Analytics GEM Refer serious misconduct / Apply for QTS unable to upgrade to DfE Analytics GEM (v1.8.0) Apr 19, 2023
@asatwal asatwal merged commit b4cddf6 into main Apr 26, 2023
@asatwal asatwal deleted the fix-precompile-assets-rack-middleware-error branch April 26, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants