ci: use jq for reliable ArgoCD patch
Some checks failed
Build & Deploy Go API / build (push) Failing after 45s
Some checks failed
Build & Deploy Go API / build (push) Failing after 45s
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 2>/dev/null || true
|
run: apk add --no-cache curl git docker-cli jq 2>/dev/null || true
|
||||||
|
|
||||||
- name: Clone + prepare
|
- name: Clone + prepare
|
||||||
run: |
|
run: |
|
||||||
@@ -42,16 +42,22 @@ jobs:
|
|||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
REGISTRY: ${{ env.REGISTRY }}
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
|
|
||||||
- name: Patch ArgoCD
|
- name: Update ArgoCD
|
||||||
run: |
|
run: |
|
||||||
SHORT=${GITHUB_SHA::8}
|
SHORT=${GITHUB_SHA::8}
|
||||||
if kubectl -n cicd get application demo-go-api &>/dev/null; then
|
# Wait for ArgoCD to be ready
|
||||||
kubectl -n cicd patch application demo-go-api --type merge \
|
for i in {1..10}; do
|
||||||
-p "{\"spec\":{\"source\":{\"helm\":{\"parameters\":[{\"name\":\"image.registry\",\"value\":\"${REGISTRY}\"},{\"name\":\"image.tag\",\"value\":\"${SHORT}\"}]}}}}"
|
if kubectl -n cicd get application demo-go-api &>/dev/null; then
|
||||||
echo "✓ ArgoCD patched"
|
break
|
||||||
else
|
fi
|
||||||
echo "⚠ demo-go-api Application not yet created"
|
echo "Waiting for ArgoCD application..."
|
||||||
fi
|
sleep 3
|
||||||
|
done
|
||||||
|
# Patch using JSON
|
||||||
|
PATCH=$(jq -n --arg tag "$SHORT" --arg reg "$REGISTRY" \
|
||||||
|
'{"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 }}
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
|
|||||||
Reference in New Issue
Block a user