Escape newlines in docker env files
When env variables were passed via `-e` newlines were escaped. This updates the env file to do the same thing.
This commit is contained in:
@@ -92,6 +92,13 @@ module Kamal::Utils
|
||||
.gsub(DOLLAR_SIGN_WITHOUT_SHELL_EXPANSION_REGEX, '\$')
|
||||
end
|
||||
|
||||
# Escape a value to make it safe to dump in a docker file.
|
||||
def escape_docker_env_file_value(value)
|
||||
# Doublequotes are treated literally in docker env files
|
||||
# so remove leading and trailing ones and unescape any others
|
||||
value.to_s.dump[1..-2].gsub(/\\"/, "\"")
|
||||
end
|
||||
|
||||
# Abbreviate a git revhash for concise display
|
||||
def abbreviate_version(version)
|
||||
if version
|
||||
@@ -109,10 +116,6 @@ module Kamal::Utils
|
||||
end
|
||||
|
||||
def docker_env_file_line(key, value)
|
||||
if key.include?("\n") || value.to_s.include?("\n")
|
||||
raise ArgumentError, "docker env file format does not support newlines in keys or values, key: #{key}"
|
||||
end
|
||||
|
||||
"#{key.to_s}=#{value.to_s}\n"
|
||||
"#{key.to_s}=#{escape_docker_env_file_value(value)}\n"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user