-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Specify env file + envify on the config file #825
base: main
Are you sure you want to change the base?
Changes from all commits
8eb78d4
2250a2e
03df0a9
d1bb836
8f21f7b
2571da2
4959f31
de38809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
class Kamal::Configuration::Env | ||
attr_reader :secrets_keys, :clear, :secrets_file | ||
attr_reader :secrets_keys, :clear, :secrets_file, :env_file | ||
delegate :argumentize, to: Kamal::Utils | ||
|
||
def self.from_config(config:, secrets_file: nil) | ||
secrets_keys = config.fetch("secret", []) | ||
clear = config.fetch("clear", config.key?("secret") || config.key?("tags") ? {} : config) | ||
env_key_config = config.class == Kamal::Configuration ? config.env : config.fetch("env", {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "config" variable name is not too clear to what this represents. This is not "config", this is the "env" key from config with this values. Maybe we can also extract this to his own PR also? |
||
secrets_keys = env_key_config.fetch("secret", []) | ||
clear = env_key_config.fetch("clear", env_key_config.key?("secret") || env_key_config.key?("tags") ? {} : env_key_config) | ||
# TODO: Support a wide env_file | ||
env_file = config.class == Kamal::Configuration ? nil : config.fetch("env_file", nil) | ||
|
||
new clear: clear, secrets_keys: secrets_keys, secrets_file: secrets_file | ||
new clear: clear, secrets_keys: secrets_keys, secrets_file: secrets_file, env_file: env_file | ||
end | ||
|
||
def initialize(clear:, secrets_keys:, secrets_file:) | ||
def initialize(clear:, secrets_keys:, secrets_file:, env_file:) | ||
@clear = clear | ||
@secrets_keys = secrets_keys | ||
@secrets_file = secrets_file | ||
@env_file = env_file | ||
end | ||
|
||
def args | ||
|
@@ -24,7 +28,13 @@ def secrets_io | |
end | ||
|
||
def secrets | ||
@secrets ||= secrets_keys.to_h { |key| [ key, ENV.fetch(key) ] } | ||
# TODO: More than one @env_file | ||
# TODO: Considerer a merge between env_file and env | ||
if @env_file | ||
Dotenv::Environment.new(@env_file) | ||
else | ||
secrets_keys.to_h { |key| [ key, ENV.fetch(key) ] } | ||
end | ||
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main goal. Not sure how we can tackle this. Any thoughts @djmb ? (sorry to tag you, but I saw that you did the last merges around here) |
||
end | ||
|
||
def secrets_directory | ||
|
@@ -35,6 +45,7 @@ def merge(other) | |
self.class.new \ | ||
clear: @clear.merge(other.clear), | ||
secrets_keys: @secrets_keys | other.secrets_keys, | ||
env_file: @env_file ? @env_file : other.env_file, | ||
secrets_file: secrets_file | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract this to his own PR.