From 9399e3223467cdacd010e70b58ad6093e128213d Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Fri, 8 Mar 2024 16:40:58 +0000 Subject: [PATCH] fix: don't override paths in dockerfile This allows for these paths to continue to be set in the config file or environment variable while still maintaining the default of having the default paths in the same directory as the postal config file. --- Dockerfile | 3 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- lib/postal/config_schema.rb | 19 ++++++++++++++++--- spec/lib/postal/legacy_config_source_spec.rb | 4 +++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index a0a209e..b1f4a2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,9 +48,6 @@ RUN echo $VERSION > VERSION # Set paths for when running in a container ENV POSTAL_CONFIG_FILE_PATH=/config/postal.yml -ENV POSTAL_SIGNING_KEY_PATH=/config/signing.key -ENV SMTP_SERVER_TLS_CERTIFICATE_PATH=/config/smtp.cert -ENV SMTP_SERVER_TLS_PRIVATE_KEY_PATH=/config/smtp.key # Set the CMD ENTRYPOINT [ "/docker-entrypoint.sh" ] diff --git a/Gemfile b/Gemfile index 46eca03..c3efa37 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem "hashie" gem "highline", require: false gem "kaminari" gem "klogger-logger" -gem "konfig-config", "~> 2.0" +gem "konfig-config", "~> 3.0" gem "mail" gem "moonrope" gem "mysql2" diff --git a/Gemfile.lock b/Gemfile.lock index 172a522..c6b997b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,7 +149,7 @@ GEM concurrent-ruby (>= 1.0, < 2.0) json rouge (>= 3.30, < 5.0) - konfig-config (2.1.1) + konfig-config (3.0.0) hashie loofah (2.22.0) crass (~> 1.0.2) @@ -353,7 +353,7 @@ DEPENDENCIES jquery-rails kaminari klogger-logger - konfig-config (~> 2.0) + konfig-config (~> 3.0) mail moonrope mysql2 diff --git a/lib/postal/config_schema.rb b/lib/postal/config_schema.rb index 42a661a..45a5508 100644 --- a/lib/postal/config_schema.rb +++ b/lib/postal/config_schema.rb @@ -68,7 +68,8 @@ module Postal string :signing_key_path do description "Path to the private key used for signing" - default "config/postal/signing.key" + default "$config-file-root/signing.key" + transform { |v| Postal.substitute_config_file_root(v) } end string :smtp_relays do @@ -253,12 +254,14 @@ module Postal string :tls_certificate_path do description "The path to the SMTP server's TLS certificate" - default "config/postal/smtp.cert" + default "$config-file-root/smtp.cert" + transform { |v| Postal.substitute_config_file_root(v) } end string :tls_private_key_path do description "The path to the SMTP server's TLS private key" - default "config/postal/smtp.key" + default "$config-file-root/smtp.key" + transform { |v| Postal.substitute_config_file_root(v) } end string :tls_ciphers do @@ -502,4 +505,14 @@ module Postal end end + class << self + + def substitute_config_file_root(string) + return if string.nil? + + string.gsub(/\$config-file-root/i, File.dirname(Postal.config_file_path)) + end + + end + end diff --git a/spec/lib/postal/legacy_config_source_spec.rb b/spec/lib/postal/legacy_config_source_spec.rb index a3b6955..0032a3b 100644 --- a/spec/lib/postal/legacy_config_source_spec.rb +++ b/spec/lib/postal/legacy_config_source_spec.rb @@ -17,7 +17,9 @@ module Postal # by the schema itself. Otherwise, we might see a value returned that # looks correct but is actually the default rather than the value from # config file. - allow_any_instance_of(Konfig::SchemaAttribute).to receive(:default).and_return(nil) + allow_any_instance_of(Konfig::SchemaAttribute).to receive(:default) do |a| + a.array? ? [] : nil + end end let(:source) { described_class.new(SOURCE_CONFIG) }