9 min read
Deployment
Production runs on one AWS Lightsail server in Mumbai (4 GB RAM / 2 vCPU), managed by
Dokploy (self-hosted, Apache-2.0 core; its panel runs on a separate small server, and this
machine appears in it as the server LightSail). The server runs the worker, admin and
storefront apps plus Postgres and Dragonfly. Nothing is built on it: images are built on
another machine, pushed to Amazon ECR, and Dokploy only pulls the new tag and restarts the app.
Domains sit behind Cloudflare (proxied, Full (strict) SSL).
Why off the server: an early setup had Dokploy build on the box that serves traffic. Building the admin alone used about 7 GB and crashed Docker. Building elsewhere keeps the server’s memory for the running apps.
GitHub Actions is stopped (billing), so no image is built there and nothing is pushed to GHCR;
.github/workflows/release.yml is not part of the release path. Checks run on the developer’s
machine before each PR (Testing).
Branches: dev and main
| Branch | What goes in | Deployed to |
|---|---|---|
feat/…, fix/…, docs/… | One piece of work. Start from origin/dev. | nowhere |
dev (default branch) | Every reviewed PR is merged here first. Several features collect here and are tested together. | test server (vioratech.in), deployed by hand |
main | Only a release PR dev → main, once dev has been checked on the test server. | production |
- Open PRs with
--base dev(it is the default, sogh pr createdoes this). - After a PR merges, GitHub deletes its branch automatically (
delete_branch_on_merge). A release PR’s merge deletesdevtoo, so restore it straight after. - Hotfix for production: branch from
main, PR intomain, then mergemainback intodev. - The org is on GitHub Free, so branch protection rules aren’t available on this private repo; the rule above is a convention, kept by review.
Test server (vioratech.in)
The test server runs dev. Auto deploy is off: someone deploys it by hand, from Dokploy,
when dev should be tried there (before a release, or to check a merged PR). Same order as
production: worker first, then admin, then storefront.
Releasing to production
- Release PR
dev→mainafter the smoke checklist on the test server (Release checklist). - Build the
worker,adminandstorefrontimages for x86 from the merged commit, from the monorepo root, tagged with the short commit sha:- locally with Docker on an x86 machine:
docker build -f apps/<app>/Dockerfile -t <registry>/vextro/<app>:<sha> .(the admin also takes--build-arg NEXT_PUBLIC_WORKER_URL=https://api.koomerce.app, which Next bakes into the browser bundle), or - on AWS CodeBuild (Builds on CodeBuild).
- locally with Docker on an x86 machine:
- Push each image to Amazon ECR (ap-south-1):
924422830513.dkr.ecr.ap-south-1.amazonaws.com/vextro/<app>:<sha>. - Deploy in Dokploy, one app at a time: set the app’s image to the new tag and redeploy.
Worker first: it applies database migrations when it starts. Then admin, then storefront.
deploy/codebuild/deploy-dokploy.mjsdoes the same through Dokploy’s API and stops at the first failure. Auto deploy is off on every app. - Check the worker’s
/health, the storefront’s/api/health, the admin’s sign-in page and a real store page. The monitor (Monitoring) checks the same URLs every five minutes.
Migrations
The worker applies pending migrations when it starts (packages/db/src/migrate.ts, against
DATABASE_URL_OWNER; its log says migrations applied). That is why it deploys first: by the
time admin and storefront roll, the schema is new.
deploy/docker-compose.prod.yml also has a one-shot migrate service that runs the same script
before any app starts (depends_on: service_completed_successfully). That is the path for
running the compose file directly (for example on a fresh server or locally); production on
Dokploy uses the worker.
A schema change must be safe for the code that is still running while the apps roll, and for the previous release if you roll back: write migrations additively (a new nullable column, not a rename) when a same-day rollback matters. There is no automatic “down” migration.
Zero downtime
Admin and storefront start the new container, wait for its health check, then stop the old one, so there is no moment when neither serves traffic. The worker restarts plainly: BullMQ jobs are retried, not user requests. After a storefront deploy the worker warms each store’s front pages and purges Cloudflare’s cache twice, so no cached page points at the old build’s scripts (Performance and caching).
Rollback
Every release leaves its images in ECR under their commit sha, so rolling back is pointing an app at an older tag: no rebuild.
- Find the last good sha (
git log main, or the tags in ECR). - In Dokploy, set the app’s image back to
vextro/<app>:<that sha>and redeploy. Usually roll back only the app that broke. - If the bad release’s migration must also be undone, that is a manual restore from the backup taken before it ran (see Restore).
- Fix forward on
dev(preferablygit revertthe bad commit) and release again.
One-step rollback
Production apps are separate Dokploy applications that run ECR images tagged with the commit sha
(see Builds on CodeBuild). deploy/rollback.sh points one
of them back at an earlier image and redeploys it, in one command, with no rebuild:
export DOKPLOY_URL=https://<dokploy host>
export DOKPLOY_API_KEY=<token> # Dokploy → Settings → Profile → API keys; never commit it
export DOKPLOY_APP_ID_ADMIN=<application id>
deploy/rollback.sh admin # dry run: shows the live image, recent tags, the plan
deploy/rollback.sh admin --apply # back to the image pushed before the live one
deploy/rollback.sh admin --to <sha> --apply # back to a chosen tag- Apps:
worker,admin,storefront, one per run (DOKPLOY_APP_ID_WORKER,_ADMIN,_STOREFRONT, the same namesdeploy/codebuild/deploy-dokploy.mjsreads). - It reads the live image from the Dokploy application (
application.one), lists the last 20 images of924422830513.dkr.ecr.ap-south-1.amazonaws.com/vextro/<app>(aws ecr describe-images, newest first;:buildcacheand the movinglatesttags are left out) and picks the one pushed just before the live tag.--to <tag>chooses instead;--last <n>lists more.ECR_REGISTRY,ECR_PREFIXandAWS_REGIONoverride the defaults. - Dry run by default: nothing changes without
--apply. With it:application.saveDockerProviderwith the older image (registry fields empty, as the deploy script does: the server pulls with its instance role),application.deploytitledRollback to <sha>, SSM/vextro/deploy/last-sha/<app>set to that sha (so the next build rebuilds the app from there), then it waits for the deploy (--no-waitto skip,DEPLOY_TIMEOUT_MIN, default 15). - Needs
curl,node(JSON) and the AWS CLI withecr:DescribeImagesandssm:PutParameter. The token is passed to curl through a file descriptor, never on the command line. - The worker runs migrations, and a rollback does not undo them: roll the worker back only if the older code works with the newer schema (write migrations additively).
Example dry run (output from a run against stubbed curl and aws, admin live on cccc3333):
App: admin (app1)
Live image: 924422830513.dkr.ecr.ap-south-1.amazonaws.com/vextro/admin:cccc3333
Recent ECR tags in vextro/admin, newest first:
dddd4444
cccc3333
bbbb2222
aaaa1111
Plan:
1. Dokploy application.saveDockerProvider: 924422830513.dkr.ecr.ap-south-1.amazonaws.com/vextro/admin:cccc3333
-> 924422830513.dkr.ecr.ap-south-1.amazonaws.com/vextro/admin:bbbb2222
2. Dokploy application.deploy ("Rollback to bbbb2222")
3. SSM /vextro/deploy/last-sha/admin = bbbb2222 (the next build rebuilds admin from there)
Dry run: nothing changed. Run again with --apply to roll back.Server sizing
4 GB / 2 vCPU holds Postgres, Dragonfly, the three apps and Dokploy’s agent with a 2 GB swap file
as a cushion. Memory limits per service are in deploy/dokploy/README.md; the worker watches its
own memory and pauses bulk queues before it reaches its limit (apps/worker/src/memory-guard.ts).
Lightsail instances are burstable: sustained CPU above the baseline uses up burst credits, after
which the server is throttled, so heavy work (builds) stays off it.
CPU for the worker
Shoppers and the worker share the two vCPUs. Image processing and imports can use all of them: in
October 2026 an image backlog held the worker at 200% CPU and store pages went from about 1 s to 3
to 5 s. Docker splits CPU evenly between busy containers, so the limit is set on the service, in
Dokploy → the application → Advanced → Resources (Docker’s raw units: 1000000000 NanoCPUs =
1 CPU), then Deploy the app:
| App | CPU limit | CPU reservation |
|---|---|---|
| worker | 1000000000 (1 CPU) | empty |
| storefront | empty | 500000000 (0.5 CPU) |
| admin | empty | 250000000 |
| postgres | empty | 500000000 |
The worker’s limit keeps the shop fast: whatever the worker does, at least one CPU stays free
for the storefront, admin and Postgres. Image processing runs one image at a time
(MEDIA_PROCESS_CONCURRENCY, MEDIA_CPUS). While a backlog runs, the admin tells the merchant:
see Image pipeline → The “store may be slower” notice.
Environment
Environment variables live only in Dokploy, per app. Add or change one key at a time; never paste
a whole new env over an app’s existing one. Every key and what it does is in
deploy/env.production.example; the deploy-compose sweep keeps it and
deploy/docker-compose.prod.yml in line with packages/config/src/env.ts. Apps reach Postgres and
Dragonfly by their Dokploy service names on dokploy-network (deploy/dokploy/README.md).
Domains and Cloudflare
admin.koomerce.app,api.koomerce.app(the worker) and the platform names are proxied by Cloudflare with SSL mode Full (strict); Dokploy’s Traefik presents real certificates.- Merchant domains are Cloudflare for SaaS custom hostnames on the
koomerce.appzone (DOMAIN_PROVIDER=cloudflare): the merchant points a CNAME at us, Cloudflare issues the certificate, and the worker adds the store’s route in Dokploy. Setup and rollout: Custom domains. - Edge cache (live since 15 November 2026): the Cloudflare cache rule Store pages on the
koomerce.appzone caches GET requests for store pages, skipping requests that carry thecart,themeorrecently_viewedcookies and the paths/checkout,/cart,/account,/api/and/theme-actions/. The storefront setsSTOREFRONT_EDGE_TTL=600, and the worker purges a store’s hostnames about 5 seconds after an edit (CLOUDFLARE_CACHE_PURGE_TOKEN,CLOUDFLARE_ZONE_ID). Shoppers who answered the cookie banner are not served from the edge yet (an open decision). See Performance and caching.
Real client IPs
Per-IP rate limits (sign-in codes, checkout, gift card checks, newsletter, webhooks) key on the
client IP. Set TRUSTED_PROXY=cloudflare so the apps read cf-connecting-ip and nothing else.
TRUSTED_PROXY=none (the default, right for local development) believes no forwarded header; a
Next server action then has no client address and all its requests share one bucket (stricter,
never bypassable). Ideally ports 80 and 443 accept only
Cloudflare’s ranges ; that is not possible while an apex domain
reaches the server directly (the firewall note).
Outbound network
When the compose file is used, Postgres, Dragonfly and migrate sit only on the internal
network, which has no route out; worker and backup also join egress; admin and
storefront reach the internet through Dokploy’s web network. scripts/sweeps/deploy-compose.test.ts
keeps it that way.
Restore
See Backups for how backups are made and restored
(scripts/restore-db.ts). The separate tasks image is no longer built, so run restore and key
rotation from a checkout of the repo on a machine that can reach the database, with
DATABASE_URL_OWNER set. Always restore into a scratch database first (--target) and check it
before touching the real one.
Key rotation
Follow Key rotation: set the new
SETTINGS_SECRET / SETTINGS_SECRET_PREVIOUS pair in Dokploy, redeploy, run
bun run rotate-secrets --apply, confirm a dry run reports nothing left, then remove
SETTINGS_SECRET_PREVIOUS and redeploy.
Monitoring
- Monitor (
apps/monitor): a Cloudflare Worker checks the API, admin, storefront, Waimers’ home page, the landing site and the docs every five minutes and alerts when a check fails twice in a row. - Container health: Dokploy shows each service’s health check and restart count; look after every deploy.
- Errors and logs: browser and server errors go to GlitchTip (
SENTRY_DSN), with personal data scrubbed (packages/observability);docker logs <container>on the server for the rest. - Server resources: Lightsail’s metrics (CPU, burst capacity, network) and
apps/monitor/scripts/server-threshold-alerts.sh. - Backups: the nightly backup emails when it keeps failing and again when it recovers (Failure alerts); still check now and then that new objects land in R2.
Ops scripts in the worker
Scripts that need the production database settings run by hand in the worker container. The
worker image is pruned to the worker’s packages, so apps/worker/Dockerfile copies each script
from scripts/ into /repo/apps/worker/ops/. Run the file with bun from /repo/apps/worker (a
Dokploy schedule on the worker, or docker exec -it <worker> sh).
| Script | Command (from /repo/apps/worker) |
|---|---|
Store data reset (scripts/reset-store-data.ts) | bun ops/reset-store-data.ts --store <slug> (dry run; --apply deletes) |
Unlimited plan (scripts/platform-unlimited.ts) | bun ops/platform-unlimited.ts <slug> (--off to undo) |
Gateway fee backfill (apps/worker/src/payment-fees-backfill.ts) | bun src/payment-fees-backfill.ts [--store id] [--days 90] |
A new script for the worker must import only packages apps/worker/package.json depends on, and
needs its own COPY line next to the others.
Setting up a new server
The layout, sizes and hardening of the current servers (Dokploy panel, app server, swap, firewall,
DOCKER-USER rule for the panel’s port) are in deploy/dokploy/README.md. In short: create the
instance in ap-south-1 with a static IP, install Dokploy with the official installer
(docs.dokploy.com ), add it as a remote server
in the panel, create Postgres and Dragonfly services, then the three apps with the Docker
provider pointing at their ECR images (registry login for ECR in Dokploy), paste each app’s env,
and deploy worker → admin → storefront.