KKIMS on-site docs
Operate and troubleshoot

deploy.mjs

The engineer's helper, deployment-steps/scripts/deploy.mjs. Where it expects the folders, its global options, exit codes and logs, what works on which system (it was only run on Windows), and every command, local and kims, as it really behaves.

deployment-steps/scripts/deploy.mjs turns the deployment steps into commands. Each command does what a page's "By hand" steps do, checks the result, and stops with a fix when something is wrong. It is a plain Node.js script (Node 24), with no packages of its own: it borrows js-yaml and the like from the repo's node_modules.

It is a helper, not part of the product: nothing in KIMS's Jenkins or cluster runs it. Every page shows the commands it runs, so you can always do the same by hand.

Warning

deploy.mjs was written and run only on Windows (PowerShell and Git Bash, 2026-11-28). It is written to work on macOS and Linux, and the differences are listed in What works on which system, but nobody has run it there yet.

#Folders it expects

text
<KIMS_FOLDER>/
  deployment-steps/scripts/deploy.mjs     this script
  deployment-steps/scripts/logs/          one log per run
  repos/kims-v2/                          the code (--repo to use another)
  KIMS-v2-handover-2026-11-24/data-bundle the data bundle (--bundle to use another)

Run it from <KIMS_FOLDER>, as node deployment-steps/scripts/deploy.mjs <command>. It finds the other folders from its own location, not from where you are, so it works from anywhere; the examples use <KIMS_FOLDER> so the paths read the same.

#Help

bash
node deployment-steps/scripts/deploy.mjs --help
node deployment-steps/scripts/deploy.mjs local --help
node deployment-steps/scripts/deploy.mjs kims content load --help
bash
node deployment-steps/scripts/deploy.mjs --help
node deployment-steps/scripts/deploy.mjs local --help
node deployment-steps/scripts/deploy.mjs kims content load --help
powershell
node deployment-steps/scripts/deploy.mjs --help
node deployment-steps/scripts/deploy.mjs local --help
node deployment-steps/scripts/deploy.mjs kims content load --help

The first lists every command, the second those starting local, the third one command's details, options and examples.

#Global options

Option What it does
--help, -h Help for the command, or the list
--dry-run Prints the commands that would change something, without running them. Read-only checks still run
--yes Goes ahead with a command that deletes (local reset, local db reseed). Without it they only list what they would delete
--repo <path> The kims-v2 folder, if not <KIMS_FOLDER>/repos/kims-v2. Use it to run against another checkout, for example one on windows-fixes
--verbose Shows every command's output live, not only in the log

Commands that take the bundle also take --bundle <path>.

Secrets are never options. A command that needs one reads it from an environment variable or asks for it with a hidden prompt, so it never lands in your shell history. Every value it handles is masked in its output and log.

#Exit codes and logs

Code Means
0 Done, ends with a green OK: ...
1 A step failed: the message names it and a fix
2 Wrong usage: a missing or unknown option
3 A precondition isn't met (something must be done first), or a listing command that needs --yes

Each run writes deployment-steps/scripts/logs/<YYYYMMDD-HHMMSS>-<command>.log with every command and its full output. Some lines in a successful log look like failures but are probes: harmless log lines.

#What works on which system

The script is cross-platform Node, finds tools on PATH on every system, and starts them without a shell. These are the parts that differ:

