Skip to content

Multi-site CI/CD and frontend runtime config

Every service builds images for several deployments (Playtelly staging/prod, hotel, jastv, ibc) from one set of CI files. Part 1 covers the branches, pipelines and GitOps targets. Part 2 covers how the frontend apps get their per-environment URLs at container start, so the same image works on every site.

1. Multi-site CI/CD

The deploy branch decides which pipeline runs and which GitOps repo gets the new image tag.

Branch → pipeline

Branch Image GitOps repo / path GitLab environment
staging registry.nexus.castis.io/playtelly/<app>:staging-<sha> playtelly-iac services/application/<app>/overlays/staging staging
main registry.nexus.castis.io/playtelly/<app>:prod-<sha> playtelly-iac services/application/<app>/overlays/prod production
prod/hotel registry.nexus.castis.io/hotel/<app>:prod-<sha> hotel-iac application/<app>/overlays production_hotel
prod/jastv registry.nexus.castis.io/jastv/<app>:prod-<sha> 3bb-tv/jastv-iac environments/production/playtelly/<app> production_jastv
prod/ibc registry.nexus.castis.io/ibc/<app>:prod-<sha> ibc-iac main application/<app>/overlays production_ibc

Each build also pushes <env>-latest and uses <env>-cache as the registry build cache. The Nexus cleanup job keeps these two tags and deletes older <env>-<sha> tags.

flowchart LR
  F[feature branch] -->|MR| S[staging]
  S -->|merge| M[main]
  S -->|merge| H[prod/hotel]
  S -->|merge| J[prod/jastv]
  S -->|merge| I[prod/ibc]
  S -.build + tag bump.-> PI1[playtelly-iac staging]
  M -.-> PI2[playtelly-iac prod]
  H -.-> HI[hotel-iac]
  J -.-> JI[jastv-iac]
  I -.-> II[ibc-iac main]

The rule: CI changes go on staging first

