Nexus Docker registry maintenance
Overview¶
This document covers the setup and maintenance of the Nexus Docker registry used by Playtelly and Malaysia projects. It includes CI/CD build configuration, automated image cleanup, and disk management.
Architecture¶
GitLab CI (shell executor on ubuntu-mashup-gitlab-haproxy)
└── docker buildx (per-project builder)
└── BuildKit container
└── Push to registry.nexus.castis.io
└── Nexus (nexus namespace, nuc-b)
└── PVC: 100Gi (Longhorn, 2 replicas)
Registry URL¶
- External:
https://registry.nexus.castis.io - Internal:
http://nexus.nexus.svc.cluster.local:8082 - Nexus UI:
http://nexus.nexus.svc.cluster.local:8081
Image Tag Convention¶
Each project uses the following tag structure:
| Tag | Purpose |
|---|---|
prod-latest |
Current production image (used by ArgoCD) |
prod-<sha> |
Specific production version (for rollback) |
prod-cache |
BuildX cache only — never deployed |
staging-latest |
Current staging image |
staging-<sha> |
Specific staging version |
staging-cache |
BuildX cache only — never deployed |
Important: Cache tags (
*-cache) are separate from image tags to prevent digest mismatch between*-latestand*-<sha>tags.
GitLab CI Build Template¶
All projects use a shared .build_template in .gitlab-ci.yml:
.build_template:
stage: build
timeout: 2h
script:
- PROJECT_NAME=$(echo $CI_PROJECT_NAME | tr '[:upper:]' '[:lower:]')
- docker login -u $NEXUS_USER -p $NEXUS_PASSWORD $REGISTRY_URL
- |
if docker buildx inspect multiarch-$PROJECT_NAME > /dev/null 2>&1; then
if ! docker buildx inspect multiarch-$PROJECT_NAME --bootstrap > /dev/null 2>&1; then
echo "Builder unhealthy, recreating..."
docker buildx rm multiarch-$PROJECT_NAME || true
docker rm -f buildx_buildkit_multiarch-${PROJECT_NAME}0 || true
docker buildx create --use --name multiarch-$PROJECT_NAME --node multiarch-${PROJECT_NAME}0
else
echo "Builder healthy, reusing..."
docker buildx use multiarch-$PROJECT_NAME
fi
else
echo "Builder not found, creating..."
docker buildx create --use --name multiarch-$PROJECT_NAME --node multiarch-${PROJECT_NAME}0
fi
- |
docker buildx build \
--progress=plain \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=$IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-cache \
--cache-to type=registry,ref=$IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-cache,mode=max \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-$CI_COMMIT_SHORT_SHA \
--tag $IMAGE_BASE/$PROJECT_NAME:$ENV_NAME-latest \
--push \
.
Key Design Decisions¶
- Per-project builder (
multiarch-$PROJECT_NAME): prevents conflicts when multiple projects build simultaneously - Health check (
--bootstrap): detects broken BuildKit containers and recreates them automatically --progress=plain: keeps connection alive during silent ARM64 compile periods to prevent EOF errors- Separate cache tag (
$ENV_NAME-cache): prevents cache manifest from overwriting the image'slatesttag digest
BuildX Builder Management¶
Builders are persistent per project on the runner machine (ubuntu-mashup-gitlab-haproxy).
Check active builders¶
Check builder health¶
Manually recreate a broken builder¶
docker buildx rm multiarch-<project-name> || true
docker rm -f buildx_buildkit_multiarch-<project-name>0 || true
docker buildx create --use --name multiarch-<project-name> --node multiarch-<project-name>0
Automated Cleanup CronJob¶
A Kubernetes CronJob runs daily at 2:00 AM to clean old image tags and free disk space.
Location¶
What it does¶
It deletes old prod-* and staging-* tags, keeps *-latest, *-cache and every prod-vX.Y.Z release, removes cosign signatures of deleted images and untagged manifests, then runs the three Nexus tasks that free the disk. The full rules, order and troubleshooting are in Nexus Docker registry cleanup.
Manual test run¶
kubectl create job nexus-cleanup-test --from=cronjob/nexus-docker-cleanup -n nexus
kubectl logs -n nexus -l job-name=nexus-cleanup-test -f
kubectl delete job nexus-cleanup-test -n nexus
Adding a new namespace to cleanup¶
Edit the CronJob env variable:
Nexus Disk Management¶
Check disk usage¶
Check what's using space¶
PVC details¶
| Property | Value |
|---|---|
| Name | nexus-data-longhorn |
| Size | 100Gi |
| Storage Class | longhorn-retain |
| Replicas | 2 (nuc-a, mac-mini) |
Expand PVC if needed¶
kubectl patch pvc nexus-data-longhorn -n nexus \
-p '{"spec":{"resources":{"requests":{"storage":"200Gi"}}}}'
Nexus Scheduled Tasks¶
| Task | Schedule | Purpose |
|---|---|---|
| Cleanup service | Daily 08:00 | Marks old components for deletion |
| Cleanup unused docker blobs | Daily 12:00 | Soft deletes unused docker layers |
| Compact blob store | Manual / via CronJob | Physically frees disk space after soft deletes |
Note: Always run Compact blob store after cleanup tasks — without it, deleted blobs stay on disk and space is not freed.
Troubleshooting¶
BuildKit connection error (use of closed network connection)¶
The BuildKit container is broken from a previous cancelled job. The CI health check handles this automatically. To fix manually:
docker buildx rm multiarch-<project> || true
docker rm -f buildx_buildkit_multiarch-<project>0 || true
Nexus 500 error on image push¶
Check Nexus disk usage — likely full:
Nexus H2 database error after disk full¶
- Free disk space (expand PVC or delete blobs)
- Delete corrupted DB files:
nexus.mv.db,nexus.trace.db - Restart Nexus — it will rebuild the DB from blob store
Warning: Deleting the DB loses user accounts and repository configuration but not blob data (actual images).
APISIX timeout on registry push¶
Increase timeout on the Nexus route via APISIX admin API:
curl -X PATCH http://<APISIX_ADMIN_SERVICE_IP>:9180/apisix/admin/routes/<ROUTE_ID> \
-H "X-API-KEY: <APISIX_ADMIN_KEY>" \
-H "Content-Type: application/json" \
-d '{
"timeout": {
"connect": 60,
"send": 600,
"read": 600
}
}'
Projects¶
Playtelly¶
| Project | Staging | Production |
|---|---|---|
| authapi | ||
| coreapi | ||
| documentations | — | |
| playoutadmin | ||
| tellyboardadmin | ||
| tellyid |
Malaysia¶
| Project | Staging | Production |
|---|---|---|
| ticketadmin | — | |
| ticketcms | — | |
| ticketing/core | — | |
| ticketing/scheduler | — | |
| ticketing/zitadel-migrate | — | — |