9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/ecsutil/config.rb', line 9
def self.read(path, stage, outputs = {})
data = File.read(path).gsub(/(\$tf.([\w]+))+/i) do |m|
key = $2
fail "Terraform output key #{key} not found!" unless outputs[key]
outputs[key]
end
result = YAML.load(data).tap do |config|
fail "App name is required" unless config["app"]
fail "App env is required" unless config["env"]
fail "Cluster is required" unless config["cluster"]
fail "Repository is required" unless config["repository"]
if !config["aws_profile"] && !ENV["AWS_PROFILE"]
fail "AWS profile is not set! Set 'aws_profile' var in config or use AWS_PROFILE env var!"
end
ENV["AWS_PROFILE"] = config["aws_profile"]
config["user"] ||= `whoami`.strip
config["stage"] ||= stage
config["namespace"] ||= sprintf("%s-%s", config["app"], config["env"])
config["tasks"] ||= {}
config["scheduled_tasks"] ||= {}
config["services"] ||= {}
parent_dir = File.expand_path(File.join(File.dirname(path), ".."))
config.merge!(
"secrets_vaultpass" => File.join(parent_dir, "vaultpass"),
"secrets_file" => File.join(File.dirname(path), "#{stage}/secrets"),
"secrets_key" => outputs["kms_key"],
"secrets_prefix" => sprintf("/%s", config["namespace"]),
"secrets_data" => {}
)
config["git_commit"] ||= `git rev-parse HEAD`.strip
config["git_branch"] ||= `git rev-parse --abbrev-ref HEAD`.strip
end
Config.new(result)
end
|