staging is where all work starts, and it gets merged into main and every prod/* branch. So staging must hold the CI files for every branch. If you change a hotel or jastv job directly on prod/hotel, the next staging → prod/hotel merge can overwrite it or drop it.

This happened before: the hotel/jastv build files had only been edited on the prod branches. They were compared file by file and copied onto staging in AuthAPI, CoreAPI, OrgConsole, PlayoutAdmin, TellyboardAdmin and tellyid. PlatformConsole, SpatioViewAdmin, mediasoup, cdn-ai, ticketcms and conciergeguestapp already had everything on staging.

Exception: PlayTellyInternal has no staging branch. Its CI lives on prod/hotel.

File layout

.gitlab-ci.yml                       # variables, workflow rules, includes for every site
.gitlab-ci/
  .gitlab-ci-build.yml               # staging + main builds
  .gitlab-ci-update-image-tag.yml    # staging + main tag bumps -> playtelly-iac
  .hotel-ci-build.yml                # prod/hotel
  .hotel-ci-update-image-tag.yml
  .jastv-ci-build.yml                # prod/jastv
  .jastv-ci-update-image-tag.yml
  .ibc-ci-build.yml                  # prod/ibc
  .ibc-ci-update-image-tag.yml

Root .gitlab-ci.yml (OrgConsole):

variables:
  REGISTRY_URL: "registry.nexus.castis.io"
  IMAGE_BASE: "registry.nexus.castis.io/playtelly"
  GITOPS_REPO: "playtelly/playtelly-iac"
  # hotel
  HOTEL_IMAGE: "registry.nexus.castis.io/hotel"
  HOTEL_REPO: "playtelly/hotel-iac"
  # jastv
  JASTV_IMAGE: "registry.nexus.castis.io/jastv"
  JASTV_REPO: "3bb-tv/jastv-iac"
  # ibc
  IBC_IMAGE: "registry.nexus.castis.io/ibc"
  IBC_REPO: "playtelly/ibc-iac"
  IBC_BRANCH: "main"

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == "staging"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == "prod/hotel"
    - if: $CI_COMMIT_BRANCH == "prod/jastv"
    - if: $CI_COMMIT_BRANCH == "prod/ibc"
    - when: never

stages: [review, build, update_image_tag]

Each site file has its own rules: - if: $CI_COMMIT_BRANCH == "prod/<site>", so including all of them on every branch is safe.

Build job

All site build files are generated from the repo's own staging build template, so they behave the same:

  • Shared builder pool. The project name is hashed to one of multiarch-pool-0..2. Before this, every project created its own multiarch-<project> builder that was never removed (see Cloud Node Disk & Memory Cleanup).
    POOL_INDEX=$(( 0x$(echo -n "$PROJECT_NAME" | md5sum | cut -c1-6) % 3 ))
    BUILDER_NAME="multiarch-pool-${POOL_INDEX}"
    
    A builder that fails buildx inspect --bootstrap is removed and created again.
  • No VITE_* build args. Frontend images get their config at runtime (Frontend runtime config below). The values the old jobs baked in are kept as comments in each .hotel-ci-build.yml / .jastv-ci-build.yml for whoever fills in that site's ConfigMap.
  • Platforms: staging/prod/hotel/ibc build linux/amd64,linux/arm64. jastv builds linux/amd64 only.

Tag bump job

update_<site>_tag:production runs after the build (needs:):

  1. Clone the GitOps repo with the site's token ($IBC_IAC_TOKEN, etc.).
  2. cd application/<app>/overlays (path differs per site, see the table above).
  3. kustomize edit set image <SITE_IMAGE>/<app>:prod-<sha>, using the image's own name.
  4. Commit chore(<site>): update <app> to prod-<sha> [skip ci] and git push.

ArgoCD on that side picks up the commit.

Known issue: concurrent pushes. The push is a plain git push with no rebase. If two services finish at the same moment and push to the same IaC repo, the second one is rejected. Retry the failed job in GitLab.

How to

Add a new site / deploy branch

  1. On staging, copy .ibc-ci-build.yml and .ibc-ci-update-image-tag.yml to .<site>-ci-*.yml and change the variable names, branch rule and GitOps path.
  2. Add <SITE>_IMAGE / <SITE>_REPO variables, the workflow rule and the two include: lines to the root .gitlab-ci.yml.
  3. Add a CI/CD variable with a token that can push to the site's IaC repo.
  4. Do this in every service that the site deploys. Merge to staging, then create prod/<site> from staging.
  5. Add the new namespace to NAMESPACES in nexus/nexus-cleanup.yml so its old tags get cleaned up.

Release a service to a site

git checkout prod/<site> && git merge staging && git push

Watch the build and the tag bump in GitLab, then check the commit in the site's IaC repo.

ibc is one more step. CI only writes ibc-iac main, which only the lab VM follows. Hotels get the release by MR inside ibc-iac:

ibc-iac branch Followed by
main Lab VM (CI writes here)
canary Pilot hotel
stable Every other site

Test on the lab, then MR main → canary, check the pilot hotel, then MR canary → stable. ArgoCD on each site pulls its branch, so merging updates every site on that branch.


2. Frontend runtime config

The Vite frontend apps read their browser config (VITE_* URLs) when the container starts, not when the image is built. The same image can run on staging, prod, hotel, jastv and every ibc site. Only the ConfigMap differs.

Why

Vite replaces import.meta.env.VITE_* with literal strings at build time. Before this change every environment needed its own build with its own --build-arg VITE_.... That gave us:

  • one CI build job per site, each with a copy of the URLs
  • images that can't be promoted (the staging image has staging URLs inside it)
  • no way to point an on-prem ibc site at its own domain without building a new image

With runtime config the URLs move out of the image and into the cluster, where the rest of the environment config already lives.

How it works

flowchart LR
  CM[ConfigMap<br/>&lt;app&gt;-config] -->|envFrom| POD[nginx container]
  POD -->|/docker-entrypoint.d/<br/>40-runtime-env.sh| JS[env-config.js<br/>window.__ENV__]
  JS -->|loaded by index.html<br/>before the app| APP[src/config/env.*]
  APP -.->|fallback for npm run dev| VITE[import.meta.env]
Piece File What it does
Entrypoint hook docker/40-runtime-env.sh The nginx image runs every executable in /docker-entrypoint.d/ before nginx starts. This script writes the listed VITE_* env vars into env-config.js as window.__ENV__ = {...} and prints each key to the log.
Placeholder public/env-config.js window.__ENV__ = {};, so npm run dev doesn't 404. The container overwrites it.
Loader index.html <script src=".../env-config.js"> before the app bundle.
Reader src/config/env.(ts\|js) The only place that reads env config. It returns window.__ENV__[key] first, then import.meta.env[key]. Every other file imports from here.
No-cache rule nginx.conf location = /<base>/env-config.js with Cache-Control: no-store. It's an exact match, so it wins over the 1-year cache regex for *.js.
Dockerfile Dockerfile No ARG VITE_*. Copies the hook with --chmod=755.

Example (OrgConsole):

COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --chmod=755 docker/40-runtime-env.sh /docker-entrypoint.d/40-runtime-env.sh
# Exact match, so it wins over the 1y-cache regex locations below.
location = /biz-console/env-config.js {
    alias /usr/share/nginx/html/env-config.js;
    add_header Cache-Control "no-store" always;
}

Apps and their keys

App Served at ConfigMap Runtime keys
OrgConsole /biz-console/env-config.js orgconsole-config VITE_AUTH_URL, VITE_AUTH_API_URL, VITE_CORE_API_URL, VITE_PLAYOUT_URL, VITE_TELLYBOARD_URL, VITE_SPATIO_URL, VITE_TELLYCONNECT_URL, VITE_PLATFORM_URL, VITE_PREFS_COOKIE_DOMAIN
PlatformConsole /platform/env-config.js platformconsole-config VITE_AUTH_URL, VITE_AUTH_API_URL, VITE_CORE_API_URL, VITE_TELLYBOARD_URL, VITE_TELLYCONNECT_URL
SpatioViewAdmin /spatio/env-config.js spatio-config VITE_API_BASE_URL, VITE_AUTH_URL, VITE_AUTH_API_URL, VITE_CORE_API_URL, VITE_SPATIO_WORKSPACE_ID
PlayoutAdmin /playout/env-config.js playout-config VITE_TELLYID_URL, VITE_AUTH_URL
TellyboardAdmin /tellyboard/env-config.js tellyboard-config VITE_TELLYID_URL, VITE_AUTH_URL, VITE_CORE_API_URL, VITE_MEDIA_PROXY_URL, VITE_CDN_HOST, VITE_MQTT_HOST/PORT/PATH/USE_SSL/USER/PASSWORD
tellyid /env-config.js tellyid-config VITE_BACKEND_URL, VITE_CORE_API_URL, VITE_PREFS_COOKIE_DOMAIN
conciergeguestapp /concierge/env-config.js guestapp-config VITE_CORE_API_URL, VITE_MQTT_*

Things to know:

  • Everything in env-config.js is public. Any visitor can read it. Only put values there that were already in the JS bundle before. The MQTT user/password for TellyboardAdmin and conciergeguestapp were already in the bundle. Their startup log prints <set>/<unset> for the password, never the value.
  • tellyid's ConfigMap also has BACKEND_URL and TUSD_URL. Those are for the nginx template, not the browser, and the hook doesn't expose them.
  • PlayoutAdmin has no VITE_CORE_API_URL. It calls the API through nginx's /playout/api/ proxy.
  • SpatioViewAdmin's VITE_IMAGE_BASE_URL is still a build-time value (defaults to https://placehold.co).

Where the values live

Environment Repo Path Notes
staging / prod playtelly-iac services/application/<app>/overlays/{staging,prod}/configmap.yml promoweb's ConfigMap was renamed to promoweb-config because tellyboard-config collided with tellyboardadmin's
hotel hotel-iac application/<app>/overlays Values taken from the old prod/hotel build args
ibc sites ibc-iac application/<app>/overlays/configmap.yml Uses your-domain.example.com. gitops/render.sh replaces it with the site's IBC_DOMAIN. Spatio/tellyconnect/platform are empty (not deployed on sites).
jastv 3bb-tv/jastv-iac environments/production/playtelly/<app> Not done yet. The old values are in comments in each repo's .gitlab-ci/.jastv-ci-build.yml.

Order matters when rolling out: add the ConfigMap keys first, then deploy the new image. Old images ignore the extra keys. A new image with no keys starts with empty URLs and the app breaks.

How to

Change a URL in one environment

  1. Edit the ConfigMap in the IaC repo for that environment.
  2. Restart the deployment so the hook runs again (env vars are read once, at start):
    kubectl -n <ns> rollout restart deploy/<app>
    
    The overlays use a plain ConfigMap (not a hashed configMapGenerator), so ArgoCD syncing the ConfigMap does not restart the pods.

No rebuild needed.

Add a new browser key to an app

  1. Add the key to KEYS="..." in docker/40-runtime-env.sh.
  2. Export it from src/config/env.* with read("VITE_NEW_KEY") and import it from there. Don't read import.meta.env anywhere else.
  3. Add it to the ConfigMap in every IaC repo that deploys the app (table above), then merge the app.

Move another Vite app to runtime config

Copy the pieces from OrgConsole: the hook, public/env-config.js, the <script> tag, src/config/env.*, the nginx exact-match location, and the Dockerfile COPY --chmod=755. Then remove ARG/--build-arg VITE_* from the Dockerfile and CI, and add envFrom + the ConfigMap in the IaC repos.

Troubleshooting

Check what the browser gets:

curl -s https://<host>/<base>/env-config.js

An empty {} means the hook didn't run (wrong path or not executable). Empty strings mean the pod has no env vars (ConfigMap missing or no envFrom).

Check the pod log. The hook prints one line per key at start:

kubectl -n <ns> logs deploy/<app> | grep -A20 40-runtime-env

Browser still has old values: the no-store location is missing or doesn't match the exact path the page requests. Check the response headers with curl -I.

npm run dev requests /spatio/spatio/env-config.js: Vite adds base to paths in index.html itself. Write the script tag as /env-config.js and let Vite add the prefix. This was fixed in SpatioViewAdmin.

arm64 build crashes in npm install (SIGBUS in @swc/core postinstall): the JS build was running under QEMU. Build dist/ on the native platform and keep only the nginx stage multi-arch:

FROM --platform=$BUILDPLATFORM node:22-alpine AS builder

dist/ is static files and the same for every arch. This also makes the build about 2x faster.