Files
ci-templates/.gitea/workflows/deploy-k8s.yaml
Martin Maslyankov deaf9a9890 feat: add environment-based mutable tagging to CI templates
build-push.yaml:
- Add environment-tag and version-tag optional inputs
- Auto-detect environment from branch: main/master→:prod, staging→:staging, dev→:dev
- Replace :latest with :prod for main branch
- Support manual version tags for node-specific testing

deploy-k8s.yaml:
- Switch from image tag sed to deploy-timestamp annotation bump
- Mutable tags (:prod/:staging) stay constant in manifests
- ArgoCD detects rollout via timestamp annotation change
- Preserves SHA in commit message for traceability

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 00:52:15 +03:00

80 lines
2.7 KiB
YAML

# Reusable workflow: Bump deploy-timestamp in wectrl-k8s-cluster repo (GitOps deploy)
# Usage: uses: wectrl-net/ci-templates/.gitea/workflows/deploy-k8s.yaml@main
#
# With environment-based mutable tags (:prod, :staging, :dev), the image tag in
# k8s manifests stays constant. To trigger a rollout after pushing a new image,
# this workflow bumps the deploy-timestamp pod annotation, which causes ArgoCD to
# detect a diff and sync the deployment.
name: Deploy to K8s (GitOps)
on:
workflow_call:
inputs:
image-name:
description: "Full image name (e.g. git.wectrl.net/wectrl-net/my-service) — used in commit message for traceability"
required: true
type: string
deploy-paths:
description: "Space-separated paths to deployment manifests in the k8s cluster repo"
required: true
type: string
service-name:
description: "Service name for commit message (e.g. h1per-pms)"
required: true
type: string
k8s-repo:
description: "K8s cluster repo (org/repo)"
required: false
type: string
default: "wectrl-net/wectrl-k8s-cluster"
secrets:
GIT_USER:
required: true
GIT_TOKEN:
required: true
jobs:
deploy:
name: Update k8s Cluster Repo
runs-on: ubuntu-latest
if: gitea.ref == 'refs/heads/main'
steps:
- name: Install yq
run: |
set -euo pipefail
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64
chmod +x /usr/local/bin/yq
- name: Bump deploy-timestamp in cluster repo
run: |
set -euo pipefail
SHA="${{ gitea.sha }}"
SHORT_SHA="${SHA:0:7}"
TIMESTAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
RUN_URL="${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}"
git clone https://${{ secrets.GIT_USER }}:${{ secrets.GIT_TOKEN }}@git.wectrl.net/${{ inputs.k8s-repo }}.git
cd wectrl-k8s-cluster
git config user.email "ci@wectrl.net"
git config user.name "Gitea CI"
for DEPLOY_PATH in ${{ inputs.deploy-paths }}; do
yq -i '.spec.template.metadata.annotations.deploy-timestamp = "'"${TIMESTAMP}"'"' \
"${DEPLOY_PATH}"
git add "${DEPLOY_PATH}"
done
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "deploy: ${{ inputs.service-name }} sha-${SHORT_SHA}
Timestamp: ${TIMESTAMP}
Source: ${SHA}
Run: ${RUN_URL}"
git push origin main
echo "Cluster repo updated — ArgoCD will sync within ~3 min"
fi