Class: Kamal::EnvFile
- Inherits:
-
Object
- Object
- Kamal::EnvFile
- Defined in:
- lib/kamal/env_file.rb
Overview
Encode an env hash as a string where secret values have been looked up and all values escaped for Docker.
Instance Method Summary collapse
-
#initialize(env) ⇒ EnvFile
constructor
A new instance of EnvFile.
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(env) ⇒ EnvFile
Returns a new instance of EnvFile.
3 4 5 |
# File 'lib/kamal/env_file.rb', line 3 def initialize(env) @env = env end |
Instance Method Details
#to_s ⇒ Object Also known as: to_str
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kamal/env_file.rb', line 7 def to_s env_file = StringIO.new.tap do |contents| if (secrets = @env["secret"]).present? @env.fetch("secret", @env)&.each do |key| contents << docker_env_file_line(key, ENV.fetch(key)) end @env["clear"]&.each do |key, value| contents << docker_env_file_line(key, value) end else @env.fetch("clear", @env)&.each do |key, value| contents << docker_env_file_line(key, value) end end end.string # Ensure the file has some contents to avoid the SSHKIT empty file warning env_file.presence || "\n" end |