Tellyboard staging deployment notes
Project:
playtelly-iacServices:tellyboard-frontend·ArgoCD·k3s clusterStack: React (Vite) · Docker Buildx · GitLab CI · ArgoCD · k3s
1. Overview¶
Four issues were identified and resolved during the staging deployment session on 2026-06-24:
| # | Problem | Root Cause | Impact |
|---|---|---|---|
| 1 | Build timing out | No --cache-to, arm64 npm install ~6 min uncached |
CI pipeline failing after 60 min |
| 2 | ArgoCD Degraded |
ConfigMap has no built-in health check in ArgoCD | App showed Degraded despite running fine |
| 3 | Node NotReady 4 days |
Clock drift 7.7s caused etcd cascade failure | castis-desktop master node offline |
| 4 | Infinite redirect loop | VITE_TELLYID_URL not injected — missing https:// |
Users could never log in to staging |
2. Docker Build Optimization¶
2.1 Problem¶
The multiarch build (linux/amd64,linux/arm64) was taking ~11 minutes every run with no improvement over time:
--cache-fromused shorthand format — only cached the final image layers, not intermediate build steps- No
--cache-to— cache was never written back to the registry - arm64
npm installtook ~6 minutes on every build regardless
# before — shorthand format, no cache-to
--cache-from $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest ← wrong format, no writes
2.2 Fix — Dockerfile¶
Add --mount=type=cache to both npm install steps. This caches downloaded packages on the runner's local disk, surviving layer cache invalidation when package.json changes.
# ─────────────────────────────────────────
# Stage 1: Build
# ─────────────────────────────────────────
FROM node:20-alpine AS build
WORKDIR /app
RUN apk update && apk add --no-cache \
libc6-compat \
python3 \
make \
g++
COPY package.json package-lock.json* ./
ARG NPM_AUTH
RUN echo "//nexus.castis.io/repository/npm-hosted/:_auth=${NPM_AUTH}" > .npmrc && \
echo "//nexus.castis.io:9443/repository/npm-hosted/:_auth=${NPM_AUTH}" >> .npmrc && \
echo "@playtelly:registry=https://nexus.castis.io/repository/npm-hosted/" >> .npmrc
ENV ELECTRON_SKIP_BINARY_DOWNLOAD=1
RUN rm -f package-lock.json
# mount cache persists downloaded packages across builds
RUN --mount=type=cache,target=/root/.npm \
npm install --legacy-peer-deps
RUN --mount=type=cache,target=/root/.npm \
npm install --legacy-peer-deps @rollup/rollup-linux-arm64-musl --ignore-scripts || true
COPY . .
ARG VITE_TELLYID_URL
ENV VITE_TELLYID_URL=$VITE_TELLYID_URL
RUN npm run build
# ─────────────────────────────────────────
# Stage 2: Serve
# ─────────────────────────────────────────
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
2.3 How the Two Caches Work Together¶
There are two independent caching mechanisms that complement each other:
| Layer | Mechanism | Stored In | Survives |
|---|---|---|---|
| Registry cache | --cache-to/from type=registry |
Nexus registry | Any runner, any machine |
| npm mount cache | --mount=type=cache,target=/root/.npm |
Runner local disk | Same runner reuse |
Cache hit scenarios:
| Scenario | Registry Cache | npm Mount Cache | Result |
|---|---|---|---|
| Source code changed only | HIT — skip npm install entirely |
— | ~0s for install |
package.json changed |
MISS — must run install | HIT — no re-download | ~30s |
| First build after fix | MISS | MISS | ~6 min (populates both) |
Expected build time after first cached run: ~3–4 min down from ~11 min
3. GitLab CI Pipeline¶
3.1 Problems¶
--cache-fromshorthand only read final image layers, not intermediate build layers- No
--cache-toso registry cache was never written VITE_TELLYID_URL=$VITE_TELLYID_URL_$ENV_NAME— GitLab does not expand nested variable references like this, so the build arg was always empty- No
timeoutset — default 1 hour caused arm64 builds to be killed
3.2 Fix — .gitlab-ci.yml¶
# ─────────────────────────────────────────
# Templates
# ─────────────────────────────────────────
.build_template:
stage: build
timeout: 2h
image: docker:24
services:
- docker:24-dind
script:
- PROJECT_NAME=$(echo $CI_PROJECT_NAME | tr '[:upper:]' '[:lower:]')
- docker login -u $NEXUS_USER -p $NEXUS_PASSWORD $REGISTRY_URL
- docker buildx rm multiarch || true
- docker buildx create --use --name multiarch --node multiarch0
- |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=$IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--cache-to type=registry,ref=$IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest,mode=max \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-$CI_COMMIT_SHORT_SHA \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--build-arg NPM_AUTH=$(echo -n "$NEXUS_USER:$NEXUS_PASSWORD" | base64) \
--build-arg VITE_TELLYID_URL=$VITE_TELLYID_URL \
--file tellyboard-frontend/Dockerfile \
--push \
tellyboard-frontend/
# ─────────────────────────────────────────
# Jobs
# ─────────────────────────────────────────
build:staging:
extends: .build_template
variables:
ENV_NAME: staging
VITE_TELLYID_URL: ${VITE_TELLYID_URL_staging}
environment:
name: staging
rules:
- if: $CI_COMMIT_BRANCH == "staging"
build:production:
extends: .build_template
variables:
ENV_NAME: prod
VITE_TELLYID_URL: ${VITE_TELLYID_URL_prod}
environment:
name: production
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
3.3 Key Changes Explained¶
| Change | Reason |
|---|---|
timeout: 2h |
Prevents CI runner from killing the job during slow arm64 builds |
--cache-from type=registry,ref=... |
Correct format — reads all intermediate layers, not just final image |
--cache-to type=registry,ref=...,mode=max |
Writes ALL intermediate layers back to registry; mode=max is required |
VITE_TELLYID_URL: ${VITE_TELLYID_URL_staging} |
Explicit per-job mapping — avoids nested variable expansion failure |
3.4 GitLab CI Variables Required¶
Set these in Settings → CI/CD → Variables:
| Key | Value | Notes |
|---|---|---|
VITE_TELLYID_URL_staging |
https://stag.tellyid.castis.io |
Must include https:// |
VITE_TELLYID_URL_prod |
https://tellyid.castis.io |
Must include https:// |
NEXUS_USER |
gitlab-ci |
Masked |
NEXUS_PASSWORD |
*** |
Masked |
Important: The
https://protocol prefix is mandatory. Without it the browser treats the value as a relative path causing an infinite redirect loop — see Section 6.
3.5 Trigger Pipeline Without a Commit¶
If only CI variables were updated (no code change needed):
Or via API:
curl -X POST \
--header "PRIVATE-TOKEN: <your-token>" \
"https://mashup.castis.io/api/v4/projects/<project-id>/pipeline?ref=staging"
Or empty commit:
4. ArgoCD ConfigMap Health Check¶
4.1 Problem¶
ArgoCD has no built-in health check for ConfigMap resources. When a ConfigMap is part of the application, ArgoCD cannot determine its health status and marks the entire application as Degraded.
4.2 Fix¶
Patch the ArgoCD ConfigMap to tell it to always consider ConfigMaps healthy:
kubectl patch configmap argocd-cm -n argocd --type merge -p '
{
"data": {
"resource.customizations.health.ConfigMap": "hs = {}\nhs.status = \"Healthy\"\nhs.message = \"ConfigMap is always healthy\"\nreturn hs"
}
}'
Restart ArgoCD server to pick up the change:
4.3 Verify¶
Expected output:
Note:
postgresqlmay still showUnknownhealth — this is normal. ArgoCD cannot health-check StatefulSets by default. The same patch pattern can be applied forStatefulSetif needed.
5. Node Clock Drift — etcd Cascade Failure¶
5.1 Root Cause¶
castis-desktop (control-plane/etcd/master) went NotReady for 4 days due to a clock drift cascade:
Clock drift reached 7.7 seconds
│
▼
etcd peer connections timed out (port 2380)
dial tcp <NUC_A_LAN_IP>:2380: i/o timeout
dial tcp <PEER_NODE_LAN_IP>:2380: i/o timeout
│
▼
API server TLS handshake timeouts
net/http: TLS handshake timeout on port 6444
│
▼
containerd / PLEG became unhealthy
PLEG was last seen active 39m ago; threshold is 3m0s
│
▼
Kubelet stopped posting node heartbeats
NodeStatusUnknown — Kubelet stopped posting node status
│
▼
Node NotReady for 4 days
Why clock drift breaks etcd: etcd uses the Raft consensus algorithm which requires all member clocks to be within ~1 second of each other. A 7.7-second drift causes etcd to reject peer connections entirely.
5.2 Fix — Improve NTP Configuration¶
On castis-desktop:
[Time]
NTP=0.th.pool.ntp.org 1.th.pool.ntp.org
FallbackNTP=ntp.ubuntu.com
PollIntervalMinSec=32
PollIntervalMaxSec=1024
5.3 Recovery Steps¶
If a master node goes NotReady again:
# Step 1 — SSH into the node and restart k3s
sudo systemctl restart k3s
# Step 2 — Watch from another master until node rejoins
kubectl get nodes -w
# Step 3 — Force delete stuck Terminating pods on that node
kubectl get pods -A --field-selector spec.nodeName=castis-desktop | \
grep Terminating | \
awk '{print "kubectl delete pod " $2 " -n " $1 " --force --grace-period=0"}' | bash
# Step 4 — Cordon node if keeping offline intentionally
kubectl cordon castis-desktop
5.4 etcd Quorum Warning¶
The cluster has 3 master nodes:
With 3 masters, minimum 2 must be healthy for etcd quorum. If a second master goes down while castis-desktop is offline, the cluster stops accepting writes entirely. Monitor master node health proactively.
5.5 Check etcd Snapshots¶
Snapshots are taken every 12 hours by default. Confirm recent snapshots exist before performing any cluster maintenance.
6. Infinite Redirect Loop Fix¶
6.1 Root Cause¶
VITE_TELLYID_URL was not injected at build time due to nested variable expansion failure in GitLab CI. The app fell back to the hardcoded default:
const TELLYID_URL = import.meta.env.VITE_TELLYID_URL || "http://<PEER_NODE_LAN_IP>:5173"
// ↑ fallback used instead
The value stag.tellyid.castis.io (without https://) was treated by the browser as a relative path on the same domain:
Intended: https://stag.tellyid.castis.io/auth?redirect_uri=...
Actual: https://stag.tellyboard.castis.io/stag.tellyid.castis.io/auth?...
↑ treated as path, not domain
This caused nginx to serve index.html for the redirect target, which triggered another auth check, which caused another redirect — growing indefinitely:
/auth/me → 401
→ /staging/auth?redirect_uri=...
→ /auth/me → 401
→ /staging/staging/auth?redirect_uri=...
→ /auth/me → 401
→ /staging/staging/staging/auth?...
→ repeats until URL is thousands of characters long
6.2 Fix — GitLab CI Variable¶
Update the variable value in Settings → CI/CD → Variables:
6.3 Fix — Per-Job Variable Mapping¶
The template used $VITE_TELLYID_URL_$ENV_NAME which GitLab does not expand correctly as a nested reference. Each job now maps the variable explicitly:
6.4 Auth Redirect Flow (Correct)¶
1. User visits stag.tellyboard.castis.io
│
2. GET /auth/me → 401 (no session)
│
3. window.location.href = `${TELLYID_URL}/auth?redirect_uri=${redirectUri}`
= https://stag.tellyid.castis.io/auth?redirect_uri=https%3A%2F%2Fstag.tellyboard.castis.io%2F
│
4. User logs in on TellyID (different domain — no loop)
│
5. TellyID sets cookies on .castis.io and redirects back
│
6. /callback → sets session → redirect to dashboard
7. Verification Commands¶
Verify build cache is working¶
# check registry cache manifest exists
docker buildx imagetools inspect \
registry.nexus.castis.io/playtelly/tellyboardadmin:staging-latest
Verify VITE_TELLYID_URL is baked in correctly¶
# check what JS filename was deployed (changes on each build)
kubectl exec -n staging deployment/tellyboard -- \
ls /usr/share/nginx/html/assets/
# check the URL baked into the JS bundle
kubectl exec -n staging deployment/tellyboard -- \
grep -o "[a-zA-Z0-9.:/-]*tellyid[a-zA-Z0-9.:/-]*" \
/usr/share/nginx/html/assets/index-<hash>.js
# expected: https://stag.tellyid.castis.io
# check for remaining hardcoded fallback IPs
kubectl exec -n staging deployment/tellyboard -- \
grep -o "<PEER_NODE_LAN_IP>:[0-9]*[^'\"]*" \
/usr/share/nginx/html/assets/index-<hash>.js | sort -u
Verify ArgoCD application health¶
Verify node clock sync¶
# on castis-desktop
timedatectl timesync-status
timedatectl status
# compare time across nodes
date # run on each node — should be within 1 second
Verify deployment rolled out¶
kubectl get deployment tellyboard -n staging
# look for: 1/1 READY, AVAILABLE=1
kubectl rollout status deployment tellyboard -n staging
8. Troubleshooting¶
Build still slow after cache fix¶
- The first build after applying the fix will still take ~11 min — this populates the cache for the first time. Subsequent builds will be ~3–4 min.
- If still slow after second build, check that
--cache-tois writing successfully — look forexporting cachein the build log. - If the runner changes between jobs, the npm mount cache (
/root/.npm) will be empty but the registry cache will still help.
VITE_TELLYID_URL still shows fallback IP after rebuild¶
# verify the build arg was passed correctly in CI logs
# look for this line in the pipeline output:
--build-arg VITE_TELLYID_URL=https://stag.tellyid.castis.io
If the value is empty in CI logs, the GitLab variable is not set or not expanding. Check Settings → CI/CD → Variables and confirm VITE_TELLYID_URL_staging exists with the correct value including https://.
ArgoCD sync loop (OutOfSync → Synced → OutOfSync)¶
This usually means two CI pipelines pushed different image tags in quick succession and ArgoCD is chasing a moving target. Wait for the loop to settle, then:
Node goes NotReady again¶
- Check clock sync first:
timedatectl timesync-statuson the affected node - Check k3s status:
sudo systemctl status k3s - Check last logs before failure:
sudo journalctl -u k3s -b -1 | tail -50 - If clock drift is shown in logs — NTP configuration was not applied, reapply Section 5.2
etcd quorum at risk¶
If 2 or more master nodes are NotReady simultaneously:
# check etcd member health from a healthy master
sudo k3s etcdctl \
--endpoints=https://127.0.0.1:2379 \
--cacert=/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt \
--cert=/var/lib/rancher/k3s/server/tls/etcd/client.crt \
--key=/var/lib/rancher/k3s/server/tls/etcd/client.key \
endpoint health
If quorum is lost, restore from the latest etcd snapshot before attempting any other recovery.
Last updated: 2026-06-24