-
Notifications
You must be signed in to change notification settings - Fork 50
/
create_env_files.erb.tmpl
47 lines (41 loc) · 1.01 KB
/
create_env_files.erb.tmpl
1
2
3
4
5
6
7
8
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
mkdir -p /var/vcap/jobs/{{.Name}}/config/env
<%
# vim: ft=eruby
def env_file_perms(fn)
<<~EOS
if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then
chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} #{fn}
fi
chmod 0600 #{fn}
EOS
end
def env_file_content(v)
case v
when Array
v.collect(&:chomp).join("\n").chomp + "\n"
when String
v.chomp + "\n"
else
v.to_json + "\n"
end
end
def env_file_writer(v, env)
path = "/var/vcap/jobs/{{.Name}}/config/env/#{env}"
case v
when Hash
v.collect do |k, v|
fn = "#{path}_#{k}"
"cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}"
end.join("\n\n")
else
"cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}"
end
end
-%>
{{ range $prop := .EnvProperties -}}
{{- if $prop.EnvFile -}}
<% if_p("{{$prop.Name}}") do |v| -%>
<%= env_file_writer(v, "{{$prop.EnvFile}}") %>
<% end -%>
{{ end -}}
{{- end -}}