eTicket Johor CI/CD pipeline
Project: eTicket Johor — GitLab CI/CD + ArgoCD
Last Updated: June 2026
Overview¶
The CI/CD pipeline is split into two patterns:
| Pattern | Registry | Services | Branch |
|---|---|---|---|
| Old | registry.mashup.castis.io (GitLab) |
ticketing core/scheduler | main / dev |
| New | registry.nexus.castis.io (Nexus) |
ticket-cms, ticket-admin | staging / main |
Directory Structure¶
.gitlab-ci/
├── .gitlab-ci-build.yml # old pattern - production build
├── .gitlab-ci-update-image-tag.yml # old pattern - production update tag
├── .gitlab-ci-stg-build.yml # new pattern - staging build
└── .gitlab-ci-stg-update-image-tag.yml # new pattern - staging update tag
.gitlab-ci.yml # main entry, includes all above
Main .gitlab-ci.yml¶
variables:
GIT_STRATEGY: clone
REGISTRY_URL: "registry.nexus.castis.io"
IMAGE_BASE: "registry.nexus.castis.io/malaysia"
GITOPS_REPO: "malaysia/ticket-iac"
CI_SERVER_HOST: "mashup.castis.io"
stages:
- build_staging
- build_production
- update_image_tag_staging
- update_image_tag_production
- build
- update_image_tag
include:
- local: ".gitlab-ci/.gitlab-ci-build.yml"
- local: ".gitlab-ci/.gitlab-ci-update-image-tag.yml"
- local: ".gitlab-ci/.gitlab-ci-stg-build.yml"
- local: ".gitlab-ci/.gitlab-ci-stg-update-image-tag.yml"
Old Pattern (ticketing core & scheduler)¶
Build¶
# .gitlab-ci-build.yml
variables:
CONTAINER_IMAGE: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}"
KUSTOMIZE_DOCKER_IMG: registry.k8s.io/kustomize/kustomize:v5.0.0
TICKET_IAC_REPO_URL: mashup.castis.io/malaysia/ticket-iac.git
build_staging:
stage: build_staging
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
- docker tag ${CONTAINER_IMAGE} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
tags:
- mashup-runner
only:
- dev
build_production:
stage: build_production
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
- docker tag ${CONTAINER_IMAGE} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
tags:
- mashup-runner
only:
- main
Update Image Tag¶
# .gitlab-ci-update-image-tag.yml
update_image_tag_staging:
stage: update_image_tag_staging
script:
- docker pull $KUSTOMIZE_DOCKER_IMG
- rm -rf ticket-iac
- git clone -b update_queue https://gitlab-ci-token:${CI_JOB_TOKEN}@${TICKET_IAC_REPO_URL}
- cd $TARGET_DIR_STAGING
- docker run --rm -v $(pwd)/kustomization.yaml:/app/kustomization.yaml
registry.k8s.io/kustomize/kustomize:v5.0.0
edit set image ${CI_REGISTRY_IMAGE}:$IMAGE_TAG
- git add .
- git commit -m "[Staging] Update image tag to ${CI_REGISTRY_IMAGE}:$IMAGE_TAG"
- git push https://oauth2:${IAC_PUSH_TOKEN}@${TICKET_IAC_REPO_URL} HEAD:update_queue
only:
- dev
update_image_tag_production:
stage: update_image_tag_production
script:
- docker pull $KUSTOMIZE_DOCKER_IMG
- rm -rf ticket-iac
- git clone -b update_queue https://gitlab-ci-token:${CI_JOB_TOKEN}@${TICKET_IAC_REPO_URL}
- cd $TARGET_DIR_PROD
- docker run --rm -v $(pwd)/kustomization.yaml:/app/kustomization.yaml
registry.k8s.io/kustomize/kustomize:v5.0.0
edit set image ${CI_REGISTRY_IMAGE}:$IMAGE_TAG
- git add .
- git commit -m "[Production] Update image tag to ${CI_REGISTRY_IMAGE}:$IMAGE_TAG"
- git push https://oauth2:${IAC_PUSH_TOKEN}@${TICKET_IAC_REPO_URL} HEAD:update_queue
only:
- main
New Pattern (ticket-cms & ticket-admin)¶
Build Template¶
# .gitlab-ci-stg-build.yml
.build_template:
stage: build
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 build \
--platform linux/amd64 \
--cache-from $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-$CI_COMMIT_SHORT_SHA \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--build-arg VITE_API_BASE_URL=$VITE_API_BASE_URL \
--build-arg VITE_PAYMENT_GATEWAY_BASE_URL=$VITE_PAYMENT_GATEWAY_BASE_URL \
--build-arg VITE_MAINTENANCE_MODE=$VITE_MAINTENANCE_MODE \
--build-arg VITE_MAINTENANCE_PIN=$VITE_MAINTENANCE_PIN \
--build-arg VITE_TELEMETRY_URL=$VITE_TELEMETRY_URL \
--push \
./
build:staging:
extends: .build_template
variables:
ENV_NAME: staging
environment:
name: staging
tags:
- mashup-runner
rules:
- if: $CI_COMMIT_BRANCH == "staging"
Update Image Tag Template¶
# .gitlab-ci-stg-update-image-tag.yml
.update_tag_template:
stage: update_image_tag
before_script:
- git clone -b update_queue https://oauth2:$IAC_PUSH_TOKEN@$CI_SERVER_HOST/$GITOPS_REPO.git gitops
script:
- PROJECT_NAME=$(echo $CI_PROJECT_NAME | tr '[:upper:]' '[:lower:]')
- IMAGE_FULL="$IMAGE_BASE/$PROJECT_NAME"
- NEW_TAG="$ENV_NAME-$CI_COMMIT_SHORT_SHA"
- cd gitops/overlays/$ENV_NAME/$PROJECT_NAME
- docker run --rm -v $(pwd)/kustomization.yaml:/app/kustomization.yaml -w /app
registry.k8s.io/kustomize/kustomize:v5.0.0
edit set image registry.mashup.castis.io/malaysia/$PROJECT_NAME=$IMAGE_FULL:$NEW_TAG
- cd $CI_PROJECT_DIR/gitops
- git config user.email "ci@mashup.castis.io"
- git config user.name "GitLab CI"
- git add .
- |
if ! git diff --cached --quiet; then
git commit -m "chore($ENV_NAME): update $PROJECT_NAME to $NEW_TAG [skip ci]"
fi
- git push
update_tag:staging:
extends: .update_tag_template
variables:
ENV_NAME: staging
environment:
name: staging
tags:
- mashup-runner
rules:
- if: $CI_COMMIT_BRANCH == "staging"
needs: [build:staging]
Kustomization Image Pattern¶
Since base manifests use the old GitLab registry, kustomize newName is used to swap registry at deploy time:
# overlays/staging/ticket-cms/kustomization.yaml
images:
- name: registry.mashup.castis.io/malaysia/ticketcms # ← matches base manifest
newName: registry.nexus.castis.io/malaysia/ticketcms # ← swaps to Nexus
newTag: staging-fe5cb9d7 # ← CI updates this only
The CI
kustomize edit set imagecommand must reference the old name (registry.mashup.castis.io) — not the new one. Otherwise kustomize creates a duplicate entry andnewNamegets ignored.
# correct
edit set image registry.mashup.castis.io/malaysia/$PROJECT_NAME=$IMAGE_FULL:$NEW_TAG
# wrong - creates duplicate entry
edit set image $IMAGE_FULL:$NEW_TAG
GitLab CI/CD Variables Required¶
| Variable | Description | Used By |
|---|---|---|
CI_REGISTRY_USER |
GitLab registry user | old pattern |
CI_REGISTRY_PASSWORD |
GitLab registry password | old pattern |
CI_REGISTRY |
GitLab registry URL | old pattern |
NEXUS_USER |
Nexus registry user | new pattern |
NEXUS_PASSWORD |
Nexus registry password | new pattern |
IAC_PUSH_TOKEN |
Token to push to ticket-iac repo | both |
VITE_API_BASE_URL |
API base URL baked into frontend | new pattern |
VITE_PAYMENT_GATEWAY_BASE_URL |
Payment gateway URL | new pattern |
VITE_MAINTENANCE_MODE |
Maintenance mode flag | new pattern |
VITE_MAINTENANCE_PIN |
Maintenance mode PIN | new pattern |
VITE_TELEMETRY_URL |
OpenTelemetry collector URL | new pattern |
VITE_*variables are baked into the static build at image creation time. If any value changes, the image must be rebuilt and redeployed.
Flow Summary¶
Old Pattern¶
push to dev/main
↓
build_staging / build_production
→ docker build → push to GitLab registry
↓
update_image_tag_staging / update_image_tag_production
→ kustomize edit set image → push to ticket-iac
↓
ArgoCD detects change → syncs to cluster
New Pattern¶
push to staging/main
↓
build:staging
→ docker build (with VITE_* args) → push to Nexus registry
↓
update_tag:staging
→ kustomize edit set image (old name = new name:tag) → push to ticket-iac
↓
ArgoCD detects change → syncs to cluster
Trigger Pipeline Without Code Changes¶
ArgoCD Setup (k3s)¶
ArgoCD is deployed internally on the k3s cluster to handle the CD side of the pipeline.
Installation¶
kubectl create namespace argocd
kubectl apply -n argocd \
--server-side \
--force-conflicts \
-f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Always use
--server-sideto avoid the CRD annotation size limit error (applicationsets.argoproj.iotoo long).
Get Initial Admin Password¶
kubectl get secret argocd-initial-admin-secret \
-n argocd \
-o jsonpath="{.data.password}" | base64 -d && echo
Login with username admin and the password above.
Access (Internal Only)¶
ArgoCD is kept internal — no public exposure needed since it only requires outbound access to Git.
# Port-forward for on-demand access
kubectl port-forward svc/argocd-server -n argocd 8080:443
# Visit https://localhost:8080
Git Repository Secret¶
ArgoCD needs credentials to pull from the private GitLab repo. Create a secret in the argocd namespace:
apiVersion: v1
kind: Secret
metadata:
name: ticket-iac-repo
namespace: argocd
labels:
argocd.argoproj.io/secret-type: repository
type: Opaque
stringData:
type: git
url: https://mashup.castis.io/malaysia/ticket-iac.git
username: gitlab+deploy-token-9
password: <deploy-token-value>
The namespace must be
argocd— ArgoCD only picks up repo secrets from its own namespace.
ArgoCD Application¶
The staging Application watches the update_queue branch of ticket-iac and auto-syncs on every push:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: staging
namespace: argocd
spec:
project: default
source:
repoURL: https://mashup.castis.io/malaysia/ticket-iac.git
targetRevision: update_queue
path: overlays/staging
destination:
server: https://kubernetes.default.svc
namespace: staging
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
Kustomize Gotchas¶
Several issues were encountered with Kustomize path resolution under ArgoCD:
1. File path traversal blocked
Kustomize blocks direct file references (../../../base/common/file.yaml) from outside the build root. Always reference directories, not individual files:
resources:
- ../../../base/common/ # directory reference — allowed
- ../../../base/common/nexus-registry-secret.yaml # file reference — blocked
2. Namespace in patch files
Patch files must include namespace to match the target resource, otherwise Kustomize reports [noNs] and fails to find a match:
# patch-image.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ticket-cms
namespace: staging # ← required
3. Namespace in base manifests
Base manifests should not hardcode a namespace — let overlays control it via namespace: in kustomization.yaml. Hardcoded namespace: production in base causes conflicts when deploying to staging.
Gateway API Health Check Fix¶
ArgoCD doesn't have built-in health checks for Gateway API resources (HTTPRoute, Gateway, ReferenceGrant). Without a custom health check, ArgoCD marks the app as Degraded even when everything is running fine.
Fix by adding Lua health check scripts to argocd-cm:
kubectl patch configmap argocd-cm -n argocd --type merge -p '{
"data": {
"resource.customizations.health.gateway.networking.k8s.io_HTTPRoute": "hs = {}\nhs.status = \"Healthy\"\nhs.message = \"\"\nreturn hs",
"resource.customizations.health.gateway.networking.k8s.io_Gateway": "hs = {}\nhs.status = \"Healthy\"\nhs.message = \"\"\nreturn hs",
"resource.customizations.health.gateway.networking.k8s.io_ReferenceGrant": "hs = {}\nhs.status = \"Healthy\"\nhs.message = \"\"\nreturn hs"
}
}'
kubectl rollout restart deployment argocd-server -n argocd
kubectl rollout restart statefulset argocd-application-controller -n argocd
Then force a hard refresh to pick up the changes:
Useful ArgoCD Commands¶
# Check application status
kubectl get application -n argocd
# Force refresh
kubectl annotate application staging -n argocd \
argocd.argoproj.io/refresh=normal --overwrite
# Force hard refresh (re-evaluates all health checks)
kubectl annotate application staging -n argocd \
argocd.argoproj.io/refresh=hard --overwrite
# Check errors
kubectl describe application staging -n argocd | grep -A 5 "Message:"
# Check which resources are degraded
kubectl get application staging -n argocd -o json | \
jq '.status.resources[] | {name: .name, kind: .kind, health: .health, status: .status}'