Repository navigation
app/: one typed config read from VISUALCI_ variables, with generated docs and warnings for unknown ones (sc-9026) - #140
Merged
Conversation
…docs and warnings for unknown ones (sc-9026) Every setting app/ reads is now declared once in app/src/config.rs, a struct derived with the new crates/envschema (typed settings from prefixed environment variables). Its doc comments, types, defaults and required / required-in-production / secret flags drive loading, boot checks, secret masking in logs, warnings for unknown VISUALCI_ variables (naming the closest known one) and the generated docs: the new self-hosting/environment-variables page and app/.env.example, checked by a test. App-owned settings that had other names now start with VISUALCI_ (S3_*, RENDERER_*, METRICS_TOKEN, GITHUB_APP_*, GITHUB_WEBHOOK_SECRET, STRIPE_*, POSTMARK_SERVER_TOKEN, MAIL_*, DEV_LOGIN, TRUSTED_PROXIES, DB_ACQUIRE_TIMEOUT, DB_APPLICATION_NAME). Laravel Rust's and the OAuth server's variables keep their names.
VisualCIdocspring/visualci · build #175 · 3 changed, 336 unchanged · approved by visualci features agent for Nathan Broadbent This PR vs base: 3 changed since #172, across 1 build
docspring/visualci · journeys · build #174 · 12 unchanged · no changes This PR vs base: nothing since #173, across 1 build Updated as builds change. Agents can review with VisualCI's MCP tools. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shortcut: sc-9026.
Merge only after talira-ai/infra adds the new names (step 1 below). With the old names alone, production stops at boot: S3, the renderer token, GitHub, Stripe and Postmark would all be missing.
What changes
One typed config for app/ (
app/src/config.rs).Configholds every setting app/ reads, in groups: storage, renderers, hosts, network and database, sign-ups, development sign-in, GitHub App, GitLab, email, team, payments, Cloudflare, gallery and heartbeats. Each group is still its own config section (Section<Stripe>and the rest), now defined in config.rs. Every VisualCI setting is aVISUALCI_variable. Laravel Rust's variables (APP_*,DATABASE_URL,DB_*,CACHE_STORE,GITHUB_CLIENT_ID/SECRET, …) and the OAuth server's (OAUTH_*) keep their names and are described in the same file, so the docs list everything one server needs.Each setting has a description (its doc comment), a type, a default, and flags for required, required in production and secret.
At boot the app:
VISUALCI_variable it doesn't read, naming the closest known one (VISUALCI_S3_BUKET is set, but nothing reads it (did you mean VISUALCI_S3_BUCKET?)). The CLI's, the renderers' and CI scripts'VISUALCI_variables are ignored.Generated docs:
frontend/content/docs/self-hosting/environment-variables.md(in the Reference section, after Self-hosting);app/.env.example.config::tests::the_generated_docs_match_the_schemafails in CI when either differs from the schema.VISUALCI_GOLDEN_UPDATE=1rewrites them.Presence checks. These now come from the schema's
required_in_productionflags, which replace the presence-only boot checks (SignUps::check,postmark::check,github_app::check). Kept as they were: the Stripe live-key check, the host URL checks, the OAuth/host check and the dev-login check.Smaller fixes along the way:
ForgeAppsandSignInAppsboth readGITHUB_CLIENT_ID; they're replaced by the framework's own social config.LiveDatabasereadDATABASE_URLitself; it now uses the framework's database config.FrontendreadS3_PUBLIC_ENDPOINTa second time.AppUrlreadVISUALCI_APP_URLa second time; it's nowHostUrls::app_url().std::env::var(format!(…)).VISUALCI_MCP_HOSTSandTRUSTED_PROXIESwere read straight from the process.UPDATE_GOLDENSin tests/forge_reports.rs is nowVISUALCI_GOLDEN_UPDATE, like the other golden tests.The crate:
crates/envschema(+envschema-derive),publish = falseI looked at the existing crates first. Talira search
01a23c9c-13e1-76d6-bda5-a3ff7bef6bfereturned only confique and Figment. I also read confique 0.5.0's source.Config::META. It doesn't fit here for two reasons:std::env::vardirectly (confique::internal::from_env), with no other source. Laravel Rust'sEnvmerges.env, treatsnull/empty as unset, and gives each test app its own variables (with_envs) without touching the process environment. Setting process variables from parallel tests isn't an option..envoutput. Its templates are TOML, YAML and JSON5.Env::prefixed) is about layering providers, which we don't need. It has no schema to document, no secrets and no unknown-variable check.from_iter, but no metadata at all.None of them warns about unknown prefixed variables. So the crate is small, and everything is built from one derive:
Source(the process environment, a map, a closure);required_in_production;Debugand inSummary;Schema::unknown(prefix, names)with the closest name by edit distance;Schema::markdown()anddotenv_example();No adapter crates. The Laravel side is about 20 lines in
config::install(a closure source overEnv::get, thenconfig.setfor each group). A Loco app would use the crate directly withProcessEnvand keep the struct in its shared store. Its YAML config is a separate layer that this doesn't replace.Every variable app/ reads
Old name → new name. "Secret" values are masked in logs. "Prod" means required in production (the app refuses to start without it there). "Always" means required everywhere.
S3_ENDPOINTVISUALCI_S3_ENDPOINTS3_PUBLIC_ENDPOINTVISUALCI_S3_PUBLIC_ENDPOINTS3_BUCKETVISUALCI_S3_BUCKETS3_REGIONVISUALCI_S3_REGIONS3_ACCESS_KEY_IDVISUALCI_S3_ACCESS_KEY_IDS3_SECRET_ACCESS_KEYVISUALCI_S3_SECRET_ACCESS_KEYRENDERER_TOKENVISUALCI_RENDERER_TOKEN(same name the renderers read)RENDERER_VERSIONVISUALCI_RENDERER_VERSION(the image sets it; this PR's Dockerfile)METRICS_TOKENVISUALCI_METRICS_TOKENTRUSTED_PROXIESVISUALCI_TRUSTED_PROXIESDB_ACQUIRE_TIMEOUTVISUALCI_DB_ACQUIRE_TIMEOUTDB_APPLICATION_NAMEVISUALCI_DB_APPLICATION_NAMEGITHUB_APP_IDVISUALCI_GITHUB_APP_IDGITHUB_APP_PRIVATE_KEY_BASE64VISUALCI_GITHUB_APP_PRIVATE_KEY_BASE64GITHUB_WEBHOOK_SECRETVISUALCI_GITHUB_WEBHOOK_SECRETSTRIPE_SECRET_KEYVISUALCI_STRIPE_SECRET_KEYSTRIPE_WEBHOOK_SECRETVISUALCI_STRIPE_WEBHOOK_SECRETPOSTMARK_SERVER_TOKENVISUALCI_POSTMARK_SERVER_TOKENMAIL_FROMVISUALCI_MAIL_FROMMAIL_REPLY_TOVISUALCI_MAIL_REPLY_TODEV_LOGINVISUALCI_DEV_LOGINVISUALCI_SITE_URL,VISUALCI_APP_URL,VISUALCI_API_URL,VISUALCI_MCP_URLVISUALCI_MCP_HOSTSVISUALCI_WAITLISTVISUALCI_TEAM_EMAILVISUALCI_GITLAB_URL,VISUALCI_GITLAB_BOT_USERNAME,VISUALCI_FORGE_PRIVATE_ADDRESSESVISUALCI_GITLAB_BOT_TOKENVISUALCI_CLOUDFLARE_ZONE_IDVISUALCI_CLOUDFLARE_PURGE_TOKENVISUALCI_GALLERY_DAILY_CREDITSVISUALCI_<JOB>_HEARTBEAT_URL(9 jobs)VISUALCI_<JOB>_HEARTBEAT_TOKEN(9 jobs)APP_KEYAPP_ENV,APP_URL,APP_BASE_PATH,SERVER_HOST,SERVER_PORT,LOG_CHANNELDATABASE_URLDB_CONNECTION,DB_MAX_CONNECTIONS,CACHE_STORE,SESSION_DRIVER,QUEUE_CONNECTIONGITHUB_CLIENT_ID<PROVIDER>_CLIENT_ID)GITHUB_CLIENT_SECRETGITLAB_CLIENT_IDGITLAB_CLIENT_SECRETOAUTH_ISSUER,OAUTH_AUTHORIZATION_ENDPOINTVISUALCI_NOW,VISUALCI_APP_TEST_DATABASE_URL,VISUALCI_EMAIL_SNAPSHOTS,VISUALCI_GOLDEN_UPDATEUPDATE_GOLDENS→VISUALCI_GOLDEN_UPDATE)GITHUB_CLIENT_ID/SECRETstay under the framework's names on purpose. Laravel's social config builds a client for every*_CLIENT_IDvariable, soVISUALCI_GITHUB_CLIENT_IDwould register a provider calledvisualci_github.Collisions with the CLI. No app setting takes a CLI variable's name with a different meaning.
VISUALCI_API_URLandVISUALCI_MCP_URLmean the same address to the CLI and the server.VISUALCI_RENDERER_TOKENandVISUALCI_RENDERER_VERSIONare the renderers' own values. The testno_setting_takes_another_programs_namekeeps it that way.Infra change (talira-ai/infra,
k3s/resources/visualci/laravel)No 1Password item, field or ExternalSecret remote key changes. Only the variable names inside the cluster change.
Step 1, before this PR merges (additive: today's app ignores the new names):
config.yaml(ConfigMapvisualci-app-env): addVISUALCI_TRUSTED_PROXIESVISUALCI_DB_ACQUIRE_TIMEOUTVISUALCI_S3_ENDPOINTVISUALCI_S3_BUCKETVISUALCI_MAIL_FROMVISUALCI_MAIL_REPLY_TOEach takes the same value as the variable without the prefix.
web.yaml,worker.yaml,scheduler.yaml,migrate.yamlenv:: add the following with the samevalueFrom/valueas their old names:VISUALCI_DB_APPLICATION_NAMEVISUALCI_GITHUB_APP_IDVISUALCI_GITHUB_APP_PRIVATE_KEY_BASE64VISUALCI_GITHUB_WEBHOOK_SECRETVISUALCI_STRIPE_SECRET_KEYVISUALCI_STRIPE_WEBHOOK_SECRETVISUALCI_POSTMARK_SERVER_TOKENThe secretKeyRef keys stay as they are.
The same four Deployments: add
VISUALCI_RENDERER_TOKEN(secretKeyRefvisualci-renderer-token/RENDERER_TOKEN) andVISUALCI_METRICS_TOKEN(secretKeyRefvisualci-metrics-token/METRICS_TOKEN). Today these arrive throughenvFromunder the old names. The Secrets' keys stay, because renderer.yaml and podmonitors.yaml read them.visualci-r2: addVISUALCI_S3_ACCESS_KEY_IDandVISUALCI_S3_SECRET_ACCESS_KEY, either as env entries from the Secret'sS3_ACCESS_KEY_ID/S3_SECRET_ACCESS_KEYkeys or by renaming the ExternalSecret's target keys in step 2.Step 2, after this PR is deployed:
TRUSTED_PROXIES,DB_ACQUIRE_TIMEOUT,DB_APPLICATION_NAMES3_*MAIL_FROM,MAIL_REPLY_TOGITHUB_APP_ID,GITHUB_APP_PRIVATE_KEY_BASE64,GITHUB_WEBHOOK_SECRETSTRIPE_*POSTMARK_SERVER_TOKENRENDERER_TOKEN/METRICS_TOKEN, if you switch those to explicit entries.RENDERER_VERSION. It setsVISUALCI_RENDERER_VERSIONinstead (docker/app.Dockerfile, in this PR).Leftover old names are harmless: the unknown-variable warning only covers
VISUALCI_names.VisualCI build
The PR's build shows the docs home (
docs/index) with the new Environment variables entry in the sidebar's Reference section. The new page itself isn't captured: since 2 Dec only the docs home is (scripts/screenshots/pages.mjs). Add it there if you want it reviewed visually.Tests (agents-build-1, Postgres 17 and RustFS 1.0.6)
cargo fmt --all --check,cargo clippy --locked --workspace --all-targets -- -D warnings: clean.cargo test --locked --workspace(app/ against its own test database): all passed. New tests:config::tests::an_unknown_variable_is_warned_about_with_the_closest_known_one(captures the WARN log line);hosts::production_needs_github_stripe_and_email_configured(missing GitHub, Stripe, Postmark or App settings stop production at boot, listed together) andproduction_doesnt_boot_without_saying_whether_sign_ups_are_open;config::tests::secrets_are_masked_when_the_configuration_is_logged(summary,Debugand the log line);config::tests::the_generated_docs_match_the_schema(the CI check for the page and.env.example);the_schema_has_no_mistakes,no_setting_takes_another_programs_name,every_default_is_valid;pnpm install --frozen-lockfile && pnpm build && pnpm test(43 passed),node scripts/skills.mjs --check: clean.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.