Service definitions can export environment variables.

This commit is contained in:
Luka Vandervelden 2019-06-09 15:20:36 +02:00
parent 5b864dcb58
commit 21f8d2d7d2

View File

@ -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 isnt 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|