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>
This commit is contained in:
@@ -34,6 +34,16 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
default: "ubuntu-latest"
|
default: "ubuntu-latest"
|
||||||
|
environment-tag:
|
||||||
|
description: "Mutable environment tag to push (e.g. prod, staging, dev). If empty, auto-detected from branch: main/master→prod, staging→staging, dev→dev."
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
|
version-tag:
|
||||||
|
description: "Pinned version tag to push (e.g. dev-v123). Used for node-specific testing."
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
secrets:
|
secrets:
|
||||||
REGISTRY_USER:
|
REGISTRY_USER:
|
||||||
required: true
|
required: true
|
||||||
@@ -77,7 +87,11 @@ jobs:
|
|||||||
images: ${{ inputs.image-name }}
|
images: ${{ inputs.image-name }}
|
||||||
tags: |
|
tags: |
|
||||||
type=sha,prefix=sha-
|
type=sha,prefix=sha-
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=prod,enable=${{ gitea.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/master' }}
|
||||||
|
type=raw,value=staging,enable=${{ gitea.ref == 'refs/heads/staging' }}
|
||||||
|
type=raw,value=dev,enable=${{ gitea.ref == 'refs/heads/dev' }}
|
||||||
|
type=raw,value=${{ inputs.environment-tag }},enable=${{ inputs.environment-tag != '' }}
|
||||||
|
type=raw,value=${{ inputs.version-tag }},enable=${{ inputs.version-tag != '' }}
|
||||||
type=semver,pattern={{version}}
|
type=semver,pattern={{version}}
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
# Reusable workflow: Update image tag in wectrl-k8s-cluster repo (GitOps deploy)
|
# Reusable workflow: Bump deploy-timestamp in wectrl-k8s-cluster repo (GitOps deploy)
|
||||||
# Usage: uses: wectrl-net/ci-templates/.gitea/workflows/deploy-k8s.yaml@main
|
# 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)
|
name: Deploy to K8s (GitOps)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
image-name:
|
image-name:
|
||||||
description: "Full image name (e.g. git.wectrl.net/wectrl-net/my-service)"
|
description: "Full image name (e.g. git.wectrl.net/wectrl-net/my-service) — used in commit message for traceability"
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
deploy-paths:
|
deploy-paths:
|
||||||
@@ -40,13 +45,13 @@ jobs:
|
|||||||
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64
|
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
|
chmod +x /usr/local/bin/yq
|
||||||
|
|
||||||
- name: Update image tag in cluster repo
|
- name: Bump deploy-timestamp in cluster repo
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SHA="${{ gitea.sha }}"
|
SHA="${{ gitea.sha }}"
|
||||||
SHORT_SHA="${SHA:0:7}"
|
SHORT_SHA="${SHA:0:7}"
|
||||||
IMAGE_TAG="sha-${SHORT_SHA}"
|
TIMESTAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||||
RUN_URL="${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}"
|
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
|
git clone https://${{ secrets.GIT_USER }}:${{ secrets.GIT_TOKEN }}@git.wectrl.net/${{ inputs.k8s-repo }}.git
|
||||||
@@ -56,16 +61,17 @@ jobs:
|
|||||||
git config user.name "Gitea CI"
|
git config user.name "Gitea CI"
|
||||||
|
|
||||||
for DEPLOY_PATH in ${{ inputs.deploy-paths }}; do
|
for DEPLOY_PATH in ${{ inputs.deploy-paths }}; do
|
||||||
yq -i '(.spec.template.spec.containers[].image | select(test("^${{ inputs.image-name }}:"))) = "${{ inputs.image-name }}:'"${IMAGE_TAG}"'"' \
|
yq -i '.spec.template.metadata.annotations.deploy-timestamp = "'"${TIMESTAMP}"'"' \
|
||||||
"${DEPLOY_PATH}"
|
"${DEPLOY_PATH}"
|
||||||
git add "${DEPLOY_PATH}"
|
git add "${DEPLOY_PATH}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if git diff --staged --quiet; then
|
if git diff --staged --quiet; then
|
||||||
echo "No image tag changes to commit"
|
echo "No changes to commit"
|
||||||
else
|
else
|
||||||
git commit -m "deploy: ${{ inputs.service-name }} ${IMAGE_TAG}
|
git commit -m "deploy: ${{ inputs.service-name }} sha-${SHORT_SHA}
|
||||||
|
|
||||||
|
Timestamp: ${TIMESTAMP}
|
||||||
Source: ${SHA}
|
Source: ${SHA}
|
||||||
Run: ${RUN_URL}"
|
Run: ${RUN_URL}"
|
||||||
git push origin main
|
git push origin main
|
||||||
|
|||||||
Reference in New Issue
Block a user