peridot/ci/db.jsonnet

32 lines
1.5 KiB
Text
Raw Normal View History

2022-07-07 20:11:50 +00:00
local stage = std.extVar('stage');
local origUser = std.extVar('user');
local domainUser = std.extVar('domain_user');
local ociRegistry = std.extVar('oci_registry');
local utils = import 'ci/utils.jsonnet';
local user = if domainUser != 'user-orig' then domainUser else origUser;
2022-10-31 02:23:40 +00:00
local default_host_port = 'resf-peridot-dev.ctxqgglmfofx.us-east-2.rds.amazonaws.com:5432';
2022-07-07 20:11:50 +00:00
2022-10-31 02:23:40 +00:00
local host_port = if !utils.helm_mode then default_host_port else '{{ .Values.postgresqlHostPort }}';
2022-07-07 20:11:50 +00:00
2022-10-31 02:23:40 +00:00
{
2022-07-07 20:11:50 +00:00
staged_name(name)::
2022-10-31 02:23:40 +00:00
'%s%s' % [name, if utils.helm_mode then '{{ template !"resf.stage!" . }}!!' else std.strReplace(stage, '-', '')],
2022-07-07 20:11:50 +00:00
2022-10-31 02:23:40 +00:00
dsn_inner(name, no_add=false, ns=null)::
2022-07-07 20:11:50 +00:00
local staged_name = $.staged_name(name);
if utils.local_image then 'postgresql://postgres:postgres@postgres-postgresql.default.svc.cluster.local:5432/%s?sslmode=disable' % staged_name
2022-10-31 02:23:40 +00:00
else 'postgresql://%s%s:REPLACEME@%s' %
[if !no_add then (if utils.helm_mode then '!!{{ .Release.Namespace }}-' else (if stage == '-dev' then '%s-dev' % user else if ns != null then ns else name)+'-') else '', if no_add then name else staged_name, host_port] +
2022-07-07 20:11:50 +00:00
'/%s?sslmode=disable' %
[if no_add then name else staged_name],
2022-10-31 02:23:40 +00:00
dsn(name, no_add=false, ns=null)::
local res = $.dsn_inner(name, no_add, ns);
if utils.helm_mode then '!!{{ if .Values.databaseUrl }}{{ .Values.databaseUrl }}{{ else }}%s{{end}}!!' % res else res,
dsn_legacy(name, no_add=false, ns=null)::
$.dsn(name, no_add, ns),
2022-07-07 20:11:50 +00:00
}