fix(laravel): apply runtime DB config and startup entrypoint

Laravel images no longer bake config:cache at build time, which ignored
K8s DB env vars. Add DB_CONNECTION, clear config on boot, generate APP_KEY
when missing, run migrations, and rebuild caches at container start.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
keyhan
2026-05-15 00:30:17 +03:30
parent cca6cdc1a5
commit 5fd4069821
4 changed files with 41 additions and 33 deletions
@@ -90,6 +90,25 @@ PostgreSQL PGDATA path — must be a subdirectory of the mount to avoid "initdb:
/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
*/}}
@@ -54,13 +54,7 @@ spec:
- name: DATABASE_URL
value: "postgresql://$(DB_USER):$(DB_PASSWORD)@{{ include "cloudhost-app.dbDeploymentName" . }}:5432/{{ include "cloudhost-app.dbName" . }}"
{{- if or (eq .Values.app.runtime "laravel") (eq .Values.app.runtime "php") }}
- name: DB_DATABASE
value: {{ include "cloudhost-app.dbName" . }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ $name }}-db-secret
key: username
{{ include "cloudhost-app.laravelDbEnv" . }}
{{- end }}
{{- end }}
{{- if and .Values.database.enabled (eq .Values.database.type "mysql") }}
@@ -83,13 +77,7 @@ spec:
- name: DATABASE_URL
value: "mysql://$(DB_USER):$(DB_PASSWORD)@{{ include "cloudhost-app.dbDeploymentName" . }}:3306/{{ include "cloudhost-app.dbName" . }}"
{{- if or (eq .Values.app.runtime "laravel") (eq .Values.app.runtime "php") }}
- name: DB_DATABASE
value: {{ include "cloudhost-app.dbName" . }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ $name }}-db-secret
key: username
{{ include "cloudhost-app.laravelDbEnv" . }}
{{- end }}
{{- end }}
{{- if and .Values.database.enabled (eq .Values.database.type "mariadb") }}
@@ -112,13 +100,7 @@ spec:
- name: DATABASE_URL
value: "mysql://$(DB_USER):$(DB_PASSWORD)@{{ include "cloudhost-app.dbDeploymentName" . }}:3306/{{ include "cloudhost-app.dbName" . }}"
{{- if or (eq .Values.app.runtime "laravel") (eq .Values.app.runtime "php") }}
- name: DB_DATABASE
value: {{ include "cloudhost-app.dbName" . }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ $name }}-db-secret
key: username
{{ include "cloudhost-app.laravelDbEnv" . }}
{{- end }}
{{- end }}
{{- if and .Values.database.enabled (eq .Values.database.type "mongodb") }}
@@ -143,13 +125,7 @@ spec:
- name: DATABASE_URL
value: "mongodb://$(DB_USER):$(DB_PASSWORD)@{{ include "cloudhost-app.dbDeploymentName" . }}:27017/{{ include "cloudhost-app.dbName" . }}?authSource=admin"
{{- if or (eq .Values.app.runtime "laravel") (eq .Values.app.runtime "php") }}
- name: DB_DATABASE
value: {{ include "cloudhost-app.dbName" . }}
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: {{ $name }}-db-secret
key: username
{{ include "cloudhost-app.laravelDbEnv" . }}
{{- end }}
{{- end }}
{{- /* Redis connection env vars */}}