Command or part Windows macOS Linux
Tested Yes, 2026-11-28 No No
local check Full: also checks Git Bash, the native .node modules (Application Control), and tools installed by winget but not yet on PATH Skips the Windows-only checks Same as macOS
Chrome for the Lighthouse gate Found in Program Files or %LOCALAPPDATA% Not found in /Applications: local website build skips Lighthouse unless CHROME_PATH is set Found as google-chrome or chromium on PATH (local check also tries chromium-browser; website build doesn't)
local apps start, stopping Ends each app's whole process tree (taskkill /T /F) Sends SIGTERM to each app; a child left behind may hold its port Same as macOS
local apps start, port-in-use fix text PowerShell line Shows the PowerShell line too: use lsof instead (Port already in use) Same, use ss
local website build on main Fails at Build locales (spawnSync npx ENOENT), needs windows-fixes Works Works
local website build, last hint Prints python -m http.server ... Use python3 Use python3
local kube up, rehearse-load Works with Docker Desktop Expected to work with Docker Desktop Pods reach the host as host.docker.internal, which Docker Engine doesn't provide inside kind: use Docker Desktop for Linux
Sign-in on the kind CMS (3102) Needs windows-fixes Same Same
kims google-client save Needs deploy/handover/node-tools-pod.yaml, only on windows-fixes Same Same
kims secrets create hidden prompt Works in PowerShell and Windows Terminal Works in any terminal Same
kims content load, kubectl cp Copies by relative name (a C:\ path breaks kubectl cp); handled Fine Fine

Everything else (the services, migrations, the load, Jenkins, the kims commands) runs the same commands on every system.

#Local commands

All of these need Docker running, the repo with npm install done, and .env.local (The env file), and say so if not.

#local check

Checks the machine is ready; changes nothing. Tools and versions (Node 24, npm 10, git, Docker 24 with Compose and buildx, kubectl, kind, Helm 3, Chrome, openssl), Docker running, the repo and its packages, .env.local, and the data bundle's checksums.

Option
--for <step> Only what one local step needs: 00 to 08
--skip-bundle Skip the bundle check

Each line is OK, WARN, MISSING, FAIL or BLOCKED (installed but stopped by Windows Application Control), with a fix. It fails if anything a local step needs is missing. See Local overview.

#local up

Runs local storage up, local db up, local keycloak up, then local db seed (which does nothing if the database already has content). Stops at the first failure. Safe to run again. Takes --bundle. See Services.

#local storage up

Starts the S3 stand-in (port 9100) and creates the assets and website buckets.

#local db up

Starts Postgres (port 5418) and runs the migrations. --database <name> migrates another local database (made if missing).

#local db seed

Loads the data bundle into the database and assets bucket. Refuses a database that already has content, and one that is half loaded. Takes --database, --bundle. See Database and content.

#local db reseed

Drops the database, recreates it, migrates it and loads the bundle again: every CMS edit is lost. Lists what it would do; deletes only with --yes. Takes --database, --bundle.

#local keycloak up

Starts Keycloak (port 8180) with the kims realm and its test users, and checks the realm answers.

#local apps prepare

Writes the local website's content snapshot (.local-content/), its media manifest, and copies the resized images from the bundle into apps/website/public/media/. Run it again after publishing, then restart the website. See Apps.

#local apps start [cms] [website] [worker]

Starts the named apps, or all three, in this window: the CMS on 3101, the website on 3100, and the worker. Each line is prefixed with the app's name. It checks each one is ready, stops the others if one stops, and stops all on Ctrl+C. Refuses to start an app whose port is in use.

#local website build

Runs the repo's site build (scripts/site-build/run.mjs, the same Jenkins runs) into the local website bucket. Records it in site_builds, so the CMS Builds screen shows it. About 10 GB of free disk.

Option
--version <n> The published version. Default: the newest
--fixtures Build the repo's test content instead. Refused once real content was built here (the logo check)
--skip-deploy Stop before touching the bucket
--skip-lighthouse Skip the Lighthouse gate even with Chrome

Without Chrome it skips Lighthouse with a warning. See Site build.

#local jenkins up

Starts the local Jenkins on 8190, building its image the first time (Jenkins LTS, Node 24, Chromium, the plugins). --rebuild rebuilds the image. Setting up the credentials and job is done in Jenkins's screens: Local Jenkins.

#local kube up

Builds the image, creates the kind cluster kims-v2 if missing, loads the image, creates the namespace and Secrets from .env.local, installs the chart, waits for it, and checks the health address. --skip-build reuses the loaded image; --database <name> points it at another local database. A Node version of the repo's deploy/kind/up.sh, so it needs no Git Bash. See kind and Helm rehearsal.

#local kube rehearse-load

Recreates the empty database kims_rehearsal, points the kind deploy at it, redeploys (the migrate Job makes the tables), runs the repo's load pod with the bundle, deletes the pod, and checks the rows. --keep-pod keeps the pod. Afterwards the kind CMS uses kims_rehearsal until local kube up.

#local kube down

Deletes the kind cluster. No data is lost: it lives in the Compose services.

#local down

Stops the Compose services (Jenkins too). Their data stays. It doesn't stop the apps; Ctrl+C them first.

#local reset

Lists the kims-v2_ Docker volumes, the kind cluster and the generated files in the repo (each checked to be gitignored), with sizes, and exits with code 3. With --yes, deletes them all. Keeps the code, .env.local, the handover and the Docker images. Doesn't delete <KIMS_FOLDER>/jenkins-site-dist. See Stop and reset.

#kims commands

These act on KIMS's cluster. Every one that changes something requires --context, so it never acts on whichever context happens to be current.

Option
--context <context> The kubectl context for KIMS's cluster (kubectl config get-contexts)
--namespace <ns> Default kims (production). For UAT pass --namespace kims-uat

They need kubectl with access to the cluster (VPN if KIMS requires it), the repo with npm install done, and nothing else on your machine: the database and buckets are reached from pods inside the cluster.

#kims bundle check

Checks every file in the data bundle against its checksum and prints what it holds and the migrations it was made with. Needs no cluster or network. Run it before leaving with the bundle and after copying it. Ends bundle ok: ....

#kims values check

bash
node deployment-steps/scripts/deploy.mjs kims values check --file <PATH_TO_VALUES_YAML>

Checks a filled-in Helm values file before it goes into Jenkins, then renders the chart with it (helm template) if Helm is installed. Needs no cluster. It checks:

  • no <...> placeholder is left
  • image.repository is <registry>/kims/kims-v2, and image.tag is empty (Jenkins sets it)
  • serviceAccount.roleArn is an IAM role ARN
  • S3_REGION, ASSETS_BUCKET, WEBSITE_BUCKET set, and the two buckets differ
  • KEYCLOAK_ISSUER is https://.../realms/<realm>; KEYCLOAK_CLIENT_ID set
  • CMS_URL and SITE_URL are https://; JENKINS_JOB_URL contains /job/; JENKINS_USER set
  • KIMS_BOOTSTRAP_ADMINS is a list of emails
  • no local-only setting or secret in env
  • the ingress host matches CMS_URL; secretEnv names every Secret
Warning

It doesn't check KIMS_ENVIRONMENT, which main's kims-platform job requires: the job refuses a values file whose KIMS_ENVIRONMENT isn't production on main or uat on uat. Check that line yourself. Also check that JENKINS_JOB_URL includes the folder (.../job/kims-production/job/kims-site-build); the script only checks it contains /job/. Its help text names the old file values-uat.yaml and credential kims-helm-values-uat; on main the credential is kims-helm-values in each folder (Environments).

#kims secrets create

Creates the four Secrets the chart reads, in the namespace (which KIMS creates):

Secret Keys From
kims-database url KIMS_DATABASE_URL, or the hidden prompt
kims-keycloak client-secret KIMS_KEYCLOAK_CLIENT_SECRET, or the prompt
kims-app session-secret, secrets-key Generated here (48 and 32 random bytes); nobody needs to know them
kims-jenkins token KIMS_JENKINS_TOKEN, or the prompt
bash
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KIMS_EKS_CONTEXT>
bash
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KIMS_EKS_CONTEXT>
powershell
node deployment-steps/scripts/deploy.mjs kims secrets create --context <KIMS_EKS_CONTEXT>

Add --namespace kims-uat for UAT. How it behaves:

  • A Secret that exists is left alone and reported. If all four exist, it says so and changes nothing.
  • The connection string must be postgres:// with user and password, not localhost, 127.0.0.1 or host.docker.internal, have a database name, and end ?sslmode=require.
  • All three values are needed in the same run. An empty answer stops it with no value for <Secret>: the Jenkins token can't be left for later. Create the Jenkins user's API token first (Jenkins API token).
  • Not in a terminal (for example piped) and the variable unset: it stops with ... isn't set, and this window can't be asked.
  • --replace kims-database,kims-keycloak,kims-jenkins (any of them) replaces those after a change. Then restart the CMS and worker; it reminds you.
  • kims-app is never replaced: --replace kims-app is refused. Its secrets-key must stay the same for the life of the environment (Backup and restore).

#kims content load

Loads the data bundle into KIMS's empty database and assets bucket, from a one-off pod in the namespace (Content load):

  1. checks the bundle here
  2. checks the first deploy is done: the kims service account (its IAM role writes the bucket), the kims-database Secret, the completed kims-migrate Job
  3. starts the repo's deploy/handover/load-bundle-pod.yaml, with --image and --bucket filled in
  4. copies the bundle in (about 530 MB, a few minutes over a VPN)
  5. runs data-bundle load: checksums, refuses a database that isn't migrated or already has content, uploads the files, writes all rows in one transaction
  6. deletes the pod, always (--keep-pod keeps it)
  7. checks the rows written match the bundle
bash
node deployment-steps/scripts/deploy.mjs kims content load --context <KIMS_EKS_CONTEXT> --image <REGISTRY>/kims/kims-v2:<COMMIT_SHA> --bucket <ASSETS_BUCKET> --region <AWS_REGION>
bash
node deployment-steps/scripts/deploy.mjs kims content load --context <KIMS_EKS_CONTEXT> --image <REGISTRY>/kims/kims-v2:<COMMIT_SHA> --bucket <ASSETS_BUCKET> --region <AWS_REGION>
powershell
node deployment-steps/scripts/deploy.mjs kims content load --context <KIMS_EKS_CONTEXT> --image <REGISTRY>/kims/kims-v2:<COMMIT_SHA> --bucket <ASSETS_BUCKET> --region <AWS_REGION>
Warning

Always pass --region. It defaults to ap-south-1 and overrides the region in the pod file. The runbook on main recommends ap-south-2 (Hyderabad), and the chart's default S3_REGION is ap-south-2. Use the buckets' real region.

  • --image must be the exact image the deploy runs, with its commit tag (or a digest). latest or no tag is refused. kubectl -n kims get deployment kims-cms -o jsonpath="{.spec.template.spec.containers[0].image}" prints it.
  • If it stops part way, nothing is half-written in the database (one transaction), and files already in the bucket at the same size are skipped: run it again.
  • A second run against loaded content stops with already has N rows; load only goes into an empty database.

#kims google-client save

Saves the Google OAuth client for Google reviews, encrypted in the database, from a one-off pod (Google reviews OAuth). Reads the CMS's image, CMS_URL and KIMS_ENVIRONMENT from the deployment; checks the client file here (a Web application client, and whether it lists the CMS's redirect address); starts the node-tools pod; copies a bundled save-google-client script and the file in; saves; deletes the pod.

