ci: switch to commit-back GitOps (update values.yaml)
Some checks failed
Build & Deploy Go API / build (push) Failing after 16s
Some checks failed
Build & Deploy Go API / build (push) Failing after 16s
This commit is contained in:
@@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
- name: Install build tools
|
- name: Install build tools
|
||||||
run: apk add --no-cache curl git docker-cli jq 2>/dev/null || true
|
run: apk add --no-cache curl git docker-cli 2>/dev/null || true
|
||||||
|
|
||||||
- name: Clone + prepare
|
- name: Clone + prepare
|
||||||
run: |
|
run: |
|
||||||
@@ -42,22 +42,21 @@ jobs:
|
|||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
REGISTRY: ${{ env.REGISTRY }}
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
|
|
||||||
- name: Update ArgoCD
|
- name: Update image tag in values.yaml (commit-back GitOps)
|
||||||
run: |
|
run: |
|
||||||
|
WORK=/root/.cache/demo-go-api
|
||||||
|
cd $WORK
|
||||||
SHORT=${GITHUB_SHA::8}
|
SHORT=${GITHUB_SHA::8}
|
||||||
# Wait for ArgoCD to be ready
|
# Use sed to update image.tag in helm values.yaml
|
||||||
for i in {1..10}; do
|
sed -i "s/^ tag:.*/ tag: \"${SHORT}\"/" deploy/helm/values.yaml
|
||||||
if kubectl -n cicd get application demo-go-api &>/dev/null; then
|
# Show the diff
|
||||||
break
|
git diff deploy/helm/values.yaml
|
||||||
fi
|
# Commit and push
|
||||||
echo "Waiting for ArgoCD application..."
|
git config user.email "ci@local"
|
||||||
sleep 3
|
git config user.name "gitea-ci"
|
||||||
done
|
git add deploy/helm/values.yaml
|
||||||
# Patch using JSON
|
git commit -m "ci: update image tag to ${SHORT}"
|
||||||
PATCH=$(jq -n --arg tag "$SHORT" --arg reg "$REGISTRY" \
|
git push origin main
|
||||||
'{"spec":{"source":{"helm":{"parameters":[{"name":"image.registry","value":$reg},{"name":"image.tag","value":$tag}]}}}}')
|
|
||||||
kubectl -n cicd patch application demo-go-api --type=merge -p "$PATCH"
|
|
||||||
echo "✓ ArgoCD updated with tag ${SHORT}"
|
|
||||||
env:
|
env:
|
||||||
GITHUB_SHA: ${{ github.sha }}
|
GITHUB_SHA: ${{ github.sha }}
|
||||||
REGISTRY: ${{ env.REGISTRY }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
|||||||
Reference in New Issue
Block a user