Files
cloud-host/backend/helm/cloudhost-app/templates/_helpers.tpl
T
keyhan 22359be40e fix(platform): apply production hardening from audit plan
Close billing, tenancy, migration, build, and CI/CD gaps identified in the
audit: wallet/gateway guards, full-UUID namespaces, idempotent migrations with
base schema, stateful service stability, safer Dockerfiles/git builds, and
platform chart hardening (Redis auth, RollingUpdate, backups, Swagger off).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-02 19:35:07 +03:30

161 lines
5.0 KiB
Smarty

{{/*
CloudHost App template helpers
*/}}
{{/*
Expand the name of the chart.
*/}}
{{- define "cloudhost-app.name" -}}
{{- .Values.app.name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Namespace for the release.
*/}}
{{- define "cloudhost-app.namespace" -}}
{{- .Values.app.namespace }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "cloudhost-app.labels" -}}
app: {{ include "cloudhost-app.name" . }}
app.kubernetes.io/managed-by: cloudhost-helm
runtime: {{ .Values.app.runtime }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "cloudhost-app.selectorLabels" -}}
app: {{ include "cloudhost-app.name" . }}
{{- end }}
{{/*
Database name (app name with dashes replaced by underscores)
*/}}
{{- define "cloudhost-app.dbName" -}}
{{- .Values.app.name | replace "-" "_" }}
{{- end }}
{{/*
Database deployment name
*/}}
{{- define "cloudhost-app.dbDeploymentName" -}}
{{- printf "%s-db" .Values.app.name }}
{{- end }}
{{/*
Optional mirror registry prefix for Docker Hub images.
Usage: {{ include "cloudhost-app.baseImage" (dict "root" $ "image" "redis:7.2-alpine") }}
*/}}
{{- define "cloudhost-app.baseImage" -}}
{{- $reg := "" -}}
{{- with .root.Values.images -}}{{- $reg = .baseRegistry | default "" -}}{{- end -}}
{{- if $reg -}}{{ printf "%s/%s" $reg .image }}{{- else -}}{{ .image }}{{- end -}}
{{- end }}
{{/*
Database image auto-computed from type + version if not explicitly set
*/}}
{{- define "cloudhost-app.dbImage" -}}
{{- if .Values.database.image }}
{{- .Values.database.image }}
{{- else if eq .Values.database.type "postgresql" }}
{{- include "cloudhost-app.baseImage" (dict "root" $ "image" (printf "postgres:%s-alpine" .Values.database.version)) }}
{{- else if eq .Values.database.type "mariadb" }}
{{- include "cloudhost-app.baseImage" (dict "root" $ "image" (printf "mariadb:%s" .Values.database.version)) }}
{{- else if eq .Values.database.type "mongodb" }}
{{- include "cloudhost-app.baseImage" (dict "root" $ "image" (printf "mongo:%s" .Values.database.version)) }}
{{- else }}
{{- include "cloudhost-app.baseImage" (dict "root" $ "image" (printf "mysql:%s" .Values.database.version)) }}
{{- end }}
{{- end }}
{{/*
Database port
*/}}
{{- define "cloudhost-app.dbPort" -}}
{{- if eq .Values.database.type "postgresql" }}5432
{{- else if eq .Values.database.type "mongodb" }}27017
{{- else }}3306
{{- end }}
{{- end }}
{{/*
Database data mount path (volume mount target)
*/}}
{{- define "cloudhost-app.dbDataPath" -}}
{{- if eq .Values.database.type "postgresql" }}/var/lib/postgresql/data
{{- else if eq .Values.database.type "mongodb" }}/data/db
{{- else }}/var/lib/mysql
{{- end }}
{{- end }}
{{/*
PostgreSQL PGDATA path must be a subdirectory of the mount to avoid "initdb: directory not empty" errors
*/}}
{{- define "cloudhost-app.pgDataDir" -}}
/var/lib/postgresql/data/pgdata
{{- end }}
{{- define "cloudhost-app.laravelDbConnection" -}}
{{- if eq .Values.database.type "postgresql" }}pgsql{{- else if eq .Values.database.type "mongodb" }}mongodb{{- else }}mysql{{- end }}
{{- end }}
{{/*
Laravel-specific DB env vars (DB_CONNECTION, DB_DATABASE, DB_USERNAME)
*/}}
{{- define "cloudhost-app.laravelDbEnv" -}}
- name: DB_CONNECTION
value: {{ include "cloudhost-app.laravelDbConnection" . | quote }}
- name: DB_DATABASE
value: {{ include "cloudhost-app.dbName" . }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ include "cloudhost-app.name" . }}-db-secret
key: username
{{- end }}
{{/*
App storage mount path based on runtime
*/}}
{{- define "cloudhost-app.storageMountPath" -}}
{{- if eq .Values.app.runtime "wordpress" }}/var/www/html/wp-content
{{- else if or (eq .Values.app.runtime "laravel") (eq .Values.app.runtime "php") }}/var/www/html/storage
{{- else if eq .Values.app.runtime "django" }}/app/media
{{- else }}/app/data
{{- end }}
{{- end }}
{{/*
Default log paths based on runtime
*/}}
{{- define "cloudhost-app.defaultLogPaths" -}}
{{- if eq .Values.app.runtime "wordpress" }}/var/www/html/wp-content/debug.log,/var/log/app/*.log
{{- else if eq .Values.app.runtime "laravel" }}/var/www/html/storage/logs/*.log,/var/log/app/*.log
{{- else if or (eq .Values.app.runtime "php") }}/var/www/html/storage/logs/*.log,/var/log/php/*.log,/var/log/app/*.log
{{- else }}/var/log/app/*.log
{{- end }}
{{- end }}
{{/*
Shell start command for stdout capture (must match CloudHost-generated images).
*/}}
{{- define "cloudhost-app.runtimeStartCommand" -}}
{{- if eq .Values.app.runtime "nodejs" -}}
if [ -f /app/.mode ] && [ "$(cat /app/.mode)" = "standalone" ] && [ -f server.js ]; then node server.js; else npm start; fi
{{- else if eq .Values.app.runtime "go" -}}
./main
{{- else if eq .Values.app.runtime "dotnet" -}}
DLL=$(find . -maxdepth 1 -name '*.dll' ! -name '*.deps.dll' ! -name '*.runtimeconfig.dll' | head -1) && dotnet "$DLL"
{{- else -}}
{{- end }}
{{- end }}
{{- define "cloudhost-app.loggingWrapEnabled" -}}
{{- and .Values.elasticsearch.enabled (include "cloudhost-app.runtimeStartCommand" .) -}}
{{- end }}