bash
node deployment-steps/scripts/deploy.mjs kims google-client save --context <KIMS_EKS_CONTEXT> --file <PATH_TO_CLIENT_JSON> --dry-run
node deployment-steps/scripts/deploy.mjs kims google-client save --context <KIMS_EKS_CONTEXT> --file <PATH_TO_CLIENT_JSON>

The same in all three shells. --dry-run stops after checking the file. Other options: --namespace, --cms-origin, --env, --image, --keep-pod. Running it again replaces the saved client.

Warning

Needs the windows-fixes commits, not yet merged into main: the pod file deploy/handover/node-tools-pod.yaml exists only there. On main the dry run works and the real save stops with ENOENT naming that file. Google reviews OAuth has the way round.

#kims check

Read-only. Checks kims-cms and kims-worker have all pods ready, kims-migrate completed, the CronJobs exist, and the CMS answers /api/health?check=ready with {"status":"ready","database":"ok"} (through a kubectl port-forward to svc/kims-cms that it stops afterwards). With --content, it also counts the content rows from inside the CMS pod and compares them with the bundle (and prints cms_users).

bash
node deployment-steps/scripts/deploy.mjs kims check --context <KIMS_EKS_CONTEXT>
node deployment-steps/scripts/deploy.mjs kims check --context <KIMS_EKS_CONTEXT> --content

The same in all three shells. --context is optional here (it uses the current context if left out). Ends OK: the deploy in kims is healthy. It works on kind too: --context kind-kims-v2.

#Harmless lines in the logs

Line Why
Error: release: not found (local kube up) helm status before the first install
Error: Kubernetes cluster unreachable: context "kind-kims-v2" does not exist A probe before the cluster is made
Error from server (NotFound): secrets "kims-..." not found (secrets create) It checks which Secrets exist
Red NativeCommandError around a line ending done (PowerShell) The program writes progress to stderr

#Sources

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