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
|
||||
steps:
|
||||
- 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
|
||||
run: |
|
||||
@@ -42,16 +42,22 @@ jobs:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
REGISTRY: ${{ env.REGISTRY }}
|
||||
|
||||
- name: Patch ArgoCD
|
||||
- name: Update ArgoCD
|
||||
run: |
|
||||
SHORT=${GITHUB_SHA::8}
|
||||
if kubectl -n cicd get application demo-go-api &>/dev/null; then
|
||||
kubectl -n cicd patch application demo-go-api --type merge \
|
||||
-p "{\"spec\":{\"source\":{\"helm\":{\"parameters\":[{\"name\":\"image.registry\",\"value\":\"${REGISTRY}\"},{\"name\":\"image.tag\",\"value\":\"${SHORT}\"}]}}}}"
|
||||
echo "✓ ArgoCD patched"
|
||||
else
|
||||
echo "⚠ demo-go-api Application not yet created"
|
||||
fi
|
||||
# Wait for ArgoCD to be ready
|
||||
for i in {1..10}; do
|
||||
if kubectl -n cicd get application demo-go-api &>/dev/null; then
|
||||
break
|
||||
fi
|
||||
echo "Waiting for ArgoCD application..."
|
||||
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:
|
||||
GITHUB_SHA: ${{ github.sha }}
|
||||
REGISTRY: ${{ env.REGISTRY }}
|
||||
|
||||
Reference in New Issue
Block a user