KKIMS on-site docs
Local rehearsal

Local site build

Build the real static website from a published version with npm run site:build, through every quality gate, into the local website bucket; skip Lighthouse, resume a failed build, and look at the result.

The site build turns one published content version into the static public website and copies it into the website bucket. scripts/site-build/run.mjs does all of it; KIMS's Jenkins job only installs the packages and runs that same script. Running it here proves the build and its quality gates before Jenkins ever does.

Unlike the dev server on Run the apps, this is the real site, built ahead of time, in three languages (en at the root, /kn/, /hi/).

Warning

Windows: on main, the site build fails on a Windows host at the Build locales stage: build-locales.mjs starts npx with spawnSync, which on Windows is npx.cmd and can't be started without a shell (ENOENT or EINVAL). The fix is in the windows-fixes commits, not yet merged into main. On main, build on Linux or macOS, in the local Jenkins (it runs Linux in a container), or from a windows-fixes checkout. Linux and macOS work on main.

#The stages

# Stage What it does Locally
1 Export content The published version, from the database Runs
2 Media manifest What media exists, and where Runs
3 Reviews feed The Google reviews feeds, for dist/reviews/ Runs
4 Build locales next build for every enabled language (apps/website/scripts/build-locales.mjs) Runs: the longest stage
5 Quality gates axe accessibility, Lighthouse in headless Chrome, page count, JavaScript and JSON budgets, sitemap and robots, no CMS code in the site. Any failure stops the build before anything is deployed Runs
6 Bundle media Copies every media file the pages use from the assets bucket into dist/media/ Runs
7 Sync website bucket Uploads dist with its cache rules, then deletes what the build no longer has Runs, into kims-website on the S3 stand-in
8 Invalidate CloudFront Only when CLOUDFRONT_DISTRIBUTION_ID is set Always skipped
9 Redirects Only when KIMS_REDIRECTS_KVS_ARN is set Always skipped

Every stage is recorded in the site_builds table as it starts and ends, so the CMS's Builds screen shows local builds too, failed ones included.

#The live guard

A build of version N when a newer version is already live is recorded as skipped and deploys nothing. It is checked at the start and again just before the sync. A rebuild of the live version itself goes ahead. So you can't use the site build to go back to an older version: see Day-two operations.

#Before you start

  • The services are up, the database is loaded and both buckets exist: Services, Database and content.
  • About 5 GB of free disk on your machine (the built website alone is about 4.7 GB with its images).
  • At least 8 GB of free memory: next build starts one static-generation worker per CPU, less one.
  • Chrome or Chromium installed, for the Lighthouse gate. Without it, set KIMS_LIGHTHOUSE=skip (see below).

The apps from Run the apps don't need to be running.

#Quick way

Run from <KIMS_FOLDER>:

bash
node deployment-steps/scripts/deploy.mjs local website build
bash
CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" node deployment-steps/scripts/deploy.mjs local website build
powershell
node deployment-steps/scripts/deploy.mjs local website build

It builds the newest published version, shows each stage as it runs, and ends:

text
    site build 6: succeeded, version 1
    kims-website: 87,006 files

OK: the website is built into kims-website.

Options: --version <n> builds another published version; --skip-deploy stops after the gates and the media bundle without touching the bucket; --skip-lighthouse skips that gate even with Chrome; --fixtures builds the repo's test content instead (refused once real content has been built here, see the logo check).

A full build of the three languages took about 18 minutes on the engineer's Windows laptop (2026-11-28): Build locales 11 minutes, the gates 2.5, the sync 2.5.

Note

macOS: deploy.mjs looks for Chrome only in Windows folders or as google-chrome/chromium on PATH. On macOS it doesn't find /Applications/Google Chrome.app, so without CHROME_PATH it skips the Lighthouse gate with a warning, although the gate itself would find Chrome. Setting CHROME_PATH as above avoids that. On Linux, Chrome must be on PATH as google-chrome or chromium (not chromium-browser), or set CHROME_PATH.

#By hand

