Deployment
Deploy from the standalone app repository. Inspect the proposed Railway setup first, then provision the services and verify that the deployed app responds.
mercato deploy railway provisions and deploys a standalone Open Mercato app to Railway. It creates the project, environment, PostgreSQL, Redis, app service, optional worker, environment variables, healthcheck, and public domain.
The command records Railway resource IDs locally, so running it again updates the same project instead of creating a duplicate.
Info · Shared production gate
Complete the provider-neutral Production Readiness checklist before sending production traffic to Railway. This guide covers the Railway-specific CLI, token, source, domain, volume, and state behavior.
Info · Availability
This command was implemented for issue #2414. Use a CLI release that includes mercato deploy railway; older releases do not provide it.
Prepare these pieces before the first deploy:
create-mercato-app..env file. In a fresh standalone app, run yarn setup first; it copies .env.example to .env when needed and initializes the app.railway up.Create a Railway Account token at railway.com/account/tokens:
export RAILWAY_API_TOKEN="<railway-api-token>"
Prefer the environment variable or the interactive token prompt over --token. Command-line arguments may be retained in shell history or exposed through process inspection.
RAILWAY_TOKEN is a different, project-scoped Railway credential. It is not used as the primary token for this command.
Use the default auto mode unless you need to force a path:
yarn mercato deploy railway. auto uses the GitHub remote when it is clean, pushed, and supported by Railway.yarn mercato deploy railway --source local. auto also falls back to this path when no usable GitHub remote exists.Skip this step for GitHub-backed deploys.
For local-source deploys, install the Railway CLI from the Railway CLI docs. Current supported options include the shell installer, Homebrew, npm, Scoop, pre-built binaries, and source builds. Common options:
bash <(curl -fsSL railway.com/install.sh) -y
# or
brew install railway
# or
npm install -g @railway/cli
Then confirm it is available:
railway --version
You do not need railway login when RAILWAY_API_TOKEN is set correctly. If you do run railway login, unset invalid Railway token variables first; the Railway CLI uses those variables for non-interactive authentication and skips browser login.
The command loads .env.production when it exists, otherwise .env. You can select another file with --env-file.
For a fresh standalone app:
npx create-mercato-app my-shop
cd my-shop
yarn setup
Review the generated .env before deployment. Replace placeholders and add provider keys you need for production. Missing AI provider keys do not block deployment, but payment, mail, storage, or integration credentials must be present when your enabled modules require them.
Keep environment files out of version control. The CLI uploads their values as Railway variables; it does not include the file in a local-source upload.
Before deploying, run generation and a production build from the standalone app root:
yarn generate
yarn build
yarn generate refreshes module registries and generated metadata. yarn build verifies the Next.js production build before Railway receives the source. In standalone apps, yarn build also runs generation, but running yarn generate explicitly first makes discovery or registry failures easier to identify before deployment.
Run the Readiness Scanner from the same standalone app root:
npx --yes [email protected] scan . --fail-on high
Credential checks are always enabled. Treat local .env and development-default findings as a reminder to replace unsafe values and deliver production secrets through Railway service variables, keeping environment files out of the deployed artifact. Review KMS and secret-injection warnings with the deployment owner.
Run a dry run before creating billable resources:
yarn mercato deploy railway --dry-run
The plan shows the selected source mode, Railway operations, and environment-variable changes. Secret values are redacted.
yarn mercato deploy railway
The default deployment:
production environment,mercato-app and mercato-worker,/api/healthz to report a healthy deployment.On success, the CLI prints the app URL, healthcheck URL, Railway dashboard URL, source mode, and deployed services.
Repeat the runtime scanner check inside the deployed staging and production services using their own injected environment, before sending traffic. A local scan with Railway variables does not inspect the running service. The audit workload needs Node.js 24+ and the standalone release metadata; see the guide for slim-image limitations and warnings that remain manual review items.
Select the source strategy with --source auto|git|local.
| Mode | Behavior |
|---|---|
auto | Default. Uses Git when the current branch has a usable, synchronized GitHub remote; otherwise falls back to local upload when the Railway CLI is available. The selected mode and reason appear in dry-run and deployment output. |
git | Requires a clean working tree and a branch synchronized with a GitHub remote. Railway builds from the connected repository. This is the recommended CI path. |
local | Requires the Railway CLI on PATH and uploads the current source with railway up. Use this when the repository has no supported remote. |
Use this mode when your app lives in a GitHub repository that Railway can access. Open Mercato configures Railway resources through the Railway API, then points the app service at the repository and branch.
Requirements:
The Railway CLI is not required for GitHub-backed deploys.
git status
git push -u origin HEAD
yarn mercato deploy railway --source git
The command does not create a GitHub repository. If --source git cannot resolve or access the GitHub remote, fix the remote or Railway repository access and run the command again.
Use this mode when you only have a local app directory, when you ran git init without creating a GitHub repository, or when you want Railway to receive the current local source archive.
Requirements:
railway.RAILWAY_API_TOKEN contains a valid Account token..railwayignore protects files that should never be uploaded.railway --version
yarn mercato deploy railway --source local
Local uploads run a safety preflight that requires .railwayignore entries for environment files, private keys, .git, node_modules, local databases, and local Railway state. Runtime configuration is uploaded as Railway variables, not as source files.
The CLI resolves the Railway Account token in this order:
--token <value>RAILWAY_API_TOKEN~/.config/open-mercato/railway.jsonThe optional token cache contains:
{
"token": "<token>"
}
On macOS and Linux, the file must have mode 0600. The CLI refuses a more widely readable token file. On Windows, the equivalent location is %APPDATA%\open-mercato\railway.json; protect the file with appropriate NTFS permissions and rotate the token after use on a shared machine.
The token is never written to repository state or printed in verbose output.
Use an Account token for this command. In Railway Account Settings -> Tokens, create the token with No workspace selected and do not assign it to a project. This gives the deploy command access to create projects, environments, services, databases, variables, and domains.
Do not use a Project token. Project tokens are generated from project settings, are scoped to one environment, use RAILWAY_TOKEN, and are only suitable for deployment operations inside an already-existing project. They do not authorize the account/workspace API operations that mercato deploy railway performs.
Workspace tokens can be useful for shared automation that must stay inside one workspace, but the recommended path for local first-time deployment is an Account token with no workspace or project assigned.
| Flag | Default | Description |
|---|---|---|
--project <name> | package.json name | Railway project name. For a recorded project, combine with --force-rename to change the name. |
--env <name> | production | Railway environment. A different value, such as staging, creates or updates a sibling environment in the same project. |
--service <name> | mercato-app | App service name. |
--worker / --no-worker | worker enabled | Create a dedicated mercato-worker service or remove the recorded managed worker and run workers in the app service. |
--source <mode> | auto | Select auto, git, or local. |
--region <id> | Railway default | Deploy to a Railway region validated for the project. |
--env-file <path> | .env.production, then .env | Environment file to upload as Railway variables. |
--domain <fqdn> | Railway domain | Attach a custom domain instead of creating an *.up.railway.app domain. |
--no-wait-domain | off | Print required DNS records without waiting for custom-domain verification. |
--volume <mountPath> | none | Create persistent Railway storage at the specified mount path. |
--token <value> | token resolution chain | Supply an Account token directly. Prefer RAILWAY_API_TOKEN or the prompt. |
--non-interactive | enabled when CI=true | Disable prompts and fail when required input or confirmation is missing. |
--dry-run | off | Print the selected source, planned operations, and redacted variable diff without changing local state or Railway. |
--cleanup | off | Delete the Railway project recorded in local state. |
--yes | off | Confirm destructive non-interactive operations. Required with --cleanup --non-interactive. |
--write-env | off | Write generated application secrets back to the selected local env file. |
--no-track | off | Store state in ignored .mercato/railway.json.local instead of .mercato/railway.json. |
--force-rename | off | Allow --project to rename an already-recorded project. |
--timeout <seconds> | 900 | Deployment polling timeout. |
--allow-secret-passthrough <key> | none | Allow one exact variable key through the credential scanner. Repeat for additional keys. |
--verbose | off | Print Railway operations and redacted responses. |
Values are merged from Railway service references, generated secrets, static production settings, and the selected env file.
| Variable | Source and behavior |
|---|---|
DATABASE_URL | Railway reference to the managed PostgreSQL service. The rendered database URL is not copied into local state. |
REDIS_URL | Railway reference to the managed Redis service, applied after Redis is ready. |
NODE_ENV | Set to production. |
NEXT_TELEMETRY_DISABLED | Set to 1. |
NEXT_PUBLIC_APP_URL | Derived from the provisioned Railway or custom domain. |
APP_URL | Server-side mirror of the deployed app URL. |
OM_AI_PROVIDER | Loaded from the env file; defaults to openai. |
OM_AI_MODEL | Loaded from the env file; defaults to gpt-5-mini. |
| AI provider API keys | Passed through when present. Missing AI keys do not block deployment. |
AUTH_SECRET | Generated once per Railway environment and stored on Railway. |
JWT_SECRET | Generated backward-compatible auth secret. |
TENANT_DATA_ENCRYPTION_FALLBACK_KEY | Generated fallback key for tenant data encryption. |
QUEUE_STRATEGY | Set to async. |
NEXT_PUBLIC_QUEUE_STRATEGY | Set to async. |
AUTO_SPAWN_WORKERS / OM_AUTO_SPAWN_WORKERS | Disabled in the app when a dedicated worker is provisioned; the worker service also disables nested worker spawning. |
PORT | Injected by Railway and respected by the app start command. |
Generated secrets remain only in Railway unless you pass --write-env. Before using that flag, verify the target env file is ignored by Git. The CLI refuses to write generated secrets to an env file that is not ignored.
The variable scanner blocks values that resemble the Railway Account token or common credential formats. Use --allow-secret-passthrough <key> only for a reviewed, exact key. There is no global scanner bypass.
By default the command writes .mercato/railway.json. It contains opaque Railway IDs, environment records, service and domain IDs, source metadata, last deployment IDs, a schema version, and the CLI version. It does not contain tokens, passwords, generated secrets, or rendered database URLs.
Commit this file when a team should share ownership of the deployment:
.mercato/*
!.mercato/railway.json
A teammate or CI job can then run the same command and update the recorded project. Each run validates recorded resources against Railway, recreates missing resources when appropriate, and resumes from the last completed step after an interrupted deployment.
Use --no-track to keep deployment state local. The command then writes .mercato/railway.json.local, which should remain ignored. A fresh clone without that state cannot identify the existing project and may create another one.
Deploy another environment under the same project with:
yarn mercato deploy railway --env staging
Without --domain, the CLI creates a Railway *.up.railway.app domain.
For a custom domain:
yarn mercato deploy railway --domain commerce.example.com
The command prints the required DNS records and waits up to five minutes for verification. DNS propagation can take longer; --no-wait-domain prints the records and completes without waiting. Re-run the deploy after DNS is ready to confirm the domain and app URL.
Persistent storage is opt-in:
yarn mercato deploy railway --volume /app/storage
Without a volume, files written to the service filesystem, including locally stored attachments, can be lost during redeploy or service replacement. Use a Railway volume or configure durable external object storage before relying on uploaded files in production.
Delete the project recorded in the current repository:
yarn mercato deploy railway --cleanup
Interactive cleanup shows the project name, project ID, environments, and app URL, then requires typing the project name. In CI or another non-interactive environment:
yarn mercato deploy railway --cleanup --non-interactive --yes
Cleanup deletes the entire recorded Railway project, including its services and databases, then removes the repository state file. It does not delete the user token cache. Export or back up any data you need before running it.
The command can create an app service, worker service, PostgreSQL service, Redis service, domain, and optional volume. These resources can consume Railway trial credits or incur charges on a paid plan.
Review current Railway pricing and project usage before deployment. Railway limits change over time; as of June 2026, Railway's public pricing page lists Hobby and Pro limits above 16 GB RAM per service, while the free/trial limits are much lower. For production deployments, team use, larger builds, or heavier imports, prefer Pro or another paid plan with at least 16 GB RAM available per service.
Use --dry-run to review the planned resources and --no-worker when a dedicated worker is not needed. Run --cleanup for test projects you no longer use.
Use the shared Production Readiness checklist for TLS, application secrets, access control, backups, observability, validation, rollout, and rollback. For Railway itself:
RAILWAY_API_TOKEN, the interactive prompt, or the protected token cache over --token..mercato/railway.json.local.--dry-run output before the first deploy..mercato/railway.json only when sharing opaque deployment IDs is intentional.--write-env only when the target file is ignored by Git.--allow-secret-passthrough as a narrow exception for one reviewed key.Confirm that you created an Account token from Account Settings -> Tokens with No workspace selected and no project assigned. Do not use a Project token from project settings. Also verify that RAILWAY_API_TOKEN does not contain whitespace or shell quoting. If a cached token is used, ensure its file permissions are 0600. Rotate the token in Railway if it may have been exposed.
railway login reports an invalid tokenIf RAILWAY_API_TOKEN or RAILWAY_TOKEN is exported, the Railway CLI uses that value for non-interactive auth and skips browser login. An invalid value can make railway login fail before the browser flow starts.
Unset token variables before interactive login:
unset RAILWAY_API_TOKEN
unset RAILWAY_TOKEN
railway login
For Open Mercato deployment, set only the Account token afterward:
export RAILWAY_API_TOKEN="<railway-api-token>"
auto selected an unexpected sourceRun with --dry-run --verbose to see the selected mode and reason. For Git mode, verify the remote is supported by Railway, the working tree is clean, the current branch has an upstream, and local commits are pushed. For local mode, install the Railway CLI and ensure railway is on PATH.
The safety preflight found a missing protection in .railwayignore. Add exclusions for env files, private keys, .git, node_modules, local database files, and local Railway state. Do not bypass this by adding secrets to the source archive.
Check the Railway project activity and service logs. Railway resource limits or temporary template provisioning failures can block PostgreSQL or Redis. Resolve the Railway-side error, then run the same deploy command again; recorded state allows the flow to resume.
The CLI prints redacted logs and leaves the project and state intact for inspection. Fix the build or runtime error, then re-run the command. Increase --timeout only when the deployment is progressing but needs more than 900 seconds.
503/api/healthz reports degraded when PostgreSQL or Redis is unavailable or times out. Inspect app logs and verify both Railway services are running and their reference variables are present. The public response intentionally exposes only status and ts.
Copy the exact records printed by the CLI and verify them with your DNS provider. DNS propagation may exceed the five-minute wait. The deployment remains valid; re-run after propagation or use --no-wait-domain.
Confirm that the repository contains the expected .mercato/railway.json, or the local .mercato/railway.json.local when using --no-track. Restore the correct state file before deploying again. Inspect duplicate projects carefully and use cleanup only from the repository whose state points to the project you intend to delete.
The monorepo production image runs as omuser (UID/GID 1001:1001). Its Railway entrypoint invokes a root-owned, argument-free helper to assign only the fixed /app/apps/mercato/storage mount directory to that user. The helper refuses a missing directory or a symlink at that path; it does not recurse into attachments, follow links, accept another path, or grant general privileged chown.
Fresh empty volumes initialize at the same path. Existing attachments and the .initialized marker already owned by 1001:1001 remain readable and writable. Initialization and subsequent migrations still execute as the application user.
When restoring storage from a backup with different ownership, stop the application and have a trusted operator provision the restored files and directories for 1001:1001 before restarting. Review links and mount boundaries during that offline operation; startup no longer recursively repairs imported ownership. Do not restore the previous unrestricted sudoers rule.
The create-app Docker template has no runtime sudo grant and retains its existing non-root startup. Provision externally mounted standalone-app storage for UID/GID 1001:1001 before launch.
Run node docker/tests/storage-init-smoke.mjs from the repository root to exercise the production privilege configuration in an isolated Alpine runtime fixture. It checks fresh and repeated startup with stubbed Yarn commands, existing attachment writes, refusal of arbitrary privileged commands and arguments, immutable helper/parent paths, and symlink/hard-link containment. This focused check does not build or boot the complete application image or connect to Railway.