zammad / zammad-docker-compose

Zammad Docker images for docker-compose
https://hub.docker.com/r/zammad/zammad-docker-compose/
GNU Affero General Public License v3.0
273 stars 223 forks source link

Command "rails c" failes with database error #412

Closed lordimac closed 5 months ago

lordimac commented 5 months ago

Infos

Expected behavior

Rails Shell should be opened

Actual behavior

zammad@6343e130707b:~$ rails c
/usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application/configuration.rb:352:in `database_configuration': Cannot load database configuration: (RuntimeError)
Could not load database configuration. No such file - ["config/database.yml"]
        from /usr/local/bundle/gems/activerecord-7.0.8.1/lib/active_record/railtie.rb:266:in `block (2 levels) in <class:Railtie>'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:95:in `class_eval'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:95:in `block in execute_hook'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:85:in `with_execution_control'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:90:in `execute_hook'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:60:in `block in on_load'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:59:in `each'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:59:in `on_load'
        from /usr/local/bundle/gems/activerecord-7.0.8.1/lib/active_record/railtie.rb:262:in `block in <class:Railtie>'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:32:in `instance_exec'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:32:in `run'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `call'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:60:in `run_initializers'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application.rb:372:in `initialize!'
        from /opt/zammad/config/environment.rb:7:in `<main>'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application.rb:348:in `require_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/actions.rb:28:in `require_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/commands/console/console_command.rb:105:in `perform'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/base.rb:87:in `perform'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command.rb:48:in `invoke'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/commands.rb:18:in `<main>'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:5:in `<main>'
/usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application/configuration.rb:352:in `database_configuration': Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
        from /usr/local/bundle/gems/activerecord-7.0.8.1/lib/active_record/railtie.rb:266:in `block (2 levels) in <class:Railtie>'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:95:in `class_eval'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:95:in `block in execute_hook'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:85:in `with_execution_control'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:90:in `execute_hook'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:60:in `block in on_load'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:59:in `each'
        from /usr/local/bundle/gems/activesupport-7.0.8.1/lib/active_support/lazy_load_hooks.rb:59:in `on_load'
        from /usr/local/bundle/gems/activerecord-7.0.8.1/lib/active_record/railtie.rb:262:in `block in <class:Railtie>'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:32:in `instance_exec'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:32:in `run'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `call'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
        from /usr/local/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/initializable.rb:60:in `run_initializers'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application.rb:372:in `initialize!'
        from /opt/zammad/config/environment.rb:7:in `<main>'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/application.rb:348:in `require_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/actions.rb:28:in `require_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/commands/console/console_command.rb:105:in `perform'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/bundle/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command/base.rb:87:in `perform'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/command.rb:48:in `invoke'
        from /usr/local/bundle/gems/railties-7.0.8.1/lib/rails/commands.rb:18:in `<main>'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /usr/local/bundle/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from bin/rails:5:in `<main>'

Steps to reproduce the behavior

docker compose exec zammad-railsserver /bin/bash rails c

MrGeneration commented 5 months ago

What Zammad version and tag?

mgruner commented 5 months ago

Please see https://docs.zammad.org/en/latest/install/docker-compose.html#step-4-start-zammad-using-dockerhub-images for how to run commands in the containers properly.

Jan-NiklasB commented 1 month ago

Bump, worked that way in previous versions and also is the preferred way using Portainer (using the console function on the container running the command "rails c")...

There seems to be something wrong with the database config, which as far as I understand should be set while installing the stack using default compose file and vars

mgruner commented 1 month ago

Did you read the documentation linked above? It explains how to run commands via the image's entrypoint in the proper way. This is required for Rails to have the necessary database configuration environment set up properly.

It did not work properly in previous versions, because these had a database.yml file in the image which only referred to the nulldb adapter, so that Rails would not fail but also not have the correct database available.

mgruner commented 1 month ago

Regarding portainer support see #424