#1. Find the version to build

Run from the repo:

bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"
bash
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"
powershell
docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select max(version) from publish_versions"

You should see a number: 1 straight after the load. Each publish in the CMS adds one.

#2. Run the site build

Run from the repo, with the number from step 1 in place of 1:

bash
npm run site:build -- --version 1 --cause manual
bash
npm run site:build -- --version 1 --cause manual
powershell
npm run site:build -- --version 1 --cause manual

Each stage prints === <stage> === as it starts, and it finishes with a table:

text
stage                     seconds  result
Export content                4.6  succeeded
Media manifest                1.8  succeeded
Reviews feed                  1.7  succeeded
Build locales               672.8  succeeded
Quality gates               152.7  succeeded
Bundle media                 67.9  succeeded
Sync website bucket         146.4  succeeded
Invalidate CloudFront           0  skipped
Redirects                       0  skipped
site build 6: succeeded

The exit code is 0 for succeeded or skipped, 1 for failed, 130 when interrupted (Ctrl+C records the build as aborted).

The settings come from .env.local (npm run site:build loads it): DATABASE_URL, the buckets, S3_ENDPOINT and SITE_URL. KIMS_ENV is unset, so the gates check the site as local, and the site is always marked noindex.

#Other options

Option Meaning
--version N The published version (or PUBLISH_VERSION in the environment)
--cause C publish, retry, rebuild, platform or manual, shown on the Builds screen
--actor "Name <email>" Who asked, shown on the Builds screen
--from-dir DIR Build a content folder instead of a published version, for example apps/website/content-fixtures
--manifest FILE Use this media manifest instead of making one
--skip-deploy Stop after the gates and the media bundle
--work DIR Scratch folder (default .site-build/)

#Chrome for the Lighthouse gate

The Lighthouse gate starts Chrome headless (through chrome-launcher, which finds an installed Chrome on each system). With no Chrome it fails the build: no Chrome or Chromium could be launched. To build without it, skip the gate; it is then recorded as skipped, not passed:

bash
KIMS_LIGHTHOUSE=skip npm run site:build -- --version 1 --cause manual
bash
KIMS_LIGHTHOUSE=skip npm run site:build -- --version 1 --cause manual
powershell
$env:KIMS_LIGHTHOUSE = "skip"
npm run site:build -- --version 1 --cause manual

On Windows the variable stays set for the rest of that PowerShell window: Remove-Item Env:KIMS_LIGHTHOUSE clears it.

Warning

Never skip Lighthouse on KIMS's Jenkins agent. There, Chrome must be installed: see Jenkins agent.

#Resume a failed build at a stage

Warning

--from-stage needs the windows-fixes commits, not yet merged into main. On main the option is ignored and a build always starts from the first stage.

With windows-fixes, --from-stage <stage> resumes at a stage, by name, slug or number ("Bundle media", bundle-media or 6). The stages before it are recorded as skipped, and their outputs are read back from the last run's .site-build/ and apps/website/dist, so use the same --version as that run. Run from the repo:

bash
npm run site:build -- --version 1 --cause manual --from-stage quality-gates
bash
npm run site:build -- --version 1 --cause manual --from-stage quality-gates
powershell
npm run site:build -- --version 1 --cause manual --from-stage quality-gates

If an output it needs is missing, it stops before claiming a build and names the stage to start at instead, for example Start at --from-stage build-locales or earlier.

#Fewer build workers when memory runs out

Warning

KIMS_BUILD_WORKERS needs the windows-fixes commits. On main it is ignored and next build uses one worker per CPU less one.

If Build locales dies with ENOMEM (often on a page write, not as a heap error), the machine ran out of memory with too many static-generation workers. With windows-fixes, cap them:

bash
KIMS_BUILD_WORKERS=3 npm run site:build -- --version 1 --cause manual
bash
KIMS_BUILD_WORKERS=3 npm run site:build -- --version 1 --cause manual
powershell
$env:KIMS_BUILD_WORKERS = "3"
npm run site:build -- --version 1 --cause manual

