diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index d5192c37c17..06fefc3133f 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -165,7 +165,7 @@ jobs: name: install needs: chart runs-on: ${{ (vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith') && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }} - timeout-minutes: 25 + timeout-minutes: 55 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 with: @@ -192,6 +192,43 @@ jobs: - name: Run helm test run: helm test sim --namespace sim --timeout 5m + # Kubernetes refuses any change to a StatefulSet's volumeClaimTemplates, so + # a label that moves with the chart version there breaks every upgrade of + # the bundled Postgres while fresh installs keep passing. Install the newest + # published chart in its own namespace, then upgrade it to this checkout + # with the same values, so ci/default-values.yaml and ci/kind-overlay.yaml + # must stay valid for the previous published chart too. + - name: Upgrade from the published chart + run: | + set -euo pipefail + chart=oci://ghcr.io/simstudioai/charts/sim + # The newest published version strictly below this checkout's, so a rerun after this + # version is published still tests an upgrade rather than same to same. Helm cannot list + # OCI tags, so read them from the registry API with an anonymous pull token. + current=$(awk '/^version:/ {print $2}' helm/sim/Chart.yaml) + token=$(curl -fsS "https://ghcr.io/token?scope=repository:simstudioai/charts/sim:pull" | jq -r .token) + previous=$(curl -fsS -H "Authorization: Bearer ${token}" \ + "https://ghcr.io/v2/simstudioai/charts/sim/tags/list?n=1000" \ + | jq -r '.tags[]' \ + | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \ + | { cat; echo "$current"; } | sort -uV \ + | awk -v current="$current" '$0 == current {print prev; exit} {prev = $0}') + if [ -z "$previous" ]; then + echo "::error::No published chart version below ${current} to upgrade from." + exit 1 + fi + echo "Installing published chart ${previous}, then upgrading to this checkout (${current})" + helm install sim-upgrade "$chart" --version "$previous" \ + --namespace sim-upgrade --create-namespace \ + --values helm/sim/ci/default-values.yaml \ + --values helm/sim/ci/kind-overlay.yaml \ + --wait --timeout 10m + helm upgrade sim-upgrade helm/sim \ + --namespace sim-upgrade \ + --values helm/sim/ci/default-values.yaml \ + --values helm/sim/ci/kind-overlay.yaml \ + --wait --timeout 10m + # After the test, so it also explains a failed probe, not only a failed # install. A failed test pod is kept (the hook deletes it only on success), # so its log says which URL refused. @@ -205,6 +242,8 @@ jobs: kubectl -n sim logs deploy/sim-app --tail=80 || true kubectl -n sim logs deploy/sim-realtime --tail=80 || true kubectl -n sim logs sim-test-connection || true + kubectl -n sim-upgrade get pods -o wide || true + kubectl -n sim-upgrade get events --sort-by=.lastTimestamp | tail -20 || true # Resolved once and shared, so the two publish paths cannot package the same # immutable chart version with different appVersions -- they run in parallel, @@ -296,7 +335,7 @@ jobs: # Derives appVersion rather than checking it, so the published chart cannot # be pinned to an older Sim than the release it ships with. The committed - # value is kept current too, but nothing depends on a human remembering. + # value is not kept current; only this step sets the one that ships. - name: Sync chart appVersion to the release env: APP_VERSION: ${{ needs.release-version.outputs.version }} @@ -491,7 +530,7 @@ jobs: # Derives appVersion rather than checking it, so the published chart cannot # be pinned to an older Sim than the release it ships with. The committed - # value is kept current too, but nothing depends on a human remembering. + # value is not kept current; only this step sets the one that ships. - name: Sync chart appVersion to the release if: steps.pages.outputs.exists == 'true' env: diff --git a/apps/docs/content/docs/platform/self-hosting/kubernetes.mdx b/apps/docs/content/docs/platform/self-hosting/kubernetes.mdx index 142cc2da857..d2d40d5da3c 100644 --- a/apps/docs/content/docs/platform/self-hosting/kubernetes.mdx +++ b/apps/docs/content/docs/platform/self-hosting/kubernetes.mdx @@ -88,7 +88,7 @@ Open [http://localhost:3000](http://localhost:3000). For public access, complete ## Public access [#key-configuration] -Configure a public app origin, realtime routing, allowed origins, and TLS together. This same-host example belongs in `public-values.yaml`; replace the ingress class with your installed controller's class: +Configure a public app origin and TLS together; realtime is served on the app host under `/socket.io` by default. This same-host example belongs in `public-values.yaml`; replace the ingress class with your installed controller's class: ```yaml app: @@ -96,14 +96,10 @@ app: tag: "v0.9.72" env: NEXT_PUBLIC_APP_URL: "https://sim.yourdomain.com" - BETTER_AUTH_URL: "https://sim.yourdomain.com" - NEXT_PUBLIC_SOCKET_URL: "https://sim.yourdomain.com" realtime: image: tag: "v0.9.72" - env: - ALLOWED_ORIGINS: "https://sim.yourdomain.com" migrations: image: @@ -120,17 +116,12 @@ ingress: nginx.ingress.kubernetes.io/force-ssl-redirect: null app: host: sim.yourdomain.com - realtime: - host: sim.yourdomain.com - paths: - - path: /socket.io - pathType: Prefix tls: enabled: true secretName: sim-tls ``` -The app and realtime consume shared app env values; `ALLOWED_ORIGINS` explicitly admits the public app origin. Matching ingress hosts lets the chart route `/socket.io` before the app's `/` path. Keep app, realtime, and migrations on the same image release. +The app and realtime consume shared app env values: `BETTER_AUTH_URL` follows `NEXT_PUBLIC_APP_URL`, and realtime always admits that origin (`realtime.env.ALLOWED_ORIGINS` is only for extra origins). With `ingress.realtime.host` empty, the chart routes `/socket.io` on the app host before the app's `/` path. Keep app, realtime, and migrations on the same image release. Create `sim-tls` in `simstudio` from your certificate and private key, or configure your certificate manager to populate that Secret: @@ -141,12 +132,9 @@ kubectl create secret tls sim-tls -n simstudio \ For a fresh public installation, create the namespace before creating the Secret. Configure DNS and the controller's own HTTPS redirect, upload-size, WebSocket, timeout, and streaming settings. The `null` above removes the chart's legacy nginx redirect annotation; it does not configure another controller. -For a separate realtime hostname, change all three fields together: +A separate realtime hostname is optional. Set it, and the chart points the app at it through `NEXT_PUBLIC_SOCKET_URL` (unless you set that yourself, which you must in `app.secrets.existingSecret` mode): ```yaml -app: - env: - NEXT_PUBLIC_SOCKET_URL: "https://sim-ws.yourdomain.com" ingress: realtime: host: sim-ws.yourdomain.com @@ -155,7 +143,7 @@ ingress: pathType: Prefix ``` -Keep `ALLOWED_ORIGINS` set to the app origin, and use a TLS certificate covering both hosts. App/auth URLs remain on `sim.yourdomain.com`. +Use a TLS certificate covering both hosts. App/auth URLs remain on `sim.yourdomain.com`. Apply your complete values with `helm upgrade --install`, retaining the same secrets as installation. For inline mode, repeat the secret `--set` arguments from the install command and add `-f public-values.yaml`. For secret-store mode, use a complete values file defining that strategy. @@ -238,8 +226,7 @@ Configure model provider keys, such as `OPENAI_API_KEY`, through the same select Use a cloud example as a starting file, not a complete install configuration. Fetch it from the release corresponding to the pinned chart example: ```bash -SIM_RELEASE=v0.9.72 -curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/$SIM_RELEASE/helm/sim/examples/values-aws.yaml" +curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-aws.yaml" ``` Choose `values-aws.yaml` for EKS, `values-azure.yaml` for AKS, or `values-gcp.yaml` for GKE. Review and replace provider-specific fields before installation: diff --git a/apps/docs/content/docs/platform/self-hosting/networking.mdx b/apps/docs/content/docs/platform/self-hosting/networking.mdx index 19c953b1641..229351f23bf 100644 --- a/apps/docs/content/docs/platform/self-hosting/networking.mdx +++ b/apps/docs/content/docs/platform/self-hosting/networking.mdx @@ -22,33 +22,28 @@ sim.yourdomain.com/ → app:3000 sim.yourdomain.com/socket.io → realtime:3002 ``` -`NEXT_PUBLIC_SOCKET_URL` can be left unset — the client defaults to the page origin. +`NEXT_PUBLIC_SOCKET_URL` can be left unset — the client defaults to the page origin. This is the Helm chart's default: with `ingress.realtime.host` empty, it routes `/socket.io` on the app host. -Use separate hostnames when your ingress setup cannot split paths across backends. GKE's example values use this layout. +Optionally, use separate hostnames when your ingress setup cannot split paths across backends. GKE's example values use this layout. ``` sim.yourdomain.com → app:3000 sim-ws.yourdomain.com → realtime:3002 ``` -Then tell the client where realtime lives, and tell realtime which origins to accept: +Then tell the client where realtime lives: ```yaml app: env: NEXT_PUBLIC_APP_URL: "https://sim.yourdomain.com" - BETTER_AUTH_URL: "https://sim.yourdomain.com" NEXT_PUBLIC_SOCKET_URL: "https://sim-ws.yourdomain.com" - -realtime: - env: - ALLOWED_ORIGINS: "https://sim.yourdomain.com" ``` -`ALLOWED_ORIGINS` is the CORS allowlist realtime enforces on socket connections; it must contain the app's origin. The URL keys only need to be set once under `app.env` — the chart writes them into a Secret both Deployments consume. +With the Helm chart, setting `ingress.realtime.host` is enough: the chart sets `NEXT_PUBLIC_SOCKET_URL` to that host unless you do (set it yourself in `app.secrets.existingSecret` mode). Realtime always accepts the `NEXT_PUBLIC_APP_URL` origin; `ALLOWED_ORIGINS` is only for extra origins. The URL keys only need to be set once under `app.env` — the chart writes them into a Secret both Deployments consume. Both hostnames need DNS records and TLS certificates. diff --git a/apps/docs/content/docs/platform/self-hosting/scaling.mdx b/apps/docs/content/docs/platform/self-hosting/scaling.mdx index 0b98104a6f6..ae04fbfe7ea 100644 --- a/apps/docs/content/docs/platform/self-hosting/scaling.mdx +++ b/apps/docs/content/docs/platform/self-hosting/scaling.mdx @@ -39,7 +39,7 @@ app: cpu: 1000m ``` -The `resources` block above is the chart's default — it is shown so the numbers are visible, not because it changes anything. Only `replicaCount` needs setting unless you are raising the ceiling. +The `resources` block above is the chart's default — it is shown so the numbers are visible, not because it changes anything. Only `replicaCount` needs setting unless you are raising the ceiling. More than one replica needs object storage (S3, Azure Blob, or GCS via `STORAGE_PROVIDER`), or the chart fails to render; `app.storage.allowLocalWithReplicas=true` opts out and keeps uploads on each pod, lost on restart. The app orchestrates workflows, and local JavaScript runs in Node child workers inside its container. Those workers and in-memory file parsing share the pod's memory limit. OOMKills can terminate in-flight runs. diff --git a/apps/docs/content/docs/platform/self-hosting/verify.mdx b/apps/docs/content/docs/platform/self-hosting/verify.mdx index a649427f341..0f1ca56b6fb 100644 --- a/apps/docs/content/docs/platform/self-hosting/verify.mdx +++ b/apps/docs/content/docs/platform/self-hosting/verify.mdx @@ -107,7 +107,7 @@ Expect `simstudio`, `realtime`, `db`, `redis`, and `cron` to be running, with `m | --- | --- | | App does not load | Database connectivity and migration logs. On Helm, failed migrations block the app init sequence. On Compose, the app waits for successful migrations. | | Sign-in loops or is rejected | Public app/auth origins, scheme, and trusted origins. Confirm the app and realtime use the same `BETTER_AUTH_SECRET`. | -| Socket is unavailable | WebSocket upgrades and `/socket.io` routing. For a separate realtime host, set `NEXT_PUBLIC_SOCKET_URL` and include the app origin in realtime's `ALLOWED_ORIGINS`. | +| Socket is unavailable | WebSocket upgrades and `/socket.io` routing. Realtime defaults to the app host; for a separate realtime host, `NEXT_PUBLIC_SOCKET_URL` must point at it (the Helm chart sets it from `ingress.realtime.host` unless you do). `ALLOWED_ORIGINS` is only for origins beyond `NEXT_PUBLIC_APP_URL`. | | Edits do not propagate | Realtime connectivity and Redis on every replica; verify which pods hold the connections. | | Workflow execution fails | Provider egress, saved credentials, and app logs. A decryption error can mean the current `ENCRYPTION_KEY` differs from the key that encrypted the credential. | | Cloud upload fails | Bucket CORS for the Sim origin and signed headers; server permissions to complete multipart uploads. S3 completion needs `s3:ListMultipartUploadParts`. | diff --git a/apps/docs/scripts/fixtures/content-baseline.json b/apps/docs/scripts/fixtures/content-baseline.json index 89a18efcee8..d8140275676 100644 --- a/apps/docs/scripts/fixtures/content-baseline.json +++ b/apps/docs/scripts/fixtures/content-baseline.json @@ -173934,7 +173934,7 @@ { "lang": "yaml", "meta": null, - "sha256": "795844d38101f8147ddbc9228260ac3079e0ab89a452246656ac336c74f131ce", + "sha256": "ca65367d373ed281d6a04c4677304bffbbc0c590d97d958f02404d65476790bd", "bytes": 701, "line": 85 }, @@ -173948,7 +173948,7 @@ { "lang": "yaml", "meta": null, - "sha256": "df68603f8a69b1564ae8792b1bf46bead93f1635ad2cf6aba1b0e53e250f2276", + "sha256": "b9ce9aab8d379f8e9173ab0d3fff2feaee5253bd26c6db477e96e984e9925970", "bytes": 176, "line": 138 }, @@ -173976,7 +173976,7 @@ { "lang": "bash", "meta": null, - "sha256": "d829002daa160ca953fad98f7df3af21515ccbd34feb96e5fa8f4d5d6c314278", + "sha256": "c970c43eea56151320bf4b5baa8118312be6dbfcf47eff7caf2210731151e359", "bytes": 130, "line": 232 }, @@ -174233,7 +174233,7 @@ { "lang": "yaml", "meta": null, - "sha256": "770a221e2ed89426cca37de3d61fce8a5d99e1f0cf5db0c5fe4586473de3ed0d", + "sha256": "ad130fab18b02e1e22b7229ed4d14696a5abb404e383e9738e0b2bcf4d004d47", "bytes": 243, "line": 35 }, diff --git a/helm/sim/.claude/skills/sim-helm/references/install-paths.md b/helm/sim/.claude/skills/sim-helm/references/install-paths.md index c83783d2dd7..296cf5e745c 100644 --- a/helm/sim/.claude/skills/sim-helm/references/install-paths.md +++ b/helm/sim/.claude/skills/sim-helm/references/install-paths.md @@ -79,7 +79,6 @@ postgresql: existingSecret: enabled: true name: sim-postgres-secret - passwordKey: POSTGRES_PASSWORD ``` **The chart cannot introspect your Secret.** If you forget a required key, the pod will fail at runtime with `CreateContainerConfigError: secret key "X" not found`. The required keys are: `BETTER_AUTH_SECRET`, `ENCRYPTION_KEY`, `INTERNAL_API_SECRET`, plus `CRON_SECRET` when cronjobs are enabled. diff --git a/helm/sim/.claude/skills/sim-helm/references/values-model.md b/helm/sim/.claude/skills/sim-helm/references/values-model.md index 1384c598121..820bd5bb2ab 100644 --- a/helm/sim/.claude/skills/sim-helm/references/values-model.md +++ b/helm/sim/.claude/skills/sim-helm/references/values-model.md @@ -18,7 +18,8 @@ The Sim chart splits configuration across **four** layers. Understanding which l ┌───────────────────────────────────────────────────────────────────────────┐ │ Layer 2: app.envDefaults / realtime.envDefaults │ │ → Rendered as inline env: on the Deployment │ -│ → SKIPPED for any key already set in app.env (or realtime.env) │ +│ → SKIPPED for any key already set in app.env (or realtime.env), or │ +│ mapped in externalSecrets.remoteRefs.app; none in existingSecret mode │ │ → Use for: operational tunables and safe fallback defaults │ │ → Examples: NODE_ENV=production, RATE_LIMIT_*, IVM_* │ └───────────────────────────────────────────────────────────────────────────┘ @@ -27,7 +28,9 @@ The Sim chart splits configuration across **four** layers. Understanding which l ▼ ┌───────────────────────────────────────────────────────────────────────────┐ │ Layer 3: chart-computed (inline env: on the Deployment) │ -│ → DATABASE_URL, SOCKET_SERVER_URL, OLLAMA_URL, PII_URL │ +│ → DATABASE_URL, SOCKET_SERVER_URL, OLLAMA_URL, PII_URL │ +│ → BETTER_AUTH_URL=$(NEXT_PUBLIC_APP_URL) and NEXT_PUBLIC_SOCKET_URL │ +│ (separate realtime ingress host), only when you set them nowhere │ │ → Derived from postgresql.* / externalDatabase.* / service.* values │ │ → CANNOT be overridden via app.env — chart filters them out │ └───────────────────────────────────────────────────────────────────────────┘ @@ -46,7 +49,7 @@ The Sim chart splits configuration across **four** layers. Understanding which l **ESO compatibility.** When `externalSecrets.enabled=true`, the chart-managed Secret is **not rendered** — ESO renders one instead. Anything in Layer 1 must be mapped via `remoteRefs.app.` or it's silently missing. Layers 2–4 are unaffected by ESO. -**Override precedence.** *Non-empty* values set in `app.env` (Layer 1 overrides) win over `envDefaults` (Layer 2) — so users who already had operational tunables in `app.env` continue to work. An *empty* `app.env` value does not override: it reads as "not specified" and the Layer 2 default still applies. To remove a key, override it with `null` (see "I want to REMOVE a key the chart sets" below). +**Override precedence.** *Non-empty* values set in `app.env` (Layer 1 overrides) win over `envDefaults` (Layer 2) — so users who already had operational tunables in `app.env` continue to work. In `app.secrets.existingSecret` mode no `envDefaults` are inlined (the pre-created Secret is the source of truth) and `app.env` values are inlined instead, so overrides go in `app.env`. An *empty* `app.env` value does not override: it reads as "not specified" and the Layer 2 default still applies. To remove a key, override it with `null` (see "I want to REMOVE a key the chart sets" below). ## Where keys live — the canonical list @@ -56,7 +59,7 @@ The exhaustive list of keys per layer lives in `helm/sim/values.yaml`. Read the |---|---|---| | Auth secrets | 1 (app.env) | `BETTER_AUTH_SECRET`, `ENCRYPTION_KEY`, `INTERNAL_API_SECRET`, `CRON_SECRET`, `API_ENCRYPTION_KEY` | | Provider API keys | 1 (app.env) | `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_CLIENT_SECRET`, etc. | -| Per-environment URLs | 1 (app.env) | `NEXT_PUBLIC_APP_URL`, `BETTER_AUTH_URL`, `NEXT_PUBLIC_SOCKET_URL` | +| Per-environment URLs | 1 (app.env) | `NEXT_PUBLIC_APP_URL` (`BETTER_AUTH_URL` follows it unless set; set both in the Secret in existingSecret mode) | | Feature flags | 1 (app.env) | `ENTERPRISE_ENABLED`, `ACCESS_CONTROL_ENABLED`, `ORGANIZATIONS_ENABLED`, `SSO_ENABLED` (server only; enterprise features have no `NEXT_PUBLIC_` twins) | | Operational defaults | 2 (envDefaults) | `NODE_ENV=production`, `EMAIL_VERIFICATION_ENABLED=false`, `VERTEX_LOCATION=us-central1` | | Rate limits | 2 (envDefaults) | `RATE_LIMIT_WINDOW_MS`, `RATE_LIMIT_FREE_SYNC`, etc. | @@ -124,10 +127,9 @@ Caveat worth passing to operators: `null` has no effect under `helm upgrade --re app: env: NEXT_PUBLIC_APP_URL: "https://sim.example.com" - BETTER_AUTH_URL: "https://sim.example.com" ``` -This is the right answer for any clustered deploy. The chart's default is `http://localhost:3000` (Layer 2) — fine for kind/minikube, broken for production. The realtime Deployment also reads these via the shared Secret. +This is the right answer for any clustered deploy. `BETTER_AUTH_URL` is set to `$(NEXT_PUBLIC_APP_URL)` unless you set it (in `app.secrets.existingSecret` mode the chart sets nothing, so the Secret must hold both). The chart's default is `http://localhost:3000` (Layer 2) — fine for kind/minikube, broken for production. The realtime Deployment also reads these via the shared Secret. ### "I want to inject a value from another ConfigMap" diff --git a/helm/sim/Chart.yaml b/helm/sim/Chart.yaml index 1401e875ab1..6a46f7c2b7b 100644 --- a/helm/sim/Chart.yaml +++ b/helm/sim/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: sim description: A Helm chart for Sim - the open-source AI workspace where teams build, deploy, and manage AI agents type: application -version: 1.19.0 +version: 1.20.0 appVersion: "v0.8.26" kubeVersion: ">=1.25.0-0" home: https://sim.ai diff --git a/helm/sim/README.md b/helm/sim/README.md index b55ecd76a19..7d7cfdd3385 100644 --- a/helm/sim/README.md +++ b/helm/sim/README.md @@ -310,9 +310,8 @@ Pre-built values files for common scenarios live in [`helm/sim/examples/`](https Use one with: ```bash -# The Sim release your chart version installs, so the example matches it -SIM_RELEASE=$(helm show chart oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" | awk '/^appVersion:/ {print $2}' | tr -d '"') -curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/$SIM_RELEASE/helm/sim/examples/values-production.yaml" +# The example as of your chart version's release tag +curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-production.yaml" helm install sim oci://ghcr.io/simstudioai/charts/sim \ --version "$CHART_VERSION" \ @@ -358,7 +357,7 @@ or extract it from a pulled chart with `helm pull --untar`. Before installing in production, confirm each of the following: -* **High availability** — scale `app.replicaCount > 1`. The chart auto-creates a `PodDisruptionBudget` with `maxUnavailable: "25%"`. Set `podDisruptionBudget.minAvailable` instead for a stricter policy. +* **High availability** — scale `app.replicaCount > 1`, which needs object storage (S3, Azure Blob, or GCS; see `STORAGE_PROVIDER`) or the `app.storage.allowLocalWithReplicas` opt-out. The chart auto-creates a `PodDisruptionBudget` with `maxUnavailable: "25%"`. Set `podDisruptionBudget.minAvailable` instead for a stricter policy. * **Pinned images** — override `image.tag` (or `image.digest`) with an explicit version. Do not rely on the chart's default tag in production. * **Secrets management** — provide secrets via External Secrets Operator (ESO) or pre-created Kubernetes Secrets. Never commit secrets to `values.yaml`. * **TLS / Ingress** — set the `cert-manager.io/cluster-issuer` annotation on the ingress and tune `proxy-body-size` / `proxy-read-timeout` for your workload. See commented examples in `values.yaml`. @@ -391,7 +390,7 @@ Before installing in production, confirm each of the following: ``` * **Namespace hardening** — label the install namespace with Pod Security Standards `restricted` enforcement (`pod-security.kubernetes.io/enforce=restricted`). All workloads set `runAsNonRoot`, drop all Linux capabilities, disable privilege escalation, and set `seccompProfile: RuntimeDefault` — the four controls the Restricted profile requires. `readOnlyRootFilesystem` is defaulted on only for the bundled Redis (Postgres/Ollama genuinely need a writable root; the stateless services — `realtime`, `pii`, `copilot` — could tolerate it but aren't pre-wired with a `/tmp` `emptyDir`). If your policy requires it, set `.securityContext.readOnlyRootFilesystem: true` and mount writable `emptyDir` volumes yourself via `extraVolumes`/`extraVolumeMounts`: `/tmp` for every component, plus `/app/apps/sim/.next/cache` and `/app/apps/sim/.next/server/route-cache` for `app`. * **Env validation** — keys under `app.env`, `realtime.env`, and `copilot.server.env` are passed through to the application and validated at startup. The JSON Schema intentionally does not enforce `additionalProperties: false` (would break custom user envs), so typos like `OPENA_API_KEY` (instead of `OPENAI_API_KEY`) surface as missing-key errors at runtime, not at `helm install` time. Review your env block carefully. -* **Set public URLs** — `app.env.NEXT_PUBLIC_APP_URL` and `app.env.BETTER_AUTH_URL` must match your public origin (e.g. `https://sim.example.com`). Leaving them as `localhost` breaks sign-in. +* **Set public URLs** — `app.env.NEXT_PUBLIC_APP_URL` must match your public origin (e.g. `https://sim.example.com`); `BETTER_AUTH_URL` follows it (in `app.secrets.existingSecret` mode set both in the Secret). Leaving it as `localhost` breaks sign-in. --- @@ -500,7 +499,7 @@ User-supplied `securityContext` values are merged with the defaults — your val Other security features: * `automountServiceAccountToken: false` on the ServiceAccount **and** every pod. -* Every value in `app.env` and `realtime.env` is written to a chart-managed Secret and mounted via `envFrom: secretRef` — no values are inlined on the container spec. This eliminates a sensitivity classifier (no static list of "secret" keys to maintain) and ensures new provider keys can never accidentally leak into pod manifests. Two categories are inlined on the container instead: chart-computed values (`DATABASE_URL`, `SOCKET_SERVER_URL`, `OLLAMA_URL`, `PII_URL`) and operational defaults under `app.envDefaults` / `realtime.envDefaults` (rate limits, timeouts, IVM tunables, feature-flag defaults, `http://localhost:3000` URL fallbacks). Operational defaults are non-sensitive by design — moving them out of `app.env` keeps the Secret small and means External Secrets Operator users only have to map the keys they actually set, not every chart default. A **non-empty** value placed in `app.env` wins over the same key in `app.envDefaults` (the template skips the inline default when an override exists). An **empty** value does not — to remove a key rather than change it, see [Removing an inherited env key](#removing-an-inherited-env-key). +* Every value in `app.env` and `realtime.env` is written to a chart-managed Secret and mounted via `envFrom: secretRef` — no values are inlined on the container spec. This eliminates a sensitivity classifier (no static list of "secret" keys to maintain) and ensures new provider keys can never accidentally leak into pod manifests. Two categories are inlined on the container instead: chart-computed values (`DATABASE_URL`, `SOCKET_SERVER_URL`, `OLLAMA_URL`, `PII_URL`, `BETTER_AUTH_URL` from `NEXT_PUBLIC_APP_URL`, and `NEXT_PUBLIC_SOCKET_URL` for a separate realtime ingress host, each only when you have not set it) and operational defaults under `app.envDefaults` / `realtime.envDefaults` (rate limits, timeouts, IVM tunables, feature-flag defaults, the `http://localhost:3000` `NEXT_PUBLIC_APP_URL` fallback). Operational defaults are non-sensitive by design — moving them out of `app.env` keeps the Secret small and means External Secrets Operator users only have to map the keys they actually set, not every chart default. A **non-empty** value placed in `app.env` wins over the same key in `app.envDefaults` (the template skips the inline default when an override exists). An **empty** value does not — to remove a key rather than change it, see [Removing an inherited env key](#removing-an-inherited-env-key). Likewise, under External Secrets a key mapped in `externalSecrets.remoteRefs.app` wins, and in `app.secrets.existingSecret` mode no `envDefaults` are inlined (put overrides in `app.env`). * Optional `networkPolicy.enabled=true` enforces east-west isolation and blocks cloud metadata endpoints in egress. --- @@ -644,6 +643,23 @@ kubectl --namespace sim logs deploy/sim-app -c migrations --- +## Upgrading to 1.20.0 + +Covers 1.19.0–1.20.0; 1.18.0 is the previous published chart. This release refuses some values earlier charts accepted; run `helm template` with your values before upgrading. + +* **Argo CD or `helm template | kubectl apply`: recreate the bundled Postgres StatefulSets once.** Their volume claim labels no longer carry the chart version (Kubernetes forbids changing them, which broke every upgrade). `helm upgrade` and Flux reuse the existing labels and need nothing; tools that render without `lookup` must orphan-delete first, which keeps the pods and PVCs: + + ```bash + kubectl --namespace sim delete statefulset -postgresql --cascade=orphan + kubectl --namespace sim delete statefulset -copilot-postgresql --cascade=orphan # only with copilot.postgresql.enabled + ``` +* **More than one app replica needs object storage.** With `app.replicaCount > 1` or `autoscaling.enabled` and no S3, Azure Blob, or GCS configured, the render fails. Configure one in `app.env` (see `STORAGE_PROVIDER`), mount a ReadWriteMany volume at `/app/apps/sim/uploads`, or set `app.storage.allowLocalWithReplicas=true`. +* **Realtime is served on the app host under `/socket.io`.** `ingress.realtime.host` defaults to `""` (the app host). A separate host keeps working, and the chart sets `NEXT_PUBLIC_SOCKET_URL` to it unless you do (set it yourself in `app.secrets.existingSecret` mode). A `/` realtime path on the app host now fails the render; a copied `sim-ws.local` block is read as the new default. +* **`BETTER_AUTH_URL` defaults to `NEXT_PUBLIC_APP_URL`.** Delete a copied `app.envDefaults.BETTER_AUTH_URL: http://localhost:3000`. In `app.secrets.existingSecret` mode, keep `BETTER_AUTH_URL` in the Secret. +* **External Secrets: synced keys win over `envDefaults`.** A key mapped in `externalSecrets.remoteRefs.app` is no longer masked by the chart default. No action. +* **existingSecret mode applies no `envDefaults`.** Put overrides in `app.env`, which is inlined in that mode. +* **New render checks.** An enabled `existingSecret` with an empty `name` (`app.secrets`, `postgresql.auth`, `externalDatabase`) fails, as does enabling both `postgresql` and `externalDatabase`. + ## Upgrading to 1.16.0 * **The `copilot` service runs the TypeScript Mothership image.** Its settings follow that image, and the chart fails to render with an old name, naming the new one: diff --git a/helm/sim/ci/full-values.yaml b/helm/sim/ci/full-values.yaml index a8d8fd3f519..6c0fbe49463 100644 --- a/helm/sim/ci/full-values.yaml +++ b/helm/sim/ci/full-values.yaml @@ -7,6 +7,9 @@ app: INTERNAL_API_SECRET: "cicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicici" CRON_SECRET: "cicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicici" API_ENCRYPTION_KEY: "cicicicicicicicicicicicicicicicicicicicicicicicicicicicicicicici" + # Object storage: autoscaling below runs several app replicas, which local storage refuses. + AWS_REGION: "us-east-1" + S3_BUCKET_NAME: "ci-sim-workspace-files" postgresql: auth: diff --git a/helm/sim/examples/aws-marketplace-prerequisites.yaml b/helm/sim/examples/aws-marketplace-prerequisites.yaml index 12aa148a415..c3b4eb82e5a 100644 --- a/helm/sim/examples/aws-marketplace-prerequisites.yaml +++ b/helm/sim/examples/aws-marketplace-prerequisites.yaml @@ -2,7 +2,8 @@ AWSTemplateFormatVersion: '2010-09-09' Description: >- Prerequisites for Sim from the AWS Marketplace container listing: Amazon RDS for PostgreSQL 17 (pgvector), Amazon ElastiCache (Valkey) with TLS and an auth token, and the IAM role the Sim - ServiceAccount assumes (IRSA) to check the Marketplace license in AWS License Manager. Deploy it + ServiceAccount assumes (IRSA) to check the Marketplace license in AWS License Manager and, with + UploadBuckets, to use your S3 upload buckets. Deploy it in the region and VPC of your EKS cluster, then use its outputs in values.yaml and the two Kubernetes Secrets described in the listing's usage instructions. @@ -36,6 +37,19 @@ Parameters: Type: String Default: cache.m7g.large Description: ElastiCache node type. + UploadBuckets: + Type: CommaDelimitedList + Default: '' + Description: >- + Exact names of the S3 buckets you create for uploads, comma-separated without spaces + (S3_BUCKET_NAME and every S3_*_BUCKET_NAME in values.yaml). The license role is granted read, + write and multipart access to these buckets only. Empty grants no S3 access. + +Conditions: + GrantUploadBuckets: !Not [!Equals [!Join ['', !Ref UploadBuckets], '']] + # Fn::Join takes only a literal delimiter, so each partition's ARN prefix is spelled out. + InChina: !Equals [!Ref AWS::Partition, aws-cn] + InGovCloud: !Equals [!Ref AWS::Partition, aws-us-gov] Resources: DatabaseSecurityGroup: @@ -132,7 +146,7 @@ Resources: LicenseRole: Type: AWS::IAM::Role Properties: - Description: Lets the Sim ServiceAccount check the AWS Marketplace license (IRSA) + Description: Lets the Sim ServiceAccount check the AWS Marketplace license and use its upload buckets (IRSA) # Substituted as a whole document: the condition keys embed the cluster's issuer. AssumeRolePolicyDocument: !Sub | { @@ -164,6 +178,45 @@ Resources: # resource-level permissions, so it cannot be scoped below '*'. Action: license-manager:CheckoutLicense Resource: '*' + - !If + - GrantUploadBuckets + - PolicyName: sim-upload-buckets + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: s3:ListBucket + Resource: !Split + - ',' + - !Sub + - 'arn:${AWS::Partition}:s3:::${Names}' + - Names: !If + - InChina + - !Join [',arn:aws-cn:s3:::', !Ref UploadBuckets] + - !If + - InGovCloud + - !Join [',arn:aws-us-gov:s3:::', !Ref UploadBuckets] + - !Join [',arn:aws:s3:::', !Ref UploadBuckets] + # Large uploads are multipart: Sim aborts and lists the parts of its own uploads. + - Effect: Allow + Action: + - s3:GetObject + - s3:PutObject + - s3:DeleteObject + - s3:AbortMultipartUpload + - s3:ListMultipartUploadParts + Resource: !Split + - ',' + - !Sub + - 'arn:${AWS::Partition}:s3:::${Names}/*' + - Names: !If + - InChina + - !Join ['/*,arn:aws-cn:s3:::', !Ref UploadBuckets] + - !If + - InGovCloud + - !Join ['/*,arn:aws-us-gov:s3:::', !Ref UploadBuckets] + - !Join ['/*,arn:aws:s3:::', !Ref UploadBuckets] + - !Ref AWS::NoValue Outputs: DatabaseEndpoint: diff --git a/helm/sim/examples/values-aws-marketplace.yaml b/helm/sim/examples/values-aws-marketplace.yaml index 07f1a452a65..d8d0573a4b0 100644 --- a/helm/sim/examples/values-aws-marketplace.yaml +++ b/helm/sim/examples/values-aws-marketplace.yaml @@ -21,12 +21,17 @@ # provider (for IRSA). # 2. RDS for PostgreSQL 17 and ElastiCache reachable from the cluster. The listing's # CloudFormation template creates both in your VPC. -# 3. An IAM role for the ServiceAccount below that allows license-manager:CheckoutLicense (the -# CloudFormation template creates it; AWS's managed AWSLicenseManagerConsumptionPolicy -# grants it too). License Manager must be set up in the account: open its console once, or run +# 3. An IAM role for the ServiceAccount below that allows license-manager:CheckoutLicense and +# the S3 actions on the upload buckets listed under app.env (the CloudFormation template +# creates it; list those exact bucket names, comma-separated, in its UploadBuckets parameter +# to grant the S3 actions on them). License Manager must be set up in the account: open its +# console once, or run # aws iam create-service-linked-role --aws-service-name license-manager.amazonaws.com -# 4. An ACM certificate for the two hostnames below. -# 5. Two Secrets in the install namespace (no secret ever goes in this file). The template's +# 4. S3 buckets for uploads, in the region set below: one per name under app.env +# (S3_BUCKET_NAME and the S3_*_BUCKET_NAME purpose buckets), e.g. +# aws s3 mb s3://sim-workspace-files --region us-east-1 +# 5. An ACM certificate for the two hostnames below. +# 6. Two Secrets in the install namespace (no secret ever goes in this file). The template's # DatabasePasswordArn and CacheAuthTokenArn outputs are the ARNs of the Secrets Manager # secrets holding the two passwords; read each password with: # aws secretsmanager get-secret-value --secret-id --query SecretString --output text @@ -56,6 +61,20 @@ app: # The listing's product ID, which the Marketplace chart sets; rendered from this repository, # set it to the product ID shown on the listing. Its presence turns on the License Manager check. AWS_MARKETPLACE_LICENSE_PRODUCT_SKU: "prod-xxxxxxxxxxxxx" # EDIT + # Object storage (required with more than one app replica; prerequisites 3 and 4). The IRSA + # role needs s3:ListBucket on each bucket and s3:GetObject, s3:PutObject, s3:DeleteObject, + # s3:AbortMultipartUpload and s3:ListMultipartUploadParts on its objects (large uploads are + # multipart), or add AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY to sim-app-secrets. + STORAGE_PROVIDER: "s3" + AWS_REGION: "us-east-1" # EDIT: the bucket's region + S3_BUCKET_NAME: "sim-workspace-files" # EDIT + # EDIT: these purposes do not fall back to S3_BUCKET_NAME, so each needs a + # bucket (OG images and workspace logos do fall back). + S3_KB_BUCKET_NAME: "sim-knowledge-base" + S3_EXECUTION_FILES_BUCKET_NAME: "sim-execution-files" + S3_CHAT_BUCKET_NAME: "sim-chat-files" + S3_COPILOT_BUCKET_NAME: "sim-copilot-files" + S3_PROFILE_PICTURES_BUCKET_NAME: "sim-profile-pictures" realtime: replicaCount: 2 diff --git a/helm/sim/examples/values-aws.yaml b/helm/sim/examples/values-aws.yaml index aed865f7e4e..6077a23a7de 100644 --- a/helm/sim/examples/values-aws.yaml +++ b/helm/sim/examples/values-aws.yaml @@ -13,9 +13,11 @@ # does not work with ALB — ALB cannot serve Kubernetes TLS Secrets # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-aws.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-aws.yaml \ +# --values values-aws.yaml \ # --set app.env.BETTER_AUTH_SECRET="$BETTER_AUTH_SECRET" \ # --set app.env.ENCRYPTION_KEY="$ENCRYPTION_KEY" \ # --set app.env.INTERNAL_API_SECRET="$INTERNAL_API_SECRET" \ diff --git a/helm/sim/examples/values-azure.yaml b/helm/sim/examples/values-azure.yaml index ec2c6b4c941..e30859312ea 100644 --- a/helm/sim/examples/values-azure.yaml +++ b/helm/sim/examples/values-azure.yaml @@ -11,9 +11,11 @@ # - (optional) GPU node pool tainted with sku=gpu:NoSchedule for Ollama # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-azure.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-azure.yaml \ +# --values values-azure.yaml \ # --set app.env.BETTER_AUTH_SECRET="$BETTER_AUTH_SECRET" \ # --set app.env.ENCRYPTION_KEY="$ENCRYPTION_KEY" \ # --set app.env.INTERNAL_API_SECRET="$INTERNAL_API_SECRET" \ diff --git a/helm/sim/examples/values-copilot.yaml b/helm/sim/examples/values-copilot.yaml index 4aa8ce7ac93..5299827bc29 100644 --- a/helm/sim/examples/values-copilot.yaml +++ b/helm/sim/examples/values-copilot.yaml @@ -16,10 +16,13 @@ # --docker-password="$COPILOT_REGISTRY_TOKEN" # # Install (merge with your main values file using multiple --values flags): -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-production.yaml" +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-copilot.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-production.yaml \ -# --values ./helm/sim/examples/values-copilot.yaml \ +# --values values-production.yaml \ +# --values values-copilot.yaml \ # --set app.env.BETTER_AUTH_SECRET="$BETTER_AUTH_SECRET" \ # --set app.env.ENCRYPTION_KEY="$ENCRYPTION_KEY" \ # --set app.env.INTERNAL_API_SECRET="$INTERNAL_API_SECRET" \ diff --git a/helm/sim/examples/values-development.yaml b/helm/sim/examples/values-development.yaml index b6d544d37be..fa57ac1efe8 100644 --- a/helm/sim/examples/values-development.yaml +++ b/helm/sim/examples/values-development.yaml @@ -7,9 +7,11 @@ # Prerequisites: a working kubectl context. # # Install: -# helm install sim-dev ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-development.yaml" +# helm install sim-dev oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim-dev --create-namespace \ -# --values ./helm/sim/examples/values-development.yaml \ +# --values values-development.yaml \ # --set app.env.BETTER_AUTH_SECRET=$(openssl rand -hex 32) \ # --set app.env.ENCRYPTION_KEY=$(openssl rand -hex 32) \ # --set app.env.INTERNAL_API_SECRET=$(openssl rand -hex 32) \ diff --git a/helm/sim/examples/values-existing-secret.yaml b/helm/sim/examples/values-existing-secret.yaml index 1b440e661a6..e9eea58fd38 100644 --- a/helm/sim/examples/values-existing-secret.yaml +++ b/helm/sim/examples/values-existing-secret.yaml @@ -15,9 +15,11 @@ # Full Secret manifests are at the bottom of this file. # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-existing-secret.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-existing-secret.yaml +# --values values-existing-secret.yaml app: enabled: true @@ -29,8 +31,20 @@ app: env: NEXT_PUBLIC_APP_URL: "https://sim.example.com" BETTER_AUTH_URL: "https://sim.example.com" - NEXT_PUBLIC_SOCKET_URL: "wss://sim-ws.example.com" NODE_ENV: "production" + # Object storage (required with more than one app replica). Put these here + # or in the Secret, with AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY in the + # Secret unless the pod has a cloud identity (IRSA, Workload Identity). + STORAGE_PROVIDER: "s3" + AWS_REGION: "us-east-1" # EDIT + S3_BUCKET_NAME: "example-sim-workspace-files" # EDIT + # EDIT: these purposes do not fall back to S3_BUCKET_NAME, so each needs a + # bucket (OG images and workspace logos do fall back). + S3_KB_BUCKET_NAME: "example-sim-knowledge-base" + S3_EXECUTION_FILES_BUCKET_NAME: "example-sim-execution-files" + S3_CHAT_BUCKET_NAME: "example-sim-chat-files" + S3_COPILOT_BUCKET_NAME: "example-sim-copilot-files" + S3_PROFILE_PICTURES_BUCKET_NAME: "example-sim-profile-pictures" realtime: enabled: true @@ -52,7 +66,6 @@ postgresql: existingSecret: enabled: true name: "sim-postgresql-secret" - passwordKey: "POSTGRES_PASSWORD" # --- # Create secrets before installing: diff --git a/helm/sim/examples/values-external-db.yaml b/helm/sim/examples/values-external-db.yaml index 0d7250ac1cc..21ee5e83ff7 100644 --- a/helm/sim/examples/values-external-db.yaml +++ b/helm/sim/examples/values-external-db.yaml @@ -18,9 +18,11 @@ # export CRON_SECRET=$(openssl rand -hex 32) # export DB_PASSWORD=$(openssl rand -hex 24) # -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-external-db.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-external-db.yaml \ +# --values values-external-db.yaml \ # --set externalDatabase.host=your-db.example.com \ # --set externalDatabase.username=simstudio_user \ # --set externalDatabase.password="$DB_PASSWORD" \ @@ -51,8 +53,21 @@ app: env: NEXT_PUBLIC_APP_URL: "https://simstudio.acme.com" BETTER_AUTH_URL: "https://simstudio.acme.com" - SOCKET_SERVER_URL: "https://simstudio-ws.acme.com" - NEXT_PUBLIC_SOCKET_URL: "https://simstudio-ws.acme.com" + # Realtime is served on the app host under /socket.io; leave NEXT_PUBLIC_SOCKET_URL unset. + + # Object storage (required with more than one app replica). + # Credentials: AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY here, or a pod + # identity (IRSA / EKS Pod Identity) via serviceAccount.annotations. + STORAGE_PROVIDER: "s3" + AWS_REGION: "us-east-1" # EDIT + S3_BUCKET_NAME: "acme-sim-workspace-files" # EDIT + # EDIT: these purposes do not fall back to S3_BUCKET_NAME, so each needs a + # bucket (OG images and workspace logos do fall back). + S3_KB_BUCKET_NAME: "acme-sim-knowledge-base" + S3_EXECUTION_FILES_BUCKET_NAME: "acme-sim-execution-files" + S3_CHAT_BUCKET_NAME: "acme-sim-chat-files" + S3_COPILOT_BUCKET_NAME: "acme-sim-copilot-files" + S3_PROFILE_PICTURES_BUCKET_NAME: "acme-sim-profile-pictures" # Security settings (REQUIRED - replace with your own secure secrets) # Generate using: openssl rand -hex 32 @@ -134,18 +149,13 @@ ingress: nginx.ingress.kubernetes.io/force-ssl-redirect: "true" cert-manager.io/cluster-issuer: "letsencrypt-prod" + # Realtime is routed on this host under /socket.io (ingress.realtime defaults). app: host: simstudio.acme.com paths: - path: / pathType: Prefix - realtime: - host: simstudio-ws.acme.com - paths: - - path: / - pathType: Prefix - tls: enabled: true secretName: simstudio-tls-secret @@ -186,8 +196,10 @@ networkPolicy: port: 5432 # Example deployment command with secure secret generation: -# helm install sim ./helm/sim \ -# --values ./helm/sim/examples/values-external-db.yaml \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-external-db.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ +# --values values-external-db.yaml \ # --set externalDatabase.host="your-db-host.com" \ # --set externalDatabase.username="your-db-user" \ # --set externalDatabase.password="your-db-password" \ diff --git a/helm/sim/examples/values-external-secrets.yaml b/helm/sim/examples/values-external-secrets.yaml index 04593826c2e..5874e4e9714 100644 --- a/helm/sim/examples/values-external-secrets.yaml +++ b/helm/sim/examples/values-external-secrets.yaml @@ -16,9 +16,11 @@ # externalSecrets.remoteRefs below. # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-external-secrets.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-external-secrets.yaml +# --values values-external-secrets.yaml externalSecrets: enabled: true @@ -34,6 +36,10 @@ externalSecrets: INTERNAL_API_SECRET: "sim/app/internal-api-secret" CRON_SECRET: "sim/app/cron-secret" API_ENCRYPTION_KEY: "sim/app/api-encryption-key" + # Object storage credentials, unless the pod has a cloud identity (IRSA, + # Workload Identity) granting bucket access: + # AWS_ACCESS_KEY_ID: "sim/app/aws-access-key-id" + # AWS_SECRET_ACCESS_KEY: "sim/app/aws-secret-access-key" # MSHIP_SYSPROMPT_OVERRIDE: "sim/app/mship-system-prompt-override" postgresql: password: "sim/postgresql/password" @@ -58,8 +64,18 @@ app: envDefaults: NEXT_PUBLIC_APP_URL: "https://sim.example.com" BETTER_AUTH_URL: "https://sim.example.com" - NEXT_PUBLIC_SOCKET_URL: "wss://sim-ws.example.com" NODE_ENV: "production" + # Object storage (required with more than one app replica). + STORAGE_PROVIDER: "s3" + AWS_REGION: "us-east-1" # EDIT + S3_BUCKET_NAME: "example-sim-workspace-files" # EDIT + # EDIT: these purposes do not fall back to S3_BUCKET_NAME, so each needs a + # bucket (OG images and workspace logos do fall back). + S3_KB_BUCKET_NAME: "example-sim-knowledge-base" + S3_EXECUTION_FILES_BUCKET_NAME: "example-sim-execution-files" + S3_CHAT_BUCKET_NAME: "example-sim-chat-files" + S3_COPILOT_BUCKET_NAME: "example-sim-copilot-files" + S3_PROFILE_PICTURES_BUCKET_NAME: "example-sim-profile-pictures" realtime: enabled: true diff --git a/helm/sim/examples/values-gcp.yaml b/helm/sim/examples/values-gcp.yaml index df51dd6001a..9b1834f63ce 100644 --- a/helm/sim/examples/values-gcp.yaml +++ b/helm/sim/examples/values-gcp.yaml @@ -11,9 +11,11 @@ # - (optional) GPU node pool with accelerator labels for Ollama # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-gcp.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-gcp.yaml \ +# --values values-gcp.yaml \ # --set app.env.BETTER_AUTH_SECRET="$BETTER_AUTH_SECRET" \ # --set app.env.ENCRYPTION_KEY="$ENCRYPTION_KEY" \ # --set app.env.INTERNAL_API_SECRET="$INTERNAL_API_SECRET" \ diff --git a/helm/sim/examples/values-production.yaml b/helm/sim/examples/values-production.yaml index f98a73ecdaa..77fc7dfceca 100644 --- a/helm/sim/examples/values-production.yaml +++ b/helm/sim/examples/values-production.yaml @@ -12,9 +12,11 @@ # - (recommended) External Secrets Operator — see values-external-secrets.yaml # # Install: -# helm install sim ./helm/sim \ +# # Examples are not in the chart package: fetch them at the chart's release tag. +# curl -fsSLO "https://raw.githubusercontent.com/simstudioai/sim/helm-chart-${CHART_VERSION}/helm/sim/examples/values-production.yaml" +# helm install sim oci://ghcr.io/simstudioai/charts/sim --version "$CHART_VERSION" \ # --namespace sim --create-namespace \ -# --values ./helm/sim/examples/values-production.yaml \ +# --values values-production.yaml \ # --set app.env.BETTER_AUTH_SECRET="$BETTER_AUTH_SECRET" \ # --set app.env.ENCRYPTION_KEY="$ENCRYPTION_KEY" \ # --set app.env.INTERNAL_API_SECRET="$INTERNAL_API_SECRET" \ @@ -46,7 +48,21 @@ app: env: NEXT_PUBLIC_APP_URL: "https://sim.acme.ai" BETTER_AUTH_URL: "https://sim.acme.ai" - NEXT_PUBLIC_SOCKET_URL: "https://sim-ws.acme.ai" + # Realtime is served on the app host under /socket.io; leave NEXT_PUBLIC_SOCKET_URL unset. + + # Object storage (required with more than one app replica). + # Credentials: AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY here, or a pod + # identity (IRSA / EKS Pod Identity) via serviceAccount.annotations. + STORAGE_PROVIDER: "s3" + AWS_REGION: "us-east-1" # EDIT + S3_BUCKET_NAME: "acme-sim-workspace-files" # EDIT + # EDIT: these purposes do not fall back to S3_BUCKET_NAME, so each needs a + # bucket (OG images and workspace logos do fall back). + S3_KB_BUCKET_NAME: "acme-sim-knowledge-base" + S3_EXECUTION_FILES_BUCKET_NAME: "acme-sim-execution-files" + S3_CHAT_BUCKET_NAME: "acme-sim-chat-files" + S3_COPILOT_BUCKET_NAME: "acme-sim-copilot-files" + S3_PROFILE_PICTURES_BUCKET_NAME: "acme-sim-profile-pictures" # Security settings (REQUIRED - pass with --set or an external secret manager; # the install fails while any is empty). Generate using: openssl rand -hex 32 @@ -154,20 +170,14 @@ ingress: nginx.ingress.kubernetes.io/force-ssl-redirect: "true" cert-manager.io/cluster-issuer: "letsencrypt-prod" - # Main application + # Main application. Realtime is routed on this host under /socket.io + # (ingress.realtime defaults). app: host: sim.acme.ai paths: - path: / pathType: Prefix - # Realtime service - realtime: - host: sim-ws.acme.ai - paths: - - path: / - pathType: Prefix - # TLS configuration tls: enabled: true diff --git a/helm/sim/templates/NOTES.txt b/helm/sim/templates/NOTES.txt index c3f3e211f8a..073e99de317 100644 --- a/helm/sim/templates/NOTES.txt +++ b/helm/sim/templates/NOTES.txt @@ -6,6 +6,12 @@ Keep this short and action-oriented. Users land here and decide what to do next. Thank you for installing {{ .Chart.Name }} ({{ .Chart.Name }}-{{ .Chart.Version }}, app {{ .Chart.AppVersion }}). Your release is named {{ .Release.Name }} in namespace {{ .Release.Namespace }}. +{{- if include "sim.localStorageInUse" . }} + +WARNING: no object storage is configured, so uploads stay on each app pod and +are lost when it restarts. Configure S3, Azure Blob, or GCS (see +STORAGE_PROVIDER in values.yaml). +{{- end }} 1. Watch the rollout finish: @@ -37,6 +43,12 @@ Your release is named {{ .Release.Name }} in namespace {{ .Release.Namespace }}. Ingress is disabled. Use port-forward to reach the app locally: kubectl --namespace {{ .Release.Namespace }} port-forward svc/{{ include "sim.fullname" . }}-app {{ .Values.app.service.port | default 3000 }}:{{ .Values.app.service.port | default 3000 }} +{{- if .Values.realtime.enabled }} + + and, in a second terminal, realtime (the browser connects to localhost:3002): + + kubectl --namespace {{ .Release.Namespace }} port-forward svc/{{ include "sim.fullname" . }}-realtime 3002:{{ .Values.realtime.service.port | default 3002 }} +{{- end }} Then open http://localhost:{{ .Values.app.service.port | default 3000 }} @@ -82,16 +94,10 @@ Your release is named {{ .Release.Name }} in namespace {{ .Release.Namespace }}. helm get values {{ .Release.Name }} --namespace {{ .Release.Namespace }} # Upgrade after changing values - helm upgrade {{ .Release.Name }} ./helm/sim --namespace {{ .Release.Namespace }} -f your-values.yaml - -5. Upgrade notes (read before upgrading from a chart version released before this one): + helm upgrade {{ .Release.Name }} oci://ghcr.io/simstudioai/charts/sim --version --namespace {{ .Release.Namespace }} -f your-values.yaml - * externalSecrets.apiVersion defaults to "v1". Current ESO releases no - longer serve v1beta1 (the compatibility path was removed in 2026) — set - externalSecrets.apiVersion: "v1beta1" only if you still run ESO < 0.17. - * networkPolicy.egress remains a list of custom egress rules (unchanged). - Cloud-metadata CIDR blocking is now configured via networkPolicy.egressExceptCidrs - (defaults to AWS/GCP/Azure IMDS + ECS task metadata). +5. Before upgrading the chart, read the new version's upgrade notes: + helm show readme oci://ghcr.io/simstudioai/charts/sim --version 6. Where to go next: diff --git a/helm/sim/templates/_helpers.tpl b/helm/sim/templates/_helpers.tpl index 144ce18b129..cc5dcaf7918 100644 --- a/helm/sim/templates/_helpers.tpl +++ b/helm/sim/templates/_helpers.tpl @@ -281,6 +281,18 @@ Skip validation when using existing secrets or External Secrets Operator {{- $useExternalSecrets := and .Values.externalSecrets .Values.externalSecrets.enabled }} {{- $useExistingPostgresSecret := and .Values.postgresql.auth.existingSecret .Values.postgresql.auth.existingSecret.enabled }} {{- $useExistingExternalDbSecret := and .Values.externalDatabase.existingSecret .Values.externalDatabase.existingSecret.enabled }} +{{- if and .Values.postgresql.enabled .Values.externalDatabase.enabled }} +{{- fail "postgresql.enabled and externalDatabase.enabled are both true; the chart uses the bundled database. Set externalDatabase.enabled=false to keep it, or migrate your data and set postgresql.enabled=false." }} +{{- end }} +{{- if and $useExistingAppSecret (not .Values.app.secrets.existingSecret.name) }} +{{- fail "app.secrets.existingSecret.enabled=true but app.secrets.existingSecret.name is empty. Set it to the name of your pre-created app Secret." }} +{{- end }} +{{- if and .Values.postgresql.enabled $useExistingPostgresSecret (not .Values.postgresql.auth.existingSecret.name) }} +{{- fail "postgresql.auth.existingSecret.enabled=true but postgresql.auth.existingSecret.name is empty. Set it to the name of your pre-created Secret holding POSTGRES_PASSWORD." }} +{{- end }} +{{- if and .Values.externalDatabase.enabled $useExistingExternalDbSecret (not .Values.externalDatabase.existingSecret.name) }} +{{- fail "externalDatabase.existingSecret.enabled=true but externalDatabase.existingSecret.name is empty. Set it to the name of your pre-created Secret holding EXTERNAL_DB_PASSWORD." }} +{{- end }} {{- /* App secrets validation - skip if using existing secret or ESO */ -}} {{- if not (or $useExistingAppSecret $useExternalSecrets) }} {{- if and .Values.app.enabled (not .Values.app.env.BETTER_AUTH_SECRET) }} @@ -820,50 +832,283 @@ Validate Copilot configuration {{- end }} {{/* -Inline env entries the app container applies over its Secret, in precedence order (a later entry -for the same name wins): envDefaults the operator did not override, existingSecret-mode app.env -values, then extraEnvVars. Shared with the migrations init container so both resolve a key alike. +Inline env entries a container (dict "root" $ "component" "app"|"realtime") applies over its +Secret, in precedence order (a later entry for the same name wins): envDefaults (see +sim.envDefaultsEntries); in existingSecret mode, app.env (overlaid on realtime by non-empty +realtime.env), since no chart Secret carries it; then extraEnvVars. The derived +NEXT_PUBLIC_SOCKET_URL (app only) and BETTER_AUTH_URL are emitted only when nothing else sets them; +BETTER_AUTH_URL comes last, so its $(NEXT_PUBLIC_APP_URL) expands whichever entry defines that. +The migrations init container reads the app's entries so both resolve a key alike. */}} -{{- define "sim.appEnvOverrides" -}} -{{- /* - Skip envDefaults keys that the user has explicitly overridden in app.env - with a non-empty value. K8s `env` takes precedence over `envFrom`, so an - inline default would otherwise mask the user's Secret-bound value. - Also skip envDefaults entirely in existingSecret mode: the pre-existing - Secret is the source of truth, and inlining localhost URL defaults would - silently shadow keys (NEXT_PUBLIC_APP_URL, BETTER_AUTH_URL, etc.) the - user stored in their Secret but left empty in app.env. -*/}} -{{- $appEnv := .Values.app.env | default dict }} -{{- $useExistingSecret := and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }} -{{- if not $useExistingSecret }} -{{- range $key, $value := .Values.app.envDefaults | default dict }} -{{- $override := index $appEnv $key }} -{{- if and (ne (toString $value) "") (ne (toString $value) "") (or (not $override) (eq (toString $override) "") (eq (toString $override) "")) }} +{{- define "sim.envOverrides" -}} +{{- $root := .root -}} +{{- $values := $root.Values -}} +{{- include "sim.envDefaultsEntries" (dict "root" $root "component" .component) }} +{{- if and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled) }} +{{- $chartComputed := list "DATABASE_URL" "SOCKET_SERVER_URL" "OLLAMA_URL" "PII_URL" }} +{{- /* Overlay by hand: sprig merge keeps the first source and treats "" as a value. */}} +{{- $effective := deepCopy ($values.app.env | default dict) }} +{{- if eq .component "realtime" }} +{{- range $key, $value := $values.realtime.env | default dict }} +{{- if and (ne (toString $value) "") (ne (toString $value) "") }} +{{- $_ := set $effective $key $value }} +{{- end }} +{{- end }} +{{- end }} +{{- range $key, $value := $effective }} +{{- if and (ne (toString $value) "") (ne (toString $value) "") (not (has $key $chartComputed)) }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} {{- end }} {{- end }} -{{- /* - In existingSecret mode the chart-managed Secret is not rendered, so - non-empty values in app.env would otherwise go nowhere — inline them - here so the user's overrides actually reach the pod. Skipped in ESO - mode (ESO is the source of truth; inlining would mask the synced value) - and in inline mode (values flow through the chart-managed Secret). +{{- if eq .component "app" }} +{{- include "sim.socketUrlEntry" $root }} +{{- end }} +{{- with $values.extraEnvVars }} +{{ toYaml . }} +{{- end }} +{{- include "sim.betterAuthUrlEntry" (dict "root" $root "component" .component) }} +{{- end }} + +{{/* +The app.env / realtime.env maps that reach a component's pod (dict "root" $ "component" +"app"|"realtime"), as a YAML list, lowest precedence first. The chart-managed Secret, which both +pods read, holds both maps with non-empty app.env winning; in existingSecret mode only realtime +inlines realtime.env, over app.env. */}} -{{- if and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }} -{{- $chartComputed := list "DATABASE_URL" "SOCKET_SERVER_URL" "OLLAMA_URL" "PII_URL" }} -{{- range $key, $value := $appEnv }} -{{- if and (ne (toString $value) "") (ne (toString $value) "") (not (has $key $chartComputed)) }} +{{- define "sim.secretEnvs" -}} +{{- $values := .root.Values -}} +{{- $appEnv := $values.app.env | default dict -}} +{{- $realtimeEnv := $values.realtime.env | default dict -}} +{{- if not (and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled)) -}} +{{- toYaml (list $realtimeEnv $appEnv) -}} +{{- else if eq .component "realtime" -}} +{{- toYaml (list $appEnv $realtimeEnv) -}} +{{- else -}} +{{- toYaml (list $appEnv) -}} +{{- end -}} +{{- end }} + +{{/* +The value a key resolves to on a component's pod (dict "root" $ "key" "" "component" +"app"|"realtime"), in Kubernetes precedence: envDefaults (inlined except in existingSecret mode), +then app.env and realtime.env (see sim.secretEnvs), then externalSecrets.remoteRefs.app, then +extraEnvVars (the last entry wins). "" when unset; "?" when only a secret reference supplies it, so +the chart cannot read it. A pre-created app Secret is unreadable and not considered. +*/}} +{{- define "sim.envValue" -}} +{{- $values := .root.Values -}} +{{- $key := .key -}} +{{- $value := "" -}} +{{- if not (and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled)) -}} +{{- $defaults := (index $values .component).envDefaults | default dict -}} +{{- if include "sim.nonEmptyEnv" (list $defaults $key) -}} +{{- $value = toString (index $defaults $key) -}} +{{- end -}} +{{- end -}} +{{- $envs := include "sim.secretEnvs" . | fromYamlArray -}} +{{- range $env := $envs -}} +{{- if include "sim.nonEmptyEnv" (list $env $key) -}} +{{- $value = toString (index $env $key) -}} +{{- end -}} +{{- end -}} +{{- if and $values.externalSecrets.enabled (index (default (dict) (default (dict) $values.externalSecrets.remoteRefs).app) $key) -}} +{{- $value = "?" -}} +{{- end -}} +{{- range $values.extraEnvVars | default list -}} +{{- if eq (toString .name) $key -}} +{{- $value = ternary "?" (toString (.value | default "")) (not (empty .valueFrom)) -}} +{{- end -}} +{{- end -}} +{{- $value -}} +{{- end }} + +{{/* +Inline env entries for a component's envDefaults (dict "root" $ "component" "app"|"realtime"). +Kubernetes `env` beats `envFrom`, so a default is skipped where it would mask a value the operator +supplies through the Secret: app.env or realtime.env sets the key (see sim.secretEnvs), or External +Secrets maps it in remoteRefs.app. None are inlined in existingSecret mode: the pre-created Secret +is the source of truth there, and app.env (inlined in that mode) carries overrides. +*/}} +{{- define "sim.envDefaultsEntries" -}} +{{- $values := .root.Values -}} +{{- if not (and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled)) -}} +{{- $remoteRefs := dict -}} +{{- if $values.externalSecrets.enabled -}} +{{- $remoteRefs = default (dict) (default (dict) $values.externalSecrets.remoteRefs).app -}} +{{- end -}} +{{- $maskingEnvs := include "sim.secretEnvs" . | fromYamlArray -}} +{{- range $key, $value := (index $values .component).envDefaults | default dict -}} +{{- $masked := index $remoteRefs $key -}} +{{- range $env := $maskingEnvs -}} +{{- if include "sim.nonEmptyEnv" (list $env $key) -}} +{{- $masked = true -}} +{{- end -}} +{{- end -}} +{{- if and (not $masked) (ne (toString $value) "") (ne (toString $value) "") }} - name: {{ $key }} value: {{ $value | quote }} +{{- end -}} +{{- end -}} +{{- end -}} {{- end }} + +{{/* +BETTER_AUTH_URL for a component (dict "root" $ "component" "app"|"realtime") when the operator set +it nowhere the chart can see: it follows NEXT_PUBLIC_APP_URL through dependent env expansion, which +resolves against envFrom and every earlier env entry, so it is emitted last. +Never in existingSecret mode, where the pre-created Secret may hold it and an inline entry would +mask it. +*/}} +{{- define "sim.betterAuthUrlEntry" -}} +{{- $values := .root.Values -}} +{{- $useExistingSecret := and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled) -}} +{{- $explicit := include "sim.envValue" (dict "root" .root "key" "BETTER_AUTH_URL" "component" .component) -}} +{{- if not (or $useExistingSecret $explicit) }} +- name: BETTER_AUTH_URL + value: "$(NEXT_PUBLIC_APP_URL)" +{{- end -}} {{- end }} + +{{/* +The host an ingress serves realtime on: realtime.host, or the app host when it is empty or +sim-ws.local, the old default placeholder, which no browser connects to. Takes the ingress values +(.Values.ingress or .Values.ingressInternal). +*/}} +{{- define "sim.ingressRealtimeHost" -}} +{{- if or (not .realtime.host) (eq (toString .realtime.host) "sim-ws.local") -}} +{{- .app.host -}} +{{- else -}} +{{- .realtime.host -}} +{{- end -}} {{- end }} -{{- with .Values.extraEnvVars }} -{{ toYaml . }} + +{{/* +The realtime ingress paths, as a YAML list. Under sim-ws.local, the old default placeholder, the old +default paths ([/ Prefix]) become /socket.io, since that host resolves to the app host. Takes the +ingress values. +*/}} +{{- define "sim.ingressRealtimePaths" -}} +{{- $paths := .realtime.paths | default list -}} +{{- if and (eq (toString .realtime.host) "sim-ws.local") (eq (len $paths) 1) (eq (toString (index $paths 0).path) "/") (eq (toString (index $paths 0).pathType) "Prefix") -}} +{{- $paths = list (dict "path" "/socket.io" "pathType" "Prefix") -}} +{{- end -}} +{{- toYaml $paths -}} +{{- end }} + +{{/* +Fail when realtime shares the app's ingress host with a "/" path: that rule is listed first and +would route every app request to realtime. Takes (list ""). +*/}} +{{- define "sim.validateIngressRealtimePaths" -}} +{{- $ingress := index . 0 -}} +{{- if eq (include "sim.ingressRealtimeHost" $ingress) (toString $ingress.app.host) -}} +{{- range include "sim.ingressRealtimePaths" $ingress | fromYamlArray -}} +{{- if eq (toString .path) "/" -}} +{{- fail (printf "%s.realtime.paths has \"/\" on the app host %q, which would send every app request to realtime. Use /socket.io (the default) or a separate %s.realtime.host." (index $ 1) (toString $ingress.app.host) (index $ 1)) -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end }} + +{{/* +NEXT_PUBLIC_SOCKET_URL for the app when the public ingress serves realtime on its own host and the +operator set the URL nowhere the chart can see. Browsers otherwise connect to the page's origin, +which that ingress does not route to realtime. The scheme is https when ingress.tls.enabled or the +NEXT_PUBLIC_APP_URL the pod resolves (sim.envValue) is https. A URL only a secret reference +supplies is unreadable, so it falls back to ingress.tls.enabled; with TLS +terminated in front of the ingress, set NEXT_PUBLIC_SOCKET_URL. Never in existingSecret mode (the +pre-created Secret may hold it). +*/}} +{{- define "sim.socketUrlEntry" -}} +{{- $values := .Values -}} +{{- $useExistingSecret := and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled) -}} +{{- if and $values.ingress.enabled $values.realtime.enabled (not $useExistingSecret) -}} +{{- $realtimeHost := include "sim.ingressRealtimeHost" $values.ingress -}} +{{- $explicit := include "sim.envValue" (dict "root" . "key" "NEXT_PUBLIC_SOCKET_URL" "component" "app") -}} +{{- /* https when the ingress terminates TLS, or when the public app URL says a load balancer in front does. */ -}} +{{- $appUrl := include "sim.envValue" (dict "root" . "key" "NEXT_PUBLIC_APP_URL" "component" "app") -}} +{{- $scheme := "http" -}} +{{- if or (and $values.ingress.tls $values.ingress.tls.enabled) (hasPrefix "https://" $appUrl) -}} +{{- $scheme = "https" -}} +{{- end -}} +{{- if and (ne $realtimeHost (toString $values.ingress.app.host)) (not $explicit) }} +- name: NEXT_PUBLIC_SOCKET_URL + value: {{ printf "%s://%s" $scheme $realtimeHost | quote }} +{{- end -}} +{{- end -}} {{- end }} + +{{/* +"true" when the app stores uploads on its container filesystem: STORAGE_PROVIDER is "local", or it +is unset and no object store has the keys the app needs to select it (packages/deployment-config +STORAGE_CAPABILITY: azure = AZURE_STORAGE_CONTAINER_NAME + AZURE_CONNECTION_STRING or +AZURE_ACCOUNT_NAME + AZURE_ACCOUNT_KEY, s3 = AWS_REGION + S3_BUCKET_NAME, gcs = GCS_BUCKET_NAME). +Keys resolve through sim.envValue. A pre-created app Secret cannot be read, so it is trusted, and a +volume mounted at the uploads directory keeps the files. +*/}} +{{- define "sim.localStorageInUse" -}} +{{- $root := . -}} +{{- $values := .Values -}} +{{- $useExistingSecret := and $values.app.secrets.existingSecret.enabled (not $values.externalSecrets.enabled) -}} +{{- $uploadsMounted := false -}} +{{- range concat ($values.extraVolumeMounts | default list) ($values.app.extraVolumeMounts | default list) -}} +{{- if eq (trimSuffix "/" (toString .mountPath)) "/app/apps/sim/uploads" -}} +{{- $uploadsMounted = true -}} +{{- end -}} +{{- end -}} +{{- if and $values.app.enabled (not $useExistingSecret) (not $uploadsMounted) -}} +{{- $present := dict -}} +{{- range $key := list "AWS_REGION" "S3_BUCKET_NAME" "AZURE_STORAGE_CONTAINER_NAME" "AZURE_CONNECTION_STRING" "AZURE_ACCOUNT_NAME" "AZURE_ACCOUNT_KEY" "GCS_BUCKET_NAME" -}} +{{- if include "sim.envValue" (dict "root" $root "key" $key "component" "app") -}} +{{- $_ := set $present $key true -}} +{{- end -}} +{{- end -}} +{{- $provider := include "sim.envValue" (dict "root" $root "key" "STORAGE_PROVIDER" "component" "app") -}} +{{- $azureReady := and (hasKey $present "AZURE_STORAGE_CONTAINER_NAME") (or (hasKey $present "AZURE_CONNECTION_STRING") (and (hasKey $present "AZURE_ACCOUNT_NAME") (hasKey $present "AZURE_ACCOUNT_KEY"))) -}} +{{- $s3Ready := and (hasKey $present "AWS_REGION") (hasKey $present "S3_BUCKET_NAME") -}} +{{- $gcsReady := hasKey $present "GCS_BUCKET_NAME" -}} +{{- if or (eq (lower $provider) "local") (and (eq $provider "") (not (or $azureReady $s3Ready $gcsReady))) -}} +true +{{- end -}} +{{- end -}} +{{- end }} + +{{/* +Local upload storage is per pod, so more than one app replica splits uploads between pods and loses +each pod's on restart. Refused on install and upgrade alike (helm template, which Argo CD renders +with, always reports an install), unless app.storage.allowLocalWithReplicas accepts it. +*/}} +{{- define "sim.validateStorage" -}} +{{- $allowLocal := and .Values.app.storage .Values.app.storage.allowLocalWithReplicas -}} +{{- if and (not $allowLocal) (or (gt (int .Values.app.replicaCount) 1) .Values.autoscaling.enabled) (include "sim.localStorageInUse" .) -}} +{{- fail "More than one app replica (app.replicaCount > 1 or autoscaling.enabled) needs object storage: uploads on each pod's filesystem are not shared and are lost on restart. Configure S3, Azure Blob, or GCS in app.env (see STORAGE_PROVIDER in values.yaml), mount a ReadWriteMany volume at /app/apps/sim/uploads, or set app.storage.allowLocalWithReplicas=true." -}} +{{- end -}} +{{- end }} + +{{/* +Volume claim template labels for a bundled database StatefulSet +(dict "root" $ "name" "" "claim" "" "selectorLabels" ""). +Kubernetes rejects any change to volumeClaimTemplates, so these must never change across upgrades: +an existing StatefulSet's labels are reused verbatim, and a new one gets only labels that never +change. +*/}} +{{- define "sim.volumeClaimTemplateLabels" -}} +{{- $root := .root -}} +{{- $existing := lookup "apps/v1" "StatefulSet" $root.Release.Namespace .name -}} +{{- $labels := .selectorLabels | fromYaml -}} +{{- if $existing -}} +{{- range ($existing.spec | default dict).volumeClaimTemplates | default list -}} +{{- if eq (toString .metadata.name) $.claim -}} +{{- $labels = .metadata.labels | default dict -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- with $labels -}} +labels: + {{- toYaml . | nindent 2 }} +{{- end -}} {{- end }} {{/* diff --git a/helm/sim/templates/_ingress.tpl b/helm/sim/templates/_ingress.tpl new file mode 100644 index 00000000000..18c945976bb --- /dev/null +++ b/helm/sim/templates/_ingress.tpl @@ -0,0 +1,142 @@ +{{/* +One Ingress for the public (ingress) or internal (ingressInternal) values: +(dict "root" $ "cfg" "key" "ingress"|"ingressInternal" "suffix" ""). +When services share a host, their paths join one rule: realtime, then copilot, then the app. +*/}} +{{- define "sim.ingress" -}} +{{- $root := .root -}} +{{- $cfg := .cfg -}} +{{- $key := .key -}} +{{- $suffix := .suffix -}} +{{- $appActive := $root.Values.app.enabled -}} +{{- $realtimeActive := $root.Values.realtime.enabled -}} +{{- $hasCopilotIngress := and $root.Values.copilot.enabled $cfg.copilot -}} +{{- $realtimeHost := include "sim.ingressRealtimeHost" $cfg -}} +{{- if and $appActive $realtimeActive }} +{{- include "sim.validateIngressRealtimePaths" (list $cfg $key) }} +{{- end }} +{{- $realtimeHasOwnRule := and $realtimeActive (or (not $appActive) (ne $realtimeHost (toString $cfg.app.host))) -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "sim.fullname" $root }}-{{ $suffix }} + namespace: {{ $root.Release.Namespace }} + labels: + {{- include "sim.labels" $root | nindent 4 }} + {{- with $cfg.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if $cfg.className }} + ingressClassName: {{ $cfg.className }} + {{- end }} + {{- if $cfg.tls.enabled }} + tls: + - hosts: + {{- if $appActive }} + - {{ $cfg.app.host | quote }} + {{- end }} + {{- if $realtimeHasOwnRule }} + - {{ $realtimeHost | quote }} + {{- end }} + {{- if $hasCopilotIngress }} + {{- $copilotHostCovered := false }} + {{- if and $appActive (eq $cfg.copilot.host $cfg.app.host) }} + {{- $copilotHostCovered = true }} + {{- end }} + {{- if and $realtimeHasOwnRule (eq $cfg.copilot.host $realtimeHost) }} + {{- $copilotHostCovered = true }} + {{- end }} + {{- if not $copilotHostCovered }} + - {{ $cfg.copilot.host | quote }} + {{- end }} + {{- end }} + secretName: {{ $cfg.tls.secretName }} + {{- end }} + rules: + {{- if $appActive }} + - host: {{ $cfg.app.host | quote }} + http: + paths: + {{- if and $realtimeActive (eq $realtimeHost (toString $cfg.app.host)) }} + {{- range include "sim.ingressRealtimePaths" $cfg | fromYamlArray }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-realtime + port: + number: {{ $root.Values.realtime.service.port }} + {{- end }} + {{- end }} + {{- if and $hasCopilotIngress (eq $cfg.copilot.host $cfg.app.host) }} + {{- range $cfg.copilot.paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-copilot + port: + number: {{ $root.Values.copilot.server.service.port }} + {{- end }} + {{- end }} + {{- range $cfg.app.paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-app + port: + number: {{ $root.Values.app.service.port }} + {{- end }} + {{- end }} + {{- if $realtimeHasOwnRule }} + - host: {{ $realtimeHost | quote }} + http: + paths: + {{- range include "sim.ingressRealtimePaths" $cfg | fromYamlArray }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-realtime + port: + number: {{ $root.Values.realtime.service.port }} + {{- end }} + {{- if and $hasCopilotIngress (eq $cfg.copilot.host $realtimeHost) }} + {{- range $cfg.copilot.paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-copilot + port: + number: {{ $root.Values.copilot.server.service.port }} + {{- end }} + {{- end }} + {{- end }} + {{- if $hasCopilotIngress }} + {{- $copilotServed := false }} + {{- if and $appActive (eq $cfg.copilot.host $cfg.app.host) }} + {{- $copilotServed = true }} + {{- end }} + {{- if and $realtimeHasOwnRule (eq $cfg.copilot.host $realtimeHost) }} + {{- $copilotServed = true }} + {{- end }} + {{- if not $copilotServed }} + - host: {{ $cfg.copilot.host | quote }} + http: + paths: + {{- range $cfg.copilot.paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ include "sim.fullname" $root }}-copilot + port: + number: {{ $root.Values.copilot.server.service.port }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/helm/sim/templates/deployment-app.yaml b/helm/sim/templates/deployment-app.yaml index 2d46d8e38f0..06937fa1625 100644 --- a/helm/sim/templates/deployment-app.yaml +++ b/helm/sim/templates/deployment-app.yaml @@ -1,6 +1,7 @@ {{- if .Values.app.enabled }} {{- include "sim.validateSecrets" . }} {{- include "sim.sandbox.validate" . }} +{{- include "sim.validateStorage" . }} apiVersion: apps/v1 kind: Deployment metadata: @@ -67,7 +68,7 @@ spec: extraEnvVars), else the app Secret. Without a usable key the step stays pending. */}} env: - {{- $appOverrides := include "sim.appEnvOverrides" . | fromYamlArray }} + {{- $appOverrides := include "sim.envOverrides" (dict "root" . "component" "app") | fromYamlArray }} {{- range $key := list "ENCRYPTION_KEY" "ENCRYPT_ACCOUNT_TOKENS" }} {{- $override := dict }} {{- range $appOverrides }} @@ -153,7 +154,7 @@ spec: {{- include "sim.sandbox.appEnv" . | nindent 12 }} {{- end }} {{- /* Operator overrides last, so they win over the defaults above and over envFrom. */}} - {{- include "sim.appEnvOverrides" . | trim | nindent 12 }} + {{- include "sim.envOverrides" (dict "root" . "component" "app") | trim | nindent 12 }} envFrom: # Bundled Redis URL. Listed FIRST so any operator-supplied REDIS_URL # in a later source overrides it — see templates/configmap-redis.yaml. diff --git a/helm/sim/templates/deployment-realtime.yaml b/helm/sim/templates/deployment-realtime.yaml index e7c6aa58e93..38e7b4db001 100644 --- a/helm/sim/templates/deployment-realtime.yaml +++ b/helm/sim/templates/deployment-realtime.yaml @@ -74,67 +74,9 @@ spec: - name: OTEL_RESOURCE_ATTRIBUTES value: "service.name=sim-realtime,service.version={{ .Chart.AppVersion }},deployment.environment={{ $nodeEnv }}" {{- end }} - {{- /* - Inline realtime.envDefaults, skipping keys explicitly set in realtime.env - OR app.env (K8s `env` overrides `envFrom`, so an inline default would - otherwise mask a Secret-bound value). The chart-managed Secret is shared - between app and realtime via envFrom, so a key set in app.env (e.g. - NEXT_PUBLIC_APP_URL=https://prod.example.com) lands on the realtime pod - too — inlining the localhost envDefault here would mask it. - */}} - {{- $rtEnv := .Values.realtime.env | default dict }} - {{- $appEnv := .Values.app.env | default dict }} - {{- $useExistingSecret := and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }} - {{- /* - Skip envDefaults entirely in existingSecret mode — same rationale as - deployment-app.yaml: the pre-existing Secret is the source of truth, - and inlining localhost defaults would shadow URL keys (BETTER_AUTH_URL, - ALLOWED_ORIGINS, NEXT_PUBLIC_APP_URL, etc.) stored in the Secret. - */}} - {{- if not $useExistingSecret }} - {{- range $key, $value := .Values.realtime.envDefaults | default dict }} - {{- $rtOverride := index $rtEnv $key }} - {{- $appOverride := index $appEnv $key }} - {{- $hasRt := and $rtOverride (ne (toString $rtOverride) "") (ne (toString $rtOverride) "") }} - {{- $hasApp := and $appOverride (ne (toString $appOverride) "") (ne (toString $appOverride) "") }} - {{- if and (ne (toString $value) "") (ne (toString $value) "") (not $hasRt) (not $hasApp) }} - - name: {{ $key }} - value: {{ $value | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- /* - In existingSecret mode the chart-managed Secret is not rendered, so - non-empty values in realtime.env / app.env would otherwise go nowhere - — inline them here so the user's overrides actually reach the pod. - realtime.env wins over app.env on collision (realtime-specific intent). - Skipped in ESO mode and inline mode for the same reasons as the app - deployment. - */}} - {{- if and .Values.app.secrets.existingSecret.enabled (not .Values.externalSecrets.enabled) }} - {{- $chartComputed := list "DATABASE_URL" "SOCKET_SERVER_URL" "OLLAMA_URL" "PII_URL" }} - {{- /* - Build the effective realtime env from app.env as the base, then - overlay non-empty realtime.env values. Sprig's `merge` keeps the - first source on collision and treats "" as a real value, which - would shadow non-empty app.env entries — so do the overlay - manually with an explicit empty-string check. - */}} - {{- $effective := deepCopy $appEnv }} - {{- range $key, $value := $rtEnv }} - {{- if and (ne (toString $value) "") (ne (toString $value) "") }} - {{- $_ := set $effective $key $value }} - {{- end }} - {{- end }} - {{- range $key, $value := $effective }} - {{- if and (ne (toString $value) "") (ne (toString $value) "") (not (has $key $chartComputed)) }} - - name: {{ $key }} - value: {{ $value | quote }} - {{- end }} - {{- end }} - {{- end }} - {{- with .Values.extraEnvVars }} - {{- toYaml . | nindent 12 }} + {{- /* Operator overrides last, so they win over the defaults above and over envFrom. */}} + {{- with include "sim.envOverrides" (dict "root" . "component" "realtime") | trim }} + {{- . | nindent 12 }} {{- end }} envFrom: # Bundled Redis URL. Listed FIRST so any operator-supplied REDIS_URL diff --git a/helm/sim/templates/ingress-internal.yaml b/helm/sim/templates/ingress-internal.yaml index 54a8e5766a5..0c73897e69e 100644 --- a/helm/sim/templates/ingress-internal.yaml +++ b/helm/sim/templates/ingress-internal.yaml @@ -1,129 +1,3 @@ {{- if .Values.ingressInternal.enabled }} -{{- $appActive := .Values.app.enabled -}} -{{- $realtimeActive := .Values.realtime.enabled -}} -{{- $hasCopilotIngress := and .Values.copilot.enabled .Values.ingressInternal.copilot -}} -{{- $realtimeHasOwnRule := and $realtimeActive (or (not $appActive) (ne .Values.ingressInternal.realtime.host .Values.ingressInternal.app.host)) -}} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ include "sim.fullname" . }}-ingress-internal - namespace: {{ .Release.Namespace }} - labels: - {{- include "sim.labels" . | nindent 4 }} - {{- with .Values.ingressInternal.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- if .Values.ingressInternal.className }} - ingressClassName: {{ .Values.ingressInternal.className }} - {{- end }} - {{- if .Values.ingressInternal.tls.enabled }} - tls: - - hosts: - {{- if $appActive }} - - {{ .Values.ingressInternal.app.host | quote }} - {{- end }} - {{- if $realtimeHasOwnRule }} - - {{ .Values.ingressInternal.realtime.host | quote }} - {{- end }} - {{- if $hasCopilotIngress }} - {{- $copilotHostCovered := false }} - {{- if and $appActive (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.app.host) }} - {{- $copilotHostCovered = true }} - {{- end }} - {{- if and $realtimeHasOwnRule (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.realtime.host) }} - {{- $copilotHostCovered = true }} - {{- end }} - {{- if not $copilotHostCovered }} - - {{ .Values.ingressInternal.copilot.host | quote }} - {{- end }} - {{- end }} - secretName: {{ .Values.ingressInternal.tls.secretName }} - {{- end }} - rules: - {{- if $appActive }} - - host: {{ .Values.ingressInternal.app.host | quote }} - http: - paths: - {{- if and $realtimeActive (eq .Values.ingressInternal.realtime.host .Values.ingressInternal.app.host) }} - {{- range .Values.ingressInternal.realtime.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-realtime - port: - number: {{ $.Values.realtime.service.port }} - {{- end }} - {{- end }} - {{- if and $hasCopilotIngress (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.app.host) }} - {{- range .Values.ingressInternal.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- range .Values.ingressInternal.app.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-app - port: - number: {{ $.Values.app.service.port }} - {{- end }} - {{- end }} - {{- if $realtimeHasOwnRule }} - - host: {{ .Values.ingressInternal.realtime.host | quote }} - http: - paths: - {{- range .Values.ingressInternal.realtime.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-realtime - port: - number: {{ $.Values.realtime.service.port }} - {{- end }} - {{- if and $hasCopilotIngress (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.realtime.host) }} - {{- range .Values.ingressInternal.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- end }} - {{- if $hasCopilotIngress }} - {{- $copilotServed := false }} - {{- if and $appActive (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.app.host) }} - {{- $copilotServed = true }} - {{- end }} - {{- if and $realtimeHasOwnRule (eq .Values.ingressInternal.copilot.host .Values.ingressInternal.realtime.host) }} - {{- $copilotServed = true }} - {{- end }} - {{- if not $copilotServed }} - - host: {{ .Values.ingressInternal.copilot.host | quote }} - http: - paths: - {{- range .Values.ingressInternal.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- end }} +{{- include "sim.ingress" (dict "root" . "cfg" .Values.ingressInternal "key" "ingressInternal" "suffix" "ingress-internal") }} {{- end }} diff --git a/helm/sim/templates/ingress.yaml b/helm/sim/templates/ingress.yaml index 8014705b3d1..d0de7516d09 100644 --- a/helm/sim/templates/ingress.yaml +++ b/helm/sim/templates/ingress.yaml @@ -1,129 +1,3 @@ {{- if .Values.ingress.enabled }} -{{- $appActive := .Values.app.enabled -}} -{{- $realtimeActive := .Values.realtime.enabled -}} -{{- $hasCopilotIngress := and .Values.copilot.enabled .Values.ingress.copilot -}} -{{- $realtimeHasOwnRule := and $realtimeActive (or (not $appActive) (ne .Values.ingress.realtime.host .Values.ingress.app.host)) -}} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ include "sim.fullname" . }}-ingress - namespace: {{ .Release.Namespace }} - labels: - {{- include "sim.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- if .Values.ingress.className }} - ingressClassName: {{ .Values.ingress.className }} - {{- end }} - {{- if .Values.ingress.tls.enabled }} - tls: - - hosts: - {{- if $appActive }} - - {{ .Values.ingress.app.host | quote }} - {{- end }} - {{- if $realtimeHasOwnRule }} - - {{ .Values.ingress.realtime.host | quote }} - {{- end }} - {{- if $hasCopilotIngress }} - {{- $copilotHostCovered := false }} - {{- if and $appActive (eq .Values.ingress.copilot.host .Values.ingress.app.host) }} - {{- $copilotHostCovered = true }} - {{- end }} - {{- if and $realtimeHasOwnRule (eq .Values.ingress.copilot.host .Values.ingress.realtime.host) }} - {{- $copilotHostCovered = true }} - {{- end }} - {{- if not $copilotHostCovered }} - - {{ .Values.ingress.copilot.host | quote }} - {{- end }} - {{- end }} - secretName: {{ .Values.ingress.tls.secretName }} - {{- end }} - rules: - {{- if $appActive }} - - host: {{ .Values.ingress.app.host | quote }} - http: - paths: - {{- if and $realtimeActive (eq .Values.ingress.realtime.host .Values.ingress.app.host) }} - {{- range .Values.ingress.realtime.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-realtime - port: - number: {{ $.Values.realtime.service.port }} - {{- end }} - {{- end }} - {{- if and $hasCopilotIngress (eq .Values.ingress.copilot.host .Values.ingress.app.host) }} - {{- range .Values.ingress.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- range .Values.ingress.app.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-app - port: - number: {{ $.Values.app.service.port }} - {{- end }} - {{- end }} - {{- if $realtimeHasOwnRule }} - - host: {{ .Values.ingress.realtime.host | quote }} - http: - paths: - {{- range .Values.ingress.realtime.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-realtime - port: - number: {{ $.Values.realtime.service.port }} - {{- end }} - {{- if and $hasCopilotIngress (eq .Values.ingress.copilot.host .Values.ingress.realtime.host) }} - {{- range .Values.ingress.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- end }} - {{- if $hasCopilotIngress }} - {{- $copilotServed := false }} - {{- if and $appActive (eq .Values.ingress.copilot.host .Values.ingress.app.host) }} - {{- $copilotServed = true }} - {{- end }} - {{- if and $realtimeHasOwnRule (eq .Values.ingress.copilot.host .Values.ingress.realtime.host) }} - {{- $copilotServed = true }} - {{- end }} - {{- if not $copilotServed }} - - host: {{ .Values.ingress.copilot.host | quote }} - http: - paths: - {{- range .Values.ingress.copilot.paths }} - - path: {{ .path }} - pathType: {{ .pathType }} - backend: - service: - name: {{ include "sim.fullname" $ }}-copilot - port: - number: {{ $.Values.copilot.server.service.port }} - {{- end }} - {{- end }} - {{- end }} +{{- include "sim.ingress" (dict "root" . "cfg" .Values.ingress "key" "ingress" "suffix" "ingress") }} {{- end }} diff --git a/helm/sim/templates/statefulset-copilot-postgres.yaml b/helm/sim/templates/statefulset-copilot-postgres.yaml index fcb2e797774..c3872a35f63 100644 --- a/helm/sim/templates/statefulset-copilot-postgres.yaml +++ b/helm/sim/templates/statefulset-copilot-postgres.yaml @@ -130,8 +130,7 @@ spec: volumeClaimTemplates: - metadata: name: data - labels: - {{- include "sim.copilotPostgresql.labels" . | nindent 10 }} + {{- include "sim.volumeClaimTemplateLabels" (dict "root" . "name" (printf "%s-copilot-postgresql" (include "sim.fullname" .)) "claim" "data" "selectorLabels" (include "sim.copilotPostgresql.selectorLabels" .)) | nindent 8 }} spec: accessModes: {{- range .Values.copilot.postgresql.persistence.accessModes }} diff --git a/helm/sim/templates/statefulset-postgresql.yaml b/helm/sim/templates/statefulset-postgresql.yaml index 50c78b8a03d..9b07138ec95 100644 --- a/helm/sim/templates/statefulset-postgresql.yaml +++ b/helm/sim/templates/statefulset-postgresql.yaml @@ -187,8 +187,7 @@ spec: volumeClaimTemplates: - metadata: name: postgresql-data - labels: - {{- include "sim.postgresql.labels" . | nindent 10 }} + {{- include "sim.volumeClaimTemplateLabels" (dict "root" . "name" (printf "%s-postgresql" (include "sim.fullname" .)) "claim" "postgresql-data" "selectorLabels" (include "sim.postgresql.selectorLabels" .)) | nindent 8 }} spec: {{- if .Values.postgresql.persistence.storageClass }} {{- if (eq "-" .Values.postgresql.persistence.storageClass) }} diff --git a/helm/sim/tests/env-defaults_test.yaml b/helm/sim/tests/env-defaults_test.yaml index 144f45254f7..dcf2ad1a2ca 100644 --- a/helm/sim/tests/env-defaults_test.yaml +++ b/helm/sim/tests/env-defaults_test.yaml @@ -17,7 +17,7 @@ tests: - contains: path: spec.template.spec.containers[0].env content: - name: BETTER_AUTH_URL + name: NEXT_PUBLIC_APP_URL value: http://localhost:3000 - contains: path: spec.template.spec.containers[0].env @@ -48,7 +48,7 @@ tests: - contains: path: spec.template.spec.containers[0].env content: - name: BETTER_AUTH_URL + name: NEXT_PUBLIC_APP_URL value: http://localhost:3000 - it: existingSecret mode skips envDefaults on the app pod @@ -61,7 +61,7 @@ tests: - notContains: path: spec.template.spec.containers[0].env content: - name: BETTER_AUTH_URL + name: NEXT_PUBLIC_APP_URL value: http://localhost:3000 - it: existingSecret mode skips envDefaults on the realtime pod @@ -74,7 +74,7 @@ tests: - notContains: path: spec.template.spec.containers[0].env content: - name: BETTER_AUTH_URL + name: NEXT_PUBLIC_APP_URL value: http://localhost:3000 - it: existingSecret mode inlines user-set app.env values on the app pod @@ -119,3 +119,187 @@ tests: content: name: NEXT_PUBLIC_APP_URL value: "https://realtime.example.com" + + # External Secrets: a key synced into the app Secret must not be masked by an inline envDefault. + - it: ESO mode skips an app envDefault whose key remoteRefs.app maps + template: deployment-app.yaml + set: &esoMapsAppUrl + externalSecrets.enabled: true + externalSecrets.secretStoreRef.name: store + externalSecrets.remoteRefs.app.BETTER_AUTH_SECRET: sim/app/better-auth-secret + externalSecrets.remoteRefs.app.ENCRYPTION_KEY: sim/app/encryption-key + externalSecrets.remoteRefs.app.INTERNAL_API_SECRET: sim/app/internal-api-secret + externalSecrets.remoteRefs.app.CRON_SECRET: sim/app/cron-secret + externalSecrets.remoteRefs.app.NEXT_PUBLIC_APP_URL: sim/app/public-url + externalSecrets.remoteRefs.postgresql.password: sim/postgresql/password + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_APP_URL + value: http://localhost:3000 + - contains: + path: spec.template.spec.containers[0].env + content: + name: IVM_POOL_SIZE + value: "4" + + - it: ESO mode skips a realtime envDefault whose key remoteRefs.app maps + template: deployment-realtime.yaml + set: + <<: *esoMapsAppUrl + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_APP_URL + value: http://localhost:3000 + - contains: + path: spec.template.spec.containers[0].env + content: + name: ALLOWED_ORIGINS + value: http://localhost:3000 + + # existingSecret mode: the pre-created Secret is the source of truth, so no envDefaults value is + # inlined over it, even one the operator changed (overrides go in app.env, inlined in this mode). + - it: existingSecret mode inlines no app envDefaults, even changed ones + template: deployment-app.yaml + set: + app.secrets.existingSecret.enabled: true + app.secrets.existingSecret.name: my-secret + postgresql.auth.password: xxxxxxxx + app.envDefaults.IVM_POOL_SIZE: "8" + app.envDefaults.NEXT_PUBLIC_BRAND_NAME: Sim + asserts: + - lengthEqual: + path: spec.template.spec.containers[0].env + count: 4 + + - it: existingSecret mode inlines no realtime envDefaults, even changed ones + template: deployment-realtime.yaml + set: + app.secrets.existingSecret.enabled: true + app.secrets.existingSecret.name: my-secret + postgresql.auth.password: xxxxxxxx + realtime.envDefaults.ALLOWED_ORIGINS: https://sim.example.com + asserts: + - lengthEqual: + path: spec.template.spec.containers[0].env + count: 1 + + # BETTER_AUTH_URL follows NEXT_PUBLIC_APP_URL unless the operator sets it somewhere. + - it: app BETTER_AUTH_URL defaults to NEXT_PUBLIC_APP_URL, after it + template: deployment-app.yaml + set: + <<: *defaults + asserts: + - equal: + path: spec.template.spec.containers[0].env[-1] + value: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: realtime BETTER_AUTH_URL defaults to NEXT_PUBLIC_APP_URL, after it + template: deployment-realtime.yaml + set: + <<: *defaults + asserts: + - equal: + path: spec.template.spec.containers[0].env[-1] + value: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: BETTER_AUTH_URL follows an extraEnvVars NEXT_PUBLIC_APP_URL, so the reference expands + template: deployment-app.yaml + set: + <<: *defaults + extraEnvVars: + - name: NEXT_PUBLIC_APP_URL + value: https://sim.example.com + asserts: + - equal: + path: spec.template.spec.containers[0].env[-1] + value: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: an app.env BETTER_AUTH_URL wins on both pods + templates: + - deployment-app.yaml + - deployment-realtime.yaml + set: + <<: *defaults + app.env.BETTER_AUTH_URL: https://auth.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: a realtime.env BETTER_AUTH_URL wins on the realtime pod + template: deployment-realtime.yaml + set: + <<: *defaults + realtime.env.BETTER_AUTH_URL: https://auth.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: an envDefaults BETTER_AUTH_URL is inlined instead of the reference + template: deployment-app.yaml + set: + <<: *defaults + app.envDefaults.BETTER_AUTH_URL: https://auth.example.com + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: https://auth.example.com } + - notContains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: a remoteRefs.app BETTER_AUTH_URL wins on both pods + templates: + - deployment-app.yaml + - deployment-realtime.yaml + set: + <<: *esoMapsAppUrl + externalSecrets.remoteRefs.app.BETTER_AUTH_URL: sim/app/auth-url + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + - it: existingSecret mode leaves BETTER_AUTH_URL to the pre-created Secret + templates: + - deployment-app.yaml + - deployment-realtime.yaml + set: + app.secrets.existingSecret.enabled: true + app.secrets.existingSecret.name: my-secret + postgresql.auth.password: xxxxxxxx + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: { name: BETTER_AUTH_URL, value: $(NEXT_PUBLIC_APP_URL) } + + # In inline mode realtime.env is written into the app Secret both pods read, so it counts on the app + # pod too: nothing inline may override it there. + - it: a realtime.env BETTER_AUTH_URL also wins on the app pod + template: deployment-app.yaml + set: + <<: *defaults + realtime.env.BETTER_AUTH_URL: https://auth.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: BETTER_AUTH_URL + any: true + + - it: a realtime.env value masks the app envDefault for the same key + template: deployment-app.yaml + set: + <<: *defaults + realtime.env.NEXT_PUBLIC_APP_URL: https://sim.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_APP_URL + any: true diff --git a/helm/sim/tests/env-null-deletion_test.yaml b/helm/sim/tests/env-null-deletion_test.yaml index 8a50ff957b6..9a3bd6ee1a1 100644 --- a/helm/sim/tests/env-null-deletion_test.yaml +++ b/helm/sim/tests/env-null-deletion_test.yaml @@ -93,7 +93,7 @@ tests: - contains: path: spec.template.spec.containers[0].env content: - name: BETTER_AUTH_URL + name: NEXT_PUBLIC_APP_URL value: http://localhost:3000 - contains: path: spec.template.spec.containers[0].env diff --git a/helm/sim/tests/ingress-realtime_test.yaml b/helm/sim/tests/ingress-realtime_test.yaml new file mode 100644 index 00000000000..676d1281000 --- /dev/null +++ b/helm/sim/tests/ingress-realtime_test.yaml @@ -0,0 +1,245 @@ +suite: ingress — realtime reachable where browsers connect +release: + name: t + namespace: sim +defaults: &defaults + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.password: xxxxxxxx + ingress.enabled: true + ingress.app.host: sim.example.com +tests: + # With NEXT_PUBLIC_SOCKET_URL empty, browsers open Socket.IO on the page origin, so the app host + # itself must route /socket.io to realtime. + - it: by default serves realtime on the app host under /socket.io, ahead of the app + template: ingress.yaml + set: + <<: *defaults + asserts: + - lengthEqual: + path: spec.rules + count: 1 + - equal: + path: spec.rules[0].host + value: sim.example.com + - equal: + path: spec.rules[0].http.paths[0] + value: + path: /socket.io + pathType: Prefix + backend: + service: + name: t-sim-realtime + port: + number: 3002 + - equal: + path: spec.rules[0].http.paths[1].backend.service.name + value: t-sim-app + + - it: sets no socket URL on the app when realtime shares the app host + template: deployment-app.yaml + set: + <<: *defaults + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + any: true + + - it: points the app at a separate realtime host over https when TLS is on + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + ingress.tls.enabled: true + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: https://ws.example.com + + - it: points the app at a separate realtime host over http without TLS + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: http://ws.example.com + + # TLS terminated at a load balancer in front of the ingress (ALB, cloud LB) leaves ingress.tls off. + - it: uses https for a separate realtime host when NEXT_PUBLIC_APP_URL is https + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + app.env.NEXT_PUBLIC_APP_URL: https://sim.example.com + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: https://ws.example.com + + - it: uses https when an envDefaults NEXT_PUBLIC_APP_URL is https + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + app.envDefaults.NEXT_PUBLIC_APP_URL: https://sim.example.com + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: https://ws.example.com + + - it: uses https when an extraEnvVars NEXT_PUBLIC_APP_URL is https + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + extraEnvVars: + - name: NEXT_PUBLIC_APP_URL + value: https://sim.example.com + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: https://ws.example.com + + # A URL only External Secrets supplies can't be read at render time: ingress.tls decides. + - it: falls back to ingress.tls when only External Secrets supplies NEXT_PUBLIC_APP_URL + template: deployment-app.yaml + set: + ingress.enabled: true + ingress.app.host: sim.example.com + ingress.realtime.host: ws.example.com + app.envDefaults.NEXT_PUBLIC_APP_URL: https://sim.example.com + externalSecrets.enabled: true + externalSecrets.secretStoreRef.name: store + externalSecrets.remoteRefs.app.BETTER_AUTH_SECRET: a + externalSecrets.remoteRefs.app.ENCRYPTION_KEY: b + externalSecrets.remoteRefs.app.INTERNAL_API_SECRET: c + externalSecrets.remoteRefs.app.CRON_SECRET: d + externalSecrets.remoteRefs.app.NEXT_PUBLIC_APP_URL: e + externalSecrets.remoteRefs.postgresql.password: f + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + value: http://ws.example.com + + - it: keeps a realtime.env NEXT_PUBLIC_SOCKET_URL, which the shared Secret gives the app + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + realtime.env.NEXT_PUBLIC_SOCKET_URL: wss://ws.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + any: true + + - it: keeps an operator-set NEXT_PUBLIC_SOCKET_URL for a separate realtime host + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + app.env.NEXT_PUBLIC_SOCKET_URL: wss://ws.example.com + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + any: true + + # A values file copied from a chart before 1.20.0 still names its placeholder realtime host and "/". + - it: routes the pre-1.20.0 placeholder realtime block on the app host under /socket.io + template: ingress.yaml + set: + <<: *defaults + ingress.realtime.host: sim-ws.local + ingress.realtime.paths: + - path: / + pathType: Prefix + asserts: + - lengthEqual: + path: spec.rules + count: 1 + - equal: + path: spec.rules[0].http.paths[0].path + value: /socket.io + - equal: + path: spec.rules[0].http.paths[0].backend.service.name + value: t-sim-realtime + - equal: + path: spec.rules[0].http.paths[1].path + value: / + + # A values file copied from a chart before 1.20.0 still names its placeholder realtime host. + - it: sets no socket URL for the former placeholder realtime host + template: deployment-app.yaml + set: + <<: *defaults + ingress.realtime.host: sim-ws.local + asserts: + - notContains: + path: spec.template.spec.containers[0].env + content: + name: NEXT_PUBLIC_SOCKET_URL + any: true + + - it: gives a separate realtime host its own rule with the operator's paths + template: ingress.yaml + set: + <<: *defaults + ingress.realtime.host: ws.example.com + ingress.realtime.paths: + - path: / + pathType: Prefix + asserts: + - equal: + path: spec.rules[1].host + value: ws.example.com + - equal: + path: spec.rules[1].http.paths[0].path + value: / + - equal: + path: spec.rules[0].http.paths[0].backend.service.name + value: t-sim-app + + - it: refuses a "/" realtime path on the app host + template: ingress.yaml + set: + <<: *defaults + ingress.realtime.host: sim.example.com + ingress.realtime.paths: + - path: / + pathType: Prefix + asserts: + - failedTemplate: + errorMessage: 'ingress.realtime.paths has "/" on the app host "sim.example.com", which would send every app request to realtime. Use /socket.io (the default) or a separate ingress.realtime.host.' + + - it: refuses a "/" realtime path on the internal ingress app host + template: ingress-internal.yaml + set: + <<: *defaults + ingressInternal.enabled: true + ingressInternal.realtime.paths: + - path: / + pathType: Prefix + asserts: + - failedTemplate: + errorMessage: 'ingressInternal.realtime.paths has "/" on the app host "sim-internal.local", which would send every app request to realtime. Use /socket.io (the default) or a separate ingressInternal.realtime.host.' diff --git a/helm/sim/tests/notes_test.yaml b/helm/sim/tests/notes_test.yaml new file mode 100644 index 00000000000..7a124ab263a --- /dev/null +++ b/helm/sim/tests/notes_test.yaml @@ -0,0 +1,28 @@ +suite: NOTES.txt — post-install guidance +templates: + - NOTES.txt +release: + name: t + namespace: sim +defaults: &defaults + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.password: xxxxxxxx +tests: + - it: port-forwards realtime next to the app, so a local browser can open Socket.IO + set: + <<: *defaults + asserts: + - matchRegexRaw: + pattern: "port-forward svc/t-sim-realtime 3002:3002" + + - it: upgrades from the published chart, not a checkout path + set: + <<: *defaults + asserts: + - matchRegexRaw: + pattern: "helm upgrade t oci://ghcr.io/simstudioai/charts/sim --version" + - notMatchRegexRaw: + pattern: "\\./helm/sim" diff --git a/helm/sim/tests/pdb-hpa_test.yaml b/helm/sim/tests/pdb-hpa_test.yaml index 3960f2e4006..a5c0d86b89e 100644 --- a/helm/sim/tests/pdb-hpa_test.yaml +++ b/helm/sim/tests/pdb-hpa_test.yaml @@ -8,6 +8,9 @@ defaults: &defaults app.env.INTERNAL_API_SECRET: x app.env.CRON_SECRET: x postgresql.auth.password: xxxxxxxx + # Several app replicas need object storage (local uploads are per pod). + app.env.AWS_REGION: us-east-1 + app.env.S3_BUCKET_NAME: sim-files tests: - it: PDB does not render when replicaCount=1 and HPA is off (tri-state null) template: poddisruptionbudget.yaml diff --git a/helm/sim/tests/postgres-volume-claim-labels_test.yaml b/helm/sim/tests/postgres-volume-claim-labels_test.yaml new file mode 100644 index 00000000000..ff2a8d793c6 --- /dev/null +++ b/helm/sim/tests/postgres-volume-claim-labels_test.yaml @@ -0,0 +1,131 @@ +suite: bundled Postgres — volume claim template labels never change across upgrades +release: + name: t + namespace: sim +defaults: &defaults + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.password: xxxxxxxx +copilot: &copilot + copilot.enabled: true + copilot.postgresql.auth.password: xxxxxxxx + copilot.server.image.tag: main-test + copilot.server.env.INTERNAL_API_SECRET: x + copilot.server.env.LICENSE_KEY: x + copilot.server.env.COPILOT_INBOUND_API_KEY: x + copilot.server.env.SIM_ENDPOINT: https://sim.example.com + copilot.server.env.REDIS_URL: redis://redis:6379 +tests: + # Kubernetes rejects any change to volumeClaimTemplates, so a label that moves with the chart + # version, the app version, or commonLabels there fails every `helm upgrade`. + - it: a new postgresql StatefulSet gets only stable claim labels + template: statefulset-postgresql.yaml + documentSelector: + path: kind + value: StatefulSet + set: + <<: *defaults + global.commonLabels.team: platform + asserts: + - equal: + path: spec.volumeClaimTemplates[0].metadata.labels + value: + app.kubernetes.io/name: sim + app.kubernetes.io/instance: t + app.kubernetes.io/component: postgresql + + - it: a new copilot-postgresql StatefulSet gets only stable claim labels + template: statefulset-copilot-postgres.yaml + documentSelector: + path: kind + value: StatefulSet + set: + <<: [*defaults, *copilot] + global.commonLabels.team: platform + asserts: + - equal: + path: spec.volumeClaimTemplates[0].metadata.labels + value: + app.kubernetes.io/name: sim + app.kubernetes.io/instance: t + app.kubernetes.io/component: copilot-postgresql + + - it: an existing postgresql StatefulSet keeps its claim labels, chart version included + template: statefulset-postgresql.yaml + documentSelector: + path: kind + value: StatefulSet + set: + <<: *defaults + kubernetesProvider: + scheme: + "apps/v1/StatefulSet": + gvr: + group: apps + version: v1 + resource: statefulsets + namespaced: true + objects: + - apiVersion: apps/v1 + kind: StatefulSet + metadata: + name: t-sim-postgresql + namespace: sim + spec: + volumeClaimTemplates: + - metadata: + name: postgresql-data + labels: + helm.sh/chart: sim-1.18.0 + app.kubernetes.io/version: v0.9.73 + app.kubernetes.io/name: sim + app.kubernetes.io/instance: t + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/component: postgresql + asserts: + - equal: + path: spec.volumeClaimTemplates[0].metadata.labels + value: + helm.sh/chart: sim-1.18.0 + app.kubernetes.io/version: v0.9.73 + app.kubernetes.io/name: sim + app.kubernetes.io/instance: t + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/component: postgresql + + - it: an existing copilot-postgresql StatefulSet keeps its claim labels + template: statefulset-copilot-postgres.yaml + documentSelector: + path: kind + value: StatefulSet + set: + <<: [*defaults, *copilot] + kubernetesProvider: + scheme: + "apps/v1/StatefulSet": + gvr: + group: apps + version: v1 + resource: statefulsets + namespaced: true + objects: + - apiVersion: apps/v1 + kind: StatefulSet + metadata: + name: t-sim-copilot-postgresql + namespace: sim + spec: + volumeClaimTemplates: + - metadata: + name: data + labels: + helm.sh/chart: sim-1.18.0 + app.kubernetes.io/component: copilot-postgresql + asserts: + - equal: + path: spec.volumeClaimTemplates[0].metadata.labels + value: + helm.sh/chart: sim-1.18.0 + app.kubernetes.io/component: copilot-postgresql diff --git a/helm/sim/tests/sandbox-kubernetes_test.yaml b/helm/sim/tests/sandbox-kubernetes_test.yaml index 560a58320f4..f3a6d135499 100644 --- a/helm/sim/tests/sandbox-kubernetes_test.yaml +++ b/helm/sim/tests/sandbox-kubernetes_test.yaml @@ -467,6 +467,8 @@ tests: template: deployment-app.yaml set: <<: *enabled + # Set, so the chart derives no BETTER_AUTH_URL after extraEnvVars and env[-1] is the operator's. + app.env.BETTER_AUTH_URL: https://sim.example.com extraEnvVars: - name: SANDBOX_K8S_CPU value: "2" diff --git a/helm/sim/tests/storage_test.yaml b/helm/sim/tests/storage_test.yaml new file mode 100644 index 00000000000..de47fb303d9 --- /dev/null +++ b/helm/sim/tests/storage_test.yaml @@ -0,0 +1,208 @@ +suite: upload storage — several app replicas need object storage +release: + name: t + namespace: sim +defaults: &defaults + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.password: xxxxxxxx +tests: + - it: refuses a multi-replica install that stores uploads on the pod + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + asserts: + - failedTemplate: + errorMessage: "More than one app replica (app.replicaCount > 1 or autoscaling.enabled) needs object storage: uploads on each pod's filesystem are not shared and are lost on restart. Configure S3, Azure Blob, or GCS in app.env (see STORAGE_PROVIDER in values.yaml), mount a ReadWriteMany volume at /app/apps/sim/uploads, or set app.storage.allowLocalWithReplicas=true." + + - it: refuses an autoscaled install that stores uploads on the pod + template: deployment-app.yaml + set: + <<: *defaults + autoscaling.enabled: true + asserts: + - failedTemplate: {} + + # Argo CD renders with helm template, which always reports an install, so an upgrade-only pass + # would fail every sync anyway: install and upgrade behave the same. + - it: refuses an upgrade the same way + template: deployment-app.yaml + release: + upgrade: true + set: + <<: *defaults + app.replicaCount: 2 + asserts: + - failedTemplate: {} + + - it: accepts local storage with several replicas when the operator opts in + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.storage.allowLocalWithReplicas: true + asserts: + - notFailedTemplate: {} + + - it: accepts a single replica on local storage + template: deployment-app.yaml + set: + <<: *defaults + asserts: + - notFailedTemplate: {} + + - it: accepts S3 configured in app.env + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.env.AWS_REGION: us-east-1 + app.env.S3_BUCKET_NAME: sim-files + asserts: + - notFailedTemplate: {} + + - it: refuses S3 without the region it needs + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.env.S3_BUCKET_NAME: sim-files + asserts: + - failedTemplate: {} + + - it: accepts Azure Blob configured in app.envDefaults + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.envDefaults.AZURE_STORAGE_CONTAINER_NAME: files + app.envDefaults.AZURE_ACCOUNT_NAME: simfiles + app.env.AZURE_ACCOUNT_KEY: key + asserts: + - notFailedTemplate: {} + + - it: refuses Azure Blob with an account name but no key or connection string + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.env.AZURE_STORAGE_CONTAINER_NAME: files + app.env.AZURE_ACCOUNT_NAME: simfiles + asserts: + - failedTemplate: {} + + - it: accepts GCS configured through extraEnvVars + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + extraEnvVars: + - name: GCS_BUCKET_NAME + valueFrom: + configMapKeyRef: { name: storage, key: bucket } + asserts: + - notFailedTemplate: {} + + - it: accepts storage keys mapped under External Secrets + template: deployment-app.yaml + set: + app.replicaCount: 2 + externalSecrets.enabled: true + externalSecrets.secretStoreRef.name: store + externalSecrets.remoteRefs.app.BETTER_AUTH_SECRET: a + externalSecrets.remoteRefs.app.ENCRYPTION_KEY: b + externalSecrets.remoteRefs.app.INTERNAL_API_SECRET: c + externalSecrets.remoteRefs.app.CRON_SECRET: d + externalSecrets.remoteRefs.app.GCS_BUCKET_NAME: e + externalSecrets.remoteRefs.postgresql.password: f + asserts: + - notFailedTemplate: {} + + - it: accepts an explicit non-local STORAGE_PROVIDER + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.env.STORAGE_PROVIDER: s3 + asserts: + - notFailedTemplate: {} + + - it: refuses STORAGE_PROVIDER=local even with an object store configured + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.env.STORAGE_PROVIDER: local + app.env.AWS_REGION: us-east-1 + app.env.S3_BUCKET_NAME: sim-files + asserts: + - failedTemplate: {} + + - it: trusts a pre-created app Secret it cannot read + template: deployment-app.yaml + set: + app.replicaCount: 2 + app.secrets.existingSecret.enabled: true + app.secrets.existingSecret.name: my-secret + postgresql.auth.password: xxxxxxxx + asserts: + - notFailedTemplate: {} + + - it: accepts a volume mounted at the uploads directory + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.extraVolumes: + - name: uploads + persistentVolumeClaim: { claimName: sim-uploads } + app.extraVolumeMounts: + - name: uploads + mountPath: /app/apps/sim/uploads + asserts: + - notFailedTemplate: {} + + - it: accepts the uploads mount with a trailing slash + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.extraVolumeMounts: + - name: uploads + mountPath: /app/apps/sim/uploads/ + asserts: + - notFailedTemplate: {} + + - it: does not count a mount beside or below the uploads directory + template: deployment-app.yaml + set: + <<: *defaults + app.replicaCount: 2 + app.extraVolumeMounts: + - name: cache + mountPath: /app/apps/sim/uploads-cache + - name: one-folder + mountPath: /app/apps/sim/uploads/workspace + asserts: + - failedTemplate: {} + + - it: warns in NOTES when uploads stay on the pod + template: NOTES.txt + set: + <<: *defaults + asserts: + - matchRegexRaw: + pattern: "WARNING: no object storage is configured" + + - it: does not warn in NOTES once object storage is configured + template: NOTES.txt + set: + <<: *defaults + app.env.AWS_REGION: us-east-1 + app.env.S3_BUCKET_NAME: sim-files + asserts: + - notMatchRegexRaw: + pattern: "no object storage" diff --git a/helm/sim/tests/validators_test.yaml b/helm/sim/tests/validators_test.yaml index 2346929076d..ef45c5fee6a 100644 --- a/helm/sim/tests/validators_test.yaml +++ b/helm/sim/tests/validators_test.yaml @@ -124,3 +124,51 @@ tests: asserts: - failedTemplate: errorMessage: "app.env.BETTER_AUTH_SECRET is required for production deployment" + + - it: fails when app.secrets.existingSecret is enabled without a name + set: + app.secrets.existingSecret.enabled: true + app.secrets.existingSecret.name: "" + postgresql.auth.password: xxxxxxxx + asserts: + - failedTemplate: + errorMessage: "app.secrets.existingSecret.enabled=true but app.secrets.existingSecret.name is empty. Set it to the name of your pre-created app Secret." + + - it: fails when postgresql.auth.existingSecret is enabled without a name + set: + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.existingSecret.enabled: true + postgresql.auth.existingSecret.name: "" + asserts: + - failedTemplate: + errorMessage: "postgresql.auth.existingSecret.enabled=true but postgresql.auth.existingSecret.name is empty. Set it to the name of your pre-created Secret holding POSTGRES_PASSWORD." + + - it: fails when externalDatabase.existingSecret is enabled without a name + set: + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.enabled: false + externalDatabase.enabled: true + externalDatabase.existingSecret.enabled: true + externalDatabase.existingSecret.name: "" + asserts: + - failedTemplate: + errorMessage: "externalDatabase.existingSecret.enabled=true but externalDatabase.existingSecret.name is empty. Set it to the name of your pre-created Secret holding EXTERNAL_DB_PASSWORD." + + - it: fails when both the bundled and an external database are enabled + set: + app.env.BETTER_AUTH_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.ENCRYPTION_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + app.env.INTERNAL_API_SECRET: x + app.env.CRON_SECRET: x + postgresql.auth.password: xxxxxxxx + externalDatabase.enabled: true + externalDatabase.password: xxxxxxxx + asserts: + - failedTemplate: + errorMessage: "postgresql.enabled and externalDatabase.enabled are both true; the chart uses the bundled database. Set externalDatabase.enabled=false to keep it, or migrate your data and set postgresql.enabled=false." diff --git a/helm/sim/values.schema.json b/helm/sim/values.schema.json index 1a819f635aa..c9a39856efe 100644 --- a/helm/sim/values.schema.json +++ b/helm/sim/values.schema.json @@ -40,6 +40,15 @@ "minimum": 1, "description": "Number of app replicas" }, + "storage": { + "type": "object", + "properties": { + "allowLocalWithReplicas": { + "type": "boolean", + "description": "Allow more than one app replica (or autoscaling) with uploads on each pod's filesystem; they are not shared and are lost on restart" + } + } + }, "resources": { "type": "object", "properties": { @@ -1183,8 +1192,8 @@ "properties": { "host": { "type": "string", - "format": "hostname", - "description": "Realtime service hostname" + "anyOf": [{ "format": "hostname" }, { "const": "" }], + "description": "Realtime service hostname; empty serves realtime on ingress.app.host" } } }, diff --git a/helm/sim/values.yaml b/helm/sim/values.yaml index d78f5c66eb8..59a92287a0d 100644 --- a/helm/sim/values.yaml +++ b/helm/sim/values.yaml @@ -29,6 +29,12 @@ app: # Number of replicas replicaCount: 1 + # More than one replica (or autoscaling) needs object storage (STORAGE_PROVIDER) or a shared + # volume at /app/apps/sim/uploads, or the render fails. allowLocalWithReplicas=true accepts + # per-pod uploads that are lost on restart. + storage: + allowLocalWithReplicas: false + # Resource limits and requests resources: limits: @@ -69,10 +75,9 @@ app: # Environment variables env: - # Application URLs — set NEXT_PUBLIC_APP_URL / BETTER_AUTH_URL to your public origin - # (e.g. https://sim.example.com). Defaults to http://localhost:3000 via app.envDefaults - # for local installs; override here (or via --set) for production. Set values here go - # into the chart-managed Secret and take precedence over envDefaults at runtime. + # Public origin, e.g. https://sim.example.com (defaults to http://localhost:3000 via + # envDefaults). BETTER_AUTH_URL follows NEXT_PUBLIC_APP_URL when empty, except in + # app.secrets.existingSecret mode, where your Secret must hold it. NEXT_PUBLIC_APP_URL: "" BETTER_AUTH_URL: "" INTERNAL_API_BASE_URL: "" # Optional server-side internal base URL for /api self-calls (include http:// or https://); falls back to NEXT_PUBLIC_APP_URL when empty @@ -285,6 +290,7 @@ app: # Optional file storage override. One of: local, s3, azure, gcs. # Empty preserves legacy Azure → S3 → GCS → local precedence. + # Without an object store, more than one app replica fails to render (see app.storage). STORAGE_PROVIDER: "" # AWS S3 Cloud Storage Configuration (optional - for file storage) @@ -337,9 +343,9 @@ app: # does NOT remove it: every key under `app.env` ships as a "" placeholder, so the templates # must read "" as "unspecified". See "Removing an inherited env key" in README.md. envDefaults: - # Application URLs (override in app.env or app.envDefaults for production) + # Application URL (override in app.env for production). BETTER_AUTH_URL is derived from it; + # see app.env. NEXT_PUBLIC_APP_URL: "http://localhost:3000" - BETTER_AUTH_URL: "http://localhost:3000" # Node environment NODE_ENV: "production" @@ -498,7 +504,8 @@ realtime: # Environment variables — Secret-bound. See `envDefaults` below for chart-shipped defaults. env: # Application URLs — must mirror the public origin used by the main app. - # Defaults to http://localhost:3000 via envDefaults; override here for production. + # NEXT_PUBLIC_APP_URL defaults to http://localhost:3000 via envDefaults (override here or in + # app.env for production); BETTER_AUTH_URL follows NEXT_PUBLIC_APP_URL when left empty. NEXT_PUBLIC_APP_URL: "" BETTER_AUTH_URL: "" @@ -517,7 +524,6 @@ realtime: # User-set values in `realtime.env` above take precedence. envDefaults: NEXT_PUBLIC_APP_URL: "http://localhost:3000" - BETTER_AUTH_URL: "http://localhost:3000" ALLOWED_ORIGINS: "http://localhost:3000" NODE_ENV: "production" @@ -1034,11 +1040,14 @@ ingress: - path: / pathType: Prefix - # Realtime service (use /socket.io when sharing host with app) + # Realtime. An empty host serves it on ingress.app.host under /socket.io (a "/" path there fails + # the render). With a separate host the chart sets NEXT_PUBLIC_SOCKET_URL=http(s):// unless + # you set it; set it yourself in existingSecret mode, or when TLS terminates before the ingress and + # NEXT_PUBLIC_APP_URL comes only from External Secrets. realtime: - host: sim-ws.local + host: "" paths: - - path: / + - path: /socket.io pathType: Prefix # Copilot service (optional, use /copilot when sharing host)