From 1f4a92b6d414e345871c22478d6c0581552a5786 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:07:43 +0100 Subject: [PATCH 1/5] allow log levels to be configurable via ENV --- config/environments/development.rb | 6 +++++- config/environments/production.rb | 2 +- config/environments/test.rb | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 317e27e3..c2434c8c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -51,6 +51,10 @@ Rails.application.configure do config.action_mailer.perform_caching = false + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = ENV.fetch("LOG_LEVEL") { "debug" }.to_sym + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -73,6 +77,6 @@ Rails.application.configure do # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end -# For better_errors to work inside Docker we need +# For better_errors to work inside Docker we need # to allow 0.0.0.0 as an IP in development context BetterErrors::Middleware.allow_ip! "0.0.0.0/0" diff --git a/config/environments/production.rb b/config/environments/production.rb index 5964fe5c..3ae984d5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -45,7 +45,7 @@ Rails.application.configure do # Use the lowest log level to ensure availability of diagnostic information # when problems arise. - config.log_level = :debug + config.log_level = ENV.fetch("LOG_LEVEL") { "info" }.to_sym # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] diff --git a/config/environments/test.rb b/config/environments/test.rb index 30587ef6..036f3f7a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -34,6 +34,10 @@ Rails.application.configure do # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = ENV.fetch("LOG_LEVEL") { "debug" }.to_sym + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr From f14c0f1f83549cf59d39d85c51a2c8a706c32730 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:09:32 +0100 Subject: [PATCH 2/5] Containerfile: always log to stdout --- Containerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Containerfile b/Containerfile index 9fcc7ed0..4d3a6049 100644 --- a/Containerfile +++ b/Containerfile @@ -74,4 +74,7 @@ RUN cp config/justask.yml.example config/justask.yml \ && rm config/justask.yml config/database.yml ENV SECRET_KEY_BASE= +# set some defaults +ENV RAILS_LOG_TO_STDOUT=true + EXPOSE 3000 From 8f3973bbffbbb7223f832e86e96e2d84a3f33656 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:13:26 +0100 Subject: [PATCH 3/5] Containerfile: turn `SECRET_KEY_BASE` at build-time into a buildarg this is to not have `SECRET_KEY_BASE` present in the resulting container as it's only required to run some rake tasks --- Containerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Containerfile b/Containerfile index 4d3a6049..637aebee 100644 --- a/Containerfile +++ b/Containerfile @@ -65,14 +65,13 @@ RUN bundle config set without 'development test' \ && yarn install --frozen-lockfile # temporarily set a SECRET_KEY_BASE and copy config files so rake tasks can run -ENV SECRET_KEY_BASE=secret_for_build +ARG SECRET_KEY_BASE=secret_for_build RUN cp config/justask.yml.example config/justask.yml \ && cp config/database.yml.postgres config/database.yml \ && bundle exec rails locale:generate \ && bundle exec i18n export \ && bundle exec rails assets:precompile \ && rm config/justask.yml config/database.yml -ENV SECRET_KEY_BASE= # set some defaults ENV RAILS_LOG_TO_STDOUT=true From b0644b26c7f4b2550b81ce2d80981a48f2269647 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:24:14 +0100 Subject: [PATCH 4/5] allow to set some configuration options via ENV --- config/initializers/10_config.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/config/initializers/10_config.rb b/config/initializers/10_config.rb index 2e12b5f4..deba98c4 100644 --- a/config/initializers/10_config.rb +++ b/config/initializers/10_config.rb @@ -1,5 +1,23 @@ +# frozen_string_literal: true + # Auxiliary config -APP_CONFIG = YAML.load_file(Rails.root.join('config', 'justask.yml')).with_indifferent_access + +APP_CONFIG = {}.with_indifferent_access + +# load yml config if it's present +justask_yml_path = Rails.root.join("config/justask.yml") +APP_CONFIG.merge!(YAML.load_file(justask_yml_path)) if File.exist?(justask_yml_path) + +# load config from ENV where possible +env_config = { + # The site name, shown everywhere + site_name: ENV.fetch("SITE_NAME", nil), + + hostname: ENV.fetch("HOSTNAME", nil), +}.compact +APP_CONFIG.merge!(env_config) # Update rails config for mail -Rails.application.config.action_mailer.default_url_options = { host: APP_CONFIG['hostname'] } +Rails.application.config.action_mailer.default_url_options = { + host: APP_CONFIG["hostname"], +} From 55ff8a0d241a39a77144d77ebe02ed58bfdfd425 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Sat, 4 Feb 2023 07:25:10 +0100 Subject: [PATCH 5/5] enforce trailing commas in multi-line hash literals --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 6091bca9..acd3db74 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -131,3 +131,6 @@ Style/Encoding: Style/EndlessMethod: EnforcedStyle: allow_always + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: consistent_comma