On main, close other programs, or give Docker Desktop less memory while the build runs on the host.

#Look at the built site

The pages load their styles, scripts and images from the root of the address (/_next/..., /media/...), as they will behind CloudFront. The S3 stand-in serves the bucket under /kims-website/, so a page opened from http://localhost:9100/kims-website/... shows without styles or images. Serve the build's own folder at the root of a local address instead. Run from the repo:

bash
python3 -m http.server 8080 --bind 127.0.0.1 --directory apps/website/dist
bash
python3 -m http.server 8080 --bind 127.0.0.1 --directory apps/website/dist
powershell
python -m http.server 8080 --bind 127.0.0.1 --directory apps/website/dist

Then open http://localhost:8080/bengaluru/doctors/. You should see the doctors page with its styling and photos. /kn/, /hi/ and /sitemap.xml work too. It runs until Ctrl+C. On Windows, if python opens the Microsoft Store, use py instead, or any static file server pointed at apps/website/dist.

This plain server doesn't apply CloudFront's redirects, cache rules or 404 page. apps/website/dist holds the last build run on this machine; a build in the local Jenkins lands in Jenkins's workspace instead (Jenkins).

#Check

Check Command You should see
The build succeeded docker compose -f local/docker-compose.yml exec -T postgres psql -U kims -d kims -tAc "select number, status, stage from site_builds order by number desc limit 1" (from the repo) The newest build, succeeded
Its gate results gate-results.json in the repo root, and .site-build/gate-results.json Each gate with ok: true
The website is in the bucket curl -s -o /dev/null -w "%{http_code}" http://localhost:9100/kims-website/bengaluru/doctors/index.html (Windows: curl.exe, -o NUL) 200
The CMS shows it The CMS's Builds screen The build, with each stage

#The checks that can stop a build

Besides the quality gates, two safety checks compare with the last successful build:

Check Stops a build that Overridden with (for one build)
Page floor Ships far fewer pages than the last (absolute floor 500; 0 for a --from-dir build) ALLOW_PAGE_DROP=1
Logo check Drops a hospital logo the last build showed KIMS_ALLOW_LOGO_LOSS=1, only if a hospital really lost its logo in the CMS

#The logo check refuses the test content

Once real content has been built on a machine, building the repo's fixtures (--from-dir apps/website/content-fixtures, or deploy.mjs ... --fixtures) fails with Refusing to build the "en" chrome: it would drop the logo for electronic-city, mahadevapura, which site build N rendered. That is the logo check working. Build a published version instead.

#Clean up

A build leaves .site-build/, apps/website/dist/ (about 4.7 GB), gate-results.json and sometimes build-failure.json in the repo. All are gitignored. Delete them to free disk, or use Stop and reset.

#If it goes wrong

What you see Likely cause What to do
Give --version N (or PUBLISH_VERSION), or --from-dir DIR No version given Add --version
Windows: Build locales fails at once with spawnSync npx ENOENT or EINVAL main can't run the build on a Windows host See the warning at the top
Quality gates failed A gate found a problem The output and gate-results.json list the gate and the pages. Fix the content or the page, then build again
no Chrome or Chromium could be launched Chrome isn't installed or found Install it, set CHROME_PATH, or KIMS_LIGHTHOUSE=skip
Refusing to build the "en" chrome: it would drop the logo ... The logo check The logo check refuses the test content
A build of an older version ends skipped The live guard Build the newest version
Bundle media: N /media/ path(s) in the built pages are not in the bundle The manifest and the pages disagree. On main this can also be a false alarm: Next splits a srcSet across two script chunks, and main's check reads them separately (fixed in windows-fixes) Regenerate the manifest and build again. If the listed paths are cut off mid-name, it is the false alarm: build from windows-fixes
ENOMEM during Build locales Too many workers for the memory Fewer build workers
It runs out of disk Each build needs about 5 GB Delete apps/website/dist and .site-build
The built page shows without styles or images Opened from the S3 stand-in Look at the built site

#Sources

Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.