Allow dynamic accessory files to reference declared ENVs
This commit is contained in:
@@ -74,12 +74,19 @@ class Mrsk::Configuration::Assessory
|
|||||||
|
|
||||||
def expand_local_file(local_file)
|
def expand_local_file(local_file)
|
||||||
if local_file.end_with?("erb")
|
if local_file.end_with?("erb")
|
||||||
read_dynamic_file(local_file)
|
with_clear_env_loaded { read_dynamic_file(local_file) }
|
||||||
else
|
else
|
||||||
Pathname.new(File.expand_path(local_file)).to_s
|
Pathname.new(File.expand_path(local_file)).to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_clear_env_loaded
|
||||||
|
(env["clear"] || env).each { |k, v| ENV[k] = v }
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
(env["clear"] || env).each { |k, v| ENV.delete(k) }
|
||||||
|
end
|
||||||
|
|
||||||
def read_dynamic_file(local_file)
|
def read_dynamic_file(local_file)
|
||||||
StringIO.new(ERB.new(IO.read(local_file)).result)
|
StringIO.new(ERB.new(IO.read(local_file)).result)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
@deploy[:accessories]["mysql"]["files"] << "test/fixtures/files/structure.sql.erb:/docker-entrypoint-initdb.d/structure.sql"
|
@deploy[:accessories]["mysql"]["files"] << "test/fixtures/files/structure.sql.erb:/docker-entrypoint-initdb.d/structure.sql"
|
||||||
@config = Mrsk::Configuration.new(@deploy)
|
@config = Mrsk::Configuration.new(@deploy)
|
||||||
|
|
||||||
assert_equal "This was dynamically expanded", @config.accessory(:mysql).files.keys[2].read
|
assert_match "This was dynamically expanded", @config.accessory(:mysql).files.keys[2].read
|
||||||
|
assert_match "%", @config.accessory(:mysql).files.keys[2].read
|
||||||
end
|
end
|
||||||
|
|
||||||
test "directories" do
|
test "directories" do
|
||||||
|
|||||||
3
test/fixtures/files/structure.sql.erb
vendored
3
test/fixtures/files/structure.sql.erb
vendored
@@ -1 +1,2 @@
|
|||||||
<%= "This was dynamically expanded" %>
|
<%= "This was dynamically expanded" %>
|
||||||
|
<%= ENV["MYSQL_ROOT_HOST"] %>
|
||||||
|
|||||||
Reference in New Issue
Block a user