Current_hostname: uninitialized constant

Hello! We have a somewhat complex setup here because we need to use k8s to host our forum, but I’ll try to keep it simple.

When using this application yml, we get the following error during startup. This is new as of last night – we had it running just fine up until then, but redeploying suddenly broke it.

Don’t mind the messing with email env vars in that yml, we were debugging something else.

=> Booting Puma
=> Rails 7.0.2.4 application starting in production 
=> Run `bin/rails server --help` for more startup options
Exiting
/var/www/discourse/lib/discourse.rb:443:in `current_hostname': uninitialized constant Discourse::SiteSetting (NameError)
Did you mean?  Discourse::SiteSettingMissing
        from /var/www/discourse/config/initializers/100-verify_config.rb:7:in `<main>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/engine.rb:667:in `block in load_config_initializer'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.2.4/lib/active_support/notifications.rb:208:in `instrument'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/engine.rb:666:in `load_config_initializer'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/engine.rb:619:in `each'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/engine.rb:619:in `block in <class:Engine>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:32:in `instance_exec'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:32:in `run'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:50:in `each'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:50:in `tsort_each_child'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:415:in `call'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:415:in `each_strongly_connected_component_from'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `each'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `call'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
        from /usr/local/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/initializable.rb:60:in `run_initializers'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/application.rb:372:in `initialize!'
        from /var/www/discourse/config/environment.rb:7:in `<main>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
        from config.ru:6:in `block in <main>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:312:in `block in start'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:379:in `handle_profiling'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/server.rb:311:in `start'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/commands/server/server_command.rb:38:in `start'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/commands/server/server_command.rb:143:in `block in perform'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/commands/server/server_command.rb:134:in `tap'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/commands/server/server_command.rb:134:in `perform'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/command/base.rb:87:in `perform'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/command.rb:48:in `invoke'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/railties-7.0.2.4/lib/rails/commands.rb:18:in `<main>'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:18:in `<main>'

We’ve had a quick search through the source (although most of us aren’t familiar with Ruby), but we’re pretty stumped. Any ideas?

Use launcher to build the image and launch it with the env variables needed to make it work. You can get them with a launcher command that shows just the startup call (look at launcher code to get it).

You can either build it against the live database and then launch it, or build it against a temporary database and then migrate and precompile assets after you launch.

All of that is beyond the scope of support available here.

Or you could use bitnami (also not supported here).

Thanks for the response, I do appreciate it, especially given that k8s is a bit out of scope here.

We can’t use Bitnami directly as we need to add plugins to the instance, but it looks like a useful recommendation in general.

We’re triple-checking everything, thanks for the launcher hint – hopefully we run into something.

1 Like

This did indeed appear to be an issue relating to missing env vars - not in the build files, but k8s-side. Thanks for the help.

2 Likes