Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(chart): render email SMTP env vars (#3015)

Sure Admin (bot)3974fec82075
diff --git a/charts/sure/README.md b/charts/sure/README.md
index b83b8363e2..81249c58fa 100644
--- a/charts/sure/README.md
+++ b/charts/sure/README.md
@@ -555,6 +555,23 @@ rails:
Note: In self-hosted mode, if these env vars are not provided, they will be automatically generated from `SECRET_KEY_BASE`. In managed mode, these env vars must be explicitly provided via environment variables or Rails credentials.
+## Email delivery
+
+Configure SMTP delivery with the top-level `email` values. Non-secret values are rendered into the Rails workloads as the `EMAIL_SENDER`, `APP_DOMAIN`, and `SMTP_*` environment variables that Action Mailer reads.
+
+```yaml
+email:
+ appDomain: app.example.com
+ smtpAddress: smtp.example.com
+ smtpPort: 465
+ smtpUsername: smtp-user
+ smtpTlsEnabled: true
+ smtpTlsSkipVerify: false
+```
+
+If the chart creates the app Secret, a non-empty `rails.secret.values.SMTP_PASSWORD` is injected automatically. When you manage the Secret yourself, provide `SMTP_PASSWORD` through `rails.extraEnvVars` with a `secretKeyRef`. Values set in `rails.settings` or `rails.extraEnv` take precedence over the generated email env vars.
+
## Advanced environment variable injection
For simple string key/value envs, continue to use `rails.extraEnv` and the per-workload `web.extraEnv` / `worker.extraEnv` maps.
@@ -892,6 +909,7 @@ See `values.yaml` for the complete configuration surface, including:
- `image.*`: repository, tag, pullPolicy, imagePullSecrets
- `rails.*`: environment, extraEnv, existingSecret or secret.values, settings
- Also: `rails.extraEnvVars[]` (full EnvVar), `rails.extraEnvFrom[]` (EnvFromSource), and `rails.encryptionEnv.enabled` toggle
+- `email.*`: Action Mailer sender, app domain, and SMTP host/port/user/TLS env values
- `cnpg.*`: enable operator subchart and a Cluster resource, set instances, storage
- `redis-ha.*`: enable dandydev/redis-ha subchart and configure replicas/auth (Sentinel/HA); supports `existingSecret` and `existingSecretPasswordKey`
- `redisOperator.*`: optionally install OT redis-operator (`redisOperator.enabled`) and/or render a `RedisSentinel` CR (`redisOperator.managed.enabled`); configure `name`, `replicas`, `auth.existingSecret/passwordKey`, `persistence.className/size`, scheduling knobs, and `operator.resources` (controller) / `workloadResources` (Redis pods)
diff --git a/charts/sure/templates/_env.tpl b/charts/sure/templates/_env.tpl
index e0aba60d51..c355479206 100644
--- a/charts/sure/templates/_env.tpl
+++ b/charts/sure/templates/_env.tpl
@@ -13,6 +13,7 @@ The helper always injects:
- optional REDIS_URL + REDIS_PASSWORD (includeRedis=true and helper can compute a Redis URL)
- optional HTTPS_PROXY / HTTP_PROXY / NO_PROXY (pipelock.enabled=true)
- rails.settings / rails.extraEnv / rails.extraEnvVars
+- optional email SMTP settings
- optional additional per-workload env / envFrom blocks via extraEnv / extraEnvFrom.
*/}}
@@ -98,6 +99,45 @@ The helper always injects:
- name: {{ $k }}
value: {{ $v | quote }}
{{- end }}
+{{- $railsExtraEnv := (default (dict) $ctx.Values.rails.extraEnv) -}}
+{{- $railsSettings := (default (dict) $ctx.Values.rails.settings) -}}
+{{- $email := (default (dict) $ctx.Values.email) -}}
+{{- if and $email.sender (not (or (hasKey $railsExtraEnv "EMAIL_SENDER") (hasKey $railsSettings "EMAIL_SENDER"))) }}
+- name: EMAIL_SENDER
+ value: {{ $email.sender | quote }}
+{{- end }}
+{{- if and $email.appDomain (not (or (hasKey $railsExtraEnv "APP_DOMAIN") (hasKey $railsSettings "APP_DOMAIN"))) }}
+- name: APP_DOMAIN
+ value: {{ $email.appDomain | quote }}
+{{- end }}
+{{- if and $email.smtpAddress (not (or (hasKey $railsExtraEnv "SMTP_ADDRESS") (hasKey $railsSettings "SMTP_ADDRESS"))) }}
+- name: SMTP_ADDRESS
+ value: {{ $email.smtpAddress | quote }}
+{{- end }}
+{{- if and $email.smtpPort (not (or (hasKey $railsExtraEnv "SMTP_PORT") (hasKey $railsSettings "SMTP_PORT"))) }}
+- name: SMTP_PORT
+ value: {{ $email.smtpPort | quote }}
+{{- end }}
+{{- if and $email.smtpUsername (not (or (hasKey $railsExtraEnv "SMTP_USERNAME") (hasKey $railsSettings "SMTP_USERNAME"))) }}
+- name: SMTP_USERNAME
+ value: {{ $email.smtpUsername | quote }}
+{{- end }}
+{{- $secretValues := (default (dict) $ctx.Values.rails.secret.values) -}}
+{{- if and $ctx.Values.rails.secret.enabled (not $ctx.Values.rails.existingSecret) (hasKey $secretValues "SMTP_PASSWORD") (index $secretValues "SMTP_PASSWORD") (not (or (hasKey $railsExtraEnv "SMTP_PASSWORD") (hasKey $railsSettings "SMTP_PASSWORD"))) }}
+- name: SMTP_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: {{ include "sure.appSecretName" $ctx }}
+ key: SMTP_PASSWORD
+{{- end }}
+{{- if and (ne (toString $email.smtpTlsEnabled) "") (not (or (hasKey $railsExtraEnv "SMTP_TLS_ENABLED") (hasKey $railsSettings "SMTP_TLS_ENABLED"))) }}
+- name: SMTP_TLS_ENABLED
+ value: {{ $email.smtpTlsEnabled | quote }}
+{{- end }}
+{{- if and (ne (toString $email.smtpTlsSkipVerify) "") (not (or (hasKey $railsExtraEnv "SMTP_TLS_SKIP_VERIFY") (hasKey $railsSettings "SMTP_TLS_SKIP_VERIFY"))) }}
+- name: SMTP_TLS_SKIP_VERIFY
+ value: {{ $email.smtpTlsSkipVerify | quote }}
+{{- end }}
{{- if $ctx.Values.rails.externalAssistant.enabled }}
- name: EXTERNAL_ASSISTANT_URL
value: {{ $ctx.Values.rails.externalAssistant.url | quote }}
diff --git a/charts/sure/tests/email-env_test.yaml b/charts/sure/tests/email-env_test.yaml
new file mode 100644
index 0000000000..fbbee6d1b6
--- /dev/null
+++ b/charts/sure/tests/email-env_test.yaml
@@ -0,0 +1,86 @@
+suite: Email environment rendering
+templates:
+ - templates/web-deployment.yaml
+ - templates/worker-deployment.yaml
+
+tests:
+ - it: renders email values into Rails SMTP environment variables
+ set:
+ email:
+ appDomain: app.example.com
+ smtpAddress: smtp.example.com
+ smtpPort: 2465
+ smtpUsername: smtp-user
+ smtpTlsEnabled: true
+ smtpTlsSkipVerify: false
+ rails:
+ secret:
+ enabled: true
+ values:
+ SECRET_KEY_BASE: test-secret-key-base
+ SMTP_PASSWORD: test-smtp-password
+ asserts:
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: EMAIL_SENDER
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: APP_DOMAIN
+ value: app.example.com
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_ADDRESS
+ value: smtp.example.com
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_PORT
+ value: "2465"
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_USERNAME
+ value: smtp-user
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: RELEASE-NAME-sure-app
+ key: SMTP_PASSWORD
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_TLS_ENABLED
+ value: "true"
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_TLS_SKIP_VERIFY
+ value: "false"
+
+ - it: allows rails.extraEnv to override generated email env vars
+ set:
+ email:
+ smtpAddress: smtp.example.com
+ smtpPort: 2465
+ rails:
+ extraEnv:
+ SMTP_ADDRESS: override.example.com
+ asserts:
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_ADDRESS
+ value: override.example.com
+ - contains:
+ path: spec.template.spec.containers[0].env
+ content:
+ name: SMTP_PORT
+ value: "2465"
diff --git a/charts/sure/values.yaml b/charts/sure/values.yaml
index ad80622b32..8e2103232e 100644
--- a/charts/sure/values.yaml
+++ b/charts/sure/values.yaml
@@ -68,6 +68,19 @@ rails:
# name: external-assistant-secret
# key: token
+# Email delivery configuration.
+# SMTP_PASSWORD is sensitive. If the chart creates the app Secret, a non-empty
+# rails.secret.values.SMTP_PASSWORD is injected automatically; otherwise provide
+# SMTP_PASSWORD through rails.extraEnvVars with valueFrom.secretKeyRef.
+email:
+ sender: ""
+ appDomain: ""
+ smtpAddress: ""
+ smtpPort: ""
+ smtpUsername: ""
+ smtpTlsEnabled: ""
+ smtpTlsSkipVerify: ""
+
# Database: CloudNativePG (operator chart dependency) and a Cluster CR (optional)
cloudnative-pg:
config: