ci: simplify GitOps update to use Woodpecker's Git access

This commit is contained in:
Tracewebstudio Dev 2026-04-14 14:28:21 +02:00
parent 0d01e70576
commit d3cdd56ba4

View file

@ -59,42 +59,33 @@ steps:
cache: false
- name: update-gitops
image: alpine:latest
environment:
GITOPS_REPO_URL:
from_secret: GITOPS_REPO_URL
GITOPS_BRANCH:
from_secret: GITOPS_BRANCH
GITOPS_TOKEN:
from_secret: GITOPS_TOKEN
image: alpine/git:latest
commands:
- |
set -e
apk add --no-cache git bash sed
SERVICE_IMAGE="registry.nxtgauge.com:5000/nxtgauge-rust-${SERVICE}:${CI_COMMIT_SHA}"
echo "Service: ${SERVICE}, Image: ${SERVICE_IMAGE}"
echo "Updating GitOps for ${SERVICE}"
# Clone gitops repo
GIT_REPO=$(echo "${GITOPS_REPO_URL}" | sed 's|https://||')
git clone "https://x-access-token:${GITOPS_TOKEN}@${GIT_REPO}" /tmp/gitops
# Clone gitops repo using cloned source from Woodpecker
git clone https://github.com/Traceworks2023/nxtgauge-gitops.git /tmp/gitops
cd /tmp/gitops
git checkout ${GITOPS_BRANCH:-main}
git checkout main
# Find and update the image in backend overlay
# Update backend overlay
BACKEND_OVERLAY="apps/nxtgauge-backend-rust/overlays/prod"
if [ -f "${BACKEND_OVERLAY}/kustomization.yaml" ]; then
# Update to use SHA tag
sed -i "s|image: registry.nxtgauge.com:5000/nxtgauge-rust-${SERVICE}:.*|image: registry.nxtgauge.com:5000/nxtgauge-rust-${SERVICE}:${CI_COMMIT_SHA}|" \
${BACKEND_OVERLAY}/kustomization.yaml
echo "Updated ${SERVICE} in ${BACKEND_OVERLAY}/kustomization.yaml"
fi
# Commit if changed
# Commit and push
if ! git diff --quiet; then
git config user.name "Woodpecker CI"
git config user.email "woodpecker@nxtgauge.com"
git add -A
git commit -m "ci: update ${SERVICE} to ${CI_COMMIT_SHA:0:8}"
git push origin ${GITOPS_BRANCH:-main}
git push origin main
echo "Pushed GitOps update"
else
echo "No changes to push"