diff --git a/src/main.cr b/src/main.cr index e0f51a5..4231e6f 100644 --- a/src/main.cr +++ b/src/main.cr @@ -67,6 +67,11 @@ class ServiceDefinition checks: { type: Array(Checks), default: [] of Checks + }, + environment_variables: { + type: Array(String), + key: "environment-variables", + default: [] of String } }) @@ -259,6 +264,17 @@ class Service def export_environment_variables ENV["SERVICE_ENVIRONMENT"] = @environment.name ENV["SERVICE_ENVIRONMENT_TYPE"] = @environment.type.to_s + + # FIXME: Parsing should probably be done… when parsing the file. + # FIXME: Parsing is probably a bit primitive. Maybe this isn’t the right way of defining this. + @reference.environment_variables.each do |string| + # FIXME: Should probably deserve a warning. + variable = string.match(/^[^=]*=/).not_nil![0] + value = string[variable.size..string.size] + variable = variable[0..variable.size-2] + + ENV[variable] = value + end end private def evaluate(string) string.gsub /%{[a-zA-Z]+}/ do |match|