towerops/.gitlab-ci.yml
Graham McIntire 07b0ddb67d
Set DEPLOY_TIMESTAMP from GitLab CI instead of pod metadata
- Update GitLab CI deploy job to set DEPLOY_TIMESTAMP when deploying
- Use 'kubectl set env' to update all pods with same timestamp
- Change deployment.yaml to use static placeholder value
- Update documentation to explain GitLab CI timestamp approach

This ensures all pods show the same deployment time, regardless of:
- Which pod handles the request (with replicas=2)
- When individual pods were created or restarted
- Pod restarts from crashes or rolling updates

The timestamp now represents when the deployment was initiated by GitLab CI,
not when individual pods were created.
2026-01-17 11:17:07 -06:00

63 lines
1.8 KiB
YAML

stages:
- build
- deploy
variables:
DOCKER_BUILDKIT: 1
CI_BUILDX_ARCHS: "linux/amd64"
DOCKER_TLS_CERTDIR: ""
workflow:
auto_cancel:
on_new_commit: interruptible
build:
stage: build
interruptible: true
tags:
- vntx
image: docker:27
services:
- docker:27-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
# Pull latest image for layer caching (ignore failures if not exists)
- docker pull $CI_REGISTRY_IMAGE:latest || true
# Build with cache-from for faster builds and inline cache for future builds
- docker build
--cache-from $CI_REGISTRY_IMAGE:latest
--build-arg BUILDKIT_INLINE_CACHE=1
-f k8s/Dockerfile
-t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
-t $CI_REGISTRY_IMAGE:latest
.
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
rules:
- if: $CI_COMMIT_BRANCH == "main"
deploy:
stage: deploy
needs: ["build"]
tags:
- vntx
image:
name: bitnami/kubectl:latest
entrypoint: [""]
script:
- kubectl config get-contexts
- kubectl config use-context towerops/towerops:home-cluster-agent
# Set deployment timestamp (ISO 8601 format in UTC)
- DEPLOY_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
- echo "Deploying at $DEPLOY_TIMESTAMP"
# Deploy new version (migrations run on app start)
- kubectl set image deployment/towerops towerops=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n towerops
- kubectl set env deployment/towerops DEPLOY_TIMESTAMP=$DEPLOY_TIMESTAMP -n towerops
- kubectl rollout status deployment/towerops -n towerops --timeout=5m
environment:
name: production
kubernetes:
namespace: towerops
rules:
- if: $CI_COMMIT_BRANCH == "main"